1

I want to increment a counter with each play of my csound instrument. The intention is to iterate thru numerical sequences with every MIDI triggering of my csound instrument.

Test case is below. I'm just trying to get it to print 1, 2, 3, 4 etc with each subsequent play. But this is not compiling so well.

<Cabbage>
form caption("Untitled") size(400, 400), colour(58, 110, 182), pluginID("def1")
gentable bounds(10,10,380,200),tablenumber(1)
keyboard bounds(8, 258, 381, 95),channel("keyboard")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
inum init 1

;instrument will be triggered by keyboard widget
instr 1
kEnv madsr .1, .2, .6, 1
aOut oscili p5, p4, 1
amod oscili 434,aOut, 1
outs aOut*kEnv*amod, aOut*kEnv*amod
inum = inum + 1
prints "%inum"
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
f1 0 4096 11 7 3 1 13 4 8 5
</CsScore>
</CsoundSynthesizer>
1

The following code gives the desired output.

 <Cabbage>
form caption("Untitled") size(400, 400), colour(58, 110, 182), pluginID("def1")
gentable bounds(10,10,380,200),tablenumber(1)
keyboard bounds(8, 258, 381, 95),channel("keyboard")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
gicount init 0


;instrument will be triggered by keyboard widget
instr 1
gicount    =         gicount + 1 
         prints    "gicount = %d\n", gicount
kEnv madsr .1, .2, .6, 1
aOut oscili p5, p4, 1

outs aOut*kEnv, aOut*kEnv

endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
f1 0 4096 11 7 3 1 13 4 8 5
</CsScore>
</CsoundSynthesizer>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.