Cabbage Logo
Back to Cabbage Site

High CPU usage for the queue guiMode

Ok, I think this is fixed now. I might have been a little over zealous with my cabbageSetValue optimisations!

Thanks!

This still seems to be the case. I have no issue with this, just checking if you intended it to be like that?

Actually, it seems cabbageSetValue (with trigger) now works only in default mode. :upside_down_face: Could you please check?

Thanks @Samo, and this is why I shouldn’t push things on a Sunday! I’ll check tomorrow when I have more time :+1:

Please don’t feel pressed by me. I am just an enthusiast! You’re doing such an amazing job with Cabbage and this forum! And this certainly adds to my enthusiasm. What matters most is that the questions/suggestions are actually considered and addressed. So, definitely take your time (specially weekends), even though people like me might get time to fiddle and post questions mostly on weekends.

I have a fix for this. I’ll push it through a little later today.

Maybe you plan to fix this later, but I’m currently quite confused about the queue mode.
Could you please check the test below. I believe this functionality worked fine before. Change guiMode in the <Cabbage> section and by changing iQueueMode = 0/1.

  1. CabbageGetValue seems to work in both modes [see
    cabbageGetValue:i("State")]

  2. printk2 chnget:i("State") works as expected but printk2 cabbageGetValue:i(“State”) does not (inconsistency)

  3. cabbageSet (please check also cabbageSetValue) behaves strange. The "State" channel should init to 0 as it does in default mode. There seems possibly something wrong with the triggers (different ways I’m trying to trigger are commented)?

    <Cabbage> bounds(0, 0, 0, 0)
    
    form caption("test CabbageGetValue") size(300, 200), colour(0, 0, 0), pluginId("tepc") ;guiMode("queue") 
    
    ; comment/uncomment these two
    ;button bounds(28, 50, 71, 24) latched(0) channel("FlipOFF") text("OFF") colour:0(100, 100, 100, 255) colour:1(255, 255, 0, 255) fontColour:0(255, 255, 0, 255) fontColour:1(160, 0, 0, 255)
    ;button bounds(28, 24, 71, 24) latched(0) channel("FlipON") text("ON") colour:0(100, 100, 100, 255) colour:1(255, 255, 0, 255) fontColour:0(255, 255, 0, 255) fontColour:1(160, 0, 0, 255)
    
    ; comment/uncomment these two
    button bounds(28, 50, 71, 24) latched(0) channel("FlipOFF") identChannel("ID_FlipOFF") text("OFF") colour:0(100, 100, 100, 255) colour:1(255, 255, 0, 255) fontColour:0(255, 255, 0, 255) fontColour:1(160, 0, 0, 255)
    button bounds(28, 24, 71, 24) latched(0) channel("FlipON") identChannel("ID_FlipON") text("ON") colour:0(100, 100, 100, 255) colour:1(255, 255, 0, 255) fontColour:0(255, 255, 0, 255) fontColour:1(160, 0, 0, 255)
    
    button bounds(108, 36, 66, 27) channel("State") text("State") colour:0(255, 255, 0, 100) colour:1(255, 255, 0, 255) visible(1)
    
    
    </Cabbage>
    <CsoundSynthesizer>
    <CsOptions>
    -d -n -+rtmidi=null -M0 -m0d
    
    </CsOptions>
    <CsInstruments>
    
    ksmps   = 16
    
    
    instr 1
    
    ;print cabbageGetValue:i("State")
    
    iQueueMode = 0
    
    if iQueueMode == 0 then
     
    printk2 chnget:i("State")
     
    if trigger(chnget:k("FlipON"),0.5,0) == 1 then; 0->1
        chnset k(0), "State"
        printks "ON\n", 0
    endif
    
    if trigger(chnget:k("FlipOFF"),0.5,0) == 1 then; 0->1
        chnset k(1), "State"
        printks "OFF\n",0
    endif
    
    if trigger(chnget:k("State"),0.5,0) == 1 then; 0->1
        chnset "colour:0(200, 0, 0, 255)", "ID_FlipOFF"
    endif
    
    if trigger(chnget:k("State"),0.5,1) == 1 then; 1->0
        chnset "colour:0(100, 100, 100, 255)", "ID_FlipOFF"
    endif
    
    endif
    
    
    if iQueueMode == 1 then
    
    printk2 cabbageGetValue:i("State")
       
    if trigger(cabbageGetValue:k("FlipON"),0.5,0) == 1 then; 0->1
        ;cabbageSetValue "State", k(0), 1
        ;cabbageSetValue "State", k(0), k(1)
        cabbageSetValue "State", k(0)
        printks "ON\n", 0
    endif
    
    if trigger(cabbageGetValue:k("FlipOFF"),0.5,0) == 1 then; 0->1
        ;cabbageSetValue "State", k(1), 1
        ;cabbageSetValue "State", k(1), k(1)
        cabbageSetValue "State", k(1)
        printks "OFF\n", 0
    endif
    
    ;cabbageSetValue "State", k(0), trigger(cabbageGetValue:k("FlipON"),0.5,0)
    ;cabbageSetValue "State", k(1), trigger(cabbageGetValue:k("FlipOFF"),0.5,0)
    
    if trigger(cabbageGetValue:k("State"),0.5,0) == 1 then; 0->1
        ;cabbageSet 1, "FlipOFF", "colour:0", 200, 0, 0, 255
        cabbageSet k(1), "FlipOFF", "colour:0", 200, 0, 0, 255
    endif
    
    if trigger(cabbageGetValue:k("State"),0.5,1) == 1 then; 1->0
        ;cabbageSet 1, "FlipOFF", "colour:0", 100, 100, 100, 255
        cabbageSet k(1), "FlipOFF", "colour:0", 100, 100, 100, 255
    endif
    
    ;cabbageSet trigger(cabbageGetValue:k("State"),0.5,0), "FlipOFF", "colour:0", 200, 0, 0, 255
    ;cabbageSet trigger(cabbageGetValue:k("State"),0.5,1), "FlipOFF", "colour:0", 100, 100, 100, 255
     
    endif
    
    endin
    
    </CsInstruments>
    <CsScore>
    ;causes Csound to run for about 7000 years...
    f0 z ;starts instrument 1 and runs it for a week
    i 1 0 -1;[60*60*24*7]
    
    </CsScore>
    </CsoundSynthesizer>

