Debian Codegraph @

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

raw
1 /*Getting started.. Realtime Interaction: Open Sound Control
2
3 Open Sound Control (OSC) is a network protocol format for musical control data communication. A few of its advantages compared to MIDI are, that it's more accurate, quicker and much more flexible. With OSC you can easily send messages to other software like Max/Msp, Chuck or SuperCollider.
4
5 In this example, two instruments are built, which show OSC usage with CsoundQt.
6
7 Instrument 1000 will send OSC messages to an IP-adress. You can generate values on two different channels, on the yellow side of the Widget-Panel.
8 Instrument 1001 will receive the OSC data from an this IP-adress. When Csound is running, you can see the reactions on the blue side of the Widget-Panel.
9
10 Macros are used, to define the send and receive ports, so you can change them at the top of the example-file.
11
12 1. open the widget panel
13 2. press run, to start csound and its OSC responders
14 3. change the left slider value
15
16
17 */
18 <CsoundSynthesizer>
19 <CsOptions>
20 </CsOptions>
21 <CsInstruments>
22 ksmps=32
23
24 #define IPADDRESS # "localhost" #
25 #define S_PORT # 47120 #
26 #define R_PORT # 47120 #
27
28 turnon 1000 ; starts instrument 1000 immediately
29 turnon 1001 ; starts instrument 1001 immediately
30
31
32 instr 1000
33 kNumber invalue "sendNumber" ; receive data from the Widget
34 kSlider invalue "sendSlider"
35 Stext sprintf "%i", $S_PORT
36 outvalue "sndPortNum", Stext ; show the macro defined send-port-number on the Widget
37 OSCsend kNumber+kSlider, $IPADDRESS, $S_PORT, "/CsoundQt", "ff", kNumber, kSlider ; send data to the IP-adress, and port, when slider or number change
38 endin
39
40
41 instr 1001
42 kNumRcv init 0
43 kSldRcv init 0
44 Stext sprintf "%i", $R_PORT
45 outvalue "rcvPortNum", Stext ; show the macro defined receive-port-number on the Widget
46 ihandle OSCinit $R_PORT ; ; start the listening process for OSC messages on the defined receive port
47 kAction OSClisten ihandle, "/CsoundQt", "ff", kNumRcv, kSldRcv ; you must define the kind of data to receive, in this case (ff) both are floating point numbers
48 if (kAction == 1) then ; if data is received, then...
49 outvalue "rcvNumber", kNumRcv ; send the value to the channel, to update the Widgets right side
50 outvalue "rcvSlider", kSldRcv
51 endif ; ends the "if" part
52 endin
53
54
55 </CsInstruments>
56 <CsScore>
57 e 3600
58 </CsScore>
59 </CsoundSynthesizer>
60 ; written by Alex Hofmann (Dec. 2009) - Incontri HMT-Hannover
61
62 <bsbPanel>
63 <label>Widgets</label>
64 <objectName/>
65 <x>456</x>
66 <y>204</y>
67 <width>563</width>
68 <height>397</height>
69 <visible>true</visible>
70 <uuid/>
71 <bgcolor mode="background">
72 <r>125</r>
73 <g>162</g>
74 <b>160</b>
75 </bgcolor>
76 <bsbObject type="BSBLabel" version="2">
77 <objectName/>
78 <x>320</x>
79 <y>9</y>
80 <width>286</width>
81 <height>407</height>
82 <uuid>{954fadd5-cce1-413e-8112-89e726e598da}</uuid>
83 <visible>true</visible>
84 <midichan>0</midichan>
85 <midicc>-3</midicc>
86 <label>Instr 1001 receives OSC messages from port:</label>
87 <alignment>left</alignment>
88 <font>Lucida Grande</font>
89 <fontsize>10</fontsize>
90 <precision>3</precision>
91 <color>
92 <r>0</r>
93 <g>0</g>
94 <b>0</b>
95 </color>
96 <bgcolor mode="background">
97 <r>96</r>
98 <g>219</g>
99 <b>255</b>
100 </bgcolor>
101 <bordermode>noborder</bordermode>
102 <borderradius>3</borderradius>
103 <borderwidth>1</borderwidth>
104 </bsbObject>
105 <bsbObject type="BSBLabel" version="2">
106 <objectName/>
107 <x>14</x>
108 <y>8</y>
109 <width>286</width>
110 <height>407</height>
111 <uuid>{0e2ba158-c297-43ef-a8c0-97ee46884040}</uuid>
112 <visible>true</visible>
113 <midichan>0</midichan>
114 <midicc>-3</midicc>
115 <label>Instr 1000 send values via OSC to port:</label>
116 <alignment>left</alignment>
117 <font>Lucida Grande</font>
118 <fontsize>10</fontsize>
119 <precision>3</precision>
120 <color>
121 <r>0</r>
122 <g>0</g>
123 <b>0</b>
124 </color>
125 <bgcolor mode="background">
126 <r>246</r>
127 <g>255</g>
128 <b>17</b>
129 </bgcolor>
130 <bordermode>noborder</bordermode>
131 <borderradius>3</borderradius>
132 <borderwidth>1</borderwidth>
133 </bsbObject>
134 <bsbObject type="BSBScrollNumber" version="2">
135 <objectName>sendNumber</objectName>
136 <x>16</x>
137 <y>154</y>
138 <width>80</width>
139 <height>25</height>
140 <uuid>{054cd8e1-4a4f-44a5-9668-70e87bff0d9b}</uuid>
141 <visible>true</visible>
142 <midichan>0</midichan>
143 <midicc>-3</midicc>
144 <alignment>left</alignment>
145 <font>Lucida Grande</font>
146 <fontsize>10</fontsize>
147 <color>
148 <r>0</r>
149 <g>0</g>
150 <b>0</b>
151 </color>
152 <bgcolor mode="background">
153 <r>255</r>
154 <g>255</g>
155 <b>255</b>
156 </bgcolor>
157 <value>7.80000000</value>
158 <resolution>0.10000000</resolution>
159 <minimum>-999999999999.00000000</minimum>
160 <maximum>99999999999999.00000000</maximum>
161 <bordermode>border</bordermode>
162 <borderradius>1</borderradius>
163 <borderwidth>1</borderwidth>
164 <randomizable group="0">false</randomizable>
165 <mouseControl act=""/>
166 </bsbObject>
167 <bsbObject type="BSBVSlider" version="2">
168 <objectName>sendSlider</objectName>
169 <x>22</x>
170 <y>245</y>
171 <width>20</width>
172 <height>100</height>
173 <uuid>{10bd35db-21e2-4728-9b72-49ccd89f4343}</uuid>
174 <visible>true</visible>
175 <midichan>0</midichan>
176 <midicc>-3</midicc>
177 <minimum>0.00000000</minimum>
178 <maximum>1.00000000</maximum>
179 <value>0.48000000</value>
180 <mode>lin</mode>
181 <mouseControl act="jump">continuous</mouseControl>
182 <resolution>-1.00000000</resolution>
183 <randomizable group="0">false</randomizable>
184 </bsbObject>
185 <bsbObject type="BSBLabel" version="2">
186 <objectName/>
187 <x>16</x>
188 <y>128</y>
189 <width>104</width>
190 <height>25</height>
191 <uuid>{0ce4364a-da5a-4e7a-ba83-1557f1fb9857}</uuid>
192 <visible>true</visible>
193 <midichan>0</midichan>
194 <midicc>-3</midicc>
195 <label>Send this value</label>
196 <alignment>left</alignment>
197 <font>Lucida Grande</font>
198 <fontsize>10</fontsize>
199 <precision>3</precision>
200 <color>
201 <r>0</r>
202 <g>0</g>
203 <b>0</b>
204 </color>
205 <bgcolor mode="nobackground">
206 <r>255</r>
207 <g>255</g>
208 <b>255</b>
209 </bgcolor>
210 <bordermode>noborder</bordermode>
211 <borderradius>1</borderradius>
212 <borderwidth>1</borderwidth>
213 </bsbObject>
214 <bsbObject type="BSBScrollNumber" version="2">
215 <objectName>rcvNumber</objectName>
216 <x>329</x>
217 <y>143</y>
218 <width>80</width>
219 <height>25</height>
220 <uuid>{c548dd30-0a6b-4914-ab04-38fcedf9b1da}</uuid>
221 <visible>true</visible>
222 <midichan>0</midichan>
223 <midicc>-3</midicc>
224 <alignment>left</alignment>
225 <font>Lucida Grande</font>
226 <fontsize>10</fontsize>
227 <color>
228 <r>0</r>
229 <g>0</g>
230 <b>0</b>
231 </color>
232 <bgcolor mode="background">
233 <r>255</r>
234 <g>255</g>
235 <b>255</b>
236 </bgcolor>
237 <value>7.80000019</value>
238 <resolution>0.00100000</resolution>
239 <minimum>-999999999999.00000000</minimum>
240 <maximum>99999999999999.00000000</maximum>
241 <bordermode>border</bordermode>
242 <borderradius>1</borderradius>
243 <borderwidth>1</borderwidth>
244 <randomizable group="0">false</randomizable>
245 <mouseControl act=""/>
246 </bsbObject>
247 <bsbObject type="BSBLabel" version="2">
248 <objectName/>
249 <x>325</x>
250 <y>113</y>
251 <width>108</width>
252 <height>24</height>
253 <uuid>{f90b1400-53b9-4b93-b88d-09ab8f2bf22a}</uuid>
254 <visible>true</visible>
255 <midichan>0</midichan>
256 <midicc>-3</midicc>
257 <label>Receive the value</label>
258 <alignment>left</alignment>
259 <font>Lucida Grande</font>
260 <fontsize>10</fontsize>
261 <precision>3</precision>
262 <color>
263 <r>0</r>
264 <g>0</g>
265 <b>0</b>
266 </color>
267 <bgcolor mode="nobackground">
268 <r>255</r>
269 <g>255</g>
270 <b>255</b>
271 </bgcolor>
272 <bordermode>noborder</bordermode>
273 <borderradius>1</borderradius>
274 <borderwidth>1</borderwidth>
275 </bsbObject>
276 <bsbObject type="BSBLabel" version="2">
277 <objectName/>
278 <x>17</x>
279 <y>217</y>
280 <width>80</width>
281 <height>25</height>
282 <uuid>{32dde0b5-87c9-4230-bb82-453cc2cce1bd}</uuid>
283 <visible>true</visible>
284 <midichan>0</midichan>
285 <midicc>-3</midicc>
286 <label>Send this value</label>
287 <alignment>left</alignment>
288 <font>Lucida Grande</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 type="BSBLabel" version="2">
306 <objectName/>
307 <x>329</x>
308 <y>225</y>
309 <width>109</width>
310 <height>25</height>
311 <uuid>{b77c687c-f1e7-4a12-99d6-3cb8db6ac855}</uuid>
312 <visible>true</visible>
313 <midichan>0</midichan>
314 <midicc>-3</midicc>
315 <label>Receive the value</label>
316 <alignment>left</alignment>
317 <font>Lucida Grande</font>
318 <fontsize>10</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 type="BSBDisplay" version="2">
335 <objectName>sndPortNum</objectName>
336 <x>219</x>
337 <y>10</y>
338 <width>58</width>
339 <height>24</height>
340 <uuid>{31b2e623-6866-4939-a2ce-6d0057dfbe8a}</uuid>
341 <visible>true</visible>
342 <midichan>0</midichan>
343 <midicc>-3</midicc>
344 <label>47120</label>
345 <alignment>left</alignment>
346 <font>Lucida Grande</font>
347 <fontsize>10</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>border</bordermode>
360 <borderradius>3</borderradius>
361 <borderwidth>1</borderwidth>
362 </bsbObject>
363 <bsbObject type="BSBDisplay" version="2">
364 <objectName>rcvPortNum</objectName>
365 <x>548</x>
366 <y>11</y>
367 <width>51</width>
368 <height>24</height>
369 <uuid>{daa3b24a-6504-4f71-b8c1-adc5b21f5ae9}</uuid>
370 <visible>true</visible>
371 <midichan>0</midichan>
372 <midicc>-3</midicc>
373 <label>47120</label>
374 <alignment>left</alignment>
375 <font>Lucida Grande</font>
376 <fontsize>10</fontsize>
377 <precision>3</precision>
378 <color>
379 <r>0</r>
380 <g>0</g>
381 <b>0</b>
382 </color>
383 <bgcolor mode="nobackground">
384 <r>255</r>
385 <g>255</g>
386 <b>255</b>
387 </bgcolor>
388 <bordermode>border</bordermode>
389 <borderradius>3</borderradius>
390 <borderwidth>1</borderwidth>
391 </bsbObject>
392 <bsbObject type="BSBLabel" version="2">
393 <objectName/>
394 <x>16</x>
395 <y>32</y>
396 <width>281</width>
397 <height>70</height>
398 <uuid>{4569ab26-f769-4f4a-8519-1b075ec54720}</uuid>
399 <visible>true</visible>
400 <midichan>0</midichan>
401 <midicc>-3</midicc>
402 <label>You can set the send port in the orc, by changing the macro S_PORT. The messages can be received by other OSC software like Pd, Max/Msp or SuperCollider, if Csound is not receiving the same port.</label>
403 <alignment>left</alignment>
404 <font>Lucida Grande</font>
405 <fontsize>10</fontsize>
406 <precision>3</precision>
407 <color>
408 <r>0</r>
409 <g>0</g>
410 <b>0</b>
411 </color>
412 <bgcolor mode="nobackground">
413 <r>255</r>
414 <g>255</g>
415 <b>255</b>
416 </bgcolor>
417 <bordermode>noborder</bordermode>
418 <borderradius>1</borderradius>
419 <borderwidth>1</borderwidth>
420 </bsbObject>
421 <bsbObject type="BSBLabel" version="2">
422 <objectName/>
423 <x>321</x>
424 <y>33</y>
425 <width>281</width>
426 <height>70</height>
427 <uuid>{a1f95929-e6b8-4062-8eeb-0f95cb1c26c4}</uuid>
428 <visible>true</visible>
429 <midichan>0</midichan>
430 <midicc>-3</midicc>
431 <label>You can set the receive port in the orc by the macro R_PORT. Pay attention that no other software (like Pd or SuperCollider) is already bound to the same Port, otherwhise Csound will crash.</label>
432 <alignment>left</alignment>
433 <font>Lucida Grande</font>
434 <fontsize>10</fontsize>
435 <precision>3</precision>
436 <color>
437 <r>0</r>
438 <g>0</g>
439 <b>0</b>
440 </color>
441 <bgcolor mode="nobackground">
442 <r>255</r>
443 <g>255</g>
444 <b>255</b>
445 </bgcolor>
446 <bordermode>noborder</bordermode>
447 <borderradius>1</borderradius>
448 <borderwidth>1</borderwidth>
449 </bsbObject>
450 <bsbObject type="BSBDisplay" version="2">
451 <objectName>sendSlider</objectName>
452 <x>17</x>
453 <y>350</y>
454 <width>80</width>
455 <height>25</height>
456 <uuid>{98463a56-ef4a-4b20-b396-a8a64441ae16}</uuid>
457 <visible>true</visible>
458 <midichan>0</midichan>
459 <midicc>-3</midicc>
460 <label>0.480</label>
461 <alignment>left</alignment>
462 <font>Lucida Grande</font>
463 <fontsize>10</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>border</bordermode>
476 <borderradius>1</borderradius>
477 <borderwidth>1</borderwidth>
478 </bsbObject>
479 <bsbObject type="BSBDisplay" version="2">
480 <objectName>rcvSlider</objectName>
481 <x>325</x>
482 <y>359</y>
483 <width>80</width>
484 <height>25</height>
485 <uuid>{b123860f-78bb-4fdf-a8c2-318cd7ce69ea}</uuid>
486 <visible>true</visible>
487 <midichan>0</midichan>
488 <midicc>-3</midicc>
489 <label>0.480</label>
490 <alignment>left</alignment>
491 <font>Lucida Grande</font>
492 <fontsize>10</fontsize>
493 <precision>3</precision>
494 <color>
495 <r>0</r>
496 <g>0</g>
497 <b>0</b>
498 </color>
499 <bgcolor mode="nobackground">
500 <r>255</r>
501 <g>255</g>
502 <b>255</b>
503 </bgcolor>
504 <bordermode>border</bordermode>
505 <borderradius>1</borderradius>
506 <borderwidth>1</borderwidth>
507 </bsbObject>
508 <bsbObject type="BSBVSlider" version="2">
509 <objectName>rcvSlider</objectName>
510 <x>332</x>
511 <y>253</y>
512 <width>22</width>
513 <height>99</height>
514 <uuid>{17bc5558-e8b2-4705-9b4c-417fe548d1d5}</uuid>
515 <visible>true</visible>
516 <midichan>0</midichan>
517 <midicc>-3</midicc>
518 <minimum>0.00000000</minimum>
519 <maximum>1.00000000</maximum>
520 <value>0.47999999</value>
521 <mode>lin</mode>
522 <mouseControl act="jump">continuous</mouseControl>
523 <resolution>-1.00000000</resolution>
524 <randomizable group="0">false</randomizable>
525 </bsbObject>
526 <bsbObject type="BSBLabel" version="2">
527 <objectName/>
528 <x>95</x>
529 <y>155</y>
530 <width>151</width>
531 <height>24</height>
532 <uuid>{23b1c772-14d1-4112-ae09-010b4f8c51de}</uuid>
533 <visible>true</visible>
534 <midichan>0</midichan>
535 <midicc>-3</midicc>
536 <label>-> Channel "sendNumber"</label>
537 <alignment>left</alignment>
538 <font>Lucida Grande</font>
539 <fontsize>10</fontsize>
540 <precision>3</precision>
541 <color>
542 <r>0</r>
543 <g>0</g>
544 <b>0</b>
545 </color>
546 <bgcolor mode="nobackground">
547 <r>255</r>
548 <g>255</g>
549 <b>255</b>
550 </bgcolor>
551 <bordermode>noborder</bordermode>
552 <borderradius>1</borderradius>
553 <borderwidth>1</borderwidth>
554 </bsbObject>
555 <bsbObject type="BSBLabel" version="2">
556 <objectName/>
557 <x>92</x>
558 <y>278</y>
559 <width>151</width>
560 <height>24</height>
561 <uuid>{f79c35f4-b208-4337-9c1b-7d98e98c8a3f}</uuid>
562 <visible>true</visible>
563 <midichan>0</midichan>
564 <midicc>-3</midicc>
565 <label>-> Channel "sendSlider"</label>
566 <alignment>left</alignment>
567 <font>Lucida Grande</font>
568 <fontsize>10</fontsize>
569 <precision>3</precision>
570 <color>
571 <r>0</r>
572 <g>0</g>
573 <b>0</b>
574 </color>
575 <bgcolor mode="nobackground">
576 <r>255</r>
577 <g>255</g>
578 <b>255</b>
579 </bgcolor>
580 <bordermode>noborder</bordermode>
581 <borderradius>1</borderradius>
582 <borderwidth>1</borderwidth>
583 </bsbObject>
584 <bsbObject type="BSBLabel" version="2">
585 <objectName/>
586 <x>413</x>
587 <y>296</y>
588 <width>151</width>
589 <height>24</height>
590 <uuid>{375a1727-8231-45e4-bd40-8896b0c9fbe7}</uuid>
591 <visible>true</visible>
592 <midichan>0</midichan>
593 <midicc>-3</midicc>
594 <label>Channel "rcvSlider"</label>
595 <alignment>left</alignment>
596 <font>Lucida Grande</font>
597 <fontsize>10</fontsize>
598 <precision>3</precision>
599 <color>
600 <r>0</r>
601 <g>0</g>
602 <b>0</b>
603 </color>
604 <bgcolor mode="nobackground">
605 <r>255</r>
606 <g>255</g>
607 <b>255</b>
608 </bgcolor>
609 <bordermode>noborder</bordermode>
610 <borderradius>1</borderradius>
611 <borderwidth>1</borderwidth>
612 </bsbObject>
613 <bsbObject type="BSBLabel" version="2">
614 <objectName/>
615 <x>415</x>
616 <y>144</y>
617 <width>151</width>
618 <height>24</height>
619 <uuid>{8ba9eac0-f85d-4121-8bbd-d31bb788f056}</uuid>
620 <visible>true</visible>
621 <midichan>0</midichan>
622 <midicc>-3</midicc>
623 <label>Channel "rcvNumber"</label>
624 <alignment>left</alignment>
625 <font>Lucida Grande</font>
626 <fontsize>10</fontsize>
627 <precision>3</precision>
628 <color>
629 <r>0</r>
630 <g>0</g>
631 <b>0</b>
632 </color>
633 <bgcolor mode="nobackground">
634 <r>255</r>
635 <g>255</g>
636 <b>255</b>
637 </bgcolor>
638 <bordermode>noborder</bordermode>
639 <borderradius>1</borderradius>
640 <borderwidth>1</borderwidth>
641 </bsbObject>
642 </bsbPanel>
643 <bsbPresets>
644 </bsbPresets>
645 <EventPanel name="Events" tempo="60.00000000" loop="8.00000000" x="320" y="218" width="604" height="322" visible="false" loopStart="0" loopEnd="0"> </EventPanel>