Professional Documents
Culture Documents
By James Britt
All rights reserved. This book or any portion thereof may not be repro-
duced or used in any manner whatsoever without the express written
permission of the publisher except for the use of brief quotations in
a book review, and certain other noncommercial uses permitted by
copyright law.
Welcome!
Welcome to Just the Best Parts: OSC for Artists.
This book teaches you about Open Sound Control or, as its usu-
ally called, OSC.
It explains what OSC is, why you should care about it, and how
you can use it. It includes some simple hands-on examples that let you
see how it works and what it can do.
I hope you enjoy this book and find it useful.
Whence OSC
Where did OSC come from? The explanation starts not with OSC
but with MIDI.
The Musical Instrument Digital Interface (MIDI) is a music industry
specification; it is a formal description of an essentially finite set of
commands or instructions.
OSC origins
According to the OSC Web-site (http://opensoundcontrol.
org/introduction-osc),
OSC was originally developed, and continues to be a subject
of ongoing research at UC Berkeley Center for New Music
and Audio Technology (CNMAT). CNMAT is an interdisciplin-
ary research center within the UC Berkeley Department of
Music.
Before OSC there was ZIPI (Zeta Instrument Processor Interface),
an attempt to address some of the perceived shortcomings of MIDI. It
didnt catch on.
But in 1997, Matt Wright and Adrian Freed, who worked on ZIPI,
released the Open Sound Control specification.
Unlike MIDI, OSC did not define any hardware requirements. It
(Im lying about that last part. Theres a lot of software that, when
given the wrong data, just fails to do something sensibleoften with
no indication about what you need to do to make things right. But the
solution rarely requires a detailed understanding of the OSC message
format. Instead, youll just have to figure out the quirks of the applica-
tion youre using.)
The bottom line is that there are a few things that any OSC setup
absolutely requires and a dozen more things that are likely to be avail-
able. Although you might not need all the details, it is helpful to know
what kinds of data you can use with OSC.
DIY
You do not need to be a programming guru in order to
create your own OSC software. There are existing tools,
such as Processing, that manage much of the complexity
for you. If youve ever written JavaScript or done Flash
programming, youll have no trouble using Processing. If
programming is new to you, good news: its easy to get
started with Processing.
In fact, some free software was created for the book
Kinect Hacking for Artists(in Processing) that allows you
to do some basic OSC exploration. This program is dis-
cussed later on in this book.
Pattern matching
Sensible hierarchies are also good because OSC allows for pattern
matching. Suppose, for example, that you have a stage lighting system
that defines messages for setting the brightness of any given light.
Perhaps you define messages such as these:
/stage/lights/1/brightness f
/stage/lights/2/brightness f
/stage/lights/3/brightness f
Its a small stage, so there are only three lights.
For any given light, you can send a message and pass along a deci-
mal value (a.k.a. floating-point number) to indicate the brightness. 0.0
means completely off; 1.0 means as bright as the light can be. These
messages behave much like slider controls that you might have for
your lights at home.
Note the use of thefin the message description. Thats the type
Bundled messages
OSC clients can also send message bundles. A bundle is collection
of OSC messages all sent at the same time. When an OSC server gets a
bundle, it unpacks the messages and processes them as a whole. Bun-
Port selection
Some programs with built-in support for OSC are preconfigured to
use one or another port. For example, Renoise is set to use port 8000
by default.
TouchOSC, a mobile app for Android and iOS devices, also defaults
to port 8000 for sending OSC messages, and to port 9000 for receiving
messages.
Unless you run into a problem, these are perfectly usable values.
There are times when some other application, unrelated to OSC, may
also decide to use port 8000.
If you are having trouble sending or receiving OSC messages using
a particular port, try changing ports.
There are some restrictions on what port numbers you can use. If
you pick a port number somewhere from 8000 to 9999, you should be
okay.
Practical examples
The best places to read detailed descriptions of using OSC with
real-world applications are Just the Best Parts: Kinect Hacking for
Artists and Just the Best Parts: Leap Hacking with JRuby & Process-
ing (both available at http://justthebestparts.com). For now,
though, we will look at some simple programs so that you can see OSC
in action for yourself.
To start, you need a client and a server. As you might recall, the
client is the thing that sends out OSC messages; the server listens for
them and then takes some action based on whatever message was
sent.
In practice, the lines are little blurred because some OSC servers
will send back an OSC message to the client so that the client can, for
example, update its user interface based on what the server actually
did. For example, if you send a mute track message to some music
program, you would want to know that the program did in fact mute
the designated track. Likewise, if something else causes a track to be
muted (perhaps by direct interaction with the music program), its
handy to see that reflected in any OSC clients.
Conceptually, its probably simpler to think in terms of client and
server, where the server is the primary application or device you want
to control remotely..
Example applications
There are various free or inexpensive programs that use OSC.
Some are for desktops and laptops; others run on phones and tab-
lets. If you have an Android phone or tablet, or an iPhone or iPad,
then you should get TouchOSC (http://hexler.net/software/
touchosc-android for Android; http://hexler.net/soft-
ware/touchosc for iOS). The app is free for Android devices, but
Wait; code?
Yes, but dont fret.
The sample apps are written in a programming language
called Processing.
It is freely available for a variety of operating systems,
including Windows, Mac OSX, and Linux.
It was created by artists for artists.
You can use it to do fun, cool, modern stuff.
But you dont have to!
Even if you decide coding is not for you right nowand
perhaps never will beit is instructive to look at some
of the code in these examples. If you end up using OSC
for something, there is a good chance that you will not
get to see the code for the program by just using it.
However, you should have at least some idea of whats
going on behind the scenes.
OSC, programming, network communications, and so
on may have their difficult points, but theyre not magic,
and although you might not (and need not) understand
all the details, it helps to have a basic understanding of
the general concepts.
With this basic understanding, youll be much better
able to take advantage of this technologyeven without
doing any coding.
Processing IDE
OSC Commander
Some code
Most Processing programs share some common elements. If the
program is using code from other libraries (that is, reusable code bun-
dled up in a way that makes it handy to include in other sketches),this
is declared at the start of the program.
Programs make use of things called variables. Think of variables as
placeholders, or convenient names for program things. In Processing,
you must indicate what kind of program thing a variable will be. For
example, suppose that you want to use the number 2013 in various
places in your program. You could just use that number in each and
every place, but if you later decide to change that number to 2014,
youll have to change it in all the places you used this number. That
approach can lead to mistakes.
If you instead define a variable, and use the variable everywhere
you want that number throughout your code, then theres only one
thing you would need to changethe value of the variable where its
defined.
You could declare such a variable like this:
int myFavoriteYear = 2013;
This code says that the variable calledmyFavoriteYearis
void draw() {
background(0);
rectX = rectX + 10;
rectY = rectY + 10;
rectWidth = rectWidth + 10;
rectHeight = rectHeight + 10
void setup() {
size(CANVAS_WIDTH, CANVAS_HEIGHT);
if (res != null) {
println("FADER for " + res[2] );
rectScale[ int(res[2]) ] = map(value, 0.0, 1.0,
0.1, CANVAS_WIDTH);
return;
}
Some more hand-wavey stuff: because the program is tracking
multiple rectangles and the code is pairing up TouchOSC controls with
rectangles, the code uses an array called rectScale to store val-
ues. An array is a way to have multiple variables all in one variable. In
reality, its more complicated than that, but dont worry about that for
now. Thats a code detail that, for now, isnt important. You can get at
the items in an array using an integer index.
Essentially, what the code is doing here is looking at which fader
control is sending the OSC message, and matching that with a corre-
sponding rectangle size/location value. The map() function then takes
the OSC message value (a value between 0.0 and 1.0) and converts it
to a comparable value between 0.0 and the width of the canvas.
Finally, theres the return statement, which tells Processing to
exit the function.
If this was not a fader message, the function uses similar logic to
see whether this message was sent by a rotary control, andas with
the fader codewill use the rotary index and value to change one or
another rectangle value:
Code recap
The gist of all this code comes down to defining variables for use
in drawing the rectangles; these variables are then altered by different
OSC messages. Each time the draw() function is called, the canvas is
updated with new rectangles that are created using the current val-
ues.
Left alone, the circles and colors will change automatically. The
changes are constrained by the default program settings.
If you now run the OSC Commander sketch, or use the TouchOSC
app, you can alter these settings by adjusting various controls. You