Cabbage Logo
Back to Cabbage Site

Python + Cabbage

I am trying to get some Python code running, and am hitting snags just trying to do the most basic of things - maybe there’s something up with my environment.

form size(380, 160), caption("The Laurie"), pluginID("laurie")
-n -d -b128 -B1024 -M2


pyruni {{

import sys
print sys.path


instr 1
ktrig init 1
ifreq 	cpsmidi
iamp 	ampmidi 	10000
printks "received: %d, %d\n", .1, ifreq, iamp

f0 3600
f1 0 16384 10 1 

I get a crash when initially saving this file, and no print. 2 questions:

  1. Is there a log I can tail to help diagnose the problem?
  2. Should I expect python opcodes to work within a cabbage instrument?

Great work on Cabbage - thanks so much!

It should work. I know of some fairly big projects using Cabbage and Python. Some questions:
What version of Cabbage are you using?
What OS are you on?
Can you run standard Csound files with Python outside of Cabbage?
Did you install the Python opcodes when installing Csound (only an option in Windows).

If you can, please share some of the ‘fairly big projects using Cabbage and Python’ or encourage the developers of them to please share some of them! Thanks.

The ones I was referring to were by @Oeyvind, but I’m not sure he’s using Python in this context any more. I think most people using Python with Csound these days are running Csound in Python rather than Python in Csound.

Yes, I do remember @Oeyvind showing some things that he had developed which had Python inside the Cabbage Plugin, but he may be going the other route now.

Oh, nice. It is an interesting problem :slight_smile:

Yes, I used to do Python inside Csound within Cabbage like this, but have changed my workflow in later years. I have the same needs still (need for some some operations that are much easier to do in Python than in Csound). Now I usually just run Python in its own procress, like a server running in the background, then I use OSC to send data from Csound, triggering some operation in Python that returns data over OSC to Csound. I run Csound within a VST with Cabbage.
One major reason for this architecture is that I wanted to de-synchronize the audio thread from the (possibly heavy) operations done in Python. If Python takes too long to complete an operation, and you use Python synchronized within Csound (like with the py opcodes) you get audio dropouts on your whole Csound orchestra. When I de-synchronze the processes, it might happen that the instrument needing Python will have a small lag in responsitivity, some latency before the Python calculations affect the output in the intended manner, but still making sound all the time, and even more importantly not creating dropouts for other instruments that run concurrently.

I also had some thoughts that perhaps the py opcodes would not be so easily compatible with future updates (of Csound and of Python), and thus they might be likely to break (e.g. when Python has a major version update, as happened not so long ago). When I run Python as a separate process, the architecture better separated in blocks and it is easier to debug compatibility problems (when coming back to it 10 years from now, and it won’t run).

I can send some (untidy) examples if anyone wants to see. I am sure it can be optimized, but the general signal flow works well.

all best

1 Like


Thanks for these details and suggestions on your more efficient, stable, glitch-free, and future-proof approach.

I would love to see and study and share your examples.