Csound Csound-dev Csound-tekno Search About

Triggering evens by mac keyboard

Date2006-03-06 20:42
FromVadim Kupriyanov
SubjectTriggering evens by mac keyboard
Hello!

Now I try to use mac keyboard for triggering sound events in csound.  
I use operator sensekey for it. But sound start without wait pressing  
a key. How to make triggering, like cpsmidi triggering?

Best regards,
Vadim




/* sensekey.orc */

; Initialize the global variables.

sr = 44100

kr = 4410

ksmps = 10

nchnls = 1


; Instrument #1.

instr 1


k1 sensekey
   printk2 k1

asig oscil 15000, 1000,1
out asig

endin

/* sensekey.orc */

/* sensekey.sco */

; Play Instrument #1 for thirty seconds.
f0 600
f1 0 512 10 1
i 1 0 600

e

/* sensekey.sco */




Date2006-03-06 23:49
FromAndres Cabrera
SubjectRe: Triggering evens by mac keyboard
Hi,
Naturally you get sound from the outset since you are specifying:
i 1 0 600
so the oscilator is on by default.
You may want to do something like:

instr 1
k1 sensekey
if (k1!= -1) then
schedkwhen 1, 0, 1, 2, 0, 1
endif

endin

instr 2
asig oscil 15000, 1000,1
out asig

endin

However in my tests on linux, sensekey always returns -1, it seems that
it's not working. Should it?

-- 

Cheers,
Andrés


On Mon, 2006-03-06 at 23:42 +0300, Vadim Kupriyanov wrote:
> Hello!
> 
> Now I try to use mac keyboard for triggering sound events in csound.  
> I use operator sensekey for it. But sound start without wait pressing  
> a key. How to make triggering, like cpsmidi triggering?
> 
> Best regards,
> Vadim
> 
> 
> 
> 
> /* sensekey.orc */
> 
> ; Initialize the global variables.
> 
> sr = 44100
> 
> kr = 4410
> 
> ksmps = 10
> 
> nchnls = 1
> 
> 
> ; Instrument #1.
> 
> instr 1
> 
> 
> k1 sensekey
>    printk2 k1
> 
> asig oscil 15000, 1000,1
> out asig
> 
> endin
> 
> /* sensekey.orc */
> 
> /* sensekey.sco */
> 
> ; Play Instrument #1 for thirty seconds.
> f0 600
> f1 0 512 10 1
> i 1 0 600
> 
> e
> 
> /* sensekey.sco */
> 
> 
> 
> 
> 
> -- 
> Send bugs reports to this list.
> To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk
> 
> 
> �


Date2006-03-06 23:56
FromAndres Cabrera
SubjectRe: Triggering evens by mac keyboard
Hi,
Sorry, sensekey is working on linux, just not working within blue. For
some reason, keyboard events seem not to be passed to csound if it is
run by blue.


Cheers,
Andrés

On Mon, 2006-03-06 at 23:42 +0300, Vadim Kupriyanov wrote:
> Hello!
> 
> Now I try to use mac keyboard for triggering sound events in csound.  
> I use operator sensekey for it. But sound start without wait pressing  
> a key. How to make triggering, like cpsmidi triggering?
> 
> Best regards,
> Vadim
> 
> 
> 
> 
> /* sensekey.orc */
> 
> ; Initialize the global variables.
> 
> sr = 44100
> 
> kr = 4410
> 
> ksmps = 10
> 
> nchnls = 1
> 
> 
> ; Instrument #1.
> 
> instr 1
> 
> 
> k1 sensekey
>    printk2 k1
> 
> asig oscil 15000, 1000,1
> out asig
> 
> endin
> 
> /* sensekey.orc */
> 
> /* sensekey.sco */
> 
> ; Play Instrument #1 for thirty seconds.
> f0 600
> f1 0 512 10 1
> i 1 0 600
> 
> e
> 
> /* sensekey.sco */
> 
> 
> 
> 
> 
> -- 
> Send bugs reports to this list.
> To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk
> 
> 
> �

Date2006-03-07 01:43
FromDavid Akbari
SubjectRe: Triggering evens by mac keyboard
Gentlemen, good evening.

I offer to you a humble attempt at the subject line of this thread.

This file was written for use with *MacCsound* 1.2a5 and will also work 
transparently with [csoundapi~] for Pd as well as any other 
encapsulation of the CsoundLib that implements the transmission of 
invalue/outvalue; so feasibly TclCsound and [csound~] for Max/MSP as 
well - without any modification to the .csd file.

It is _not_ required that users are using version 5 of the language to 
run this example.

For users running this with version 5, you can run this without 
transmitting any of the invalues, as they are only used for the effects 
UDO's (that are not on the repository at present time but I will mark 
them up shortly) without any noticeable effect on it's basic 
functionality.

Anyway, I hope this helps to understand a good way to use the sensekey 
- in this example I am just implementing a "meta" instrument that's 
always on and that generates events. This is also a useful technique 
for MIDI, say for program change messages for example.

