Activating a Cabbage Plugin to Initiate a Python Synthesizer Using Pyo and PySimpleGUI

Posted by


In this tutorial, we will explore how to use the Cabbage plugin to trigger a Python synthesis algorithm with the help of the Pyo audio library and the PySimpleGUI graphical user interface library. The combination of these tools allows for the creation of powerful and customizable sound synthesis applications.

Step 1: Install the necessary libraries

Before we begin, you will need to install the following libraries:

  • Cabbage: a software for building audio plugins with the Csound audio engine
  • Pyo: an audio synthesis library for Python
  • PySimpleGUI: a GUI framework for Python

You can install these libraries using pip:

pip install cabbage pyo PySimpleGUI

Step 2: Write the Python synthesis algorithm

Next, we will write a simple Python synthesis algorithm using the Pyo library. In this example, we will create a basic sine wave oscillator. Copy and paste the following code into a new Python file:

from pyo import *

s = Server().boot()

osc = Sine(freq=440, mul=0.5).out()

s.gui(locals())

Save the file as synth.py.

Step 3: Create the Cabbage plugin

Now, we will create a Cabbage plugin that will trigger the Python synthesis algorithm. Copy and paste the following code into a new text file:

<Cabbage>
form caption("Python Synth") size(400, 300), guiMode("queue")
keyboard bounds(10, 10, 380, 100)

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=virtual -M0 -m0d
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
iKey cabbageGetValue "keyboard"
if iKey != 0 then
    event "i", 100, 0, 1
endif
endin

</CsInstruments>
<CsScore>
i 1 0 z
</CsScore>
</CsoundSynthesizer>

Save the file as plugin.csd.

Step 4: Connect the Python synthesis algorithm with the Cabbage plugin

In order to connect the Cabbage plugin with the Python synthesis algorithm, we will use the PySimpleGUI library to create a graphical interface that will trigger the plugin. Copy and paste the following code into a new Python file:

import subprocess
import PySimpleGUI as sg

# Start the Cabbage plugin
subprocess.Popen(["csound", "-odac", "plugin.csd"])

# Create a simple GUI to trigger the plugin
layout = [[sg.Button("Play")]]
window = sg.Window("Python Synth", layout)

while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED:
        break
    elif event == "Play":
        # Trigger the plugin
        subprocess.Popen(["csound", "-s", "plugin.csd"])

window.close()

Save the file as gui.py.

Step 5: Run the application

Finally, run the gui.py file in your Python environment. You should see a simple GUI with a "Play" button. Clicking the button will trigger the Cabbage plugin, which in turn will trigger the Python synthesis algorithm, producing a sine wave sound.

Congratulations! You have successfully created a sound synthesis application using the Cabbage plugin, Pyo library, and PySimpleGUI framework. Feel free to experiment with different synthesis algorithms and GUI designs to create your own custom music applications.

0 0 votes
Article Rating
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@POGRetroModernGaming
2 months ago

I thinking learn phyton simplegui, is a vst ?

@POGRetroModernGaming
2 months ago

Wow is a vst ?

@PySimpleGUI
2 months ago

Be sure and get the latest PySimpleGUI because you'll be able to use COLOR for your buttons and everything else for that matter.

@matrixview
2 months ago

What/who's song is this…? I recognize it…