| 1 |
Introduction on how to use pyo inside an OpenFrameworks project. |
| 2 |
================================================================ |
| 3 |
|
| 4 |
To use pyo inside an OpenFrameworks project, first you need a |
| 5 |
working install of pyo for python 2.7 on your system (will switch |
| 6 |
to python 3 as soon as possible). After installing pyo, you can |
| 7 |
move on and create an OpenFrameworks project. |
| 8 |
|
| 9 |
------------------------------------------------------------------------ |
| 10 |
Step 1 - Create a default project with the project generator. To avoid |
| 11 |
any include or linking problem, you should save your project in the |
| 12 |
default location (OF_ROOT/apps/myApps). |
| 13 |
|
| 14 |
------------------------------------------------------------------------ |
| 15 |
Step 2 - Add pyo files to your project. You only need to copy |
| 16 |
these files in your project's src folder: |
| 17 |
|
| 18 |
- from the folder pyo/embedded: |
| 19 |
m_pyo.h |
| 20 |
|
| 21 |
- from the folder pyo/embedded/openframeworks: |
| 22 |
PyoClass.cpp |
| 23 |
PyoClass.h |
| 24 |
|
| 25 |
------------------------------------------------------------------------ |
| 26 |
Step 3 - Make sure that your project includes flags for compiling |
| 27 |
and linking against Python. On Unix systems, you can set the Python |
| 28 |
flags in the file config.make. Uncomment and complete these lines: |
| 29 |
|
| 30 |
PROJECT_LDFLAGS = `python-config --ldflags` # linker flags for Python |
| 31 |
PROJECT_CFLAGS = `python-config --cflags` # compiler flags for Python |
| 32 |
|
| 33 |
------------------------------------------------------------------------ |
| 34 |
Step 4 - Make a scripts folder at the root level of your project and |
| 35 |
create a python file, named "stereoDelay.py", with these lines in it: |
| 36 |
|
| 37 |
# Get the input sound and apply a stereo delay + reverb on it. |
| 38 |
st_input = Input([0,1]) |
| 39 |
st_delay = Delay(st_input, delay=[.4, .5], feedback=0.7) |
| 40 |
st_rev = WGVerb(st_delay, feedback=0.8, cutoff=4000, bal=0.25).out() |
| 41 |
|
| 42 |
------------------------------------------------------------------------ |
| 43 |
Step 5 - Edit src/ofApp.h |
| 44 |
|
| 45 |
- Include PyoClass definition: |
| 46 |
|
| 47 |
#include "PyoClass.h" |
| 48 |
|
| 49 |
- Add audio in/out callbacks to the public attributes of the ofApp class: |
| 50 |
|
| 51 |
void audioIn(float * input, int bufferSize, int nChannels); |
| 52 |
void audioOut(float * input, int bufferSize, int nChannels); |
| 53 |
|
| 54 |
- Add an ofSoundStream object to the public attributes of the ofApp class: |
| 55 |
|
| 56 |
ofSoundStream soundStream; |
| 57 |
|
| 58 |
- Add a Pyo object to the public attributes of the ofApp class: |
| 59 |
|
| 60 |
Pyo pyo; |
| 61 |
|
| 62 |
------------------------------------------------------------------------ |
| 63 |
Step 6 - Edit src/ofApp.cpp |
| 64 |
|
| 65 |
- Creates the setup() function: |
| 66 |
|
| 67 |
void ofApp::setup(){ |
| 68 |
// define audio properties |
| 69 |
int sampleRate = 44100; |
| 70 |
int bufferSize = 256; |
| 71 |
int nChannels = 2; |
| 72 |
// initialize a pyo server |
| 73 |
pyo.setup(nChannels, bufferSize, sampleRate); |
| 74 |
// load a python file |
| 75 |
pyo.loadfile("../scripts/stereoDelay.py", 0); |
| 76 |
// initialize OpenFrameworks audio streaming channels |
| 77 |
//soundStream.listDevices() // Uncomment if you need to |
| 78 |
//soundStream.setDeviceID(1); // change the audio device. |
| 79 |
soundStream.setup(this, nChannels, nChannels, sampleRate, bufferSize, 4); |
| 80 |
} |
| 81 |
|
| 82 |
- Creates audio in/out functions: |
| 83 |
|
| 84 |
void ofApp::audioIn(float * input, int bufferSize, int nChannels){ |
| 85 |
// send audio samples to pyo |
| 86 |
pyo.fillin(input); |
| 87 |
} |
| 88 |
|
| 89 |
void ofApp::audioOut(float * output, int bufferSize, int nChannels){ |
| 90 |
// process and get new audio samples from pyo |
| 91 |
pyo.process(output); |
| 92 |
} |
| 93 |
|
| 94 |
------------------------------------------------------------------------ |
| 95 |
Step 7 - Compile your project. To compile, cd to your project folder and: |
| 96 |
|
| 97 |
# This line is for MacOS, you'll have to adapt it to your system! |
| 98 |
make && cp -r scripts bin/*.app/Contents/Resources |
| 99 |
|
| 100 |
------------------------------------------------------------------------ |
| 101 |
Here you go! You should be able to run your app created in the bin folder. |
| 102 |
|
| 103 |
Documentation |
| 104 |
============= |
| 105 |
|
| 106 |
For a complete description of functions that can be used to communicate |
| 107 |
with the pyo embedded processes, see documentation comments in the file |
| 108 |
PyoClass.cpp. |
| 109 |
|
| 110 |
|
| 111 |
(c) 2019 - belangeo |
| 112 |
|
| 113 |
|