Cabbage Logo
Back to Cabbage Site

Change pages

Hi Rory Walsh:

I have two more questions:

  1. When I press the keyboard, the Slider disappears. Why?
  2. When the window is opened, the Slider does not display. It needs to press the key twice to display.
    So can you help me fix the project?
    Thanks a lot~change page .csd (1.9 KB)

Welcome to the forums, Paradox! I’ll take a shot at this, but I might not have all of the answers for you. Hopefully it at least helps a little.

instr 1 is both getting called as an always on instrument, where you have:
i1 0 1000
And every time you press a key on the keyboard, since it triggers another instance on instr 1 in addition to the always on one you manually launched.

This can have some weird behavior, and probably wasn’t what you intended (but I could be wrong). It’s pretty common to move code that is related to updating the GUI into a separate instrument that’s called as always on, so the keyboard is free to be played without causing unintended gui updates. You can have as many instruments as you want in one cabbage file, so feel free to keep instr 1 as a keyboard synth, and maybe have another instr 99 to handle gui changes.

This is a weird one. I trimmed it down and made three examples, they’re all in this one file. Instr 1 is the keyboard still, while instr 97 and 98 are the non-working examples, and aren’t active. 99 works and is active. I included comments that try to help show what’s going on, to my limited understanding of it.

Hopefully this is helpful, let me know if you have questions about what I did.
change page2.csd (2.9 KB)

oh! I saw it succeeded! Thank you for your detailed answer!
Reminds me of using Csound, 97/98/99 as the effects screen…ahhahaha

best

W

That exactly how to think of it! You want your delays and reverbs to always be on and processing, just like your gui. Glad it helped.

To get instrument 98 working you need to rearrange some of those chnset stuff so it falls through to the default values at i-time.

; I also though this one would work too... guess not.
instr 98
    kTrig chnget "but1" 
    if(changed(kTrig)==1) then
        ; I guess stating kTrig==0 first doesn't work correctly?
        if(kTrig==1) then
            chnset "visible(0)", "sliders1"
            chnset "visible(1)", "sliders2"
        else
            chnset "visible(1)", "sliders1"
            chnset "visible(0)", "sliders2"
        endif
    endif
endin

My understanding is that string channels are a little odd in Csound. Technically strings are i-rate, so Csound will assume i-rate channels are being used when strings are passed to chnset.

instr 97 is an interesting one.

; I thought this one would work, not sure offhand why it didn't.
instr 97
    kTrig chnget "but1"
    if(changed(kTrig)==1) then
        Smessage sprintfk "visible(%d)", kTrig==0 ? 1 : 0
        chnset Smessage, "sliders2"
        Smessage sprintfk "visible(%d)", kTrig==1 ? 1 : 0
        chnset Smessage, "sliders1"
    endif
endin

It works but only after the first button press. In this case you are modifying a string at k-time and then passing that string to chnset. As far as I understand it, Smessage will not contain any valid string data until we are in k-time. So these channels are initially empty.

And finally, there is another way to do this.

instr 96
    kTrig chnget "but1"
    
    SStr[] init 4
    SStr[0] = "sliders1"
    SStr[1] = "sliders2"
    SStr[2] = "visible(1)"
    SStr[3] = "visible(0)"
    
    if(changed(kTrig)==1) then
        chnset SStr[2+kTrig], SStr[0]
        chnset SStr[2+(kTrig == 1 ? 0 : 1)], SStr[1]
    endif
endin

:crazy_face:

That’s instr 99! :joy:

Whoa… :exploding_head:

wah! You may be a genius :思维:

I’ve been called a lot of things, but never that :rofl: