Debian Codegraph @

src/Examples/McCurdy Collection/RealtimeScoreGeneration/SimpleSchedkwhenNoteGenerator.csd

raw
1 ;Written by Iain McCurdy, 2006
2
3 ;Modified for QuteCsound by René, March 2011
4 ;Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817
5
6 ;Notes on modifications from original csd:
7
8
9 ;my flags on Ubuntu: -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0
10 <CsoundSynthesizer>
11 <CsOptions>
12
13 </CsOptions>
14 <CsInstruments>
15 sr = 44100 ;SAMPLE RATE
16 ksmps = 100 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
17 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
18 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH
19
20
21 instr 10 ;GUI
22 ktrig metro 10
23 if (ktrig == 1) then
24 gkTrigFreqMin invalue "TrigFreqMin"
25 gkTrigFreqMax invalue "TrigFreqMax"
26 gkscale invalue "Scale"
27 endif
28 endin
29
30 instr 1 ;THIS INSTRUMENT TRIGGERS NOTES IN INSTRUMENT 2 WITH A MINIMUM TIME GAP BETWEEN NOTES OF kmintim SECONDS
31 kTrigFreq randomi gkTrigFreqMin, gkTrigFreqMax, 5 ;TRIGGER FREQUENCY - DEFINED RANDOMLY WITHIN THE GIVEN RANGE - FREQUENCY OF NEW RANDOM NUMBER OUTPUT=5Hz
32 ktrigger metro kTrigFreq ;CREATE A TRIGGER SIGNAL (MOMENTARY '1' IMPULSES) ACCORDING TO THE FLUCTUATING VARIABLE 'kTrigFreq'
33 ;NOTE DURATIONS WILL BE DEFINED RANDOMLY:
34 ; MIN | MAX | FREQUENCY
35 kdur randomh .1, 2, 5 ;SAMPLE-AND-HOLD RANDOM NUMBER GENERATOR
36 ; TRIGGER | MINTIM | MAXNUM | INSNUM | WHEN | KDUR
37 schedkwhen ktrigger, 0, 0, 2, 0, kdur
38 endin
39
40 instr 2 ;THIS IS THE SOUND PRODUCING INSTRUMENT - A SIMPLE SINE WAVE 'PING'
41 iamp random 0.03,0.5 ;AMPLITUDES WILL BE RANDOM VALUES BETWEEN 1000 (VERY QUIET) AND 10000 (LOUD)
42 ipan random 0, 1 ;PAN VALUES WILL BE RANDOM VALUES BETWEEN 0 (LEFT SPEAKER) AND 1 (RIGHT SPEAKER)
43 ipchndx random 0,13 ;A RANDOM INDEX VALUE IS DEFINED FOR EACH NEW NOTE.
44 ;THIS INDEX WILL BE USED TO SELECT VALUES FROM THE 'SCALE' FUNCTION TABLE.
45 ;THE MAXIMUM POSSIBLE VALUE SHOULD NOT EXCEED THE NUMBER OF VALUES (NOTES) DEFINED IN THE CORRESPONDING FUNCTION TABLE (SCALE).
46 ipch table ipchndx, 2+i(gkscale) ;THE VARIABLE ipch WILL BE SELECTED FROM THE ipchndx VALUE IN FUNCTION TABLE 2
47 aenv expseg 1, (p3), .001 ;PERCUSSIVE-TYPE AMPLITUDE ENVELOPE
48 asig oscil iamp * aenv, cpspch(ipch), 1 ;GENERATE AN AUDIO SIGNAL ACCORDING TO THE WAVEFORM IN FUNCTION TABLE 1 - USE THE SELECTED PCH VALUE AND APPLY THE AMPLITUDE ENVELOPE AND RANDOM AMPLITUDE VALUE
49 outs asig * ipan, asig * (1-ipan) ;SEND AUDIO TO OUTPUTS AND APPLY SIMPLE PANNING
50 endin
51 </CsInstruments>
52 <CsScore>
53 f 1 0 4096 10 1 ;SINE WAVE
54
55 ;TABLE_NO.|INIT_TIME|SIZE|GEN_NUMBER|VALUES.1.. 2 3 4 5 6 7 8 9 10 11 12 13
56 f 2 0 64 -2 7 7.03 7.05 7.07 7.10 8 8.03 8.05 8.07 8.10 9 ;PENTATONIC SCALE - 2 OCTAVES
57 f 3 0 64 -2 7 7.02 7.04 7.06 7.08 7.10 8.00 8.02 8.04 8.06 8.08 8.10 9.00 ;WHOLE TONE SCALE - 2 OCTAVES
58 ;GEN 2 OFFERS US A MEANS TO STORE DISCRETE VALUES, DEFINED VALUE BY VALUE - IN THIS CASE THESE VALUES WILL BE INTERPRETED IN THE ORCHESTRA AS PCH FORMAT VALUES
59 ;IF THE GEN ROUTINE NUMBER IS GIVEN AS A NEGATIVE NUMBER THEN VALUES WON'T BE NORMALIZED (RESCALED WITHIN THE RANGE -1 TO 1)
60
61 i 10 0 3600 ;GUI
62 </CsScore>
63 </CsoundSynthesizer>
64 <bsbPanel>
65 <label>Widgets</label>
66 <objectName/>
67 <x>1160</x>
68 <y>149</y>
69 <width>519</width>
70 <height>488</height>
71 <visible>true</visible>
72 <uuid/>
73 <bgcolor mode="background">
74 <r>241</r>
75 <g>226</g>
76 <b>185</b>
77 </bgcolor>
78 <bsbObject version="2" type="BSBLabel">
79 <objectName/>
80 <x>2</x>
81 <y>2</y>
82 <width>510</width>
83 <height>482</height>
84 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
85 <visible>true</visible>
86 <midichan>0</midichan>
87 <midicc>0</midicc>
88 <label>schedkwhen - Simple Algorithmic Note Generator</label>
89 <alignment>center</alignment>
90 <font>Liberation Sans</font>
91 <fontsize>18</fontsize>
92 <precision>3</precision>
93 <color>
94 <r>0</r>
95 <g>0</g>
96 <b>0</b>
97 </color>
98 <bgcolor mode="background">
99 <r>244</r>
100 <g>248</g>
101 <b>200</b>
102 </bgcolor>
103 <bordermode>border</bordermode>
104 <borderradius>5</borderradius>
105 <borderwidth>2</borderwidth>
106 </bsbObject>
107 <bsbObject version="2" type="BSBLabel">
108 <objectName/>
109 <x>6</x>
110 <y>127</y>
111 <width>501</width>
112 <height>355</height>
113 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
114 <visible>true</visible>
115 <midichan>0</midichan>
116 <midicc>0</midicc>
117 <label>--------------------------------------------------------------------------------------------------------------------------
118 This example demonstrates how the opcode 'schedkwhen' can be used to implement a simple algorithmic note generator. 'Algorithmic' refers to the fact that the pitches of notes generated will be indeterminate but not completely random. Pitches will be chosen at random from a set of notes defined in a function table. Schedkwhen allows one instrument to generate multiple notes that will be played by another instrument. Schedkwhen is activated by a trigger signal which could be pulsed, rhythmical or unpulsed/rhymically aleatoric. Schedkwhen also allows the user to define start time, note duration and any number of additional p-fields at k-rate. (The called instrument will receive these values as i-rate p-values. With these capabilties the possiblities for algorithmically generating notes are immense. In this very simple example the user can vary the random value limits for the trigger frequency. Setting these two controls to the same value will create metered note generation. The user can also choose between two different scale types (stored in two separate GEN-02 function tables). Each time a note is generated its duration will be a randomly chosen value between .1 and 2 (seconds). The amplitude of each note will also be random. Each note will occupy a randomly chosen location between the left and right speakers. This example employs very simple and uniform random number generators. Csound offers a wide variety of more powerful random number generators portraying a variety of distributions.</label>
119 <alignment>left</alignment>
120 <font>Liberation Sans</font>
121 <fontsize>14</fontsize>
122 <precision>3</precision>
123 <color>
124 <r>0</r>
125 <g>0</g>
126 <b>0</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="BSBButton">
138 <objectName/>
139 <x>8</x>
140 <y>44</y>
141 <width>80</width>
142 <height>26</height>
143 <uuid>{04d44ebe-12eb-4bb0-a3f5-9e4fd3e7830e}</uuid>
144 <visible>true</visible>
145 <midichan>0</midichan>
146 <midicc>0</midicc>
147 <type>event</type>
148 <pressedValue>1.00000000</pressedValue>
149 <stringvalue/>
150 <text> On / Off</text>
151 <image>/</image>
152 <eventLine>i 1 0 -1</eventLine>
153 <latch>true</latch>
154 <latched>false</latched>
155 </bsbObject>
156 <bsbObject version="2" type="BSBLabel">
157 <objectName/>
158 <x>109</x>
159 <y>45</y>
160 <width>80</width>
161 <height>25</height>
162 <uuid>{7c945fd6-92be-427f-bceb-ab7630e97198}</uuid>
163 <visible>true</visible>
164 <midichan>0</midichan>
165 <midicc>0</midicc>
166 <label>Scale</label>
167 <alignment>right</alignment>
168 <font>Liberation Sans</font>
169 <fontsize>10</fontsize>
170 <precision>3</precision>
171 <color>
172 <r>0</r>
173 <g>0</g>
174 <b>0</b>
175 </color>
176 <bgcolor mode="nobackground">
177 <r>255</r>
178 <g>255</g>
179 <b>255</b>
180 </bgcolor>
181 <bordermode>noborder</bordermode>
182 <borderradius>1</borderradius>
183 <borderwidth>1</borderwidth>
184 </bsbObject>
185 <bsbObject version="2" type="BSBDropdown">
186 <objectName>Scale</objectName>
187 <x>195</x>
188 <y>44</y>
189 <width>120</width>
190 <height>26</height>
191 <uuid>{2940aaee-8fb3-46d5-bb2c-a70e3e47e5cd}</uuid>
192 <visible>true</visible>
193 <midichan>0</midichan>
194 <midicc>0</midicc>
195 <bsbDropdownItemList>
196 <bsbDropdownItem>
197 <name>Pentatonic</name>
198 <value>0</value>
199 <stringvalue/>
200 </bsbDropdownItem>
201 <bsbDropdownItem>
202 <name>Whole Tone</name>
203 <value>1</value>
204 <stringvalue/>
205 </bsbDropdownItem>
206 </bsbDropdownItemList>
207 <selectedIndex>0</selectedIndex>
208 <randomizable group="0">false</randomizable>
209 </bsbObject>
210 <bsbObject version="2" type="BSBController">
211 <objectName>TrigFreqMin</objectName>
212 <x>7</x>
213 <y>83</y>
214 <width>500</width>
215 <height>12</height>
216 <uuid>{4e625263-998b-44d3-aa3d-30623c5a9616}</uuid>
217 <visible>true</visible>
218 <midichan>0</midichan>
219 <midicc>0</midicc>
220 <objectName2/>
221 <xMin>0.01000000</xMin>
222 <xMax>20.00000000</xMax>
223 <yMin>0.00000000</yMin>
224 <yMax>1.00000000</yMax>
225 <xValue>5.00750000</xValue>
226 <yValue>0.25000000</yValue>
227 <type>fill</type>
228 <pointsize>1</pointsize>
229 <fadeSpeed>0.00000000</fadeSpeed>
230 <mouseControl act="press">jump</mouseControl>
231 <color>
232 <r>85</r>
233 <g>255</g>
234 <b>255</b>
235 </color>
236 <randomizable mode="both" group="0">false</randomizable>
237 <bgcolor>
238 <r>0</r>
239 <g>0</g>
240 <b>0</b>
241 </bgcolor>
242 </bsbObject>
243 <bsbObject version="2" type="BSBController">
244 <objectName>TrigFreqMax</objectName>
245 <x>7</x>
246 <y>99</y>
247 <width>500</width>
248 <height>12</height>
249 <uuid>{5f320247-5c85-42cc-b569-5d88268b1c6b}</uuid>
250 <visible>true</visible>
251 <midichan>0</midichan>
252 <midicc>0</midicc>
253 <objectName2/>
254 <xMin>0.01000000</xMin>
255 <xMax>20.00000000</xMax>
256 <yMin>0.00000000</yMin>
257 <yMax>1.00000000</yMax>
258 <xValue>5.00750000</xValue>
259 <yValue>0.25000000</yValue>
260 <type>llif</type>
261 <pointsize>1</pointsize>
262 <fadeSpeed>0.00000000</fadeSpeed>
263 <mouseControl act="press">jump</mouseControl>
264 <color>
265 <r>85</r>
266 <g>255</g>
267 <b>255</b>
268 </color>
269 <randomizable mode="both" group="0">false</randomizable>
270 <bgcolor>
271 <r>0</r>
272 <g>0</g>
273 <b>0</b>
274 </bgcolor>
275 </bsbObject>
276 <bsbObject version="2" type="BSBLabel">
277 <objectName/>
278 <x>177</x>
279 <y>110</y>
280 <width>160</width>
281 <height>26</height>
282 <uuid>{c0e508d9-0147-47a9-8441-51028c427718}</uuid>
283 <visible>true</visible>
284 <midichan>0</midichan>
285 <midicc>0</midicc>
286 <label>Trigger Frequency: min / max</label>
287 <alignment>center</alignment>
288 <font>Liberation Sans</font>
289 <fontsize>10</fontsize>
290 <precision>3</precision>
291 <color>
292 <r>0</r>
293 <g>0</g>
294 <b>0</b>
295 </color>
296 <bgcolor mode="nobackground">
297 <r>255</r>
298 <g>255</g>
299 <b>255</b>
300 </bgcolor>
301 <bordermode>noborder</bordermode>
302 <borderradius>1</borderradius>
303 <borderwidth>1</borderwidth>
304 </bsbObject>
305 <bsbObject version="2" type="BSBDisplay">
306 <objectName>TrigFreqMax</objectName>
307 <x>447</x>
308 <y>110</y>
309 <width>60</width>
310 <height>30</height>
311 <uuid>{f7047b7a-3e79-47a8-8711-b538657cc78f}</uuid>
312 <visible>true</visible>
313 <midichan>0</midichan>
314 <midicc>0</midicc>
315 <label>5.008</label>
316 <alignment>right</alignment>
317 <font>Liberation Sans</font>
318 <fontsize>9</fontsize>
319 <precision>3</precision>
320 <color>
321 <r>0</r>
322 <g>0</g>
323 <b>0</b>
324 </color>
325 <bgcolor mode="nobackground">
326 <r>255</r>
327 <g>255</g>
328 <b>255</b>
329 </bgcolor>
330 <bordermode>noborder</bordermode>
331 <borderradius>1</borderradius>
332 <borderwidth>1</borderwidth>
333 </bsbObject>
334 <bsbObject version="2" type="BSBDisplay">
335 <objectName>TrigFreqMin</objectName>
336 <x>7</x>
337 <y>110</y>
338 <width>60</width>
339 <height>30</height>
340 <uuid>{11206a4a-c384-42c7-b034-19e06c2d1d6e}</uuid>
341 <visible>true</visible>
342 <midichan>0</midichan>
343 <midicc>0</midicc>
344 <label>5.008</label>
345 <alignment>left</alignment>
346 <font>Liberation Sans</font>
347 <fontsize>9</fontsize>
348 <precision>3</precision>
349 <color>
350 <r>0</r>
351 <g>0</g>
352 <b>0</b>
353 </color>
354 <bgcolor mode="nobackground">
355 <r>255</r>
356 <g>255</g>
357 <b>255</b>
358 </bgcolor>
359 <bordermode>noborder</bordermode>
360 <borderradius>1</borderradius>
361 <borderwidth>1</borderwidth>
362 </bsbObject>
363 </bsbPanel>
364 <bsbPresets>
365 </bsbPresets>
366 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>