Hi all,
i am trying to build a generic midi data recorder and midi player.
In the first instrument, these midi data are written to a text file in packages of 4: status (for example: controller only = 176), midi channel, CC number and value.
Then, in a second instrument that plays back the midi data, this playback should be flexible in its playback speed. And this is the issue that i do not know how to solve…
Right now, my code is not really using real midi data, but mimicking it. When this flexible issue is resolved, i can then move on and add the midi input ports and record different controller numbers etc.
This is my code:
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac ;--displays ;;;realtime audio out
;-iadc ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o gen02.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 128
nchnls = 2
0dbfs = 1
giFt ftgen 0, 0, kr*4, -2, 0 ; kr = 375
giFtable ftgen 0, 0, kr*4, -2, 0
seed 0
instr 1 ; mimic CC midi controller
kndx init 0
;kndx linseg 0, 1, ftlen(giFt) ; move through table in 1 second
kvalue linseg 100, p3*.5, 0, p3 *.5, 100 ; 100 Hz, back to 0, up to 100
kstatus = 176 ; CC
kchan = 1 ; midi channel 1
kCC = 7 ; controller 7
tablew kstatus, kndx, giFt ; load CC
tablew kchan, kndx+1, giFt ; load midi channel
tablew kCC, kndx+2, giFt ; load controller 7
tablew int(kvalue), kndx+3, giFt ; value 0 - 127
kndx += 4
ares poscil3 .5, 100+int(kvalue) ; sine, add 100Hz and back down
outs ares, ares
krel release ; write in last k cycle
if (krel == 1) then
ftsavek "/home/menno/MidiData2.txt", 1, 1, giFt ; write as text file to disk (k rate)
endif
endin
instr 2 ; play back
ftload "/home/menno/MidiData2.txt", 1, giFtable ; load textfile in new table (i rate)
kndx init 0
;kval0 table3 kndx, giFtable
;kval1 table3 kndx+1, giFtable
;kval2 table3 kndx+2, giFtable
kval3 table3 kndx+3, giFtable ; use only these values in vco2
;printsk "status = %d channel = %d controller = %d value = %d\n", kval0, kval1, kval2, kval3
printk2 kval3
ares vco2 .3, 100+(kval3) ; saw, add 100Hz and back down
outs ares, ares
kndx += 4
endin
</CsInstruments>
<CsScore>
i1 0 1 1 ; 1 sec.
i2 2 1 1 ; 1 sec, as recorded
i2 4 2 .5 ; trying to stretch 2 x ....
e
</CsScore>
</CsoundSynthesizer>
What happens now is that only the changing value of every 4th index is read; the changing value of the controller 7. How can i influence the speed of the reading back of the file, relative to p3?