Cabbage Logo
Back to Cabbage Site

Csound code efficiency

Hi all,

Is there a document around for optimizing the performance of our code specifically for csound ?
just some guidelines like this:



No, at least none I’m aware of. It would be nice, although, it’s much harder to write completely inefficient code with Csound than C/C++. The biggest issue I see with Cabbage code is users calling cabbageSet on each cycle. That’s a performance red-flag every time.

1 Like

I try to trigger code as conditionally as possible. Here are some things I’ve started doing that have improved the performance of my plugins:

  • Use changed2() to trigger cabbageSet
  • Use the kTrig from cabbageGetValue
  • Trigger instruments with event

Is using a kTrig to a cabbageSet statement like an ‘if’ where the statement would be ignored entirely ?
The only issue I had with this is that double-clicking a widget to default value doesn’t get detected by the trigger, so I had to enter ‘1’ as kTrig for it to work at the moment.

It should get picked up if the widget isn’t at its default value?

Recently started doing kTrig at “cabbageGetValue” simply for using less lines.
There was no “changed2()”-version for kTrig at cabbageGetValue-statement, which would have been nice though.
Haven’t had much need so far for event statements.

Thanks for adding your tips !

I used 2 widgets representing the same value, which both used a trigger to update the other.
When I double-clicked 1 of them, I do an opcode to get a derived value from the main value for the other widget.
Using kTrig, it gets triggered but doesn’t give the right value most of the time.
It only works every time when I remove the kTrig.

Could you prepare a small example of this?

As @hdale94 suggests, a minimal example of the problem would be most helpful. Thanks.


Not gonna work
The problem disappeared in a stripped down version … :thinking:
I’ll take a look at it when I have time,
thanks anyway.


1 Like