Debian Codegraph @

src/Examples/CsoundQt/Getting Started/Realtime_Interaction/MIDI_Synth.csd

raw
1 /*Getting started.. Realtime Interaction: MIDI Notes / MIDI Synth
2
3 Generating the frequency for one voice, has to become computed individually for each midi note. So a new instance of instr 1 is started for every key pressed on the keyboard.
4
5 Instruments 101 (Feedback Delay) and 102 (Reverb) are global effects, which are not necessary to compute for each individual voice independently. So started once from the score, one instance each runs constantly whether a note is played or not. The Widget Panel, gives access to some of their parameters. You can add more..
6 */
7
8 <CsoundSynthesizer>
9 <CsOptions>
10 --midi-key-cps=4 --midi-velocity=5
11 </CsOptions>
12 <CsInstruments>
13
14 sr = 44100
15 ksmps = 32
16 nchnls = 2
17 0dbfs = 1
18
19 gaOut init 0.0 ; a global audio variable is initialised, this can be seen as an "global audio Bus" (g.a.Bus), where audiodata can be send and read from, but first it is NULL
20
21 instr 1 ; Sawthooth Oscillator triggered with notes on MIDI CH: 1
22 icps = p4
23 iamp = p5/127 ; MIDI received velocity (from 0-127), becomes devided by 127 -> amplitude-range is now 0-1
24 kFfreq invalue "filter_freq"
25 kFfreq port kFfreq, 0.05
26
27 aSrc oscili iamp, icps, 1 ; reads form f-table 1, containing a sawthooth waveform
28 aFiltered moogvcf aSrc, kFfreq, 0.1 ; the source signal becomes low pass filtered
29 aEnv madsr 0.01, 0.1, 0.9, 0.01 ; defining the envelope
30 gaOut = (aFiltered*aEnv) + gaOut ; the signal becomes scaled by the envelope and is added to the "g.a.Bus"
31 ; that no information (from other sources, or simultaneous voices) which already exists on the global variable will be lost, itself needs to become added as well
32 endin
33
34 instr 2 ; Sine Oscillator triggered with notes on MIDI CH: 2
35 icps = p4
36 iamp = p5/127
37 aSrc oscili iamp, icps, 2 ; this instrument reads from f-table 2, containing a sinus waveform
38 aEnv madsr 0.01, 0.1, 0.9, 0.01 ; defining the envelope
39 gaOut = (aSrc*aEnv) + gaOut
40 endin
41
42
43 instr 101 ; Global Feedback Delay
44 kDryWet invalue "d_w_delay" ; receive values from the Widget Panel
45 kDelTime invalue "time_delay"
46 kFeedback invalue "feedb_delay"
47 aDelay delayr 1 ; a delayline, with 1 second maximum delay-time is initialised
48 aWet deltapi kDelTime ; data at a flexible position is read from the delayline
49 delayw gaOut+(aWet*kFeedback) ; the "g.a.Bus" is written to the delayline, - to get a feedbackdelay, the delaysignal (aWet) is also added, but scaled by kFeedback
50 gaOut = (1-kDryWet) * gaOut + (kDryWet * aWet) ; the amount of pure-signal and delayed-signal is mixed, and written to the "g.a.Bus"
51 endin
52
53 instr 102 ; Global Reverb
54 kroomsize init 0.4 ; fixed values for reverb-roomsize and damp, but you can add knobs or faders on the Widget Panel and invalue the data here...
55 khfdamp init 0.8
56 kDryWet invalue "d_w_reverb"
57 aWetL, aWetR freeverb gaOut, gaOut, kroomsize, khfdamp ; the freeverb opcode works with stereo input, so we read twice the "g.a.Bus"
58 aOutL = (1-kDryWet) * gaOut + (kDryWet * aWetL) ; the amount of pure-signal (g.a.Bus) and reverbed-signal for the left side is mixed, and written to a local variable
59 aOutR = (1-kDryWet) * gaOut + (kDryWet * aWetR)
60 outs aOutL, aOutR ; main output of the final signal
61 gaOut = 0.0 ; clear the global audio channel for the next k-loop
62 endin
63
64
65 </CsInstruments>
66 <CsScore>
67 f 1 0 1024 7 0 512 1 0 -1 512 0
68 f 2 0 1024 10 1
69 i 101 0 3600 ; the delay runs for one hour
70 i 102 0 3600 ; the reverb runs for one hour
71 e
72 </CsScore>
73 </CsoundSynthesizer>
74 ; written by Alex Hofmann (Dec. 2009) - Incontri HMT-Hannover
75
76
77
78
79 <bsbPanel>
80 <label>Widgets</label>
81 <objectName/>
82 <x>1013</x>
83 <y>279</y>
84 <width>563</width>
85 <height>397</height>
86 <visible>true</visible>
87 <uuid/>
88 <bgcolor mode="background">
89 <r>182</r>
90 <g>109</g>
91 <b>0</b>
92 </bgcolor>
93 <bsbObject version="2" type="BSBHSlider">
94 <objectName>d_w_reverb</objectName>
95 <x>22</x>
96 <y>458</y>
97 <width>311</width>
98 <height>38</height>
99 <uuid>{965ddedd-20e0-4abd-859a-dfd4ff860060}</uuid>
100 <visible>true</visible>
101 <midichan>0</midichan>
102 <midicc>-3</midicc>
103 <description/>
104 <minimum>0.00000000</minimum>
105 <maximum>1.00000000</maximum>
106 <value>0.18971100</value>
107 <mode>lin</mode>
108 <mouseControl act="jump">continuous</mouseControl>
109 <resolution>-1.00000000</resolution>
110 <randomizable group="0">false</randomizable>
111 </bsbObject>
112 <bsbObject version="2" type="BSBLabel">
113 <objectName/>
114 <x>22</x>
115 <y>421</y>
116 <width>131</width>
117 <height>35</height>
118 <uuid>{26d8fbb2-0a09-4332-9b18-5cc0250b8cf2}</uuid>
119 <visible>true</visible>
120 <midichan>0</midichan>
121 <midicc>-3</midicc>
122 <description/>
123 <label>Reverb Mix</label>
124 <alignment>left</alignment>
125 <valignment>top</valignment>
126 <font>Lucida Grande</font>
127 <fontsize>18</fontsize>
128 <precision>3</precision>
129 <color>
130 <r>0</r>
131 <g>0</g>
132 <b>0</b>
133 </color>
134 <bgcolor mode="nobackground">
135 <r>255</r>
136 <g>255</g>
137 <b>255</b>
138 </bgcolor>
139 <bordermode>noborder</bordermode>
140 <borderradius>1</borderradius>
141 <borderwidth>0</borderwidth>
142 </bsbObject>
143 <bsbObject version="2" type="BSBHSlider">
144 <objectName>d_w_delay</objectName>
145 <x>22</x>
146 <y>277</y>
147 <width>311</width>
148 <height>38</height>
149 <uuid>{b8bc48f2-c2b1-4687-85e7-1066b06a33c7}</uuid>
150 <visible>true</visible>
151 <midichan>0</midichan>
152 <midicc>-3</midicc>
153 <description/>
154 <minimum>0.00000000</minimum>
155 <maximum>1.00000000</maximum>
156 <value>0.07074000</value>
157 <mode>lin</mode>
158 <mouseControl act="jump">continuous</mouseControl>
159 <resolution>-1.00000000</resolution>
160 <randomizable group="0">false</randomizable>
161 </bsbObject>
162 <bsbObject version="2" type="BSBLabel">
163 <objectName/>
164 <x>22</x>
165 <y>240</y>
166 <width>131</width>
167 <height>35</height>
168 <uuid>{1c5ee867-4ad1-434f-a5e0-6ea3dafd89b3}</uuid>
169 <visible>true</visible>
170 <midichan>0</midichan>
171 <midicc>-3</midicc>
172 <description/>
173 <label>Delay Mix</label>
174 <alignment>left</alignment>
175 <valignment>top</valignment>
176 <font>Lucida Grande</font>
177 <fontsize>18</fontsize>
178 <precision>3</precision>
179 <color>
180 <r>0</r>
181 <g>0</g>
182 <b>0</b>
183 </color>
184 <bgcolor mode="nobackground">
185 <r>255</r>
186 <g>255</g>
187 <b>255</b>
188 </bgcolor>
189 <bordermode>noborder</bordermode>
190 <borderradius>1</borderradius>
191 <borderwidth>0</borderwidth>
192 </bsbObject>
193 <bsbObject version="2" type="BSBVSlider">
194 <objectName>time_delay</objectName>
195 <x>244</x>
196 <y>147</y>
197 <width>20</width>
198 <height>100</height>
199 <uuid>{8dbbbd5a-8e3f-48ad-9b17-4d4ec077d56f}</uuid>
200 <visible>true</visible>
201 <midichan>0</midichan>
202 <midicc>-3</midicc>
203 <description/>
204 <minimum>0.05000000</minimum>
205 <maximum>1.00000000</maximum>
206 <value>0.35400000</value>
207 <mode>lin</mode>
208 <mouseControl act="jump">continuous</mouseControl>
209 <resolution>-1.00000000</resolution>
210 <randomizable group="0">false</randomizable>
211 </bsbObject>
212 <bsbObject version="2" type="BSBVSlider">
213 <objectName>feedb_delay</objectName>
214 <x>313</x>
215 <y>148</y>
216 <width>20</width>
217 <height>100</height>
218 <uuid>{60c2bf77-6001-4508-98c7-9b589819aee1}</uuid>
219 <visible>true</visible>
220 <midichan>0</midichan>
221 <midicc>-3</midicc>
222 <description/>
223 <minimum>0.05000000</minimum>
224 <maximum>1.00000000</maximum>
225 <value>0.47750000</value>
226 <mode>lin</mode>
227 <mouseControl act="jump">continuous</mouseControl>
228 <resolution>-1.00000000</resolution>
229 <randomizable group="0">false</randomizable>
230 </bsbObject>
231 <bsbObject version="2" type="BSBLabel">
232 <objectName/>
233 <x>235</x>
234 <y>121</y>
235 <width>45</width>
236 <height>23</height>
237 <uuid>{db1823ae-b35e-452a-9d18-71821c7feb40}</uuid>
238 <visible>true</visible>
239 <midichan>0</midichan>
240 <midicc>-3</midicc>
241 <description/>
242 <label>Time</label>
243 <alignment>left</alignment>
244 <valignment>top</valignment>
245 <font>Lucida Grande</font>
246 <fontsize>10</fontsize>
247 <precision>3</precision>
248 <color>
249 <r>0</r>
250 <g>0</g>
251 <b>0</b>
252 </color>
253 <bgcolor mode="nobackground">
254 <r>255</r>
255 <g>255</g>
256 <b>255</b>
257 </bgcolor>
258 <bordermode>noborder</bordermode>
259 <borderradius>1</borderradius>
260 <borderwidth>0</borderwidth>
261 </bsbObject>
262 <bsbObject version="2" type="BSBLabel">
263 <objectName/>
264 <x>294</x>
265 <y>121</y>
266 <width>57</width>
267 <height>23</height>
268 <uuid>{d7b1bce9-3493-4b44-81cb-6fe3917d3e79}</uuid>
269 <visible>true</visible>
270 <midichan>0</midichan>
271 <midicc>-3</midicc>
272 <description/>
273 <label>Feedback</label>
274 <alignment>left</alignment>
275 <valignment>top</valignment>
276 <font>Lucida Grande</font>
277 <fontsize>10</fontsize>
278 <precision>3</precision>
279 <color>
280 <r>0</r>
281 <g>0</g>
282 <b>0</b>
283 </color>
284 <bgcolor mode="nobackground">
285 <r>255</r>
286 <g>255</g>
287 <b>255</b>
288 </bgcolor>
289 <bordermode>noborder</bordermode>
290 <borderradius>1</borderradius>
291 <borderwidth>0</borderwidth>
292 </bsbObject>
293 <bsbObject version="2" type="BSBLabel">
294 <objectName/>
295 <x>22</x>
296 <y>116</y>
297 <width>184</width>
298 <height>35</height>
299 <uuid>{bff2f5ef-9393-4a63-be7d-f9ba7f9e6ed9}</uuid>
300 <visible>true</visible>
301 <midichan>0</midichan>
302 <midicc>-3</midicc>
303 <description/>
304 <label>DELAY SECTION</label>
305 <alignment>left</alignment>
306 <valignment>top</valignment>
307 <font>Noto Sans</font>
308 <fontsize>18</fontsize>
309 <precision>3</precision>
310 <color>
311 <r>0</r>
312 <g>0</g>
313 <b>0</b>
314 </color>
315 <bgcolor mode="nobackground">
316 <r>255</r>
317 <g>255</g>
318 <b>255</b>
319 </bgcolor>
320 <bordermode>true</bordermode>
321 <borderradius>1</borderradius>
322 <borderwidth>1</borderwidth>
323 </bsbObject>
324 <bsbObject version="2" type="BSBLabel">
325 <objectName/>
326 <x>21</x>
327 <y>313</y>
328 <width>80</width>
329 <height>25</height>
330 <uuid>{f1ea1508-3b35-40d8-8a18-b3866212a5cd}</uuid>
331 <visible>true</visible>
332 <midichan>0</midichan>
333 <midicc>-3</midicc>
334 <description/>
335 <label>Dry</label>
336 <alignment>left</alignment>
337 <valignment>top</valignment>
338 <font>Lucida Grande</font>
339 <fontsize>10</fontsize>
340 <precision>3</precision>
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 <bordermode>noborder</bordermode>
352 <borderradius>1</borderradius>
353 <borderwidth>0</borderwidth>
354 </bsbObject>
355 <bsbObject version="2" type="BSBLabel">
356 <objectName/>
357 <x>294</x>
358 <y>315</y>
359 <width>37</width>
360 <height>27</height>
361 <uuid>{8e7b41c0-8c87-4bea-ad04-4b8cf886cd69}</uuid>
362 <visible>true</visible>
363 <midichan>0</midichan>
364 <midicc>-3</midicc>
365 <description/>
366 <label>Wet</label>
367 <alignment>left</alignment>
368 <valignment>top</valignment>
369 <font>Lucida Grande</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>0</borderwidth>
385 </bsbObject>
386 <bsbObject version="2" type="BSBLabel">
387 <objectName/>
388 <x>22</x>
389 <y>494</y>
390 <width>80</width>
391 <height>25</height>
392 <uuid>{0e2fb652-9ae9-43f4-b61e-b22ab50a5607}</uuid>
393 <visible>true</visible>
394 <midichan>0</midichan>
395 <midicc>-3</midicc>
396 <description/>
397 <label>Dry</label>
398 <alignment>left</alignment>
399 <valignment>top</valignment>
400 <font>Lucida Grande</font>
401 <fontsize>10</fontsize>
402 <precision>3</precision>
403 <color>
404 <r>0</r>
405 <g>0</g>
406 <b>0</b>
407 </color>
408 <bgcolor mode="nobackground">
409 <r>255</r>
410 <g>255</g>
411 <b>255</b>
412 </bgcolor>
413 <bordermode>noborder</bordermode>
414 <borderradius>1</borderradius>
415 <borderwidth>0</borderwidth>
416 </bsbObject>
417 <bsbObject version="2" type="BSBLabel">
418 <objectName/>
419 <x>296</x>
420 <y>494</y>
421 <width>37</width>
422 <height>25</height>
423 <uuid>{6dbb3852-766d-478f-a270-db1249eca234}</uuid>
424 <visible>true</visible>
425 <midichan>0</midichan>
426 <midicc>-3</midicc>
427 <description/>
428 <label>Wet</label>
429 <alignment>left</alignment>
430 <valignment>top</valignment>
431 <font>Lucida Grande</font>
432 <fontsize>10</fontsize>
433 <precision>3</precision>
434 <color>
435 <r>0</r>
436 <g>0</g>
437 <b>0</b>
438 </color>
439 <bgcolor mode="nobackground">
440 <r>255</r>
441 <g>255</g>
442 <b>255</b>
443 </bgcolor>
444 <bordermode>noborder</bordermode>
445 <borderradius>1</borderradius>
446 <borderwidth>0</borderwidth>
447 </bsbObject>
448 <bsbObject version="2" type="BSBLabel">
449 <objectName/>
450 <x>20</x>
451 <y>381</y>
452 <width>184</width>
453 <height>35</height>
454 <uuid>{2c94e6b7-a8b7-4a2c-a420-a95fc5a7fd7a}</uuid>
455 <visible>true</visible>
456 <midichan>0</midichan>
457 <midicc>-3</midicc>
458 <description/>
459 <label>REVERB SECTION</label>
460 <alignment>left</alignment>
461 <valignment>top</valignment>
462 <font>Noto Sans</font>
463 <fontsize>18</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>true</bordermode>
476 <borderradius>1</borderradius>
477 <borderwidth>1</borderwidth>
478 </bsbObject>
479 <bsbObject version="2" type="BSBLabel">
480 <objectName/>
481 <x>223</x>
482 <y>250</y>
483 <width>69</width>
484 <height>24</height>
485 <uuid>{71d02974-0a9e-46d9-9bf5-13f597e24907}</uuid>
486 <visible>true</visible>
487 <midichan>0</midichan>
488 <midicc>-3</midicc>
489 <description/>
490 <label>50-1000 ms</label>
491 <alignment>left</alignment>
492 <valignment>top</valignment>
493 <font>Lucida Grande</font>
494 <fontsize>10</fontsize>
495 <precision>3</precision>
496 <color>
497 <r>0</r>
498 <g>0</g>
499 <b>0</b>
500 </color>
501 <bgcolor mode="nobackground">
502 <r>255</r>
503 <g>255</g>
504 <b>255</b>
505 </bgcolor>
506 <bordermode>noborder</bordermode>
507 <borderradius>1</borderradius>
508 <borderwidth>0</borderwidth>
509 </bsbObject>
510 <bsbObject version="2" type="BSBLabel">
511 <objectName/>
512 <x>300</x>
513 <y>251</y>
514 <width>69</width>
515 <height>24</height>
516 <uuid>{9805b83f-cbfb-4f90-bc8a-4fb9d0cf4bc4}</uuid>
517 <visible>true</visible>
518 <midichan>0</midichan>
519 <midicc>-3</midicc>
520 <description/>
521 <label>0-100 %</label>
522 <alignment>left</alignment>
523 <valignment>top</valignment>
524 <font>Lucida Grande</font>
525 <fontsize>10</fontsize>
526 <precision>3</precision>
527 <color>
528 <r>0</r>
529 <g>0</g>
530 <b>0</b>
531 </color>
532 <bgcolor mode="nobackground">
533 <r>255</r>
534 <g>255</g>
535 <b>255</b>
536 </bgcolor>
537 <bordermode>noborder</bordermode>
538 <borderradius>1</borderradius>
539 <borderwidth>0</borderwidth>
540 </bsbObject>
541 <bsbObject version="2" type="BSBLabel">
542 <objectName/>
543 <x>19</x>
544 <y>44</y>
545 <width>273</width>
546 <height>25</height>
547 <uuid>{93d0d968-20d9-4e1a-b1c0-224bf6a4f360}</uuid>
548 <visible>true</visible>
549 <midichan>0</midichan>
550 <midicc>-3</midicc>
551 <description/>
552 <label>Filterfrequency Control for Instr 1</label>
553 <alignment>left</alignment>
554 <valignment>top</valignment>
555 <font>Lucida Grande</font>
556 <fontsize>10</fontsize>
557 <precision>3</precision>
558 <color>
559 <r>0</r>
560 <g>0</g>
561 <b>0</b>
562 </color>
563 <bgcolor mode="nobackground">
564 <r>255</r>
565 <g>255</g>
566 <b>255</b>
567 </bgcolor>
568 <bordermode>noborder</bordermode>
569 <borderradius>1</borderradius>
570 <borderwidth>0</borderwidth>
571 </bsbObject>
572 <bsbObject version="2" type="BSBLabel">
573 <objectName/>
574 <x>19</x>
575 <y>9</y>
576 <width>184</width>
577 <height>35</height>
578 <uuid>{f8582472-2877-4113-8834-13da608069b8}</uuid>
579 <visible>true</visible>
580 <midichan>0</midichan>
581 <midicc>-3</midicc>
582 <description/>
583 <label>SYNTH SECTION</label>
584 <alignment>left</alignment>
585 <valignment>top</valignment>
586 <font>Noto Sans</font>
587 <fontsize>18</fontsize>
588 <precision>3</precision>
589 <color>
590 <r>0</r>
591 <g>0</g>
592 <b>0</b>
593 </color>
594 <bgcolor mode="nobackground">
595 <r>255</r>
596 <g>255</g>
597 <b>255</b>
598 </bgcolor>
599 <bordermode>true</bordermode>
600 <borderradius>1</borderradius>
601 <borderwidth>1</borderwidth>
602 </bsbObject>
603 <bsbObject version="2" type="BSBHSlider">
604 <objectName>filter_freq</objectName>
605 <x>18</x>
606 <y>68</y>
607 <width>311</width>
608 <height>38</height>
609 <uuid>{b868baaf-46dd-40eb-8b7b-f7afa7925c6a}</uuid>
610 <visible>true</visible>
611 <midichan>0</midichan>
612 <midicc>-3</midicc>
613 <description/>
614 <minimum>10.00000000</minimum>
615 <maximum>5000.00000000</maximum>
616 <value>1919.35691300</value>
617 <mode>lin</mode>
618 <mouseControl act="jump">continuous</mouseControl>
619 <resolution>-1.00000000</resolution>
620 <randomizable group="0">false</randomizable>
621 </bsbObject>
622 </bsbPanel>
623 <bsbPresets>
624 </bsbPresets>
625 <EventPanel name="Events" tempo="60.00000000" loop="8.00000000" x="60" y="304" width="604" height="322" visible="false" loopStart="0" loopEnd="0"> </EventPanel>