| 1 |
Introduction on how to use pyo inside a Juce audio plugin. |
| 2 |
========================================================== |
| 3 |
|
| 4 |
To use pyo inside a Juce audio plugin, first you need a working |
| 5 |
install of pyo (for python 2.7 at the moment) on your system. |
| 6 |
After installing pyo, you can move on and create a Juce audio plugin project. |
| 7 |
|
| 8 |
------------------------------------------------------------------------------ |
| 9 |
Step 1 - Create an Audio Plug-In project with the Projucer. |
| 10 |
|
| 11 |
------------------------------------------------------------------------------ |
| 12 |
Step 2 - Add pyo files to your project. You need to copy these files in your |
| 13 |
project "Source" folder and add them in Projucer: |
| 14 |
|
| 15 |
- from this folder: |
| 16 |
* PyoClass.cpp |
| 17 |
* PyoClass.h |
| 18 |
- from the folder "embedded": |
| 19 |
* m_pyo.h |
| 20 |
|
| 21 |
------------------------------------------------------------------------------ |
| 22 |
Step 3 - Make sure that your project includes flags for compiling |
| 23 |
and linking against Python. Within the Projucer, you can set extra |
| 24 |
flags for your selected exporter. For example, on linux, if you select |
| 25 |
"Linux Makefile", you can add extra compiler and linker flags. Add |
| 26 |
these in the specific fields: |
| 27 |
|
| 28 |
Extra linker flags : |
| 29 |
|
| 30 |
`python-config --ldflags` |
| 31 |
|
| 32 |
Extra compiler flags : |
| 33 |
|
| 34 |
`python-config --cflags` |
| 35 |
|
| 36 |
On MacOS, the default compiler in Xcode is LLVM and it will complain about |
| 37 |
python-config command. All you have to do is to run these two commands (without |
| 38 |
the backtick symbols) in a terminal window and copy the results in the appropriate |
| 39 |
field (you can leave out "-Wstrict-prototypes" flag as it is not valid in C++. |
| 40 |
|
| 41 |
On MacOS, add the Python framework to your project. In the field "Extra Frameworks", |
| 42 |
add : |
| 43 |
|
| 44 |
Python |
| 45 |
|
| 46 |
|
| 47 |
------------------------------------------------------------------------------ |
| 48 |
Step 4 - Make sure that your project links to the Steinberg's VST SDK. |
| 49 |
VST SDK can be freely downloaded from Steinberg web site: |
| 50 |
http://www.steinberg.net/en/company/developers/ . |
| 51 |
|
| 52 |
Enter the path of your SDK in the field "VST3 SDK" in the "Global Search Paths" |
| 53 |
window. |
| 54 |
|
| 55 |
On MacOS, I managed to build both VST 2 and VST 3 plugins but only the VST 3 |
| 56 |
plugin actually runs in Reaper. The VST 2 plugin crashes the app. |
| 57 |
|
| 58 |
------------------------------------------------------------------------------ |
| 59 |
Step 5 - Create a python file, named "stereoDelay.py", with these lines in |
| 60 |
it: |
| 61 |
|
| 62 |
# Retrieve the stereo input of the plugin. |
| 63 |
st_input = Input([0,1]) |
| 64 |
# Parameters to change. |
| 65 |
dtime = SigTo(.5, 0.05, .5) |
| 66 |
feed = SigTo(.5, 0.05, .5) |
| 67 |
# Simple process. Stereo delay -> reverb. |
| 68 |
st_delay = SmoothDelay(st_input, delay=dtime, feedback=feed) |
| 69 |
st_rev = WGVerb(st_delay, feedback=0.8, cutoff=4000, bal=0.25).out() |
| 70 |
|
| 71 |
Save "stereoDelay.py" in your project "Source" folder, add it to the project |
| 72 |
(drag-and-drop to the File explorer in the Projucer) and ensure that the |
| 73 |
option "Binary Resources" is checked when you select "Source" in the File |
| 74 |
explorer. Save your project. This should add two files, "BinaryData.h" and |
| 75 |
"BinaryData.cpp", in the "JuceLibraryCode" folder. |
| 76 |
|
| 77 |
------------------------------------------------------------------------------ |
| 78 |
|
| 79 |
**For all the remaining steps, don't forget to replace XXX by your plugin's |
| 80 |
name.** |
| 81 |
|
| 82 |
------------------------------------------------------------------------------ |
| 83 |
|
| 84 |
Step 6 - Edit Source/PluginProcessor.h |
| 85 |
|
| 86 |
Include PyoClass definition: |
| 87 |
|
| 88 |
#include "PyoClass.h" |
| 89 |
|
| 90 |
Add a Pyo object to the public attributes of the *XXXAudioProcessor* class: |
| 91 |
|
| 92 |
Pyo pyo; |
| 93 |
|
| 94 |
------------------------------------------------------------------------------ |
| 95 |
Step 7 - Edit Source/PluginProcessor.cpp |
| 96 |
|
| 97 |
Add these lines to *XXXAudioProcessor::prepareToPlay* method: |
| 98 |
|
| 99 |
pyo.setup(getTotalNumOutputChannels(), samplesPerBlock, sampleRate); |
| 100 |
pyo.exec(BinaryData::stereoDelay_py); |
| 101 |
|
| 102 |
Replace the processing part of *XXXAudioProcessor::processBlock* method with this |
| 103 |
line: |
| 104 |
|
| 105 |
pyo.process(buffer); |
| 106 |
|
| 107 |
The processing part is the code after this comment: |
| 108 |
|
| 109 |
// This is the place where you'd normally do the guts of your plugin's |
| 110 |
// audio processing... |
| 111 |
|
| 112 |
------------------------------------------------------------------------------ |
| 113 |
|
| 114 |
Here you go! Compile, Run and Enjoy! |
| 115 |
|
| 116 |
|
| 117 |
Adding GUI controls to your plugin |
| 118 |
---------------------------------- |
| 119 |
|
| 120 |
Now, we will add two sliders to control the delay time and the feedback |
| 121 |
of our process. |
| 122 |
|
| 123 |
------------------------------------------------------------------------------ |
| 124 |
Step 8 - Edit Source/PluginEditor.h |
| 125 |
|
| 126 |
Add the inheritance to *Slider::Listener* to your *XXXAudioProcessorEditor* |
| 127 |
class definition: |
| 128 |
|
| 129 |
class XXXAudioProcessorEditor : public AudioProcessorEditor, |
| 130 |
private Slider::Listener |
| 131 |
|
| 132 |
Add the default callback function in the public attributes of the class: |
| 133 |
|
| 134 |
void sliderValueChanged(Slider* slider) override; |
| 135 |
|
| 136 |
Create two sliders in the public attributes of the class: |
| 137 |
|
| 138 |
Slider p1; |
| 139 |
Slider p2; |
| 140 |
|
| 141 |
------------------------------------------------------------------------------ |
| 142 |
Step 9 - Edit Source/PluginEditor.cpp |
| 143 |
|
| 144 |
Set the sliders properties in the editor constructor function named |
| 145 |
*XXXAudioProcessorEditor::XXXAudioProcessorEditor* (this is the first function |
| 146 |
in the PluginEditor.cpp file). Add these lines at the end of the function: |
| 147 |
|
| 148 |
// these define the parameters of our slider object |
| 149 |
p1.setSliderStyle(Slider::LinearBarVertical); |
| 150 |
p1.setRange(0.0, 1.0, 0.01); |
| 151 |
p1.setTextBoxStyle(Slider::NoTextBox, false, 90, 0); |
| 152 |
p1.setPopupDisplayEnabled(true, true, this); |
| 153 |
p1.setTextValueSuffix(" Delay Time"); |
| 154 |
p1.setValue(0.5); |
| 155 |
p1.addListener(this); |
| 156 |
// this function adds the slider to the editor |
| 157 |
addAndMakeVisible(&p1); |
| 158 |
|
| 159 |
p2.setSliderStyle(Slider::LinearBarVertical); |
| 160 |
p2.setRange(0.0, 1.0, 0.01); |
| 161 |
p2.setTextBoxStyle(Slider::NoTextBox, false, 90, 0); |
| 162 |
p2.setPopupDisplayEnabled(true, true, this); |
| 163 |
p2.setTextValueSuffix(" Delay Feedback"); |
| 164 |
p2.setValue(0.5); |
| 165 |
p2.addListener(this); |
| 166 |
addAndMakeVisible(&p2); |
| 167 |
|
| 168 |
Set the size and position of the sliders. Add these lines in |
| 169 |
*XXXAudioProcessorEditor::resized* function: |
| 170 |
|
| 171 |
p1.setBounds(40, 30, 20, getHeight() - 60); |
| 172 |
p2.setBounds(70, 30, 20, getHeight() - 60); |
| 173 |
|
| 174 |
------------------------------------------------------------------------------ |
| 175 |
Step 10 - Connect the sliders to the audio process |
| 176 |
|
| 177 |
At the end of the file PluginEditor.cpp, create the slider's callback |
| 178 |
function which will pass the values to the audio processing objects: |
| 179 |
|
| 180 |
void XXXAudioProcessorEditor::sliderValueChanged (Slider* slider) |
| 181 |
{ |
| 182 |
processor.pyo.value("dtime", p1.getValue()); |
| 183 |
processor.pyo.value("feed", p2.getValue()); |
| 184 |
} |
| 185 |
|
| 186 |
------------------------------------------------------------------------------ |
| 187 |
|
| 188 |
That's it! Compile and Run... |
| 189 |
|
| 190 |
Documentation |
| 191 |
------------- |
| 192 |
|
| 193 |
For a complete description of functions used to communicate with the pyo |
| 194 |
embedded processes, see documentation comments in the file PyoClass.cpp. |
| 195 |
|
| 196 |
|
| 197 |
(c) 2017 - belangeo |