Fundamentals
Export Targets
Code Export
Patcher UI
Special Topics
RNBO Raspberry Pi OSCQuery Runner
How to Include RNBO in Your C++ Project
When you export C++ source code from RNBO, two important export artifacts are generated. The first is the exported patcher, which will have the name rnbo_source.cpp
by default. The second is a folder called rnbo
, which will contain the static parts of the RNBO library. This rnbo
folder contains all of the dependencies needed for any C++ project using RNBO. There are no additional third party libraries to install.
The basic steps for including RNBO in a C++ project are as follows:
- Include the header files located at
rnbo/RNBO.h
andrnbo/common/*.h
- Add
rnbo_source.cpp
andrnbo/RNBO.cpp
to your compiled sources.
In this exapmple we'll see how to setup a very simple command line application using both Xcode as well as CMake. Hopefully these instructions should be easy enough to translate to any other development environment.
Xcode
Start by creating a new Xcode Project (File > New > Project...). Navigate to the macOS
tab and select "Command Line Tool". You can name the project whatever you like.
You should have a simple project with one file main.cpp
.
Export some code from your RNBO patcher by opening the export sidebar and using C++ Source Code Export. You can export the code directly into the source folder of your Xcode project. After export, your file tree may look something like this:
Now add the RNBO headers to the project. For older versions of Xcode, this can be accomplished by adding rnbo
and rnbo/common
folders to the "Header Search Paths" build setting.
Newer versions of Xcode, using the newer build system, may not have this build setting. In this case, you can drag RNBO.h
into the Project navigator, along with the common
folder. When you drop common
into the project navigator, be sure to select the option to create a group, and not the option to create a folder reference.
After dropping in RNBO.h
and the common
folder, your project navigator should look something like this:
Now add rnbo_source.cpp
and RNBO.cpp
to the project. The easiest way to accomplish this is simply to drag and drop these files into the Project navigator.
At this point you can try building the project to make sure that everything compiles successfully. When you're ready, modify the contents of main.cpp
to call into RNBO. The only two functions that must be called are prepareToProcess
and process
.
#include "RNBO.h"
int main(int argc, const char * argv[]) {
RNBO::CoreObject rnboObject;
rnboObject.prepareToProcess(44100, 64);
RNBO::SampleValue** inputs = nullptr;
RNBO::SampleValue** outputs = new RNBO::SampleValue*[2];
for(int i = 0; i < 2; i++)
outputs[i] = new double[64];
rnboObject.process(inputs, 0, outputs, 2, 64);
rnboObject.process(inputs, 0, outputs, 2, 64);
rnboObject.process(inputs, 0, outputs, 2, 64);
rnboObject.process(inputs, 0, outputs, 2, 64);
rnboObject.process(inputs, 0, outputs, 2, 64);
for(int i = 0; i < 2; i++)
delete [] outputs[i];
delete [] outputs;
return 0;
}
RNBO::CoreObject
is generally the most important access point to RNBO. It is used to call processing, schedule events, set and get parameter values etc.
CMake
Start with a new empty folder. Create a file main.cpp
with a simple program.
#include <iostream>
int main(int argc, const char * argv[]) {
std::cout << "Hello, World!\n";
return 0;
}
Now add a CMakeLists.txt
file that adds main.cpp
to the project as an executable.
cmake_minimum_required(VERSION 3.10) # Set the project name project(RNBOCommandLine) # Add the executable add_executable(RNBOCommandLine main.cpp)
At this point, you should already be able to compile and run your program.
> mkdir build > cd build > cmake .. > cmake --build . > ./RNBOCommandLine Hello, World!
Now export your RNBO patcher into the same directory.
Modify CMakeLists.txt
to include the RNBO headers and source files. You will also need to add a line specifying the c++11
standard, which is necessary for RNBO.
cmake_minimum_required(VERSION 3.10) # Set the C++ standard to at least C++11, which is needed for RNBO set (CMAKE_CXX_STANDARD 11) # Set the project name project(RNBOCommandLine) # Add the main executable as well as the RNBO sources add_executable(RNBOCommandLine main.cpp rnbo_source.cpp rnbo/RNBO.cpp) # Include the RNBO headers target_include_directories(RNBOCommandLine PRIVATE rnbo rnbo/common)
And finally, modify main.cpp
to use RNBO in some way.
#include <iostream>
#include "RNBO.h"
int main(int argc, const char * argv[]) {
RNBO::CoreObject rnboObject;
rnboObject.prepareToProcess(44100, 64);
RNBO::SampleValue** outputs = new RNBO::SampleValue*[1];
outputs[0] = new double[64];
rnboObject.process((RNBO::SampleValue**) nullptr, 0, outputs, 1, 64);
for (int i = 0; i < 64; i++) {
std::cout << outputs[0][i] << "\n";
}
delete [] outputs[0];
delete [] outputs;
return 0;
}
You should be able to build and run this program, the output of which prints the first 64 samples output from your patcher (assuming it generates audio).
> cd build > cmake .. > cmake --build . > ./RNBOCommandLine 0 0 5.38019e-05 0.000161382 0.000322715 0.000537777 ...