The OSC protocol is a wide spread means for communication between software components or systems, not only suited for music applications. Read more in the OSC chapter of the Computer Music Basics. There is a large variety of OSC libraries available in C/C++. The examples in this class are based on the liblo, a lightweight OSC implementation for POSIX systems.
Installing the Library
On Ubuntu systems, as the ones used in this class, the liblo library is installed with the following command:
Including the Library
The liblo comes with additional C++11 wrappers to offer an object-oriented workflow. This feature is also used in the examples of this class. The following lines include both headers:
The GainExample is based on the ThroughExample, adding the capability to control the gain of the passed through signal with OSC messages.
Passing Command Line Arguments
The main function of this example accepts the OSC port to listen to as a command line argument. This is realized with a string comparison. The compiled binary is then started with an extra argument for the port:
The OSC Manager Class
The OSC-ready examples in these tutorials rely on a basic class for receiving OSC messages and making them accessible to other program parts. It opens a server thread, which listens to incoming messages in the background. With the add_method function, OSC paths and arguments specifications can be linked to a callback function.
// create new server st = new lo::ServerThread ( p ); // / Add the example handler to the server ! st->add_method("/gain", "f", gain_callback, this); st -> start ();
Inside the callback function gain_callback, the incoming value is stored to the member variable gain of the OscMan class.
The Processing Function
At the beginning of each call of the processing function, the recent incoming OSC messages are read from the OSC Manager:
The gain values are applied later in the processing function, when copying the input buffers to the output buffers: