| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
-Ma |
| 4 |
</CsOptions> |
| 5 |
<CsInstruments> |
| 6 |
sr = 44100 |
| 7 |
ksmps = 32 |
| 8 |
nchnls = 1 |
| 9 |
0dbfs = 1 |
| 10 |
|
| 11 |
massign 0, 1 ;assign all incoming midi to instr 1 |
| 12 |
giInstrs ftgen 0, 0, -5, -2, 2, 3, 4, 10, 100 ;instruments to be triggered |
| 13 |
|
| 14 |
opcode MidiTrig, 0, io |
| 15 |
;triggers the first inum instruments in the function table ifn by a midi event |
| 16 |
; with fractional numbers containing channel and note number information |
| 17 |
|
| 18 |
; -- if inum=0 or not given, all instrument numbers in ifn are triggered |
| 19 |
ifn, inum xin |
| 20 |
inum = (inum == 0 ? ftlen(ifn) : inum) |
| 21 |
inote notnum |
| 22 |
ichn midichn |
| 23 |
iturnon = 0 |
| 24 |
turnon: |
| 25 |
iinstrnum tab_i iturnon, ifn |
| 26 |
if iinstrnum > 0 then |
| 27 |
ifracnum = iinstrnum + ichn/100 + inote/100000 |
| 28 |
event_i "i", ifracnum, 0, -1 |
| 29 |
endif |
| 30 |
loop_lt iturnon, 1, inum, turnon |
| 31 |
kend release |
| 32 |
if kend == 1 then |
| 33 |
kturnoff = 0 |
| 34 |
turnoff: |
| 35 |
kinstrnum tab kturnoff, ifn |
| 36 |
if kinstrnum > 0 then |
| 37 |
kfracnum = kinstrnum + ichn/100 + inote/100000 |
| 38 |
event "i", -kfracnum, 0, 1 |
| 39 |
loop_lt kturnoff, 1, inum, turnoff |
| 40 |
endif |
| 41 |
endif |
| 42 |
endop |
| 43 |
|
| 44 |
instr 1 ;global midi instrument |
| 45 |
; -- trigger the first two instruments in the giInstrs table |
| 46 |
MidiTrig giInstrs, 2 |
| 47 |
endin |
| 48 |
|
| 49 |
instr 2 |
| 50 |
ichn = int(frac(p1)*100) |
| 51 |
inote = round(frac(frac(p1)*100)*1000) |
| 52 |
prints "instr %f: ichn = %f, inote = %f%n", p1, ichn, inote |
| 53 |
printks "instr %f playing!%n", 1, p1 |
| 54 |
endin |
| 55 |
|
| 56 |
instr 3 |
| 57 |
ichn = int(frac(p1)*100) |
| 58 |
inote = round(frac(frac(p1)*100)*1000) |
| 59 |
prints "instr %f: ichn = %f, inote = %f%n", p1, ichn, inote |
| 60 |
printks "instr %f playing!%n", 1, p1 |
| 61 |
endin |
| 62 |
|
| 63 |
</CsInstruments> |
| 64 |
<CsScore> |
| 65 |
</CsScore> |
| 66 |
</CsoundSynthesizer> |
| 67 |
;Example by Joachim Heintz, using code of Victor Lazzarini |