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 2.7 on your system (will switch to python 3 as soon as possible). After installing pyo, you can move on and create an OpenFrameworks 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: m_pyo.h - from the folder pyo/embedded/openframeworks: 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 = `python-config --ldflags` # linker flags for Python PROJECT_CFLAGS = `python-config --cflags` # compiler flags for Python ------------------------------------------------------------------------ Step 4 - Make a scripts folder at the root level of your project and create a python file, named "stereoDelay.py", with these lines in 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("../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(float * input, int bufferSize, int nChannels){ // send audio samples to pyo pyo.fillin(input); } void ofApp::audioOut(float * output, int bufferSize, int nChannels){ // process and get new audio samples from pyo pyo.process(output); } ------------------------------------------------------------------------ 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 ------------------------------------------------------------------------ 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) 2019 - belangeo