Please do not hesitate to email this list further with any inquiries 
regarding the attached file. I'll be happy to clarify or elaborate on 
anything you may wonder or postulate about.





sr		=	44100
kr		=	4410
ksmps	=	10
nchnls	=	2

gifn1	ftgen	1,0,16384,10,1
gifn5	ftgen	5,0,16384,21,6,1

/*---

::  ASCII Key Drum Model
--::  by David Akbari

Current Implementation:

(Key)	:	(Drum type)
-----		-----------
A	=	Snare drum
S	=	Kick drum
D	=	Closed Hi-hat
F	=	Open Hi-hat

(Invalue)	:	(Function)

"pre"	=	Pre-gain to Hyperbolic tangent distortion UDO
"vol"	=	Output volume of Hyperbolic tangent distortion UDO
"levl"	=	Output volume of sample rate reduce UDO
"sr"		=	Sample rate of sample rate reduce UDO

---*/

/* hyperbolic tangent distortion UDO */
		opcode	hyptan, a, akk
asig, kpre, kvol	xin
; make these continuously variable??
ks1	=	0.8
ks2	=	0.8
;;
kpregn   =       kpre / 8000        ; Pregain/Overdrive
kpostg   =       kvol * 20000       ; Postgain/Volume
ka1      =       ks1 / 8000         ; Shape 1 0=flat
ka2      =       ks2 / 8000         ; Shape 2
irect    =       0                  ; Rectification
ioutlvl  =       1                  ; Output Level
krms     rms     asig, 10
asig     =       asig + irect * krms
koffs1   =       irect * krms * (kpre / 1000 + (ks1 - .5) / 8000)
koffs2   =      -irect * krms * (kpre / 1000 + (ks2 - .5) / 8000)
koffs3   =       irect * krms * (kpre / 1000)
koffs    =       ( exp(koffs1) - exp(koffs2)) / ( exp(koffs3) + 
exp(-koffs3))
ax1      =       asig * (kpregn + ka1)                ; Precalculate a 
few values to save time
ax2      =      -asig * (kpregn + ka2)
ax3      =       asig * kpregn
aout     =       (( exp(ax1) - exp(ax2)) / ( exp(ax3) + exp(-ax3)) - 
koffs) * kpostg ; modified tanh distortion
	xout     aout * ioutlvl ; Output the result
		endop

/* sample rate reduce UDO */
		opcode	srReduce, a, akk
ain, klevl, ksr	xin
ibits    = (2 ^ 16)                 ; Bit depth
kfold    = sr / ksr                 ; Sample rate
kin      downsamp  ain              ; Convert to kr
kin      = kin + 32768              ; Add DC to avoid (-)
kin      = kin*(ibits/65536)        ; Divide signal level
kin      = int(kin)                 ; Quantise
aout     upsamp  kin                ; Convert to sr
aout     = aout*(65536/ibits) - 32768        ; Scale and remove DC
aout     fold  aout, kfold          ; Resample
	xout      aout * klevl         ; Level and output
		endop

/**********************************/

		instr	1	;snare drum

;	init

kpre	invalue	"pre"
kvol	invalue	"vol"
klevl	invalue	"levl"
ksr	invalue	"sr"

idur		=	p3
iamp		=	ampdb(p4)
ifrq		=	p5
iatk		=	p6

;	synth

kampenv	expseg	iatk,	.5,	.001
;asnare	oscil		kampenv,	ifrq,	5
asnare	foscil	kampenv,	ifrq,	1,	1,	100,	5
klfo		oscil		.5,	.25,	1
klfo		=	klfo + .5

;asnare hyptan	asnare,kpre,kvol
;asnare srReduce	asnare,klevl,ksr

	outs		asnare*klfo, asnare*(1-klfo)	

		endin

/**********************************/

		instr	2	;kick drum

;	init

kpre	invalue	"pre"
kvol	invalue	"vol"
klevl	invalue	"levl"
ksr	invalue	"sr"

idur		=	p3
indx		=	p4
ivel		=	p5

;	synth

kpenv		expon		60, 1, 40
kampenv	expseg	.001, .01, ivel, 1, .001
akick		foscil	kampenv, kpenv, 1, 4, indx, 1
alpf		butterlp	akick, 80

;alpf hyptan		alpf,kpre,kvol
;alpf srReduce	alpf,klevl,ksr

	outs		alpf, alpf

		endin

/**********************************/

		instr	3	;hi hat

;	init

kpre	invalue	"pre"
kvol	invalue	"vol"
klevl	invalue	"levl"
ksr	invalue	"sr"

idur		=	p3
iamp		=	p4
ifrq		=	p5
idrum		=	p6
ilforate	=	p7
iseed		=	p8

ipan		=	.5

if	(idrum	==	1)	kgoto closed
if	(idrum	==	2)	kgoto	open
	kgoto end

;	synth

closed:
kampenv	expseg	p4+5000, .2, .01
	kgoto contin

open:
kampenv	linseg	p4+5000, .2, .01
	kgoto contin