Thanks for the sample code, that should make things a lot easier. I won’t have a chance to put it through its paces till morning time. I’ll let you know. :+1:

Hi @Samo. I just had a chance to look at this.

This is correct, and has always been the case. This opcode merely retrieves data from a channel. It’s quite Cabbage agnostic. cabbageSetValue on the other hand is a guiMode("queue") only opcode.

You’re using k-rate print opcodes with i-rate variables? If you use print it behaves as one would expect.

if trigger(cabbageGetValue:k("FlipOFF"),0.5,0) == 1 then; 0->1
    ;cabbageSetValue "State", k(1), 1
    ;cabbageSetValue "State", k(1), k(1)
    cabbageSetValue "State", k(1)
    printks "OFF\n", 0
endif  

k-rate checks like this fall through at init time and trigger an init pass in any of the opcodes contained within. Hence the code within this test will always execute at init time. That’s what I added the trigger parameters to cabbageGet/Set/Value. Try this instead, it’s cleaner and doesn’t suffer from the same problems as the code above.

kOn, kOnTrig cabbageGetValue "FlipON"   
cabbageSetValue "State", kOn, kOnTrig

Please keep pushing these to their limits. It’s nice to see them given a good test run!

Btw, you can also do this:

if trigger(cabbageGetValue:k("FlipON"), .5, 0) == 0 then
    cabbageSetValue "State", cabbageGetValue:k("FlipON")
endif

