| 1 |
;Writen by Iain McCurdy, 2006 |
| 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 icps and iamp displays |
| 8 |
|
| 9 |
;my flags on Ubuntu: -dm0 -odac -+rtaudio=alsa -b1024 -B2048 -+rtmidi=alsa -Ma |
| 10 |
<CsoundSynthesizer> |
| 11 |
<CsOptions> |
| 12 |
|
| 13 |
</CsOptions> |
| 14 |
<CsInstruments> |
| 15 |
sr = 44100 ;SAMPLE RATE |
| 16 |
ksmps = 128 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE |
| 17 |
nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO) |
| 18 |
0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH |
| 19 |
|
| 20 |
|
| 21 |
instr 1 ; SIMPLE BEEP INSTRUMENT - CAN BE ACTIVATED VIA A CONNECTED MIDI KEYBOARD |
| 22 |
icps cpsmidi ; THE OPCODE 'CPSMIDI' OUTPUTS A CYCLES-PER-SECOND REPRESENTATION OF A RECEIVED MIDI NOTE. |
| 23 |
; IN THIS EXAMPLE I HAVE CALLED THE OUTPUT VARIABLE 'ICPS'. |
| 24 |
; 'CPSMIDI' TAKES NO INPUT ARGUMENTS. |
| 25 |
; E.G. IF A4 IS STRUCK ICPS WILL EQUAL 440 |
| 26 |
|
| 27 |
iscale = 0.2 |
| 28 |
iamp ampmidi iscale |
| 29 |
; THE OPCODE 'AMPMIDI' OUTPUTS A VALUE (IN THIS CASE CALLED IAMP) CORRESPONDING TO THE |
| 30 |
; KEY VELOCITY OF A RECEIVED NOTE ON MESSAGE. |
| 31 |
; THE FIRST ,AND ONLY OBLIGATORY ARGUMENT RESCALES THE RECEIVED VELOCITY VALUE (WHICH WOULD |
| 32 |
; NORMALLY BE IN THE RANGE 0-127 TO THE RANGE 0-ISCALE, WHICH IN THIS CASE MEANS THAT THE |
| 33 |
; VARIABLE IAMP WILL BE WITHIN THE RANGE 0-10000 DEPENDING ON HOW HARD |
| 34 |
; I HIT THE NOTE ON THE KEYBOARD |
| 35 |
|
| 36 |
outvalue "icps", icps |
| 37 |
outvalue "iamp", iamp |
| 38 |
|
| 39 |
;OUTPUT OPCODE AMPLITUDE | FREQUENCY | FUNCTION_TABLE |
| 40 |
asig oscili iamp, icps, 1 |
| 41 |
outs asig, asig ;SEND AUDIO OUTPUT OF OSCILLATOR TO THE SPEAKERS |
| 42 |
endin |
| 43 |
</CsInstruments> |
| 44 |
<CsScore> |
| 45 |
f 1 0 1024 10 1 ; SINE WAVE |
| 46 |
f 0 600 ; THIS LINE FUNCTIONS AS A DUMMY SCORE EVENT AND ALLOWS REALTIME MIDI PLAYING FOR 10 MINUTES |
| 47 |
</CsScore> |
| 48 |
</CsoundSynthesizer> |
| 49 |
<bsbPanel> |
| 50 |
<label>Widgets</label> |
| 51 |
<objectName/> |
| 52 |
<x>729</x> |
| 53 |
<y>354</y> |
| 54 |
<width>642</width> |
| 55 |
<height>353</height> |
| 56 |
<visible>true</visible> |
| 57 |
<uuid/> |
| 58 |
<bgcolor mode="nobackground"> |
| 59 |
<r>170</r> |
| 60 |
<g>170</g> |
| 61 |
<b>170</b> |
| 62 |
</bgcolor> |
| 63 |
<bsbObject version="2" type="BSBLabel"> |
| 64 |
<objectName/> |
| 65 |
<x>2</x> |
| 66 |
<y>2</y> |
| 67 |
<width>638</width> |
| 68 |
<height>349</height> |
| 69 |
<uuid>{c37e13f6-7642-465f-9b2a-f059eef7bce8}</uuid> |
| 70 |
<visible>true</visible> |
| 71 |
<midichan>0</midichan> |
| 72 |
<midicc>0</midicc> |
| 73 |
<label> Converting MIDI Pitch and Velocity into Csound Variables</label> |
| 74 |
<alignment>center</alignment> |
| 75 |
<font>Liberation Sans</font> |
| 76 |
<fontsize>18</fontsize> |
| 77 |
<precision>3</precision> |
| 78 |
<color> |
| 79 |
<r>0</r> |
| 80 |
<g>0</g> |
| 81 |
<b>0</b> |
| 82 |
</color> |
| 83 |
<bgcolor mode="background"> |
| 84 |
<r>244</r> |
| 85 |
<g>248</g> |
| 86 |
<b>200</b> |
| 87 |
</bgcolor> |
| 88 |
<bordermode>border</bordermode> |
| 89 |
<borderradius>5</borderradius> |
| 90 |
<borderwidth>2</borderwidth> |
| 91 |
</bsbObject> |
| 92 |
<bsbObject version="2" type="BSBLabel"> |
| 93 |
<objectName/> |
| 94 |
<x>5</x> |
| 95 |
<y>27</y> |
| 96 |
<width>632</width> |
| 97 |
<height>268</height> |
| 98 |
<uuid>{e41f02b8-6ad4-46dc-805c-0b2eeafbd476}</uuid> |
| 99 |
<visible>true</visible> |
| 100 |
<midichan>0</midichan> |
| 101 |
<midicc>0</midicc> |
| 102 |
<label>------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 103 |
The opcode 'cpsmidi' is used to convert a received MIDI pitch into an i-rate variable useable in Csound orchestra code. A variety of other pitch format are available: |
| 104 |
* 'octmidi' provides a value in the 'oct' format. |
| 105 |
* 'pchmidi' provides a value in the 'pch' format. |
| 106 |
* 'notnum' provides the actual note MIDI note number (range 0 - 127) |
| 107 |
|
| 108 |
More information on this opcode is given in the actual code of this example. The opcode 'ampmidi' converts a received MIDI velocity value into an i-rate variable useable in Csound orchestra code. MIDI velocity values are normally within the range 0 to 127 but the maximum limit for ampmidi's output can be modified using using the opcode's only input argument. More information on this opcode is given in the actual code of this example. An alternative opcode for scanning MIDI velocity is 'veloc'. This example uses ampmidi's output for raw amplitude values but it might be found that using its output for decibel values produces a more useful velocity response.</label> |
| 109 |
<alignment>left</alignment> |
| 110 |
<font>Liberation Sans</font> |
| 111 |
<fontsize>14</fontsize> |
| 112 |
<precision>3</precision> |
| 113 |
<color> |
| 114 |
<r>0</r> |
| 115 |
<g>0</g> |
| 116 |
<b>0</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>5</x> |
| 130 |
<y>292</y> |
| 131 |
<width>316</width> |
| 132 |
<height>50</height> |
| 133 |
<uuid>{b143f42f-2cbc-4532-8df7-4ba643c60b37}</uuid> |
| 134 |
<visible>true</visible> |
| 135 |
<midichan>0</midichan> |
| 136 |
<midicc>0</midicc> |
| 137 |
<label/> |
| 138 |
<alignment>left</alignment> |
| 139 |
<font>Liberation Sans</font> |
| 140 |
<fontsize>10</fontsize> |
| 141 |
<precision>3</precision> |
| 142 |
<color> |
| 143 |
<r>0</r> |
| 144 |
<g>0</g> |
| 145 |
<b>0</b> |
| 146 |
</color> |
| 147 |
<bgcolor mode="nobackground"> |
| 148 |
<r>255</r> |
| 149 |
<g>255</g> |
| 150 |
<b>255</b> |
| 151 |
</bgcolor> |
| 152 |
<bordermode>border</bordermode> |
| 153 |
<borderradius>5</borderradius> |
| 154 |
<borderwidth>2</borderwidth> |
| 155 |
</bsbObject> |
| 156 |
<bsbObject version="2" type="BSBLabel"> |
| 157 |
<objectName/> |
| 158 |
<x>180</x> |
| 159 |
<y>301</y> |
| 160 |
<width>54</width> |
| 161 |
<height>30</height> |
| 162 |
<uuid>{841ed5e4-ff5c-45b7-9988-c19b801e45a6}</uuid> |
| 163 |
<visible>true</visible> |
| 164 |
<midichan>0</midichan> |
| 165 |
<midicc>0</midicc> |
| 166 |
<label>iamp:</label> |
| 167 |
<alignment>right</alignment> |
| 168 |
<font>Liberation Sans</font> |
| 169 |
<fontsize>14</fontsize> |
| 170 |
<precision>3</precision> |
| 171 |
<color> |
| 172 |
<r>255</r> |
| 173 |
<g>0</g> |
| 174 |
<b>0</b> |
| 175 |
</color> |
| 176 |
<bgcolor mode="nobackground"> |
| 177 |
<r>255</r> |
| 178 |
<g>255</g> |
| 179 |
<b>255</b> |
| 180 |
</bgcolor> |
| 181 |
<bordermode>noborder</bordermode> |
| 182 |
<borderradius>1</borderradius> |
| 183 |
<borderwidth>1</borderwidth> |
| 184 |
</bsbObject> |
| 185 |
<bsbObject version="2" type="BSBDisplay"> |
| 186 |
<objectName>icps</objectName> |
| 187 |
<x>72</x> |
| 188 |
<y>303</y> |
| 189 |
<width>80</width> |
| 190 |
<height>25</height> |
| 191 |
<uuid>{f8119d82-f052-4a86-8790-440c42c5d41d}</uuid> |
| 192 |
<visible>true</visible> |
| 193 |
<midichan>0</midichan> |
| 194 |
<midicc>0</midicc> |
| 195 |
<label>195.987</label> |
| 196 |
<alignment>left</alignment> |
| 197 |
<font>Liberation Sans</font> |
| 198 |
<fontsize>12</fontsize> |
| 199 |
<precision>3</precision> |
| 200 |
<color> |
| 201 |
<r>255</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 version="2" type="BSBLabel"> |
| 215 |
<objectName/> |
| 216 |
<x>18</x> |
| 217 |
<y>301</y> |
| 218 |
<width>54</width> |
| 219 |
<height>30</height> |
| 220 |
<uuid>{4dc3e62f-8cd7-48cb-8f7f-25878ba3b97e}</uuid> |
| 221 |
<visible>true</visible> |
| 222 |
<midichan>0</midichan> |
| 223 |
<midicc>0</midicc> |
| 224 |
<label>icps:</label> |
| 225 |
<alignment>right</alignment> |
| 226 |
<font>Liberation Sans</font> |
| 227 |
<fontsize>14</fontsize> |
| 228 |
<precision>3</precision> |
| 229 |
<color> |
| 230 |
<r>255</r> |
| 231 |
<g>0</g> |
| 232 |
<b>0</b> |
| 233 |
</color> |
| 234 |
<bgcolor mode="nobackground"> |
| 235 |
<r>255</r> |
| 236 |
<g>255</g> |
| 237 |
<b>255</b> |
| 238 |
</bgcolor> |
| 239 |
<bordermode>noborder</bordermode> |
| 240 |
<borderradius>1</borderradius> |
| 241 |
<borderwidth>1</borderwidth> |
| 242 |
</bsbObject> |
| 243 |
<bsbObject version="2" type="BSBDisplay"> |
| 244 |
<objectName>iamp</objectName> |
| 245 |
<x>234</x> |
| 246 |
<y>303</y> |
| 247 |
<width>80</width> |
| 248 |
<height>25</height> |
| 249 |
<uuid>{302c2f66-32d0-49a4-8178-24865dfedde6}</uuid> |
| 250 |
<visible>true</visible> |
| 251 |
<midichan>0</midichan> |
| 252 |
<midicc>0</midicc> |
| 253 |
<label>0.053</label> |
| 254 |
<alignment>left</alignment> |
| 255 |
<font>Liberation Sans</font> |
| 256 |
<fontsize>12</fontsize> |
| 257 |
<precision>3</precision> |
| 258 |
<color> |
| 259 |
<r>255</r> |
| 260 |
<g>0</g> |
| 261 |
<b>0</b> |
| 262 |
</color> |
| 263 |
<bgcolor mode="nobackground"> |
| 264 |
<r>255</r> |
| 265 |
<g>255</g> |
| 266 |
<b>255</b> |
| 267 |
</bgcolor> |
| 268 |
<bordermode>noborder</bordermode> |
| 269 |
<borderradius>1</borderradius> |
| 270 |
<borderwidth>1</borderwidth> |
| 271 |
</bsbObject> |
| 272 |
</bsbPanel> |
| 273 |
<bsbPresets> |
| 274 |
</bsbPresets> |