| 1 |
;Written by Iain McCurdy, 2010 |
| 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 |
|
| 7 |
;Notes on modifications from original csd: |
| 8 |
|
| 9 |
|
| 10 |
;my flags on Ubuntu: -dm0 -iadc -odac -+rtaudio=jack -b16 -B4096 -+rtmidi=null |
| 11 |
<CsoundSynthesizer> |
| 12 |
<CsOptions> |
| 13 |
|
| 14 |
</CsOptions> |
| 15 |
<CsInstruments> |
| 16 |
sr = 44100 ;SAMPLE RATE |
| 17 |
ksmps = 16 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE |
| 18 |
nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO) |
| 19 |
0dbfs = 1 ;MAXIMUM AMPLITUDE WILL BE 1 |
| 20 |
|
| 21 |
|
| 22 |
gisine ftgen 0, 0, 1024, 10, 1 ;A SINE WAVE |
| 23 |
|
| 24 |
|
| 25 |
instr 1 ;GUI AND THRESHOLD CROSSING TESTING INSTRUMENT |
| 26 |
|
| 27 |
ktrig metro 10 |
| 28 |
if (ktrig == 1) then |
| 29 |
gkthreshold invalue "Threshold" |
| 30 |
gksignal invalue "TriggerSignal" |
| 31 |
gkmode invalue "Mode" |
| 32 |
endif |
| 33 |
|
| 34 |
ain inch 1 |
| 35 |
afollow follow2 ain, 0.01, 0.01 ;CREATE A AMPLITUDE FOLLOWING UNIPOLAR SIGNAL |
| 36 |
kfollow downsamp afollow ;DOWNSAMPLE TO CREATE A K-RATE VERSION OF THE AMPLITUDE FOLLOWING SIGNAL |
| 37 |
kbang trigger gksignal, gkthreshold, gkmode ;OUTPUT A MOMENTARY 1 IF 'gksignal' crosses 'gkthreshold' IN THE DIRECTION(S) ACCORDING TO 'gkmode' |
| 38 |
; OPCODE KTRIGGER, KMINTIME, KMAXNUM, KINSNUM, KWHEN, KDUR |
| 39 |
schedkwhen kbang, 0, 0, 2, 0, 1 ;INSTRUCT instr 2 TO PLAY A NOTE WHENEVER 'kbang' IS 1 |
| 40 |
endin |
| 41 |
|
| 42 |
instr 2 |
| 43 |
icps = (i(gksignal)>i(gkthreshold)?500:300) ;DEFINE THE PITCH OF THE NOTE ACCORDING TO WHETHER THIS NOTE WAS GENERATED BY AN UPWARD OR A DOWNWARD CROSSING |
| 44 |
aenv expon 0.5,p3,0.0001 ;PERCUSSIVE ENVELOPE |
| 45 |
asig oscili aenv, icps, gisine ;AUDIO OSCILLATOR |
| 46 |
outs asig, asig ;SEND AUDIO TO OUTPUTS |
| 47 |
endin |
| 48 |
</CsInstruments> |
| 49 |
<CsScore> |
| 50 |
i 1 0 3600 ;THRESHOLD CROSSING TESTING INSTRUMENT PLAYS FOR 1 HOUR (AND KEEPS REALTIME PERFORMANCE GOING) |
| 51 |
</CsScore> |
| 52 |
</CsoundSynthesizer> |
| 53 |
<bsbPanel> |
| 54 |
<label>Widgets</label> |
| 55 |
<objectName/> |
| 56 |
<x>1158</x> |
| 57 |
<y>144</y> |
| 58 |
<width>521</width> |
| 59 |
<height>348</height> |
| 60 |
<visible>true</visible> |
| 61 |
<uuid/> |
| 62 |
<bgcolor mode="background"> |
| 63 |
<r>241</r> |
| 64 |
<g>226</g> |
| 65 |
<b>185</b> |
| 66 |
</bgcolor> |
| 67 |
<bsbObject version="2" type="BSBLabel"> |
| 68 |
<objectName/> |
| 69 |
<x>2</x> |
| 70 |
<y>2</y> |
| 71 |
<width>512</width> |
| 72 |
<height>344</height> |
| 73 |
<uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid> |
| 74 |
<visible>true</visible> |
| 75 |
<midichan>0</midichan> |
| 76 |
<midicc>0</midicc> |
| 77 |
<label>trigger</label> |
| 78 |
<alignment>center</alignment> |
| 79 |
<font>Liberation Sans</font> |
| 80 |
<fontsize>18</fontsize> |
| 81 |
<precision>3</precision> |
| 82 |
<color> |
| 83 |
<r>255</r> |
| 84 |
<g>255</g> |
| 85 |
<b>255</b> |
| 86 |
</color> |
| 87 |
<bgcolor mode="background"> |
| 88 |
<r>5</r> |
| 89 |
<g>27</g> |
| 90 |
<b>150</b> |
| 91 |
</bgcolor> |
| 92 |
<bordermode>border</bordermode> |
| 93 |
<borderradius>5</borderradius> |
| 94 |
<borderwidth>2</borderwidth> |
| 95 |
</bsbObject> |
| 96 |
<bsbObject version="2" type="BSBLabel"> |
| 97 |
<objectName/> |
| 98 |
<x>8</x> |
| 99 |
<y>23</y> |
| 100 |
<width>499</width> |
| 101 |
<height>161</height> |
| 102 |
<uuid>{e41f02b8-6ad4-46dc-805c-0b2eeafbd476}</uuid> |
| 103 |
<visible>true</visible> |
| 104 |
<midichan>0</midichan> |
| 105 |
<midicc>0</midicc> |
| 106 |
<label>------------------------------------------------------------------------------------------------------------------------- |
| 107 |
The trigger opcode can be used to output a momentary '1' if a k-rate signal crosses a user defined threshold. It can be asked to sense upward crossings, downward crossings or both upward and downward crossings. In this example the momentary '1' (called a 'bang' in MaxMSP) is used to trigger a sounding instrument using schedkwhen. The sounding instrument itself checks whether it is an upward or a downward crossing and generates a high or a low tone accordingly. |
| 108 |
This opcode can be useful in using a MIDI continuous controller to trigger a Csound instrument.</label> |
| 109 |
<alignment>left</alignment> |
| 110 |
<font>Liberation Sans</font> |
| 111 |
<fontsize>14</fontsize> |
| 112 |
<precision>3</precision> |
| 113 |
<color> |
| 114 |
<r>255</r> |
| 115 |
<g>255</g> |
| 116 |
<b>255</b> |
| 117 |
</color> |
| 118 |
<bgcolor mode="nobackground"> |
| 119 |
<r>255</r> |
| 120 |
<g>255</g> |
| 121 |
<b>255</b> |
| 122 |
</bgcolor> |
| 123 |
<bordermode>noborder</bordermode> |
| 124 |
<borderradius>1</borderradius> |
| 125 |
<borderwidth>1</borderwidth> |
| 126 |
</bsbObject> |
| 127 |
<bsbObject version="2" type="BSBLabel"> |
| 128 |
<objectName/> |
| 129 |
<x>8</x> |
| 130 |
<y>270</y> |
| 131 |
<width>200</width> |
| 132 |
<height>30</height> |
| 133 |
<uuid>{3ebc1139-1fdb-48dc-9150-49ee8dfdbd4a}</uuid> |
| 134 |
<visible>true</visible> |
| 135 |
<midichan>0</midichan> |
| 136 |
<midicc>0</midicc> |
| 137 |
<label>Trigger Signal</label> |
| 138 |
<alignment>left</alignment> |
| 139 |
<font>Liberation Sans</font> |
| 140 |
<fontsize>10</fontsize> |
| 141 |
<precision>3</precision> |
| 142 |
<color> |
| 143 |
<r>255</r> |
| 144 |
<g>255</g> |
| 145 |
<b>255</b> |
| 146 |
</color> |
| 147 |
<bgcolor mode="nobackground"> |
| 148 |
<r>255</r> |
| 149 |
<g>255</g> |
| 150 |
<b>255</b> |
| 151 |
</bgcolor> |
| 152 |
<bordermode>noborder</bordermode> |
| 153 |
<borderradius>1</borderradius> |
| 154 |
<borderwidth>1</borderwidth> |
| 155 |
</bsbObject> |
| 156 |
<bsbObject version="2" type="BSBHSlider"> |
| 157 |
<objectName>TriggerSignal</objectName> |
| 158 |
<x>8</x> |
| 159 |
<y>247</y> |
| 160 |
<width>500</width> |
| 161 |
<height>27</height> |
| 162 |
<uuid>{2cf97843-5b49-438e-8034-62a459597e86}</uuid> |
| 163 |
<visible>true</visible> |
| 164 |
<midichan>0</midichan> |
| 165 |
<midicc>0</midicc> |
| 166 |
<minimum>0.00000000</minimum> |
| 167 |
<maximum>1.00000000</maximum> |
| 168 |
<value>0.00000000</value> |
| 169 |
<mode>lin</mode> |
| 170 |
<mouseControl act="jump">continuous</mouseControl> |
| 171 |
<resolution>-1.00000000</resolution> |
| 172 |
<randomizable group="0">false</randomizable> |
| 173 |
</bsbObject> |
| 174 |
<bsbObject version="2" type="BSBDisplay"> |
| 175 |
<objectName>TriggerSignal</objectName> |
| 176 |
<x>448</x> |
| 177 |
<y>270</y> |
| 178 |
<width>60</width> |
| 179 |
<height>30</height> |
| 180 |
<uuid>{e54486c5-f9aa-4d0e-9a67-6506dae3c790}</uuid> |
| 181 |
<visible>true</visible> |
| 182 |
<midichan>0</midichan> |
| 183 |
<midicc>0</midicc> |
| 184 |
<label>0.000</label> |
| 185 |
<alignment>right</alignment> |
| 186 |
<font>Liberation Sans</font> |
| 187 |
<fontsize>9</fontsize> |
| 188 |
<precision>3</precision> |
| 189 |
<color> |
| 190 |
<r>255</r> |
| 191 |
<g>255</g> |
| 192 |
<b>255</b> |
| 193 |
</color> |
| 194 |
<bgcolor mode="nobackground"> |
| 195 |
<r>255</r> |
| 196 |
<g>255</g> |
| 197 |
<b>255</b> |
| 198 |
</bgcolor> |
| 199 |
<bordermode>noborder</bordermode> |
| 200 |
<borderradius>1</borderradius> |
| 201 |
<borderwidth>1</borderwidth> |
| 202 |
</bsbObject> |
| 203 |
<bsbObject version="2" type="BSBLabel"> |
| 204 |
<objectName/> |
| 205 |
<x>8</x> |
| 206 |
<y>217</y> |
| 207 |
<width>200</width> |
| 208 |
<height>30</height> |
| 209 |
<uuid>{78a7e9cd-fb57-421c-8e1f-40b60a90dfc0}</uuid> |
| 210 |
<visible>true</visible> |
| 211 |
<midichan>0</midichan> |
| 212 |
<midicc>0</midicc> |
| 213 |
<label>Threshold</label> |
| 214 |
<alignment>left</alignment> |
| 215 |
<font>Liberation Sans</font> |
| 216 |
<fontsize>10</fontsize> |
| 217 |
<precision>3</precision> |
| 218 |
<color> |
| 219 |
<r>255</r> |
| 220 |
<g>255</g> |
| 221 |
<b>255</b> |
| 222 |
</color> |
| 223 |
<bgcolor mode="nobackground"> |
| 224 |
<r>255</r> |
| 225 |
<g>255</g> |
| 226 |
<b>255</b> |
| 227 |
</bgcolor> |
| 228 |
<bordermode>noborder</bordermode> |
| 229 |
<borderradius>1</borderradius> |
| 230 |
<borderwidth>1</borderwidth> |
| 231 |
</bsbObject> |
| 232 |
<bsbObject version="2" type="BSBDisplay"> |
| 233 |
<objectName>Threshold</objectName> |
| 234 |
<x>448</x> |
| 235 |
<y>217</y> |
| 236 |
<width>60</width> |
| 237 |
<height>30</height> |
| 238 |
<uuid>{58265963-6245-459e-8071-9ed8bba850a4}</uuid> |
| 239 |
<visible>true</visible> |
| 240 |
<midichan>0</midichan> |
| 241 |
<midicc>0</midicc> |
| 242 |
<label>0.500</label> |
| 243 |
<alignment>right</alignment> |
| 244 |
<font>Liberation Sans</font> |
| 245 |
<fontsize>9</fontsize> |
| 246 |
<precision>3</precision> |
| 247 |
<color> |
| 248 |
<r>255</r> |
| 249 |
<g>255</g> |
| 250 |
<b>255</b> |
| 251 |
</color> |
| 252 |
<bgcolor mode="nobackground"> |
| 253 |
<r>255</r> |
| 254 |
<g>255</g> |
| 255 |
<b>255</b> |
| 256 |
</bgcolor> |
| 257 |
<bordermode>noborder</bordermode> |
| 258 |
<borderradius>1</borderradius> |
| 259 |
<borderwidth>1</borderwidth> |
| 260 |
</bsbObject> |
| 261 |
<bsbObject version="2" type="BSBController"> |
| 262 |
<objectName>Threshold</objectName> |
| 263 |
<x>8</x> |
| 264 |
<y>192</y> |
| 265 |
<width>500</width> |
| 266 |
<height>22</height> |
| 267 |
<uuid>{67b02203-fc2c-4185-9414-a35ea6a940d7}</uuid> |
| 268 |
<visible>true</visible> |
| 269 |
<midichan>0</midichan> |
| 270 |
<midicc>0</midicc> |
| 271 |
<objectName2/> |
| 272 |
<xMin>0.00000000</xMin> |
| 273 |
<xMax>1.00000000</xMax> |
| 274 |
<yMin>0.00000000</yMin> |
| 275 |
<yMax>1.00000000</yMax> |
| 276 |
<xValue>0.50000000</xValue> |
| 277 |
<yValue>0.00000000</yValue> |
| 278 |
<type>fill</type> |
| 279 |
<pointsize>1</pointsize> |
| 280 |
<fadeSpeed>0.00000000</fadeSpeed> |
| 281 |
<mouseControl act="press">jump</mouseControl> |
| 282 |
<color> |
| 283 |
<r>255</r> |
| 284 |
<g>0</g> |
| 285 |
<b>0</b> |
| 286 |
</color> |
| 287 |
<randomizable mode="both" group="0">false</randomizable> |
| 288 |
<bgcolor> |
| 289 |
<r>0</r> |
| 290 |
<g>0</g> |
| 291 |
<b>0</b> |
| 292 |
</bgcolor> |
| 293 |
</bsbObject> |
| 294 |
<bsbObject version="2" type="BSBDropdown"> |
| 295 |
<objectName>Mode</objectName> |
| 296 |
<x>222</x> |
| 297 |
<y>302</y> |
| 298 |
<width>123</width> |
| 299 |
<height>30</height> |
| 300 |
<uuid>{004ff588-9f8c-4edc-9dba-8f30f0605e3b}</uuid> |
| 301 |
<visible>true</visible> |
| 302 |
<midichan>0</midichan> |
| 303 |
<midicc>0</midicc> |
| 304 |
<bsbDropdownItemList> |
| 305 |
<bsbDropdownItem> |
| 306 |
<name>Up</name> |
| 307 |
<value>0</value> |
| 308 |
<stringvalue/> |
| 309 |
</bsbDropdownItem> |
| 310 |
<bsbDropdownItem> |
| 311 |
<name>Down</name> |
| 312 |
<value>1</value> |
| 313 |
<stringvalue/> |
| 314 |
</bsbDropdownItem> |
| 315 |
<bsbDropdownItem> |
| 316 |
<name>Up / Down</name> |
| 317 |
<value>2</value> |
| 318 |
<stringvalue/> |
| 319 |
</bsbDropdownItem> |
| 320 |
</bsbDropdownItemList> |
| 321 |
<selectedIndex>1</selectedIndex> |
| 322 |
<randomizable group="0">false</randomizable> |
| 323 |
</bsbObject> |
| 324 |
<bsbObject version="2" type="BSBLabel"> |
| 325 |
<objectName/> |
| 326 |
<x>139</x> |
| 327 |
<y>306</y> |
| 328 |
<width>80</width> |
| 329 |
<height>30</height> |
| 330 |
<uuid>{5682fe9d-e29a-40ac-9a5b-fbecaaf87e54}</uuid> |
| 331 |
<visible>true</visible> |
| 332 |
<midichan>0</midichan> |
| 333 |
<midicc>0</midicc> |
| 334 |
<label>Mode:</label> |
| 335 |
<alignment>right</alignment> |
| 336 |
<font>Liberation Sans</font> |
| 337 |
<fontsize>10</fontsize> |
| 338 |
<precision>3</precision> |
| 339 |
<color> |
| 340 |
<r>255</r> |
| 341 |
<g>255</g> |
| 342 |
<b>255</b> |
| 343 |
</color> |
| 344 |
<bgcolor mode="nobackground"> |
| 345 |
<r>255</r> |
| 346 |
<g>255</g> |
| 347 |
<b>255</b> |
| 348 |
</bgcolor> |
| 349 |
<bordermode>noborder</bordermode> |
| 350 |
<borderradius>1</borderradius> |
| 351 |
<borderwidth>1</borderwidth> |
| 352 |
</bsbObject> |
| 353 |
</bsbPanel> |
| 354 |
<bsbPresets> |
| 355 |
</bsbPresets> |
| 356 |
<EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel> |