-Ma
sr = 44100
ksmps = 64
nchnls = 2
0dbfs = 1
; By Joachim Heintz 2010
; This csd allows triggering multiple csound instruments from a single MIDI note.
massign 0, 1; assign all incoming midi to instr 1
giInstrs ftgen 0, 0, -5, -2, 2, 3, 4, 10, 100; instruments to be triggered
opcode MidiTrig, 0, io
;triggers the first inum instruments in the function table ifn by a midi event, with fractional numbers containing channel and note number information
ifn, inum xin; if inum=0 or not given, all instrument numbers in ifn are triggered
inum = (inum == 0 ? ftlen(ifn) : inum)
inote notnum
ichn midichn
iturnon = 0
turnon:
iinstrnum tab_i iturnon, ifn
if iinstrnum > 0 then
ifracnum = iinstrnum + ichn/100 + inote/100000
event_i "i", ifracnum, 0, -1
endif
loop_lt iturnon, 1, inum, turnon
kend release
if kend == 1 then
kturnoff = 0
turnoff:
kinstrnum tab kturnoff, ifn
if kinstrnum > 0 then
kfracnum = kinstrnum + ichn/100 + inote/100000
event "i", -kfracnum, 0, 1
loop_lt kturnoff, 1, inum, turnoff
endif
endif
endop
instr 1; global midi instrument
MidiTrig giInstrs, 2; triggers the first two instruments in the giInstrs table
endin
instr 2
ichn = int(frac(p1)*100)
inote = round(frac(frac(p1)*100)*1000)
prints "instr %f: ichn = %f, inote = %f%n", p1, ichn, inote
printks "instr %f playing!%n", 1, p1
endin
instr 3
ichn = int(frac(p1)*100)
inote = round(frac(frac(p1)*100)*1000)
prints "instr %f: ichn = %f, inote = %f%n", p1, ichn, inote
printks "instr %f playing!%n", 1, p1
endin
f 0 36000
e
757
268
253
152
true
0
0
0
27
12
202
127
{4b805386-0c5c-4b8f-beb9-6464db5856f3}
true
0
-3
center
Times New Roman
20
3
255
255
255
255
255
255
noborder
1
1
ioView background {0, 0, 0}
ioText {23, 24} {184, 78} label 0.000000 0.00100 "" center "Times New Roman" 20 {65280, 65280, 65280} {63232, 62720, 61952} nobackground noborder This csd shows how to layer csound instruments triggered by a single MIDI note.