contin:
kamplfo	oscil		.5,	ilforate,	1
kpan		oscil		.5,	idur/4,	1
kamplfo	=	kamplfo + .5
;ahhat		oscil		((kampenv + ampdb(kamplfo))/2), ifrq, 5
ahhat		foscil	((kampenv + ampdb(kamplfo))/2), ifrq, 1, 1, 100, 5
afilt2	atone		ahhat, 8000
afilt1	atone		afilt2, 8000
kpan		=	kpan + .5

;afilt1 hyptan	afilt1,kpre,kvol
;afilt1 srReduce	afilt1,klevl,ksr

	outs		afilt1 * (1 - kpan), afilt1 * (kpan)
end:
		endin

/**********************************/

		instr	4	;meta keys

k1	sensekey

	if	(k1 == 97) then
	event	"i",1,0,1,78,1289,15000
elseif	(k1 == 115) then
	event "i",2,0,0.75,1,15000
elseif	(k1 == 100) then
	event "i",3,0,0.5,20000,1289,1,0.25,0
elseif	(k1 == 102) then
	event "i",3,0,0.5,20000,1289,2,0.25,0
else
		endif

		endin


i4	0	300

e




Version: 3
Render: Real
Ask: Yes
Functions: ioObject
WindowBounds: 364 44 1037 793
Options: -b1024 -A -s -m7 -K -R


ioView background {65535, 64997, 56784}
ioListing {14, 11} {405, 500}
ioGraph {419, 11} {447, 500}
ioSlider {25, 524} {102, 34} 0.000000 1.000000 0.464700 pre
ioSlider {147, 524} {102, 34} 0.000000 1.000000 0.676000 vol
ioSlider {277, 522} {102, 34} 0.000000 1.000000 1.000000 levl
ioSlider {418, 521} {102, 34} 1.000000 44100.000000 26085.560547 sr
ioText {24, 556} {103, 37} label 0.000000 0.001000 "" left "Lucida 
Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder 
pregain
ioText {148, 558} {101, 35} label 0.000000 0.001000 "" left "Lucida 
Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder volume
ioText {277, 557} {101, 35} label 0.000000 0.001000 "" left "Lucida 
Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder level
ioText {418, 557} {101, 35} label 0.000000 0.001000 "" left "Lucida 
Grande" 10 {0, 0, 0} {65535, 65535, 65535} nobackground noborder sr



-David

Date2006-03-07 06:29
From"Steven Yi"
SubjectRe: Triggering evens by mac keyboard
AttachmentsNone  

Date2006-03-07 15:24
FromAndres Cabrera
SubjectRe: Triggering evens by mac keyboard
Hi Steven
This is not really necessary for me. When it is, I just export to csd
and run from terminal, so it's no hassle, just wanted to mention in case
it was something trivial.

Cheers,
Andrés

On Mon, 2006-03-06 at 22:29 -0800, Steven Yi wrote:
> Hi Andres,
> 
> If csound is run from blue, blue will take over the pipes (stdin,
> stdout, stderr) to handle displaying to user as well as using stdin
> for blueLive.  I could possibly add a couple of textfield boxes in the
> csound output dialog so that in one you could type and pass keys to
> csound while in the other you could type score lines and send as a
> chunk.  I'm assuming this works but don't know the implementation of
> sensekey and if it uses stdin or has some kind of low-level key event
> detection.  If this is of interest please file an RFE (request for
> enhancement) on the blue project page (accesible from the help menu)
> and I will try to take a look at it as soon as I can.
> 
> Thanks!
> steven
> 
> 
> On 3/6/06, Andres Cabrera  wrote:
> > Hi,
> > Sorry, sensekey is working on linux, just not working within blue. For
> > some reason, keyboard events seem not to be passed to csound if it is
> > run by blue.
> >
> >
> > Cheers,
> > Andrés
> >
> > On Mon, 2006-03-06 at 23:42 +0300, Vadim Kupriyanov wrote:
> > > Hello!
> > >
> > > Now I try to use mac keyboard for triggering sound events in csound.
> > > I use operator sensekey for it. But sound start without wait pressing
> > > a key. How to make triggering, like cpsmidi triggering?
> > >
> > > Best regards,
> > > Vadim
> > >
> > >
> > >
> > >
> > > /* sensekey.orc */
> > >
> > > ; Initialize the global variables.
> > >
> > > sr = 44100
> > >
> > > kr = 4410
> > >
> > > ksmps = 10
> > >
> > > nchnls = 1
> > >
> > >
> > > ; Instrument #1.
> > >
> > > instr 1
> > >
> > >
> > > k1 sensekey
> > >    printk2 k1
> > >
> > > asig oscil 15000, 1000,1
> > > out asig
> > >
> > > endin
> > >
> > > /* sensekey.orc */
> > >
> > > /* sensekey.sco */
> > >
> > > ; Play Instrument #1 for thirty seconds.
> > > f0 600
> > > f1 0 512 10 1
> > > i 1 0 600
> > >
> > > e
> > >
> > > /* sensekey.sco */
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Send bugs reports to this list.
> > > To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk
> > >
> > >
> > > �
> >
> > --
> > Send bugs reports to this list.
> > To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk
> >
> 
> 
> �