; STARTER
;
; a BIG button to start Sequenc-Air (https://www.fullbucket.de/music/sequencair.html)
;
; (s) Severák 2019
; licensed with MIT license
<Cabbage>
form caption("Starter") size(150, 100), colour(58, 110, 182), pluginid("strt")

button bounds(7, 6, 136, 62) text("START", "STOP") channel("starter")
checkbox bounds(14, 70, 118, 25) channel("extclock") text("external clock")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -Q0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget
instr GUI
    kextclock chnget "extclock"
    
    if kextclock==1 then
        kStart chnget "IS_PLAYING"
    else
        kStart chnget "starter"
    endif

    
    if changed:k(kStart) == 1 then
        if kextclock==1 then
            chnset kStart, "starter"
        endif
    
        if kStart == 1 then
            midiout 144, 1, 60, 60
            
        elseif kStart == 0 then
            midiout 128, 1, 60, 0
        endif
        ;printks "%d\n", 0, kStart
    endif


endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z

i "GUI" 0 3600
</CsScore>
</CsoundSynthesizer>
