Debian Codegraph @

src/Examples/CsoundQt/Miscellaneous/Keyboard_Control.csd

raw
1 <CsoundSynthesizer>
2 <CsOptions>
3 </CsOptions>
4 <CsInstruments>
5
6 sr = 44100
7 ksmps = 128
8 nchnls = 2
9 0dbfs = 1
10
11 ; This example shows the usage of sense key to use the ascii keyboard
12 ; as a keyboard to play notes. It uses an always on instrument (1), which
13 ; listens to key events and turns on and off notes.
14 ; It is important to give focus to the main Csound Output Console (giving focus
15 ; to a console widget will not work!).
16 ; Note that key press auto-repeats are discarded!
17
18
19 ; This table calculates the pitch values for the ascii key codes
20 ; Using shift or caps lock will raise 2 octaves (except for the numbers)
21
22 giascii ftgen 0, 0, 256, -17, 0,0, \
23 48, 9.03, 49, 0, 50, 8.01, 51, 8.03, 52, 0, 53, 8.06, 54, 8.08, \
24 55, 8.10, 56,0, 57, 9.01, \
25 65, 0, 66, 9.07, 67, 9.04, 68, 9.03, 69, 10.04, 70, 0, 71, 9.06, 72, 9.08, \
26 73, 11.00, 74, 9.10, 75, 0, 76, 0, 77, 9.11, 78, 9.09, 79, 11.02, 80, 11.04, \
27 81, 10.00, 82, 10.05, 83, 9.01, 84, 10.07, 85, 10.11, 86, 9.05, 87, 10.02, \
28 88, 9.02, 89, 10.09, 90, 9.00, \
29 97, 0, 98, 7.07, 99, 7.04, 100, 7.03, 101, 8.04, 102, 0, 103, 7.06, 104, 7.08, \
30 105, 9.00, 106, 7.10, 107, 0, 108, 0, 109, 7.11, 110, 7.09, 111, 9.02, 112, 9.04, \
31 113, 8.00, 114, 8.05, 115, 7.01, 116, 8.07, 117, 8.11, 118, 7.05, 119, 8.02, \
32 120, 7.02, 121, 8.09, 122, 7.00
33
34 instr 1 ;always on, sensing key events
35 kres,kkeydown sensekey
36
37 ktrig changed kres, kkeydown
38
39 if ktrig == 1 then
40 printks "kres %i. kkeydown %i\n", 0, kres, kkeydown
41 endif
42
43 kpch table kres, giascii
44 if kkeydown == 1 then
45 Smessage sprintfk "Key pressed. Code = %i", kres
46 outvalue "data", Smessage
47 event "i", 2 + (kpch/100), 0, -5, kpch
48 elseif (kkeydown == 0 && kres != -1) then
49 turnoff2 2 + (kpch/100), 4, 1
50 Smessage sprintfk "Key released. Code = %i", kres
51 outvalue "data", Smessage
52 endif
53 endin
54
55 instr 2 ;actual synth. Put anything here
56 iamp = 0.2
57 iatt = 0.03
58 idec = 0.01
59 irel = 1.3
60 ifreq = cpspch(p4)
61 print ifreq
62 if ifreq < 20 then
63 turnoff
64 endif
65 kenv madsr iatt, idec, 0.6, irel
66 asig vco2 kenv*iamp, ifreq
67 asig moogladder asig, ifreq*2, 0.8
68 outs asig, asig
69 endin
70
71 </CsInstruments>
72 <CsScore>
73 f 1 0 1024 10 1
74 i 1 0 3600
75 </CsScore>
76 </CsoundSynthesizer>
77 <bsbPanel>
78 <label>Widgets</label>
79 <objectName/>
80 <x>0</x>
81 <y>0</y>
82 <width>294</width>
83 <height>189</height>
84 <visible>true</visible>
85 <uuid/>
86 <bgcolor mode="background">
87 <r>85</r>
88 <g>170</g>
89 <b>127</b>
90 </bgcolor>
91 <bsbObject type="BSBLabel" version="2">
92 <objectName/>
93 <x>5</x>
94 <y>52</y>
95 <width>289</width>
96 <height>104</height>
97 <uuid>{b7cc6e90-2fe6-429e-a4c2-59bece5d87ce}</uuid>
98 <visible>true</visible>
99 <midichan>0</midichan>
100 <midicc>-3</midicc>
101 <label>The sensekey opcode can be used to receive keyboard action. It is VERY IMPORTANT to click on the Dock Console or the Widget Panel to give it focus, otherwise key events will NOT be passed to Csound.</label>
102 <alignment>left</alignment>
103 <font>DejaVu Sans</font>
104 <fontsize>12</fontsize>
105 <precision>3</precision>
106 <color>
107 <r>0</r>
108 <g>0</g>
109 <b>0</b>
110 </color>
111 <bgcolor mode="nobackground">
112 <r>255</r>
113 <g>255</g>
114 <b>255</b>
115 </bgcolor>
116 <bordermode>border</bordermode>
117 <borderradius>1</borderradius>
118 <borderwidth>1</borderwidth>
119 </bsbObject>
120 <bsbObject type="BSBLabel" version="2">
121 <objectName/>
122 <x>6</x>
123 <y>11</y>
124 <width>287</width>
125 <height>37</height>
126 <uuid>{4cd046a0-3748-49fd-b4da-b1fe395b72dd}</uuid>
127 <visible>true</visible>
128 <midichan>0</midichan>
129 <midicc>-3</midicc>
130 <label>Keyboard control</label>
131 <alignment>center</alignment>
132 <font>DejaVu Sans</font>
133 <fontsize>22</fontsize>
134 <precision>3</precision>
135 <color>
136 <r>0</r>
137 <g>0</g>
138 <b>0</b>
139 </color>
140 <bgcolor mode="background">
141 <r>97</r>
142 <g>194</g>
143 <b>144</b>
144 </bgcolor>
145 <bordermode>noborder</bordermode>
146 <borderradius>1</borderradius>
147 <borderwidth>1</borderwidth>
148 </bsbObject>
149 <bsbObject type="BSBDisplay" version="2">
150 <objectName>data</objectName>
151 <x>46</x>
152 <y>163</y>
153 <width>198</width>
154 <height>26</height>
155 <uuid>{9a382452-2e20-4ccd-8eb3-28a5bf34dee1}</uuid>
156 <visible>true</visible>
157 <midichan>0</midichan>
158 <midicc>-3</midicc>
159 <label>Key released. Code = 115</label>
160 <alignment>left</alignment>
161 <font>DejaVu Sans</font>
162 <fontsize>10</fontsize>
163 <precision>3</precision>
164 <color>
165 <r>0</r>
166 <g>0</g>
167 <b>0</b>
168 </color>
169 <bgcolor mode="background">
170 <r>255</r>
171 <g>255</g>
172 <b>255</b>
173 </bgcolor>
174 <bordermode>border</bordermode>
175 <borderradius>1</borderradius>
176 <borderwidth>1</borderwidth>
177 </bsbObject>
178 </bsbPanel>
179 <bsbPresets>
180 </bsbPresets>