This is a quick and dirty tutorial that shows exactly how to communicate between Max/MSP and SuperCollider 3 with Open Sound Control (OSC). This could be useful for a number of things. If you want to use SC3, but would like to be able to do video processing with Jitter, for instance. Or, if you want to write a patch in SC3, but design an interface for it in Max.
Learn more about OSC here:
http://www.cnmat.berkeley.edu/OpenSoundControl/
OSC is a pretty fundamental part of SC3, so you won’t need to add anything there, but you will need to install the OSC externals into Max/MSP. They’re available for Mac and Windows here:
http://www.cnmat.berkeley.edu/OpenSoundControl/Max/
Max/MSP => SC3
Now that you have the OSC externals installed, I’ll start by showing how to send a message from Max to SC3. First, in SC3, you’ll want to set up an OSCResponder:
OSCresponder(nil, '/goNOW', { : ... args :
args.postln;
}).add;
This particular OSCresponder responds on all ports because there’s no NetAddr specified. For now, that’s just easier than worrying about addresses and ports.
Then, in Max, set up a patch like this:
Clicking on the message box /goNOW 1 will send that message to SC3, and SC3 will do whatever you asked it to do in the OSCResponder.
If you’d like to specify a specific address and port that the OSCResponder will listen to, you have to set up a NetAddr in SC3:
a = NetAddr.new(“127.0.0.1”, 49155);
The IP address, 127.0.0.1, is just localhost, but any IP address can be specified. The port shown here, 49155, will not necessarily be 49155, and is the “read” port that is displayed in Max/MSP when you send a “tellmeeverything” message to the “otudp write” object. To find out what port number to use, go to Max, and create a message box with “tellmeeverything” in it, and link that to the left inlet of “otudp write”. Clicking on “tellmeeverything” will give you a bunch of stuff in the output box. Part of it will look like this:
You asked to write to internet host "127.0.0.1"
Writing to internet host 127.0.0.1
Writing to port 57120
This object reads from port 49155
Buffer sanity check passed
Buffers are 1024 bytes
The port number bolded above (49155) is the port number you want to use in the NetAddr statement. Why? I don’t know. It just seems to work.
So, that’s about all you need to know to send a message from Max/MSP to SC3. Now, how about the other direction?
SC3 => Max/MSP
First, define a server for the address and port that Max/MSP will be listening on:
max = Server(“aServer”, NetAddr(“localhost”, 8000));
Then, set a Max patch to listen on port 8000:
Then, send Max a message from SC3:
max.sendMsg(“one”, “two”);
That’s it. Enjoy!