Thanks!
The translation from default to queue is still not logical to me.

But with Cabbage in its name? Confusing…

Yes, but if I do that with chnget:i it doesn’t print, while cabbageGetValue:i obviously reads at k-rate since it gets the updated values. Also confusing…

Have you tried running my code? Please check what I am trying to do in default mode - where it works as I wanted.
I’m using non latched buttons. Your suggestion doesn’t seem to work in this case. I’d like to prevent it triggering on the init pass. Furthermore, I’m also trying to minimize k-variables and doing other things within the trigger block.

Could you try to adjust my code in queue mode so that it replicates the behaviour of my code in default mode? This would be of great help to me, and maybe it would help to elucidate the issue.

Yes, I will try to do that tomorrow with I get a chance :+1:

I append cabbage to all of the opcodes that ship with Cabbage to make it clear to Csounders that these opcodes are not available in the canonical version of Csound. I believe it might otherwise lead to confusion.

Here is your code with a guiMode(“queue”) section that I think replicates yours polling mode exactly. It’s early here and I may have missed something , but to me it looks spot on.

<Cabbage> bounds(0, 0, 0, 0)

form caption("test CabbageGetValue") size(300, 200), colour(0, 0, 0), pluginId("tepc") guiMode("queue") 

; comment/uncomment these two
;button bounds(28, 50, 71, 24) latched(0) channel("FlipOFF") text("OFF") colour:0(100, 100, 100, 255) colour:1(255, 255, 0, 255) fontColour:0(255, 255, 0, 255) fontColour:1(160, 0, 0, 255)
;button bounds(28, 24, 71, 24) latched(0) channel("FlipON") text("ON") colour:0(100, 100, 100, 255) colour:1(255, 255, 0, 255) fontColour:0(255, 255, 0, 255) fontColour:1(160, 0, 0, 255)

; comment/uncomment these two
button bounds(28, 50, 71, 24) latched(0) channel("FlipOFF") identChannel("ID_FlipOFF") text("OFF") colour:0(100, 100, 100, 255) colour:1(255, 255, 0, 255) fontColour:0(255, 255, 0, 255) fontColour:1(160, 0, 0, 255)
button bounds(28, 24, 71, 24) latched(0) channel("FlipON") identChannel("ID_FlipON") text("ON") colour:0(100, 100, 100, 255) colour:1(255, 255, 0, 255) fontColour:0(255, 255, 0, 255) fontColour:1(160, 0, 0, 255)

button bounds(108, 36, 66, 27) channel("State") text("State") colour:0(255, 255, 0, 100) colour:1(255, 255, 0, 255) visible(1)


</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-d -n -+rtmidi=null -M0 -m0d

</CsOptions>
<CsInstruments>

ksmps   = 16


instr 1

;print cabbageGetValue:i("State")

iQueueMode = 1

if iQueueMode == 0 then
 
printk2 chnget:i("State")
 
if trigger(chnget:k("FlipON"),0.5,0) == 1 then; 0->1
    chnset k(0), "State"
    printks "ON\n", 0
endif

if trigger(chnget:k("FlipOFF"),0.5,0) == 1 then; 0->1
    chnset k(1), "State"
    printks "OFF\n",0
endif

if trigger(chnget:k("State"),0.5,0) == 1 then; 0->1
    chnset "colour:0(200, 0, 0, 255)", "ID_FlipOFF"
endif

if trigger(chnget:k("State"),0.5,1) == 1 then; 1->0
    chnset "colour:0(100, 100, 100, 255)", "ID_FlipOFF"
endif

endif


if iQueueMode == 1 then

    kOn, kOnTrig cabbageGetValue "FlipON"   
    cabbageSetValue "State", k(0), kOnTrig   
 
    kOff, kOffTrig cabbageGetValue "FlipOFF"   
    cabbageSetValue "State", k(1), kOffTrig   
    
    
    kState cabbageGetValue "State"
    if kState == 0 then
        cabbageSet kOffTrig + kOnTrig, "FlipOFF", "colour", 100, 100, 100, 255
    else
        cabbageSet kOffTrig + kOnTrig, "FlipOFF", "colour", 200, 0, 0, 255
    endif
    
