Cabbage Logo
Back to Cabbage Site

Problem with "schedwhen" & "turnoff2"

I’m trying tu build a multi-effect: 1 master instrument with buttons that start instances of other instruments.
I have a problem: I can start & and stop the instrument but only 1 time.

Thankyou.

<Cabbage>
form caption("ON - OFF") size(400, 300), colour(220, 220, 220), pluginID("ON_OFF_start")


checkbox bounds(50, 30, 100, 30) channel("fx1")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1


instr 10


ktrig1 chnget "fx1"
printk 0.2, ktrig1
    
schedwhen ktrig1, 11, 0, 10 
     
     if (ktrig1 == 0) then
     turnoff2 11, 2, 0
     endif
     
     
endin


instr 11

a1 oscili 0.2, 440, 1

outch 1, a1
outch 2, a1

endin
                

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
f1 0 1024 10 1 1 1 1 

;starts instrument 10 and runs it for a week
i10 0 z

</CsScore>
</CsoundSynthesizer>

Hi @Asterix, thanks for posting. As much as I find Slack useful at times, I hate the fact that all the great information and help shared there is not very public. Anyone can view this forum, which is something I like :wink:

As for your question, I’m not sure as I have never used that opcode. However, this seems like typical behaviour going by what the example in the manual says. I refer specifically to the code example:

instr 1

kmtr metro 100				;produce 100 triggers per second
     schedwhen kmtr, 2, 1, .3		;but schedwhen plays instr. 2 only once		

endin

I’m not sure why it only triggers instrument 2 once. Have you looked at schedkwhen?

Personally I would just use the event opcode as I think it read better.

instr 10

    ktrig1 chnget "fx1"
    printk 0.2, ktrig1
    
    if changed(ktrig1) == 1 then
        if (ktrig1 == 1) then
            event "i", 11, 0, 1  
        else
            turnoff2 11, 2, 0
        endif 
    endif  
     
endin

Thank you! @rorywalsh

Perfect!!!

1 Like