Debian Codegraph @

src/Examples/McCurdy Collection/Miscellaneous/sensekey.csd

raw
1 ;Written by Iain McCurdy, 2011
2
3
4 ;Modified for QuteCsound by René, May 2011
5 ;Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817
6
7 ;Notes on modifications from original csd:
8 ; Add kkeydown output variable to sensekey opcode, if not it does not work !
9
10
11 ;my flags on Ubuntu: -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
12 <CsoundSynthesizer>
13 <CsOptions>
14
15 </CsOptions>
16 <CsInstruments>
17 sr = 44100 ;SAMPLE RATE
18 ksmps = 32 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
19 nchnls = 1 ;NUMBER OF CHANNELS (2=STEREO)
20 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH
21
22
23 gkMIDInote init 60
24 giwave ftgen 0,0,4096,10,1, 1/2, 0, 1/4, 0, 0, 1/8
25
26
27 instr 1 ;SENSE KEYBOARD ACTIVITY AND START RECORD OR PLAYBACK INSTRUMENTS ACCORDINGLY
28 kKey, kkeydown sensekey ;SENSE ACTIVITY ON THE COMPUTER KEYBOARD
29
30 if kkeydown == 1 then
31 Smessage sprintfk "Key pressed. Code = %i", kKey
32 outvalue "data", Smessage
33 elseif (kkeydown == 0 && kKey != -1) then
34 Smessage sprintfk "Key released. Code = %i", kKey
35 outvalue "data", Smessage
36 endif
37
38 if kKey=112 then ;IF ASCCI VALUE OF 112 IS OUTPUT, I.E. 'p' HAS BEEN PRESSED...
39 event "i", 2, 0, -1 ;START INSTRUMENT 2
40 elseif kKey=115 then ;IF ASCII VALUE OF 115 IS OUTPUT, I.E. 's' HAS BEEN PRESSED...
41 turnoff2 2,0,1 ;STOP INSTRUMENT 2
42 elseif kKey=43 then ;IF ASCII VALUE OF 43 IS OUTPUT, I.E. '+' HAS BEEN PRESSED...
43 gkMIDInote limit gkMIDInote + 1, 0, 127 ;INCREMENT MIDI NOTE NUMBER UP ONE STEP (LIMIT RANGE TO BE BETWEEN ZERO AND 127)
44 elseif kKey=45 then ;IF ASCII VALUE OF 45 IS OUTPUT, I.E. '-' HAS BEEN PRESSED...
45 gkMIDInote limit gkMIDInote - 1, 0, 127 ;DECREMENT MIDI NOTE NUMBER DOWN ONE STEP (LIMIT RANGE TO BE BETWEEN ZERO AND 127)
46 endif ;END OF CONDITIONAL BRANCH
47 endin
48
49 instr 2 ;PLAYS A TONE
50 aenv linsegr 0,0.01,1,0.01,0
51 a1 oscili 0.2*aenv, cpsmidinn(gkMIDInote), giwave
52 out a1
53 endin
54 </CsInstruments>
55 <CsScore>
56 i 1 0 3600 ;SENSES KEYBOARD ACTIVITY INSTRUMENT
57 </CsScore>
58 </CsoundSynthesizer>
59
60 <bsbPanel>
61 <label>Widgets</label>
62 <objectName/>
63 <x>941</x>
64 <y>239</y>
65 <width>417</width>
66 <height>347</height>
67 <visible>true</visible>
68 <uuid/>
69 <bgcolor mode="background">
70 <r>241</r>
71 <g>226</g>
72 <b>185</b>
73 </bgcolor>
74 <bsbObject version="2" type="BSBLabel">
75 <objectName/>
76 <x>2</x>
77 <y>2</y>
78 <width>412</width>
79 <height>344</height>
80 <uuid>{049f4dd4-ff71-4d6d-9157-43c84efad8a4}</uuid>
81 <visible>true</visible>
82 <midichan>0</midichan>
83 <midicc>0</midicc>
84 <label>sensekey</label>
85 <alignment>center</alignment>
86 <font>Liberation Sans</font>
87 <fontsize>18</fontsize>
88 <precision>3</precision>
89 <color>
90 <r>255</r>
91 <g>255</g>
92 <b>255</b>
93 </color>
94 <bgcolor mode="background">
95 <r>5</r>
96 <g>27</g>
97 <b>150</b>
98 </bgcolor>
99 <bordermode>border</bordermode>
100 <borderradius>5</borderradius>
101 <borderwidth>2</borderwidth>
102 </bsbObject>
103 <bsbObject version="2" type="BSBLabel">
104 <objectName/>
105 <x>8</x>
106 <y>105</y>
107 <width>400</width>
108 <height>233</height>
109 <uuid>{a22504a1-aa44-46e3-9ff9-60d7e5c3b024}</uuid>
110 <visible>true</visible>
111 <midichan>0</midichan>
112 <midicc>0</midicc>
113 <label>---------------------------------------------------------------------------------------------------
114 This example demonstrates the sensekey opcode which senses key presses on the computer's keyboard and outputs the decimal value. To be able to use key presses we will need to know their decimal values. These can be found on line in an ASCII table (http://www.asciitable.com/) or by using this example.
115 Note that the Widgets window will need to be in focus for key presses to be sensed.
116 sensekey follows each key press value with a '-1', but key press values are reiterated according to repeat-key settings in QuteCsound configuration.
117 Each reiteration is again followed with a '-1'.
118 sensekey is case sensitive.</label>
119 <alignment>left</alignment>
120 <font>Liberation Sans</font>
121 <fontsize>14</fontsize>
122 <precision>3</precision>
123 <color>
124 <r>255</r>
125 <g>255</g>
126 <b>255</b>
127 </color>
128 <bgcolor mode="nobackground">
129 <r>255</r>
130 <g>255</g>
131 <b>255</b>
132 </bgcolor>
133 <bordermode>noborder</bordermode>
134 <borderradius>1</borderradius>
135 <borderwidth>1</borderwidth>
136 </bsbObject>
137 <bsbObject version="2" type="BSBLabel">
138 <objectName/>
139 <x>8</x>
140 <y>34</y>
141 <width>400</width>
142 <height>25</height>
143 <uuid>{6f0e0438-b1dd-4f4d-b357-6580db16bd7a}</uuid>
144 <visible>true</visible>
145 <midichan>0</midichan>
146 <midicc>0</midicc>
147 <label>Press 'p' to play, 's' to stop, '+' to raise pitch, '-' to lower pitch.</label>
148 <alignment>center</alignment>
149 <font>Liberation Sans</font>
150 <fontsize>14</fontsize>
151 <precision>3</precision>
152 <color>
153 <r>255</r>
154 <g>255</g>
155 <b>255</b>
156 </color>
157 <bgcolor mode="nobackground">
158 <r>255</r>
159 <g>255</g>
160 <b>255</b>
161 </bgcolor>
162 <bordermode>noborder</bordermode>
163 <borderradius>1</borderradius>
164 <borderwidth>1</borderwidth>
165 </bsbObject>
166 <bsbObject version="2" type="BSBDisplay">
167 <objectName>data</objectName>
168 <x>8</x>
169 <y>64</y>
170 <width>400</width>
171 <height>40</height>
172 <uuid>{d9e70b9e-4de4-401c-b0bd-9f0d5d0b0a5e}</uuid>
173 <visible>true</visible>
174 <midichan>0</midichan>
175 <midicc>0</midicc>
176 <label>Key released. Code = 115</label>
177 <alignment>center</alignment>
178 <font>Liberation Sans</font>
179 <fontsize>15</fontsize>
180 <precision>3</precision>
181 <color>
182 <r>255</r>
183 <g>255</g>
184 <b>255</b>
185 </color>
186 <bgcolor mode="nobackground">
187 <r>255</r>
188 <g>255</g>
189 <b>255</b>
190 </bgcolor>
191 <bordermode>border</bordermode>
192 <borderradius>1</borderradius>
193 <borderwidth>1</borderwidth>
194 </bsbObject>
195 </bsbPanel>
196 <bsbPresets>
197 </bsbPresets>
198 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>