Cabbage Logo
Back to Cabbage Site

Ascii midi keyboard control

Start the instrument with an infinite duration (negative p3), or a really long duration. And then stop the instrument whenever you release a key.

<Cabbage>
form caption("Note State Example") size(300, 200), guiMode("queue"), pluginId("def1")
keyboard bounds(10, 10, 280, 100), channel("noteState")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -dm0 --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>

ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
    event_i "i", 2, 0, -1, p4
    if release() == 1 then
        turnoff2 2, 0, 1
    endif 
endin


instr 2
    k1 madsr .1, .2, .8, .5
    a2 oscili k1, p4
    outs a2, a2
endin

</CsInstruments>
<CsScore>
f0 z
</CsScore>
</CsoundSynthesizer>

the release in the main instrument only worked as long as it didn’t have to distinguish between other instruments/elements, that’s why I bothered trying to separate them in different instruments.

You wrote in your code:

schedkwhen kSTrigE, 0, 1, 4, 0, ..., p4, p5 ; I need to sound instr 4 as long as I hold the key, which plays the sound

I then provided an example of an instrument sounding for as long as you hold a note :+1:

It probably has to do with assigning different midi channel numbers to the different instruments, so they don’t get triggered from one another.