;Written by Iain McCurdy, 2011
;Modified for QuteCsound by René, May 2011
;Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817
;Notes on modifications from original csd:
; Add kkeydown output variable to sensekey opcode, if not it does not work !
;my flags on Ubuntu: -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
sr = 44100 ;SAMPLE RATE
ksmps = 32 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
nchnls = 1 ;NUMBER OF CHANNELS (2=STEREO)
0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH
gkMIDInote init 60
giwave ftgen 0,0,4096,10,1, 1/2, 0, 1/4, 0, 0, 1/8
instr 1 ;SENSE KEYBOARD ACTIVITY AND START RECORD OR PLAYBACK INSTRUMENTS ACCORDINGLY
kKey, kkeydown sensekey ;SENSE ACTIVITY ON THE COMPUTER KEYBOARD
if kkeydown == 1 then
Smessage sprintfk "Key pressed. Code = %i", kKey
outvalue "data", Smessage
elseif (kkeydown == 0 && kKey != -1) then
Smessage sprintfk "Key released. Code = %i", kKey
outvalue "data", Smessage
endif
if kKey=112 then ;IF ASCCI VALUE OF 112 IS OUTPUT, I.E. 'p' HAS BEEN PRESSED...
event "i", 2, 0, -1 ;START INSTRUMENT 2
elseif kKey=115 then ;IF ASCII VALUE OF 115 IS OUTPUT, I.E. 's' HAS BEEN PRESSED...
turnoff2 2,0,1 ;STOP INSTRUMENT 2
elseif kKey=43 then ;IF ASCII VALUE OF 43 IS OUTPUT, I.E. '+' HAS BEEN PRESSED...
gkMIDInote limit gkMIDInote + 1, 0, 127 ;INCREMENT MIDI NOTE NUMBER UP ONE STEP (LIMIT RANGE TO BE BETWEEN ZERO AND 127)
elseif kKey=45 then ;IF ASCII VALUE OF 45 IS OUTPUT, I.E. '-' HAS BEEN PRESSED...
gkMIDInote limit gkMIDInote - 1, 0, 127 ;DECREMENT MIDI NOTE NUMBER DOWN ONE STEP (LIMIT RANGE TO BE BETWEEN ZERO AND 127)
endif ;END OF CONDITIONAL BRANCH
endin
instr 2 ;PLAYS A TONE
aenv linsegr 0,0.01,1,0.01,0
a1 oscili 0.2*aenv, cpsmidinn(gkMIDInote), giwave
out a1
endin
i 1 0 3600 ;SENSES KEYBOARD ACTIVITY INSTRUMENT
941
239
417
347
true
241
226
185
2
2
412
344
{049f4dd4-ff71-4d6d-9157-43c84efad8a4}
true
0
0
center
Liberation Sans
18
3
255
255
255
5
27
150
border
5
2
8
105
400
233
{a22504a1-aa44-46e3-9ff9-60d7e5c3b024}
true
0
0
left
Liberation Sans
14
3
255
255
255
255
255
255
noborder
1
1
8
34
400
25
{6f0e0438-b1dd-4f4d-b357-6580db16bd7a}
true
0
0
center
Liberation Sans
14
3
255
255
255
255
255
255
noborder
1
1
data
8
64
400
40
{d9e70b9e-4de4-401c-b0bd-9f0d5d0b0a5e}
true
0
0
center
Liberation Sans
15
3
255
255
255
255
255
255
border
1
1