| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-odac |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
|
| 7 |
/* |
| 8 |
Graph Widget |
| 9 |
|
| 10 |
Graph Widgets can display tables, audio signals and fft analysis. The currently |
| 11 |
visible table can be changed by sending values on the widget's channel. |
| 12 |
Positive values change the table by index and negative values change the |
| 13 |
table by table number. The displayed table can also be changed using the |
| 14 |
menu on the upper left corner. |
| 15 |
Graph widgets can also show the spectrum from signals using the dispfft opcode, |
| 16 |
or time varying signals (a-rate and k-rate) using the display opcode. |
| 17 |
In spectrum mode, clicking near a peak will detect and display the frequency |
| 18 |
of the highest peak near the mouse. If @getPeak was set, this value will also |
| 19 |
be output to the given named channel |
| 20 |
|
| 21 |
|
| 22 |
Keyboard Shortcuts: |
| 23 |
|
| 24 |
C: toggle table information (only in table mode) |
| 25 |
F: freeze graph (only in spectrum mode) |
| 26 |
G: toggle grid |
| 27 |
H: help, show a dialog with this information |
| 28 |
S: toggle selector menu |
| 29 |
Z: toggle scrollbars |
| 30 |
+/-: zoom in / out |
| 31 |
|
| 32 |
|
| 33 |
String commands: |
| 34 |
|
| 35 |
@set <index:int> Sets the index graph to be displayed, similar to `outvalue "graphid", index` |
| 36 |
@find fft <signal:str> |
| 37 |
@find audio <signal:str> |
| 38 |
@find table <tablenumber:int> |
| 39 |
@freeze <status:int> 1 - freeze the display, 0 - unfreeze |
| 40 |
@getPeak <chan:str> The peak frequency is output to the given named channel. The peak |
| 41 |
is output whenever the user clicks on a spectrum graph |
| 42 |
NB: see Examples/Useful/SpectrumAnalyzer for an example of this |
| 43 |
feature |
| 44 |
|
| 45 |
*/ |
| 46 |
|
| 47 |
sr = 44100 |
| 48 |
ksmps = 64 |
| 49 |
nchnls = 2 |
| 50 |
0dbfs = 1 |
| 51 |
|
| 52 |
gisin1 ftgen 0, 0, 1024, 10, 1 |
| 53 |
gisin2 ftgen 0, 0, 1024, 10, 1, 0.5, 0.333 |
| 54 |
gisin3 ftgen 0, 0, 1024, 10, 1, 0, 0.333, 0, 0.25, 0, 0.166 |
| 55 |
gisqr ftgen 0, 0, 1024, 7, 1, 512, 1, 0, -1, 512, -1 |
| 56 |
gisaw ftgen 0, 0, 1024, 7, 1, 1024, -1 |
| 57 |
|
| 58 |
instr Oscil |
| 59 |
|
| 60 |
itables[] fillarray gisin1, gisin2, gisin3, gisqr, gisaw |
| 61 |
kindex init -1 |
| 62 |
kindex invalue "tabindex" |
| 63 |
kindex = limit:k(kindex, 0, lenarray(itables)-1) |
| 64 |
ktab = itables[kindex] |
| 65 |
kfreq invalue "freq" |
| 66 |
asig oscilikt 0.2, kfreq, ktab |
| 67 |
asig *= 0.1 |
| 68 |
outch 1, asig, 2, asig |
| 69 |
|
| 70 |
dispfft asig, 0.05, 4096 |
| 71 |
|
| 72 |
adisp = asig*5 |
| 73 |
display adisp, 0.01 |
| 74 |
|
| 75 |
if timeinstk() == 1 || changed(kindex) == 1 then |
| 76 |
; A numeric value sent to the graph widget sets it to display graph |
| 77 |
; at that index. In this case, the graph is only enabled for tables, |
| 78 |
; so that the index corresponds to the index of the itables array |
| 79 |
; outvalue "graph1", kindex |
| 80 |
; Another possibility is to the the table number directly via the |
| 81 |
; @find command: |
| 82 |
; outvalue "graph1", sprintfk("@find table %d", ktab) |
| 83 |
; Or, you can set the table directly as negative number: |
| 84 |
outvalue "graph1", -ktab |
| 85 |
outvalue "plot1", ktab |
| 86 |
endif |
| 87 |
|
| 88 |
endin |
| 89 |
|
| 90 |
instr SetupGraphs |
| 91 |
; It is possible to select the desired graph through the @find string command |
| 92 |
|
| 93 |
outvalue "graph2", "@find fft asig" |
| 94 |
outvalue "graph3", "@find audio adisp" |
| 95 |
; outvalue "plot1", gisin1 |
| 96 |
|
| 97 |
; To select a table by number: |
| 98 |
; outvalue "graph1", sprintf("@find table %d", itabnum) |
| 99 |
turnoff |
| 100 |
endin |
| 101 |
|
| 102 |
; If started too early, the table display will fail |
| 103 |
schedule "Oscil", 0.3, -1 |
| 104 |
|
| 105 |
; setup the display graphs. Notice that we need to schedule this in the |
| 106 |
; future since audio and fft graphs start existing when the first |
| 107 |
; display is ready, which in the case of fft graphs is after the first |
| 108 |
; window has been filled (delay = winsize/sr) and in the case of audio |
| 109 |
; signals is the period itself |
| 110 |
|
| 111 |
schedule "SetupGraphs", 0.5, 1 |
| 112 |
|
| 113 |
</CsInstruments> |
| 114 |
<CsScore> |
| 115 |
f0 3600 |
| 116 |
</CsScore> |
| 117 |
</CsoundSynthesizer> |
| 118 |
<bsbPanel> |
| 119 |
<label>Widgets</label> |
| 120 |
<objectName/> |
| 121 |
<x>0</x> |
| 122 |
<y>0</y> |
| 123 |
<width>730</width> |
| 124 |
<height>739</height> |
| 125 |
<visible>true</visible> |
| 126 |
<uuid/> |
| 127 |
<bgcolor mode="background"> |
| 128 |
<r>212</r> |
| 129 |
<g>221</g> |
| 130 |
<b>230</b> |
| 131 |
</bgcolor> |
| 132 |
<bsbObject version="2" type="BSBGraph"> |
| 133 |
<objectName>graph1</objectName> |
| 134 |
<x>5</x> |
| 135 |
<y>65</y> |
| 136 |
<width>360</width> |
| 137 |
<height>189</height> |
| 138 |
<uuid>{ec9057d4-b17b-4c85-b694-0dec1a12500a}</uuid> |
| 139 |
<visible>true</visible> |
| 140 |
<midichan>0</midichan> |
| 141 |
<midicc>-3</midicc> |
| 142 |
<description/> |
| 143 |
<value>2</value> |
| 144 |
<objectName2/> |
| 145 |
<zoomx>1.00000000</zoomx> |
| 146 |
<zoomy>1.00000000</zoomy> |
| 147 |
<dispx>1.00000000</dispx> |
| 148 |
<dispy>1.00000000</dispy> |
| 149 |
<modex>lin</modex> |
| 150 |
<modey>lin</modey> |
| 151 |
<showSelector>true</showSelector> |
| 152 |
<showGrid>true</showGrid> |
| 153 |
<showTableInfo>true</showTableInfo> |
| 154 |
<showScrollbars>true</showScrollbars> |
| 155 |
<enableTables>true</enableTables> |
| 156 |
<enableDisplays>true</enableDisplays> |
| 157 |
<all>true</all> |
| 158 |
</bsbObject> |
| 159 |
<bsbObject version="2" type="BSBSpinBox"> |
| 160 |
<objectName>tabindex</objectName> |
| 161 |
<x>90</x> |
| 162 |
<y>262</y> |
| 163 |
<width>50</width> |
| 164 |
<height>40</height> |
| 165 |
<uuid>{12cab531-987e-41ac-9262-d5f71c064805}</uuid> |
| 166 |
<visible>true</visible> |
| 167 |
<midichan>0</midichan> |
| 168 |
<midicc>0</midicc> |
| 169 |
<description/> |
| 170 |
<alignment>left</alignment> |
| 171 |
<font>Liberation Sans</font> |
| 172 |
<fontsize>16</fontsize> |
| 173 |
<color> |
| 174 |
<r>85</r> |
| 175 |
<g>0</g> |
| 176 |
<b>255</b> |
| 177 |
</color> |
| 178 |
<bgcolor mode="background"> |
| 179 |
<r>218</r> |
| 180 |
<g>218</g> |
| 181 |
<b>218</b> |
| 182 |
</bgcolor> |
| 183 |
<resolution>1.00000000</resolution> |
| 184 |
<minimum>0</minimum> |
| 185 |
<maximum>4</maximum> |
| 186 |
<randomizable group="0">false</randomizable> |
| 187 |
<value>2</value> |
| 188 |
</bsbObject> |
| 189 |
<bsbObject version="2" type="BSBLabel"> |
| 190 |
<objectName/> |
| 191 |
<x>5</x> |
| 192 |
<y>267</y> |
| 193 |
<width>85</width> |
| 194 |
<height>30</height> |
| 195 |
<uuid>{d70336af-31c0-46c6-8288-9113647dfccf}</uuid> |
| 196 |
<visible>true</visible> |
| 197 |
<midichan>0</midichan> |
| 198 |
<midicc>-3</midicc> |
| 199 |
<description/> |
| 200 |
<label>Table Index</label> |
| 201 |
<alignment>right</alignment> |
| 202 |
<valignment>top</valignment> |
| 203 |
<font>Arial</font> |
| 204 |
<fontsize>16</fontsize> |
| 205 |
<precision>3</precision> |
| 206 |
<color> |
| 207 |
<r>0</r> |
| 208 |
<g>0</g> |
| 209 |
<b>0</b> |
| 210 |
</color> |
| 211 |
<bgcolor mode="nobackground"> |
| 212 |
<r>255</r> |
| 213 |
<g>255</g> |
| 214 |
<b>255</b> |
| 215 |
</bgcolor> |
| 216 |
<bordermode>false</bordermode> |
| 217 |
<borderradius>1</borderradius> |
| 218 |
<borderwidth>0</borderwidth> |
| 219 |
</bsbObject> |
| 220 |
<bsbObject version="2" type="BSBGraph"> |
| 221 |
<objectName>graph2</objectName> |
| 222 |
<x>5</x> |
| 223 |
<y>350</y> |
| 224 |
<width>570</width> |
| 225 |
<height>189</height> |
| 226 |
<uuid>{23c327bd-bf0d-492b-90dd-e6536e96ae62}</uuid> |
| 227 |
<visible>true</visible> |
| 228 |
<midichan>0</midichan> |
| 229 |
<midicc>-3</midicc> |
| 230 |
<description/> |
| 231 |
<value>5</value> |
| 232 |
<objectName2/> |
| 233 |
<zoomx>4.00000000</zoomx> |
| 234 |
<zoomy>1.00000000</zoomy> |
| 235 |
<dispx>1.00000000</dispx> |
| 236 |
<dispy>1.00000000</dispy> |
| 237 |
<modex>lin</modex> |
| 238 |
<modey>lin</modey> |
| 239 |
<showSelector>true</showSelector> |
| 240 |
<showGrid>true</showGrid> |
| 241 |
<showTableInfo>true</showTableInfo> |
| 242 |
<showScrollbars>false</showScrollbars> |
| 243 |
<enableTables>false</enableTables> |
| 244 |
<enableDisplays>true</enableDisplays> |
| 245 |
<all>true</all> |
| 246 |
</bsbObject> |
| 247 |
<bsbObject version="2" type="BSBGraph"> |
| 248 |
<objectName>graph3</objectName> |
| 249 |
<x>5</x> |
| 250 |
<y>560</y> |
| 251 |
<width>570</width> |
| 252 |
<height>189</height> |
| 253 |
<uuid>{43a72640-7329-4222-abdb-bbd4584d49c0}</uuid> |
| 254 |
<visible>true</visible> |
| 255 |
<midichan>0</midichan> |
| 256 |
<midicc>-3</midicc> |
| 257 |
<description/> |
| 258 |
<value>6</value> |
| 259 |
<objectName2/> |
| 260 |
<zoomx>1.00000000</zoomx> |
| 261 |
<zoomy>1.00000000</zoomy> |
| 262 |
<dispx>1.00000000</dispx> |
| 263 |
<dispy>1.00000000</dispy> |
| 264 |
<modex>lin</modex> |
| 265 |
<modey>lin</modey> |
| 266 |
<showSelector>false</showSelector> |
| 267 |
<showGrid>true</showGrid> |
| 268 |
<showTableInfo>true</showTableInfo> |
| 269 |
<showScrollbars>true</showScrollbars> |
| 270 |
<enableTables>true</enableTables> |
| 271 |
<enableDisplays>true</enableDisplays> |
| 272 |
<all>true</all> |
| 273 |
</bsbObject> |
| 274 |
<bsbObject version="2" type="BSBKnob"> |
| 275 |
<objectName>freq</objectName> |
| 276 |
<x>210</x> |
| 277 |
<y>255</y> |
| 278 |
<width>55</width> |
| 279 |
<height>55</height> |
| 280 |
<uuid>{e273f498-ec83-4aa1-bc8a-5dbde9a50fcf}</uuid> |
| 281 |
<visible>true</visible> |
| 282 |
<midichan>0</midichan> |
| 283 |
<midicc>0</midicc> |
| 284 |
<description/> |
| 285 |
<minimum>20.00000000</minimum> |
| 286 |
<maximum>1000.00000000</maximum> |
| 287 |
<value>743.73000000</value> |
| 288 |
<mode>lin</mode> |
| 289 |
<mouseControl act="">continuous</mouseControl> |
| 290 |
<resolution>0.01000000</resolution> |
| 291 |
<randomizable group="0">false</randomizable> |
| 292 |
<color> |
| 293 |
<r>245</r> |
| 294 |
<g>124</g> |
| 295 |
<b>0</b> |
| 296 |
</color> |
| 297 |
<textcolor>#4a2600</textcolor> |
| 298 |
<border>1</border> |
| 299 |
<borderColor>#4a2600</borderColor> |
| 300 |
<showvalue>true</showvalue> |
| 301 |
<flatstyle>true</flatstyle> |
| 302 |
<integerMode>false</integerMode> |
| 303 |
</bsbObject> |
| 304 |
<bsbObject version="2" type="BSBLabel"> |
| 305 |
<objectName/> |
| 306 |
<x>145</x> |
| 307 |
<y>267</y> |
| 308 |
<width>64</width> |
| 309 |
<height>30</height> |
| 310 |
<uuid>{e0e7e340-f91d-4b1a-83f7-99afd9b06fec}</uuid> |
| 311 |
<visible>true</visible> |
| 312 |
<midichan>0</midichan> |
| 313 |
<midicc>-3</midicc> |
| 314 |
<description/> |
| 315 |
<label>Freq</label> |
| 316 |
<alignment>right</alignment> |
| 317 |
<valignment>top</valignment> |
| 318 |
<font>Arial</font> |
| 319 |
<fontsize>16</fontsize> |
| 320 |
<precision>3</precision> |
| 321 |
<color> |
| 322 |
<r>0</r> |
| 323 |
<g>0</g> |
| 324 |
<b>0</b> |
| 325 |
</color> |
| 326 |
<bgcolor mode="nobackground"> |
| 327 |
<r>255</r> |
| 328 |
<g>255</g> |
| 329 |
<b>255</b> |
| 330 |
</bgcolor> |
| 331 |
<bordermode>false</bordermode> |
| 332 |
<borderradius>1</borderradius> |
| 333 |
<borderwidth>0</borderwidth> |
| 334 |
</bsbObject> |
| 335 |
<bsbObject version="2" type="BSBLabel"> |
| 336 |
<objectName/> |
| 337 |
<x>6</x> |
| 338 |
<y>1</y> |
| 339 |
<width>174</width> |
| 340 |
<height>40</height> |
| 341 |
<uuid>{9084758a-d369-4258-a038-c3887349a499}</uuid> |
| 342 |
<visible>true</visible> |
| 343 |
<midichan>0</midichan> |
| 344 |
<midicc>-3</midicc> |
| 345 |
<description/> |
| 346 |
<label>Graph Widget</label> |
| 347 |
<alignment>left</alignment> |
| 348 |
<valignment>top</valignment> |
| 349 |
<font>Arial</font> |
| 350 |
<fontsize>28</fontsize> |
| 351 |
<precision>3</precision> |
| 352 |
<color> |
| 353 |
<r>0</r> |
| 354 |
<g>0</g> |
| 355 |
<b>0</b> |
| 356 |
</color> |
| 357 |
<bgcolor mode="nobackground"> |
| 358 |
<r>255</r> |
| 359 |
<g>255</g> |
| 360 |
<b>255</b> |
| 361 |
</bgcolor> |
| 362 |
<bordermode>false</bordermode> |
| 363 |
<borderradius>1</borderradius> |
| 364 |
<borderwidth>0</borderwidth> |
| 365 |
</bsbObject> |
| 366 |
<bsbObject version="2" type="BSBTableDisplay"> |
| 367 |
<objectName>plot1</objectName> |
| 368 |
<x>370</x> |
| 369 |
<y>65</y> |
| 370 |
<width>360</width> |
| 371 |
<height>189</height> |
| 372 |
<uuid>{ccc0ad50-1250-4166-987c-eb32de8a9566}</uuid> |
| 373 |
<visible>true</visible> |
| 374 |
<midichan>0</midichan> |
| 375 |
<midicc>-3</midicc> |
| 376 |
<description/> |
| 377 |
<color> |
| 378 |
<r>255</r> |
| 379 |
<g>193</g> |
| 380 |
<b>3</b> |
| 381 |
</color> |
| 382 |
<range>0.00</range> |
| 383 |
</bsbObject> |
| 384 |
<bsbObject version="2" type="BSBLabel"> |
| 385 |
<objectName/> |
| 386 |
<x>5</x> |
| 387 |
<y>45</y> |
| 388 |
<width>247</width> |
| 389 |
<height>21</height> |
| 390 |
<uuid>{895a45e4-944d-4121-b5ed-d012a62b8893}</uuid> |
| 391 |
<visible>true</visible> |
| 392 |
<midichan>0</midichan> |
| 393 |
<midicc>-3</midicc> |
| 394 |
<description/> |
| 395 |
<label>Graph Widget can display STATIC tables</label> |
| 396 |
<alignment>left</alignment> |
| 397 |
<valignment>top</valignment> |
| 398 |
<font>Arial</font> |
| 399 |
<fontsize>11</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>false</bordermode> |
| 412 |
<borderradius>1</borderradius> |
| 413 |
<borderwidth>0</borderwidth> |
| 414 |
</bsbObject> |
| 415 |
<bsbObject version="2" type="BSBLabel"> |
| 416 |
<objectName/> |
| 417 |
<x>370</x> |
| 418 |
<y>44</y> |
| 419 |
<width>247</width> |
| 420 |
<height>21</height> |
| 421 |
<uuid>{ec8cdf60-0106-4db3-8ca6-49dc35779522}</uuid> |
| 422 |
<visible>true</visible> |
| 423 |
<midichan>0</midichan> |
| 424 |
<midicc>-3</midicc> |
| 425 |
<description/> |
| 426 |
<label>Table Plot widget would show changes in a table</label> |
| 427 |
<alignment>left</alignment> |
| 428 |
<valignment>top</valignment> |
| 429 |
<font>Liberation Sans</font> |
| 430 |
<fontsize>11</fontsize> |
| 431 |
<precision>3</precision> |
| 432 |
<color> |
| 433 |
<r>0</r> |
| 434 |
<g>0</g> |
| 435 |
<b>0</b> |
| 436 |
</color> |
| 437 |
<bgcolor mode="nobackground"> |
| 438 |
<r>255</r> |
| 439 |
<g>255</g> |
| 440 |
<b>255</b> |
| 441 |
</bgcolor> |
| 442 |
<bordermode>false</bordermode> |
| 443 |
<borderradius>1</borderradius> |
| 444 |
<borderwidth>0</borderwidth> |
| 445 |
</bsbObject> |
| 446 |
<bsbObject version="2" type="BSBLabel"> |
| 447 |
<objectName/> |
| 448 |
<x>4</x> |
| 449 |
<y>310</y> |
| 450 |
<width>303</width> |
| 451 |
<height>38</height> |
| 452 |
<uuid>{9a77618a-96c8-4a63-b6a7-74e9af0b3ee2}</uuid> |
| 453 |
<visible>true</visible> |
| 454 |
<midichan>0</midichan> |
| 455 |
<midicc>-3</midicc> |
| 456 |
<description/> |
| 457 |
<label>Spectrum graph widget, driven by dispfft |
| 458 |
Click on a peak to display its frequency</label> |
| 459 |
<alignment>left</alignment> |
| 460 |
<valignment>top</valignment> |
| 461 |
<font>Liberation Sans</font> |
| 462 |
<fontsize>11</fontsize> |
| 463 |
<precision>3</precision> |
| 464 |
<color> |
| 465 |
<r>0</r> |
| 466 |
<g>0</g> |
| 467 |
<b>0</b> |
| 468 |
</color> |
| 469 |
<bgcolor mode="nobackground"> |
| 470 |
<r>255</r> |
| 471 |
<g>255</g> |
| 472 |
<b>255</b> |
| 473 |
</bgcolor> |
| 474 |
<bordermode>false</bordermode> |
| 475 |
<borderradius>1</borderradius> |
| 476 |
<borderwidth>0</borderwidth> |
| 477 |
</bsbObject> |
| 478 |
<bsbObject version="2" type="BSBLabel"> |
| 479 |
<objectName/> |
| 480 |
<x>5</x> |
| 481 |
<y>540</y> |
| 482 |
<width>238</width> |
| 483 |
<height>23</height> |
| 484 |
<uuid>{95516290-ec6d-42db-aea9-418260ff1003}</uuid> |
| 485 |
<visible>true</visible> |
| 486 |
<midichan>0</midichan> |
| 487 |
<midicc>-3</midicc> |
| 488 |
<description/> |
| 489 |
<label>Signal graph widget, driven by display opcode</label> |
| 490 |
<alignment>left</alignment> |
| 491 |
<valignment>top</valignment> |
| 492 |
<font>Arial</font> |
| 493 |
<fontsize>11</fontsize> |
| 494 |
<precision>3</precision> |
| 495 |
<color> |
| 496 |
<r>0</r> |
| 497 |
<g>0</g> |
| 498 |
<b>0</b> |
| 499 |
</color> |
| 500 |
<bgcolor mode="nobackground"> |
| 501 |
<r>255</r> |
| 502 |
<g>255</g> |
| 503 |
<b>255</b> |
| 504 |
</bgcolor> |
| 505 |
<bordermode>false</bordermode> |
| 506 |
<borderradius>1</borderradius> |
| 507 |
<borderwidth>0</borderwidth> |
| 508 |
</bsbObject> |
| 509 |
</bsbPanel> |
| 510 |
<bsbPresets> |
| 511 |
</bsbPresets> |