Introduction on how to use pyo inside an OpenFrameworks project.
================================================================ 

To use pyo inside an OpenFrameworks project, first you need a 
working install of pyo for python 3 on your system.
After installing pyo, you can 
move on and create an OpenFrameworks project.

------------------------------------------------------------------------
This folder already includes an openFrameworks example which you can
copy in OF/apps/myApps and compile it.
Below are instructions for making your own project.

------------------------------------------------------------------------
Step 1 - Create a default project with the project generator. To avoid
any include or linking problem, you should save your project in the 
default location (OF_ROOT/apps/myApps).

------------------------------------------------------------------------
Step 2 - Add pyo files to your project. You only need to copy 
these files in your project's src folder:

- from the folder pyo/embedded/openframeworks/pyoExample/srd
(m_pyo.h is the same for all embedded projects, not only OF):
m_pyo.h
PyoClass.cpp
PyoClass.h

------------------------------------------------------------------------
Step 3 - Make sure that your project includes flags for compiling 
and linking against Python. On Unix systems, you can set the Python 
flags in the file config.make. Uncomment and complete these lines:

PROJECT_LDFLAGS = `python3-config --ldflags --embed` # linker flags for Python
PROJECT_CFLAGS = `python3-config --cflags` # compiler flags for Python

------------------------------------------------------------------------
Step 4 - Make a scripts folder in bin/data of your project's directory and 
create a python file, named "stereoDelay.py", with these lines in it
(if the bin/data/ directory doesn't exist, create it):

# Get the input sound and apply a stereo delay + reverb on it.
st_input = Input([0,1])
st_delay = Delay(st_input, delay=[.4, .5], feedback=0.7)
st_rev = WGVerb(st_delay, feedback=0.8, cutoff=4000, bal=0.25).out()

------------------------------------------------------------------------
Step 5 - Edit src/ofApp.h

- Include PyoClass definition:

#include "PyoClass.h"

- Add audio in/out callbacks to the public attributes of the ofApp class:

void audioIn(float * input, int bufferSize, int nChannels);
void audioOut(float * input, int bufferSize, int nChannels);

- Add an ofSoundStream object to the public attributes of the ofApp class:

ofSoundStream soundStream;

- Add a Pyo object to the public attributes of the ofApp class:

Pyo pyo;

------------------------------------------------------------------------
Step 6 - Edit src/ofApp.cpp

- Creates the setup() function:

void ofApp::setup(){
    // define audio properties
    int sampleRate = 44100;
    int bufferSize = 256;
    int nChannels = 2;
    // initialize a pyo server
    pyo.setup(nChannels, bufferSize, sampleRate);
    // load a python file
    pyo.loadfile("data/scripts/stereoDelay.py", 0);
    // initialize OpenFrameworks audio streaming channels 
    //soundStream.listDevices()     // Uncomment if you need to
    //soundStream.setDeviceID(1);   // change the audio device.
	soundStream.setup(this, nChannels, nChannels, sampleRate, bufferSize, 4);
}

- Creates audio in/out functions:

void ofApp::audioIn(ofSoundBuffer & buffer){
    pyo.fillin(&buffer[0]);
}

void ofApp::audioOut(ofSoundBuffer & buffer){
	pyo.process(&buffer[0]);
}

------------------------------------------------------------------------
Step 7 - Compile your project. To compile, cd to your project folder and:

# This line is for MacOS, you'll have to adapt it to your system!
make && cp -r scripts bin/*.app/Contents/Resources

# In Linux just run
make

------------------------------------------------------------------------
Here you go! You should be able to run your app created in the bin folder.

Documentation
=============

For a complete description of functions that can be used to communicate 
with the pyo embedded processes, see documentation comments in the file 
PyoClass.cpp.


(c) 2026 - belangeo


