| 1 |
<CsoundSynthesizer> |
| 2 |
<CsOptions> |
| 3 |
; enter name of input midi file |
| 4 |
-F InputMidiFile.mid |
| 5 |
</CsOptions> |
| 6 |
<CsInstruments> |
| 7 |
|
| 8 |
;ksmps needs to be small to ensure accurate rendering of timings |
| 9 |
ksmps = 8 |
| 10 |
|
| 11 |
massign 0,1 |
| 12 |
|
| 13 |
instr 1 |
| 14 |
iChan midichn |
| 15 |
iCps cpsmidi ; read pitch in frequency from midi notes |
| 16 |
iVel veloc 0, 127 ; read in velocity from midi notes |
| 17 |
kDur timeinsts ; running total of duration of this note |
| 18 |
kRelease release ; sense when note is ending |
| 19 |
if kRelease=1 then ; if note is about to end |
| 20 |
; p1 p2 p3 p4 p5 p6 |
| 21 |
event "i", 2, 0, kDur, iChan, iCps, iVel ; send full note data to instr 2 |
| 22 |
endif |
| 23 |
endin |
| 24 |
|
| 25 |
instr 2 |
| 26 |
iDur = p3 |
| 27 |
iChan = p4 |
| 28 |
iCps = p5 |
| 29 |
iVel = p6 |
| 30 |
iStartTime times ; read current time since the start of performance |
| 31 |
; form file name for this channel (1-16) as a string variable |
| 32 |
SFileName sprintf "Channel%d.sco",iChan |
| 33 |
; write a line to the score for this channel's .sco file |
| 34 |
fprints SFileName, "i%d\\t%f\\t%f\\t%f\\t%d\\n",\ |
| 35 |
iChan,iStartTime-iDur,iDur,iCps,iVel |
| 36 |
endin |
| 37 |
|
| 38 |
</CsInstruments> |
| 39 |
<CsScore> |
| 40 |
f 0 480 ; ensure this duration is as long or longer that duration of midi file |
| 41 |
</CsScore> |
| 42 |
</CsoundSynthesizer> |
| 43 |
;example by Iain McCurdy |