1;Writen by Iain McCurdy, 2008 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 8 9;my flags on Ubuntu: -dm0 -iadc -odac -+rtaudio=jack -b16 -B4096 -+rtmidi=alsa -Ma 10<CsoundSynthesizer> 11<CsOptions> 12 13</CsOptions> 14<CsInstruments> 15sr = 44100 ;SAMPLE RATE 16ksmps = 16 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE 17nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO) 18 19 20gkTime init 1 ;INITIALISE VARIABLE FOR TIME GAP BETWEEN KEY PRESSES 21gkDlyTim init 1 ;INITIALISE DELAY TIME VARIABLE USED IN THE DELAY EFFECT IN INSTR 4 22 23 24instr 1 ;MIDI TRIGGERED INSTRUMENT - RECEIVES 'TAPS' 25 event_i "i", p1+2, 0, 0.001, i(gkTime) ;TRIGGER TEMPO CALCULATING INSTRUMENT 26 event_i "i", p1+1, 0, -1 ;START 'TIMER' INSTRUMENT (-1 DURATION INDICATES A MONPHONIC HELD NOTE) 27 outvalue "Delay_Time", i(gkDlyTim) ;SEND CURRENT DELAY TIME VALUE TO THE ON-SCREEN VALUATOR BOX 28 turnoff ;TURNOFF THIS INSTRUMENT IMMEDIATELY 29endin 30 31instr 2 ;TIMER TO MEASURE TIME GAP BETWEEN KEY PRESSES 32 gkTime timeinsts ;timeinsts OUTPUTS THE TIME SINCE THE START OF THE THIS NOTE BEING TRIGGERED 33endin 34 35instr 3 ;CALCULATE CURRENT TEMPO BASED ON TIME GAP BETWEEN THE LAST TWO KEY PRESSES 36 gkDlyTim init p4 ;SET DELAY TIME (FOR DELAY EFFECT IN INSTR 4) TO CURRENT TIME GAP VALUE 37 iTempo = 60/p4 ;DERIVE TEMPO FROM TIME GAP 38 outvalue "Tempo", iTempo ;SEND CURRENT DELAY TIME VALUE TO THE ON-SCREEN VALUATOR BOX 39endin 40 41instr 4 ;DELAY INSTRUMENT - TAKES LIVE AUDIO IN AS ITS INPUT 42 iMaxDlyTim init 10 ;INITIALISE VARIABLE FOR MAXIMUM DELAY TIME 43 kDlyTim limit gkDlyTim, 0.001, iMaxDlyTim ;LIMIT DELAY TIME TO PREVENT CRASHES 44 45 ain1 inch 1 ;READ AUDIO FROM LIVE INPUT CHANNEL 1 46 aFeedback init 0 ;INITIALISE FEEDBACK SIGNAL FOR FIRST k PASS 47 aBuffer delayr iMaxDlyTim ;DEFINE AUDIO BUFFER FOR DELAY 48 aTap deltap3 kDlyTim ;READ AUDIO FROM A DELAY TAP FROM WITHIN THIS BUFFER 49 delayw ain1+(aFeedback) ;WRITE AUDIO INTO THE DELAY BUFFER (MIXTURE OF LIVE IN AND FEEDBACK LOOP) 50 aFeedback = aTap*.5 ;DEFINE THE AUDIO FEEDBACK SIGNAL FOR THE NEXT k PASS 51 outs (aTap+ain1)*.5, (aTap+ain1)*.5 ;SEND AUDIO TO OUTPUTS (AND ATTENUATE) 52endin 53</CsInstruments> 54<CsScore> 55i 1 0 0.001 ;INSTR 1 (SHORT NOTE) 56i 4 0 3600 ;INSTR 4 (DELAY) PLAYS FOR 1 HOUR 57</CsScore> 58</CsoundSynthesizer> 59<bsbPanel> 60 <label>Widgets</label> 61 <objectName/> 62 <x>915</x> 63 <y>239</y> 64 <width>519</width> 65 <height>225</height> 66 <visible>true</visible> 67 <uuid/> 68 <bgcolor mode="background"> 69 <r>170</r> 70 <g>170</g> 71 <b>170</b> 72 </bgcolor> 73 <bsbObject version="2" type="BSBLabel"> 74 <objectName/> 75 <x>2</x> 76 <y>2</y> 77 <width>513</width> 78 <height>217</height> 79 <uuid>{aa607456-d368-4d59-8497-d16d608404c3}</uuid> 80 <visible>true</visible> 81 <midichan>0</midichan> 82 <midicc>0</midicc> 83 <label>MIDI Tap Tempo</label> 84 <alignment>center</alignment> 85 <font>Liberation Sans</font> 86 <fontsize>18</fontsize> 87 <precision>3</precision> 88 <color> 89 <r>0</r> 90 <g>0</g> 91 <b>0</b> 92 </color> 93 <bgcolor mode="background"> 94 <r>244</r> 95 <g>248</g> 96 <b>200</b> 97 </bgcolor> 98 <bordermode>border</bordermode> 99 <borderradius>5</borderradius> 100 <borderwidth>2</borderwidth> 101 </bsbObject> 102 <bsbObject version="2" type="BSBLabel"> 103 <objectName/> 104 <x>6</x> 105 <y>28</y> 106 <width>506</width> 107 <height>125</height> 108 <uuid>{d4bdb5ce-87d8-4c8c-9c64-40ec2eed6f5a}</uuid> 109 <visible>true</visible> 110 <midichan>0</midichan> 111 <midicc>0</midicc> 112 <label>---------------------------------------------------------------------------------------------------------------------------- 113The example demonstrate a method for defining a tempo by tapping notes on a MIDI keyboard. The time difference between consecutive MIDI note-ons is recorded and used to derive a tempo value. In this example this value is used to define the delay time of a simple delay effect that is applied to the live audio input of the computer.</label> 114 <alignment>left</alignment> 115 <font>Liberation Sans</font> 116 <fontsize>14</fontsize> 117 <precision>3</precision> 118 <color> 119 <r>0</r> 120 <g>0</g> 121 <b>0</b> 122 </color> 123 <bgcolor mode="nobackground"> 124 <r>255</r> 125 <g>255</g> 126 <b>255</b> 127 </bgcolor> 128 <bordermode>noborder</bordermode> 129 <borderradius>1</borderradius> 130 <borderwidth>1</borderwidth> 131 </bsbObject> 132 <bsbObject version="2" type="BSBLabel"> 133 <objectName/> 134 <x>6</x> 135 <y>153</y> 136 <width>505</width> 137 <height>60</height> 138 <uuid>{b143f42f-2cbc-4532-8df7-4ba643c60b37}</uuid> 139 <visible>true</visible> 140 <midichan>0</midichan> 141 <midicc>0</midicc> 142 <label/> 143 <alignment>left</alignment> 144 <font>Liberation Sans</font> 145 <fontsize>10</fontsize> 146 <precision>3</precision> 147 <color> 148 <r>0</r> 149 <g>0</g> 150 <b>0</b> 151 </color> 152 <bgcolor mode="nobackground"> 153 <r>255</r> 154 <g>255</g> 155 <b>255</b> 156 </bgcolor> 157 <bordermode>border</bordermode> 158 <borderradius>5</borderradius> 159 <borderwidth>2</borderwidth> 160 </bsbObject> 161 <bsbObject version="2" type="BSBLabel"> 162 <objectName/> 163 <x>217</x> 164 <y>166</y> 165 <width>93</width> 166 <height>30</height> 167 <uuid>{a3c622cc-d6a0-4f7c-b9b8-5179d6261036}</uuid> 168 <visible>true</visible> 169 <midichan>0</midichan> 170 <midicc>0</midicc> 171 <label>Delay Time</label> 172 <alignment>right</alignment> 173 <font>Liberation Sans</font> 174 <fontsize>10</fontsize> 175 <precision>3</precision> 176 <color> 177 <r>0</r> 178 <g>0</g> 179 <b>0</b> 180 </color> 181 <bgcolor mode="nobackground"> 182 <r>255</r> 183 <g>255</g> 184 <b>255</b> 185 </bgcolor> 186 <bordermode>noborder</bordermode> 187 <borderradius>1</borderradius> 188 <borderwidth>1</borderwidth> 189 </bsbObject> 190 <bsbObject version="2" type="BSBLabel"> 191 <objectName/> 192 <x>18</x> 193 <y>166</y> 194 <width>93</width> 195 <height>30</height> 196 <uuid>{830ca56f-fafc-4c8c-b8b0-8ac877fd49ac}</uuid> 197 <visible>true</visible> 198 <midichan>0</midichan> 199 <midicc>0</midicc> 200 <label>Tempo</label> 201 <alignment>right</alignment> 202 <font>Liberation Sans</font> 203 <fontsize>10</fontsize> 204 <precision>3</precision> 205 <color> 206 <r>0</r> 207 <g>0</g> 208 <b>0</b> 209 </color> 210 <bgcolor mode="nobackground"> 211 <r>255</r> 212 <g>255</g> 213 <b>255</b> 214 </bgcolor> 215 <bordermode>noborder</bordermode> 216 <borderradius>1</borderradius> 217 <borderwidth>1</borderwidth> 218 </bsbObject> 219 <bsbObject version="2" type="BSBDisplay"> 220 <objectName>Tempo</objectName> 221 <x>110</x> 222 <y>166</y> 223 <width>80</width> 224 <height>30</height> 225 <uuid>{0c475a5a-d0aa-4fcd-9caa-a95cbaf1ad9d}</uuid> 226 <visible>true</visible> 227 <midichan>0</midichan> 228 <midicc>0</midicc> 229 <label>60.000</label> 230 <alignment>left</alignment> 231 <font>Liberation Sans</font> 232 <fontsize>12</fontsize> 233 <precision>3</precision> 234 <color> 235 <r>0</r> 236 <g>0</g> 237 <b>0</b> 238 </color> 239 <bgcolor mode="nobackground"> 240 <r>255</r> 241 <g>255</g> 242 <b>255</b> 243 </bgcolor> 244 <bordermode>noborder</bordermode> 245 <borderradius>1</borderradius> 246 <borderwidth>1</borderwidth> 247 </bsbObject> 248 <bsbObject version="2" type="BSBDisplay"> 249 <objectName>Delay_Time</objectName> 250 <x>309</x> 251 <y>166</y> 252 <width>80</width> 253 <height>30</height> 254 <uuid>{d39e4f0b-318a-4a5b-b29d-5972c1cf8789}</uuid> 255 <visible>true</visible> 256 <midichan>0</midichan> 257 <midicc>0</midicc> 258 <label>1.000</label> 259 <alignment>left</alignment> 260 <font>Liberation Sans</font> 261 <fontsize>12</fontsize> 262 <precision>3</precision> 263 <color> 264 <r>0</r> 265 <g>0</g> 266 <b>0</b> 267 </color> 268 <bgcolor mode="nobackground"> 269 <r>255</r> 270 <g>255</g> 271 <b>255</b> 272 </bgcolor> 273 <bordermode>noborder</bordermode> 274 <borderradius>1</borderradius> 275 <borderwidth>1</borderwidth> 276 </bsbObject> 277</bsbPanel> 278<bsbPresets> 279</bsbPresets> 280<EventPanel name="" tempo="60.00000000" loop="8.00000000" x="913" y="162" width="655" height="346" visible="true" loopStart="0" loopEnd="0"> </EventPanel> 281