endif

endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z ;starts instrument 1 and runs it for a week
i 1 0 -1;[60*60*24*7]

</CsScore>
</CsoundSynthesizer>

Thank you for the translation and for your patience!

I think, the only remaining confusion / issue I have is that cabbageGetValue triggeres on the init pass and I’d like to avoid / control that. It sets the “State” channel to 0 and then 1 even though there is no trigger on “FlipOFF”. Is there a way to prevent this? Setting “State” channel to 1 first and then to 0 or using timek to avoid the first pass seems a bit brute force.

Thus, your translation matches my original only if we change the order of

kOn, kOnTrig cabbageGetValue "FlipON"   
cabbageSetValue "State", k(0), kOnTrig

and

kOff, kOffTrig cabbageGetValue "FlipOFF"   
cabbageSetValue "State", k(1), kOffTrig      

So that we have “State” = 0 after the init pass. Here this is not a problem, but there might be other real situations where it could be. The default mode doesn’t have this issue.

Related to this is my previous question:

I understand that cabbageGetValue:i should be used with opcodes that run only at init, but it seems to me that currently there is really no way to prevent cabbageGetValue running either at i or k-time. It seems to always run. I might be missing some background, but from the user perspective it feels like loosing some control. :worried:

I have now removed the init pass from these opcodes when using k-rate input and output args. Let me know if that helps.

Thanks! Sorry for the delayed reply, I was away for a while. I’m not sure, but it seems cabbageSetValue still runs at init when using k-var in ver. 2.6.10. But let me try the new versions first and send you a more concise feedback.

This weekend I tried using Cabbage on another computer (MacBook Pro 15, 2019 with OS 10.15.7) and I experienced some strangeness… The last Cabbage 2.7.1 installation makes a “damaged” app, with the error message: “You can’t open the application because it may be damaged or incomplete”. It works fine with the versions 2.7.0 and 2.6.10 though. I tried re-downloading the “bad” version and reverting to older versions and back to the newer version a few times with the same error only with the newer version. I’ll just wait for the next version :wink:

Another little quirk, which might be just related to some other quirk on the computer was a crackling sound (interruptions) with v. 2.7.0 which stopped when I reverted to v. 2.6.10. Restarting Cabbage or computer was not sufficient to stop the interruption (of course I also tried varying the audio settings). Could it be something strange with these latest installers?

Hmm, this is strange. I haven’t tried the beta installers but will do tomorrow. I’ll let you know what happens.

The latest versions require Csound 6.16, I wonder if you are still using an older version?

[edit] there was a build error in the last beta version for Mac, hence the damaged app warning…

Btw, I’m not experiencing any weird audio dropouts. In 2.7 or later? Did you have a particular .csd file that triggered these issues? If so, can you send it to me so that I can check? You can attach to a PM if you don’t wish to make it public. Thanks.

OK, good to know it was not my system this time:)

I have Csound 6.15 on my home “sound making” laptop. Last weekend I was travelling and had Cabbage on my work computer, where I have no other audio applications. To keep it minimal, I only installed Cabbage there - no Csound. I have a stupid question on this. In what way do Cabbage installers update/take care of Csound? I could use Cabbage, but I haven’t attempted exporting plugins. I suppose they wouldn’t work without a separate Csound installation? I tried exporting standalone, which didn’t work. I should probably read up to understand better the relation between Csound and Cabbage.

Thank you, so kind of you that you could check my csd. I could PM it to you (how?), but I’d like to first try it in my “controlled” environment. Last time I was connected into my friend’s system with possibly other factors causing issues. Even though reverting to an older Cabbage version apparently solved the issue, it could have been other factors.