Debian Codegraph @

src/Examples/McCurdy Collection/MIDI/LiveQuantize.csd

raw
1 ;Writen by Iain McCurdy, 2008
2
3 ; Modified for QuteCsound by René, February 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 ; Add instr 6 for bar display
8
9
10 ;my flags on Ubuntu: -dm0 -odac -+rtaudio=alsa -b1024 -B2048 -+rtmidi=alsa -Ma
11 <CsoundSynthesizer>
12 <CsOptions>
13
14 </CsOptions>
15 <CsInstruments>
16 sr = 44100 ;SAMPLE RATE
17 ksmps = 10 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE
18 nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO)
19 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH
20
21
22 gisine ftgen 0,0,65537,10,1 ;A SINE WAVE
23
24 giSubDiv = 1000 ;SUBDIVISION OF THE BEAT (ESSENTIALLY THIS WILL DETERMINE THE PRECISION OF THE QUANTIZING EFFECT
25 gkTempoClock init 0 ;INITIALISE VARIABLE FOR MAIN CLOCK
26
27 ;maxalloc 4,1 ;POLYPHONY CONTROL FOR THE SOUND PREODUCING INSTRUMENT
28
29
30 instr 10 ;GUI
31 gkLiveQuantize invalue "On_Off" ;lance i2
32 kB_ON trigger gkLiveQuantize, 0.5, 0
33 schedkwhen kB_ON, 0, 0, 2, 0, -1 ;Start instr
34
35 gkTempo invalue "Tempo"
36 gkNoteVal invalue "Beat"
37 gkMetroGain invalue "Metronone"
38 endin
39
40 instr 1 ;MIDI TRIGGERED INSTRUMENT
41 icps cpsmidi
42 iamp veloc 0,0.2
43 idelay = frac(i(gkTempoClock))
44 idelay = (1-idelay)*(60/(i(gkTempo)*i(gkNoteVal)))
45 event_i "i", p1+3, idelay, 1, icps, iamp
46 endin
47
48 instr 2 ;TURNS ON THE QUANTIZER
49 gkTempoClock init 0 ;INITIALISE VARIABLE FOR MAIN CLOCK
50 if gkLiveQuantize!=0 goto CONTINUE
51 turnoff
52
53 CONTINUE:
54 kTrigger metro (gkTempo*giSubDiv*gkNoteVal)/60
55 schedkwhen kTrigger, 0, 0, p1+1, 0, 0.001
56
57 kMetronome metro gkTempo/240
58 kbeat = 240/gkTempo
59 schedkwhen kMetronome, 0, 0, 5, 0, .05, 600, 0
60 schedkwhen kMetronome, 0, 0, 5, kbeat*.25, .05, 300, 1
61 schedkwhen kMetronome, 0, 0, 5, kbeat*.50, .05, 300, 2
62 schedkwhen kMetronome, 0, 0, 5, kbeat*.75, .05, 300, 3
63 endin
64
65 instr 3 ;INCREMENT THE CLOCK BY 1 SUBDIVISION
66 kTempoClock = gkTempoClock + (1/giSubDiv)
67 gkTempoClock = kTempoClock
68 turnoff
69 endin
70
71 instr 4 ;SOUND PRODUCING INSTRUMENT
72 aenv expseg 0.0001, 0.01, 1, p3-0.01, 0.0001
73 a1 oscili aenv*p5, p4, gisine
74 outs a1, a1
75 endin
76
77 instr 5 ;METRONOME SOUND GENERATOR
78 if gkLiveQuantize=0 then
79 turnoff
80 endif
81
82 aenv linseg 0, 0.001,1, p3-0.001,0
83 asig oscili 0.2*aenv*i(gkMetroGain), p4, gisine
84 outs asig, asig
85
86 schedkwhen 1, 0, 0, 6, 0, 0, p5 ;START (ONLY INIT) BAR DISPLAY INSTR
87 endin
88
89 instr 6 ;BAR DISPLAY
90 ;All leds OFF
91 outvalue "Bar1", 0
92 outvalue "Bar2", 0
93 outvalue "Bar3", 0
94 outvalue "Bar4", 0
95
96 ;One led ON
97 if p4 = 0 igoto BAR1
98 if p4 = 1 igoto BAR2
99 if p4 = 2 igoto BAR3
100 if p4 = 3 igoto BAR4
101
102 BAR1:
103 outvalue "Bar1", 1
104 igoto END
105 BAR2:
106 outvalue "Bar2", 1
107 igoto END
108 BAR3:
109 outvalue "Bar3", 1
110 igoto END
111 BAR4:
112 outvalue "Bar4", 1
113 igoto END
114 END:
115 endin
116 </CsInstruments>
117 <CsScore>
118 i 10 0 3600 ;GUI - REAL TIME PERFORMANCE FOR 1 HOUR
119 </CsScore>
120 </CsoundSynthesizer>
121 <bsbPanel>
122 <label>Widgets</label>
123 <objectName/>
124 <x>924</x>
125 <y>199</y>
126 <width>522</width>
127 <height>377</height>
128 <visible>true</visible>
129 <uuid/>
130 <bgcolor mode="background">
131 <r>170</r>
132 <g>170</g>
133 <b>170</b>
134 </bgcolor>
135 <bsbObject version="2" type="BSBLabel">
136 <objectName/>
137 <x>2</x>
138 <y>2</y>
139 <width>516</width>
140 <height>371</height>
141 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
142 <visible>true</visible>
143 <midichan>0</midichan>
144 <midicc>0</midicc>
145 <label>Live Quantize</label>
146 <alignment>center</alignment>
147 <font>Liberation Sans</font>
148 <fontsize>18</fontsize>
149 <precision>3</precision>
150 <color>
151 <r>0</r>
152 <g>0</g>
153 <b>0</b>
154 </color>
155 <bgcolor mode="background">
156 <r>244</r>
157 <g>248</g>
158 <b>200</b>
159 </bgcolor>
160 <bordermode>border</bordermode>
161 <borderradius>5</borderradius>
162 <borderwidth>2</borderwidth>
163 </bsbObject>
164 <bsbObject version="2" type="BSBLabel">
165 <objectName/>
166 <x>7</x>
167 <y>21</y>
168 <width>505</width>
169 <height>240</height>
170 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
171 <visible>true</visible>
172 <midichan>0</midichan>
173 <midicc>0</midicc>
174 <label>----------------------------------------------------------------------------------------------------------------------------
175 This example quantizes an incoming stream of MIDI notes according to an internal metronone. If a MIDI note-on is received the orchestra calculates how much time will elapse until the next beat and then delays the onset of the note by that amount. To provide the user with the frame of reference used by the orchestra, a metronome sounds the beats of a 4/4 bar as well as this being indicated visually with flashing dots. 'Beat Subdiv' defines how the quantizing grid relates to the beats outlined by the metronome. Giving this a value of '1' will cause each note-on to be moved to the next beat, giving it a value of '4' will cause it to move each note-on to the next quarter of a beat. Note onset delay is implemented by passing the duty of sounding the note onto another instrument through the 'schedkwhen' opcode. The 'start time' of the scheduled note is given the value of the derived delay time.</label>
176 <alignment>left</alignment>
177 <font>Liberation Sans</font>
178 <fontsize>14</fontsize>
179 <precision>3</precision>
180 <color>
181 <r>0</r>
182 <g>0</g>
183 <b>0</b>
184 </color>
185 <bgcolor mode="nobackground">
186 <r>255</r>
187 <g>255</g>
188 <b>255</b>
189 </bgcolor>
190 <bordermode>noborder</bordermode>
191 <borderradius>1</borderradius>
192 <borderwidth>1</borderwidth>
193 </bsbObject>
194 <bsbObject version="2" type="BSBLabel">
195 <objectName/>
196 <x>7</x>
197 <y>263</y>
198 <width>505</width>
199 <height>101</height>
200 <uuid>{b143f42f-2cbc-4532-8df7-4ba643c60b37}</uuid>
201 <visible>true</visible>
202 <midichan>0</midichan>
203 <midicc>0</midicc>
204 <label/>
205 <alignment>left</alignment>
206 <font>Liberation Sans</font>
207 <fontsize>10</fontsize>
208 <precision>3</precision>
209 <color>
210 <r>0</r>
211 <g>0</g>
212 <b>0</b>
213 </color>
214 <bgcolor mode="nobackground">
215 <r>255</r>
216 <g>255</g>
217 <b>255</b>
218 </bgcolor>
219 <bordermode>border</bordermode>
220 <borderradius>5</borderradius>
221 <borderwidth>2</borderwidth>
222 </bsbObject>
223 <bsbObject version="2" type="BSBLabel">
224 <objectName/>
225 <x>10</x>
226 <y>331</y>
227 <width>180</width>
228 <height>30</height>
229 <uuid>{2e52a7a7-dc13-405e-896d-db2a7431d8dd}</uuid>
230 <visible>true</visible>
231 <midichan>0</midichan>
232 <midicc>0</midicc>
233 <label>Metronone Volume</label>
234 <alignment>left</alignment>
235 <font>Liberation Sans</font>
236 <fontsize>10</fontsize>
237 <precision>3</precision>
238 <color>
239 <r>0</r>
240 <g>0</g>
241 <b>0</b>
242 </color>
243 <bgcolor mode="nobackground">
244 <r>255</r>
245 <g>255</g>
246 <b>255</b>
247 </bgcolor>
248 <bordermode>noborder</bordermode>
249 <borderradius>1</borderradius>
250 <borderwidth>1</borderwidth>
251 </bsbObject>
252 <bsbObject version="2" type="BSBHSlider">
253 <objectName>Metronone</objectName>
254 <x>10</x>
255 <y>313</y>
256 <width>500</width>
257 <height>26</height>
258 <uuid>{6ab84e0f-82a7-4b9c-af23-35bd7d9b7fa2}</uuid>
259 <visible>true</visible>
260 <midichan>0</midichan>
261 <midicc>0</midicc>
262 <minimum>0.00000000</minimum>
263 <maximum>1.00000000</maximum>
264 <value>1.00000000</value>
265 <mode>lin</mode>
266 <mouseControl act="jump">continuous</mouseControl>
267 <resolution>-1.00000000</resolution>
268 <randomizable group="0">false</randomizable>
269 </bsbObject>
270 <bsbObject version="2" type="BSBDisplay">
271 <objectName>Metronone</objectName>
272 <x>450</x>
273 <y>331</y>
274 <width>60</width>
275 <height>30</height>
276 <uuid>{99d6bf8b-3c85-4911-a29a-7dd678a940ed}</uuid>
277 <visible>true</visible>
278 <midichan>0</midichan>
279 <midicc>0</midicc>
280 <label>1.000</label>
281 <alignment>right</alignment>
282 <font>Liberation Sans</font>
283 <fontsize>9</fontsize>
284 <precision>3</precision>
285 <color>
286 <r>0</r>
287 <g>0</g>
288 <b>0</b>
289 </color>
290 <bgcolor mode="nobackground">
291 <r>255</r>
292 <g>255</g>
293 <b>255</b>
294 </bgcolor>
295 <bordermode>noborder</bordermode>
296 <borderradius>1</borderradius>
297 <borderwidth>1</borderwidth>
298 </bsbObject>
299 <bsbObject version="2" type="BSBSpinBox">
300 <objectName>Tempo</objectName>
301 <x>175</x>
302 <y>272</y>
303 <width>60</width>
304 <height>30</height>
305 <uuid>{d8448b52-b521-4a49-93f8-727644a5f9e8}</uuid>
306 <visible>true</visible>
307 <midichan>0</midichan>
308 <midicc>0</midicc>
309 <alignment>right</alignment>
310 <font>Liberation Sans</font>
311 <fontsize>16</fontsize>
312 <color>
313 <r>0</r>
314 <g>0</g>
315 <b>0</b>
316 </color>
317 <bgcolor mode="nobackground">
318 <r>255</r>
319 <g>255</g>
320 <b>255</b>
321 </bgcolor>
322 <resolution>1.00000000</resolution>
323 <minimum>1</minimum>
324 <maximum>999</maximum>
325 <randomizable group="0">false</randomizable>
326 <value>70</value>
327 </bsbObject>
328 <bsbObject version="2" type="BSBSpinBox">
329 <objectName>Beat</objectName>
330 <x>327</x>
331 <y>272</y>
332 <width>50</width>
333 <height>30</height>
334 <uuid>{7d9dfc10-dd27-4831-95ce-0f75db398265}</uuid>
335 <visible>true</visible>
336 <midichan>0</midichan>
337 <midicc>0</midicc>
338 <alignment>center</alignment>
339 <font>Liberation Sans</font>
340 <fontsize>16</fontsize>
341 <color>
342 <r>0</r>
343 <g>0</g>
344 <b>0</b>
345 </color>
346 <bgcolor mode="nobackground">
347 <r>255</r>
348 <g>255</g>
349 <b>255</b>
350 </bgcolor>
351 <resolution>1.00000000</resolution>
352 <minimum>1</minimum>
353 <maximum>4</maximum>
354 <randomizable group="0">false</randomizable>
355 <value>1</value>
356 </bsbObject>
357 <bsbObject version="2" type="BSBLabel">
358 <objectName/>
359 <x>111</x>
360 <y>272</y>
361 <width>64</width>
362 <height>30</height>
363 <uuid>{a3c622cc-d6a0-4f7c-b9b8-5179d6261036}</uuid>
364 <visible>true</visible>
365 <midichan>0</midichan>
366 <midicc>0</midicc>
367 <label>Tempo</label>
368 <alignment>right</alignment>
369 <font>Liberation Sans</font>
370 <fontsize>10</fontsize>
371 <precision>3</precision>
372 <color>
373 <r>0</r>
374 <g>0</g>
375 <b>0</b>
376 </color>
377 <bgcolor mode="nobackground">
378 <r>255</r>
379 <g>255</g>
380 <b>255</b>
381 </bgcolor>
382 <bordermode>noborder</bordermode>
383 <borderradius>1</borderradius>
384 <borderwidth>1</borderwidth>
385 </bsbObject>
386 <bsbObject version="2" type="BSBLabel">
387 <objectName/>
388 <x>235</x>
389 <y>272</y>
390 <width>93</width>
391 <height>30</height>
392 <uuid>{830ca56f-fafc-4c8c-b8b0-8ac877fd49ac}</uuid>
393 <visible>true</visible>
394 <midichan>0</midichan>
395 <midicc>0</midicc>
396 <label>Beat Subdiv.</label>
397 <alignment>right</alignment>
398 <font>Liberation Sans</font>
399 <fontsize>10</fontsize>
400 <precision>3</precision>
401 <color>
402 <r>0</r>
403 <g>0</g>
404 <b>0</b>
405 </color>
406 <bgcolor mode="nobackground">
407 <r>255</r>
408 <g>255</g>
409 <b>255</b>
410 </bgcolor>
411 <bordermode>noborder</bordermode>
412 <borderradius>1</borderradius>
413 <borderwidth>1</borderwidth>
414 </bsbObject>
415 <bsbObject version="2" type="BSBButton">
416 <objectName>On_Off</objectName>
417 <x>11</x>
418 <y>272</y>
419 <width>100</width>
420 <height>30</height>
421 <uuid>{cee5f52d-8107-43c3-b3b3-e8d391cff31f}</uuid>
422 <visible>true</visible>
423 <midichan>0</midichan>
424 <midicc>0</midicc>
425 <type>value</type>
426 <pressedValue>1.00000000</pressedValue>
427 <stringvalue/>
428 <text> On/Off </text>
429 <image>/</image>
430 <eventLine/>
431 <latch>true</latch>
432 <latched>false</latched>
433 </bsbObject>
434 <bsbObject version="2" type="BSBController">
435 <objectName/>
436 <x>474</x>
437 <y>281</y>
438 <width>10</width>
439 <height>10</height>
440 <uuid>{ce49eac8-f6fc-4641-9137-14703a625ada}</uuid>
441 <visible>true</visible>
442 <midichan>0</midichan>
443 <midicc>0</midicc>
444 <objectName2>Bar4</objectName2>
445 <xMin>0.00000000</xMin>
446 <xMax>1.00000000</xMax>
447 <yMin>0.00000000</yMin>
448 <yMax>1.00000000</yMax>
449 <xValue>0.00000000</xValue>
450 <yValue>1.00000000</yValue>
451 <type>fill</type>
452 <pointsize>1</pointsize>
453 <fadeSpeed>0.00000000</fadeSpeed>
454 <mouseControl act="press">jump</mouseControl>
455 <color>
456 <r>255</r>
457 <g>0</g>
458 <b>0</b>
459 </color>
460 <randomizable mode="both" group="0">false</randomizable>
461 <bgcolor>
462 <r>0</r>
463 <g>0</g>
464 <b>0</b>
465 </bgcolor>
466 </bsbObject>
467 <bsbObject version="2" type="BSBController">
468 <objectName/>
469 <x>434</x>
470 <y>281</y>
471 <width>10</width>
472 <height>10</height>
473 <uuid>{2eb9cd3b-090b-40ae-92a3-f692e680f6e7}</uuid>
474 <visible>true</visible>
475 <midichan>0</midichan>
476 <midicc>0</midicc>
477 <objectName2>Bar2</objectName2>
478 <xMin>0.00000000</xMin>
479 <xMax>1.00000000</xMax>
480 <yMin>0.00000000</yMin>
481 <yMax>1.00000000</yMax>
482 <xValue>0.00000000</xValue>
483 <yValue>0.00000000</yValue>
484 <type>fill</type>
485 <pointsize>1</pointsize>
486 <fadeSpeed>0.00000000</fadeSpeed>
487 <mouseControl act="press">jump</mouseControl>
488 <color>
489 <r>255</r>
490 <g>0</g>
491 <b>0</b>
492 </color>
493 <randomizable mode="both" group="0">false</randomizable>
494 <bgcolor>
495 <r>0</r>
496 <g>0</g>
497 <b>0</b>
498 </bgcolor>
499 </bsbObject>
500 <bsbObject version="2" type="BSBController">
501 <objectName/>
502 <x>454</x>
503 <y>281</y>
504 <width>10</width>
505 <height>10</height>
506 <uuid>{7e14a3fd-0993-4a44-b46f-f1ebd1347718}</uuid>
507 <visible>true</visible>
508 <midichan>0</midichan>
509 <midicc>0</midicc>
510 <objectName2>Bar3</objectName2>
511 <xMin>0.00000000</xMin>
512 <xMax>1.00000000</xMax>
513 <yMin>0.00000000</yMin>
514 <yMax>1.00000000</yMax>
515 <xValue>0.00000000</xValue>
516 <yValue>0.00000000</yValue>
517 <type>fill</type>
518 <pointsize>1</pointsize>
519 <fadeSpeed>0.00000000</fadeSpeed>
520 <mouseControl act="press">jump</mouseControl>
521 <color>
522 <r>255</r>
523 <g>0</g>
524 <b>0</b>
525 </color>
526 <randomizable mode="both" group="0">false</randomizable>
527 <bgcolor>
528 <r>0</r>
529 <g>0</g>
530 <b>0</b>
531 </bgcolor>
532 </bsbObject>
533 <bsbObject version="2" type="BSBController">
534 <objectName/>
535 <x>414</x>
536 <y>281</y>
537 <width>10</width>
538 <height>10</height>
539 <uuid>{752e89e5-4151-468a-9cfd-e5dc4a042af0}</uuid>
540 <visible>true</visible>
541 <midichan>0</midichan>
542 <midicc>0</midicc>
543 <objectName2>Bar1</objectName2>
544 <xMin>0.00000000</xMin>
545 <xMax>1.00000000</xMax>
546 <yMin>0.00000000</yMin>
547 <yMax>1.00000000</yMax>
548 <xValue>0.00000000</xValue>
549 <yValue>0.00000000</yValue>
550 <type>fill</type>
551 <pointsize>1</pointsize>
552 <fadeSpeed>0.00000000</fadeSpeed>
553 <mouseControl act="press">jump</mouseControl>
554 <color>
555 <r>255</r>
556 <g>0</g>
557 <b>0</b>
558 </color>
559 <randomizable mode="both" group="0">false</randomizable>
560 <bgcolor>
561 <r>0</r>
562 <g>0</g>
563 <b>0</b>
564 </bgcolor>
565 </bsbObject>
566 </bsbPanel>
567 <bsbPresets>
568 </bsbPresets>
569 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>