-Ma sr = 44100 ksmps = 32 nchnls = 1 0dbfs = 1 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 ; -- if inum=0 or not given, all instrument numbers in ifn are triggered ifn, inum xin 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 ; -- trigger the first two instruments in the giInstrs table MidiTrig giInstrs, 2 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 ;Example by Joachim Heintz, using code of Victor Lazzarini