Debian Codegraph @

src/Examples/McCurdy Collection/MIDI/MonoOverlaps.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 table(s) for exp slider
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 = 2 ;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 giwaveform ftgen 0,0,4096,10,1,.5,.25,.125,.0625 ;A RICH HARMONIC WAVEFORM
23 gkvoice init 1 ;GLOBAL VARIABLE USED TO DEFINE WHETHER VOICE 1 OR VOICE 2 IS CURRENT
24
25 giExp1 ftgen 0, 0, 129, -25, 0, 0.01, 128, 2.0 ;TABLE FOR EXP SLIDER
26 giExp2 ftgen 0, 0, 129, -25, 0, 0.01, 128, 8.0 ;TABLE FOR EXP SLIDER
27
28
29 instr 10 ;GUI
30 ktrig metro 10
31 if (ktrig == 1) then
32 katt invalue "Attack"
33 gkatt tablei katt, giExp1, 1
34 outvalue "Attack_Value", gkatt
35 kdec invalue "Decay"
36 gkdec tablei kdec, giExp2, 1
37 outvalue "Decay_Value", gkdec
38 gksus invalue "Sustain"
39 krel invalue "Release"
40 gkrel tablei krel, giExp1, 1
41 outvalue "Release_Value", gkrel
42 endif
43 endin
44
45 instr 1 ; NOTE TRIGGERING INSTRUMENT
46 icps cpsmidi ;READ CYCLES PER SECOND VALUES FROM MIDI KEYBOARD INPUT
47 asig subinstr i(gkvoice)+1, icps ;CALL SOUND GENERATING INSTRUMENT AS A SUB-INSTRUMENT
48 outs asig, asig ;SEND AUDIO TO OUTPUTS
49 endin
50
51 instr 2,3 ;SOUND GENERATING INSTRUMENTS
52 gkvoice init (i(gkvoice)=1?2:1) ;FLIP VOICE ALLOCATION AT INIT TIME
53 if gkvoice=p1-1 then ;IF THE OTHER VOICE IS NOW PLAYING...
54 turnoff ;...TURN THIS INSTRUMENT OFF (ENVELOPE RELEASE STAGE WILL BE ALLOWED TO COMPLETE)
55 endif ;END OF CONDITIONAL BRANCHING
56
57 ; ATT | DEC | SUS | REL
58 aenv madsr i(gkatt), i(gkdec), i(gksus), i(gkrel) ;MIDI SENSING ADSR ENVELOPE WITH EXPONENTIALLY SHAPED SEGMENTS
59 ;OUTPUT OPCODE AMP CPS FUNCTION_TABLE
60 asig oscili 0.1*aenv, p4, giwaveform ;AUDIO OSCILLATOR
61 outch 1, asig ;SEND AUDIO BACK TO INSTR 1
62 endin
63
64 instr 999 ;QUIT
65 exitnow ;EXIT CSOUND IMMEDIATELY
66 endin
67 </CsInstruments>
68 <CsScore>
69 i 10 0 3600 ;GUI - ALLOWS REAL-TIME PLAYING FOR 1 HOUR
70 </CsScore>
71 </CsoundSynthesizer>
72 <bsbPanel>
73 <label>Widgets</label>
74 <objectName/>
75 <x>461</x>
76 <y>257</y>
77 <width>1023</width>
78 <height>320</height>
79 <visible>true</visible>
80 <uuid/>
81 <bgcolor mode="background">
82 <r>170</r>
83 <g>170</g>
84 <b>170</b>
85 </bgcolor>
86 <bsbObject version="2" type="BSBLabel">
87 <objectName/>
88 <x>516</x>
89 <y>2</y>
90 <width>502</width>
91 <height>314</height>
92 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid>
93 <visible>true</visible>
94 <midichan>0</midichan>
95 <midicc>0</midicc>
96 <label>Monophonic Instrument with Overlapping Note Releases</label>
97 <alignment>center</alignment>
98 <font>Liberation Sans</font>
99 <fontsize>18</fontsize>
100 <precision>3</precision>
101 <color>
102 <r>0</r>
103 <g>0</g>
104 <b>0</b>
105 </color>
106 <bgcolor mode="background">
107 <r>244</r>
108 <g>248</g>
109 <b>200</b>
110 </bgcolor>
111 <bordermode>border</bordermode>
112 <borderradius>5</borderradius>
113 <borderwidth>2</borderwidth>
114 </bsbObject>
115 <bsbObject version="2" type="BSBLabel">
116 <objectName/>
117 <x>520</x>
118 <y>22</y>
119 <width>495</width>
120 <height>292</height>
121 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid>
122 <visible>true</visible>
123 <midichan>0</midichan>
124 <midicc>0</midicc>
125 <label>-------------------------------------------------------------------------------------------------------------------------
126 This example demonstrates how to design a monophonic instrument that allows the release portion of the envelope of the previous note to complete whilst a new note begins. This method prevents clicks that can result from more basic designs for monophonic instruments. Studying the code, you will see that there are actually two separate but identical sound generating instruments (instrs 2 and 3). As notes are played on a keyboard instr 1 alternately directs this note activity to instr 2 and 3. If instr 2 is triggered, instr 3 is stopped (but allowed to release) and vice versa. This technique could be expanded to implement polyphony limitation beyond monophonic. There are controls for an ADSR envelope that is applied to audio oscillators. The mxadsr opcode is used to implement the envelope in this example. With this opcode, envelope segments are exponential and the envelope waits for a MIDI note-off before entering its release stage.
127 This example requires input from an external MIDI keyboard or a virtual MIDI keyboard.</label>
128 <alignment>left</alignment>
129 <font>Liberation Sans</font>
130 <fontsize>14</fontsize>
131 <precision>3</precision>
132 <color>
133 <r>0</r>
134 <g>0</g>
135 <b>0</b>
136 </color>
137 <bgcolor mode="nobackground">
138 <r>255</r>
139 <g>255</g>
140 <b>255</b>
141 </bgcolor>
142 <bordermode>noborder</bordermode>
143 <borderradius>1</borderradius>
144 <borderwidth>1</borderwidth>
145 </bsbObject>
146 <bsbObject version="2" type="BSBLabel">
147 <objectName/>
148 <x>2</x>
149 <y>2</y>
150 <width>512</width>
151 <height>314</height>
152 <uuid>{9cb1f282-09da-4c18-87db-ffd36d585a0c}</uuid>
153 <visible>true</visible>
154 <midichan>0</midichan>
155 <midicc>0</midicc>
156 <label>Monophonic Instrument with Overlapping Note Releases</label>
157 <alignment>center</alignment>
158 <font>Liberation Sans</font>
159 <fontsize>18</fontsize>
160 <precision>3</precision>
161 <color>
162 <r>0</r>
163 <g>0</g>
164 <b>0</b>
165 </color>
166 <bgcolor mode="background">
167 <r>244</r>
168 <g>248</g>
169 <b>200</b>
170 </bgcolor>
171 <bordermode>border</bordermode>
172 <borderradius>5</borderradius>
173 <borderwidth>2</borderwidth>
174 </bsbObject>
175 <bsbObject version="2" type="BSBLabel">
176 <objectName/>
177 <x>8</x>
178 <y>66</y>
179 <width>180</width>
180 <height>30</height>
181 <uuid>{2e52a7a7-dc13-405e-896d-db2a7431d8dd}</uuid>
182 <visible>true</visible>
183 <midichan>0</midichan>
184 <midicc>0</midicc>
185 <label>Attack Time</label>
186 <alignment>left</alignment>
187 <font>Liberation Sans</font>
188 <fontsize>10</fontsize>
189 <precision>3</precision>
190 <color>
191 <r>0</r>
192 <g>0</g>
193 <b>0</b>
194 </color>
195 <bgcolor mode="nobackground">
196 <r>255</r>
197 <g>255</g>
198 <b>255</b>
199 </bgcolor>
200 <bordermode>noborder</bordermode>
201 <borderradius>1</borderradius>
202 <borderwidth>1</borderwidth>
203 </bsbObject>
204 <bsbObject version="2" type="BSBHSlider">
205 <objectName>Attack</objectName>
206 <x>8</x>
207 <y>49</y>
208 <width>500</width>
209 <height>27</height>
210 <uuid>{6ab84e0f-82a7-4b9c-af23-35bd7d9b7fa2}</uuid>
211 <visible>true</visible>
212 <midichan>0</midichan>
213 <midicc>0</midicc>
214 <minimum>0.00000000</minimum>
215 <maximum>1.00000000</maximum>
216 <value>0.43400000</value>
217 <mode>lin</mode>
218 <mouseControl act="jump">continuous</mouseControl>
219 <resolution>-1.00000000</resolution>
220 <randomizable group="0">false</randomizable>
221 </bsbObject>
222 <bsbObject version="2" type="BSBDisplay">
223 <objectName>Attack_Value</objectName>
224 <x>448</x>
225 <y>66</y>
226 <width>60</width>
227 <height>30</height>
228 <uuid>{99d6bf8b-3c85-4911-a29a-7dd678a940ed}</uuid>
229 <visible>true</visible>
230 <midichan>0</midichan>
231 <midicc>0</midicc>
232 <label>0.100</label>
233 <alignment>right</alignment>
234 <font>Liberation Sans</font>
235 <fontsize>9</fontsize>
236 <precision>3</precision>
237 <color>
238 <r>0</r>
239 <g>0</g>
240 <b>0</b>
241 </color>
242 <bgcolor mode="nobackground">
243 <r>255</r>
244 <g>255</g>
245 <b>255</b>
246 </bgcolor>
247 <bordermode>noborder</bordermode>
248 <borderradius>1</borderradius>
249 <borderwidth>1</borderwidth>
250 </bsbObject>
251 <bsbObject version="2" type="BSBLabel">
252 <objectName/>
253 <x>8</x>
254 <y>113</y>
255 <width>180</width>
256 <height>30</height>
257 <uuid>{a8da19ef-d61e-452d-af2c-a79924c6890d}</uuid>
258 <visible>true</visible>
259 <midichan>0</midichan>
260 <midicc>0</midicc>
261 <label>Decay Time</label>
262 <alignment>left</alignment>
263 <font>Liberation Sans</font>
264 <fontsize>10</fontsize>
265 <precision>3</precision>
266 <color>
267 <r>0</r>
268 <g>0</g>
269 <b>0</b>
270 </color>
271 <bgcolor mode="nobackground">
272 <r>255</r>
273 <g>255</g>
274 <b>255</b>
275 </bgcolor>
276 <bordermode>noborder</bordermode>
277 <borderradius>1</borderradius>
278 <borderwidth>1</borderwidth>
279 </bsbObject>
280 <bsbObject version="2" type="BSBHSlider">
281 <objectName>Decay</objectName>
282 <x>8</x>
283 <y>96</y>
284 <width>500</width>
285 <height>27</height>
286 <uuid>{be1cab81-da6b-442b-bcc8-22c97579c797}</uuid>
287 <visible>true</visible>
288 <midichan>0</midichan>
289 <midicc>0</midicc>
290 <minimum>0.00000000</minimum>
291 <maximum>1.00000000</maximum>
292 <value>0.89800000</value>
293 <mode>lin</mode>
294 <mouseControl act="jump">continuous</mouseControl>
295 <resolution>-1.00000000</resolution>
296 <randomizable group="0">false</randomizable>
297 </bsbObject>
298 <bsbObject version="2" type="BSBDisplay">
299 <objectName>Decay_Value</objectName>
300 <x>448</x>
301 <y>113</y>
302 <width>60</width>
303 <height>30</height>
304 <uuid>{9596f9bd-afff-4b1f-8c39-be869c440d66}</uuid>
305 <visible>true</visible>
306 <midichan>0</midichan>
307 <midicc>0</midicc>
308 <label>4.046</label>
309 <alignment>right</alignment>
310 <font>Liberation Sans</font>
311 <fontsize>9</fontsize>
312 <precision>3</precision>
313 <color>
314 <r>0</r>
315 <g>0</g>
316 <b>0</b>
317 </color>
318 <bgcolor mode="nobackground">
319 <r>255</r>
320 <g>255</g>
321 <b>255</b>
322 </bgcolor>
323 <bordermode>noborder</bordermode>
324 <borderradius>1</borderradius>
325 <borderwidth>1</borderwidth>
326 </bsbObject>
327 <bsbObject version="2" type="BSBLabel">
328 <objectName/>
329 <x>8</x>
330 <y>160</y>
331 <width>180</width>
332 <height>30</height>
333 <uuid>{e646ae5a-1978-4b35-a55b-1c92c731a64a}</uuid>
334 <visible>true</visible>
335 <midichan>0</midichan>
336 <midicc>0</midicc>
337 <label>Sustain Level</label>
338 <alignment>left</alignment>
339 <font>Liberation Sans</font>
340 <fontsize>10</fontsize>
341 <precision>3</precision>
342 <color>
343 <r>0</r>
344 <g>0</g>
345 <b>0</b>
346 </color>
347 <bgcolor mode="nobackground">
348 <r>255</r>
349 <g>255</g>
350 <b>255</b>
351 </bgcolor>
352 <bordermode>noborder</bordermode>
353 <borderradius>1</borderradius>
354 <borderwidth>1</borderwidth>
355 </bsbObject>
356 <bsbObject version="2" type="BSBHSlider">
357 <objectName>Sustain</objectName>
358 <x>8</x>
359 <y>143</y>
360 <width>500</width>
361 <height>27</height>
362 <uuid>{62fc68cb-e133-4202-8b11-1367e23ed833}</uuid>
363 <visible>true</visible>
364 <midichan>0</midichan>
365 <midicc>0</midicc>
366 <minimum>0.00000000</minimum>
367 <maximum>1.00000000</maximum>
368 <value>0.45000000</value>
369 <mode>lin</mode>
370 <mouseControl act="jump">continuous</mouseControl>
371 <resolution>-1.00000000</resolution>
372 <randomizable group="0">false</randomizable>
373 </bsbObject>
374 <bsbObject version="2" type="BSBDisplay">
375 <objectName>Sustain</objectName>
376 <x>448</x>
377 <y>160</y>
378 <width>60</width>
379 <height>30</height>
380 <uuid>{ba6bd246-c54c-48aa-844b-8bbd9a6d042c}</uuid>
381 <visible>true</visible>
382 <midichan>0</midichan>
383 <midicc>0</midicc>
384 <label>0.450</label>
385 <alignment>right</alignment>
386 <font>Liberation Sans</font>
387 <fontsize>9</fontsize>
388 <precision>3</precision>
389 <color>
390 <r>0</r>
391 <g>0</g>
392 <b>0</b>
393 </color>
394 <bgcolor mode="nobackground">
395 <r>255</r>
396 <g>255</g>
397 <b>255</b>
398 </bgcolor>
399 <bordermode>noborder</bordermode>
400 <borderradius>1</borderradius>
401 <borderwidth>1</borderwidth>
402 </bsbObject>
403 <bsbObject version="2" type="BSBLabel">
404 <objectName/>
405 <x>8</x>
406 <y>207</y>
407 <width>180</width>
408 <height>30</height>
409 <uuid>{176b8dbf-8ba1-4489-95dc-30095dc766d9}</uuid>
410 <visible>true</visible>
411 <midichan>0</midichan>
412 <midicc>0</midicc>
413 <label>Release Time</label>
414 <alignment>left</alignment>
415 <font>Liberation Sans</font>
416 <fontsize>10</fontsize>
417 <precision>3</precision>
418 <color>
419 <r>0</r>
420 <g>0</g>
421 <b>0</b>
422 </color>
423 <bgcolor mode="nobackground">
424 <r>255</r>
425 <g>255</g>
426 <b>255</b>
427 </bgcolor>
428 <bordermode>noborder</bordermode>
429 <borderradius>1</borderradius>
430 <borderwidth>1</borderwidth>
431 </bsbObject>
432 <bsbObject version="2" type="BSBHSlider">
433 <objectName>Release</objectName>
434 <x>8</x>
435 <y>190</y>
436 <width>500</width>
437 <height>27</height>
438 <uuid>{20c53bec-f5cf-46d6-81b7-f2f9574d567e}</uuid>
439 <visible>true</visible>
440 <midichan>0</midichan>
441 <midicc>0</midicc>
442 <minimum>0.00000000</minimum>
443 <maximum>1.00000000</maximum>
444 <value>0.91800000</value>
445 <mode>lin</mode>
446 <mouseControl act="jump">continuous</mouseControl>
447 <resolution>-1.00000000</resolution>
448 <randomizable group="0">false</randomizable>
449 </bsbObject>
450 <bsbObject version="2" type="BSBDisplay">
451 <objectName>Release_Value</objectName>
452 <x>448</x>
453 <y>207</y>
454 <width>60</width>
455 <height>30</height>
456 <uuid>{f9658342-cd32-4d15-90b6-a27b75042579}</uuid>
457 <visible>true</visible>
458 <midichan>0</midichan>
459 <midicc>0</midicc>
460 <label>1.295</label>
461 <alignment>right</alignment>
462 <font>Liberation Sans</font>
463 <fontsize>9</fontsize>
464 <precision>3</precision>
465 <color>
466 <r>0</r>
467 <g>0</g>
468 <b>0</b>
469 </color>
470 <bgcolor mode="nobackground">
471 <r>255</r>
472 <g>255</g>
473 <b>255</b>
474 </bgcolor>
475 <bordermode>noborder</bordermode>
476 <borderradius>1</borderradius>
477 <borderwidth>1</borderwidth>
478 </bsbObject>
479 <bsbObject version="2" type="BSBButton">
480 <objectName/>
481 <x>408</x>
482 <y>256</y>
483 <width>100</width>
484 <height>30</height>
485 <uuid>{ce398444-215b-4ae2-98af-eb885bd5ebad}</uuid>
486 <visible>true</visible>
487 <midichan>0</midichan>
488 <midicc>0</midicc>
489 <type>event</type>
490 <pressedValue>1.00000000</pressedValue>
491 <stringvalue/>
492 <text>Exit</text>
493 <image>/</image>
494 <eventLine>i 999 0 0</eventLine>
495 <latch>false</latch>
496 <latched>false</latched>
497 </bsbObject>
498 <bsbObject version="2" type="BSBLabel">
499 <objectName/>
500 <x>226</x>
501 <y>258</y>
502 <width>180</width>
503 <height>30</height>
504 <uuid>{642a77e6-d731-4f03-a687-3ae7c0afa1bd}</uuid>
505 <visible>true</visible>
506 <midichan>0</midichan>
507 <midicc>0</midicc>
508 <label>Exit Csound Immediately</label>
509 <alignment>right</alignment>
510 <font>Liberation Sans</font>
511 <fontsize>12</fontsize>
512 <precision>3</precision>
513 <color>
514 <r>0</r>
515 <g>0</g>
516 <b>0</b>
517 </color>
518 <bgcolor mode="nobackground">
519 <r>255</r>
520 <g>255</g>
521 <b>255</b>
522 </bgcolor>
523 <bordermode>noborder</bordermode>
524 <borderradius>1</borderradius>
525 <borderwidth>1</borderwidth>
526 </bsbObject>
527 </bsbPanel>
528 <bsbPresets>
529 </bsbPresets>
530 <EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel>