Integrating Squeak and SuperCollider

In the last few days I've been experimenting with making two of my favorite open source programs, Squeak and SuperCollider, work together.

Squeak is an implementation of the Smalltalk programming language and environment; a project born from the minds of the Smalltalk language creators themselves and actively developed by a community of talented hackers.

SuperCollider is an environment and programming language (with a Smalltalk-ish syntax) for real time audio synthesis and algorithmic composition.

At first I made the two talk to each other via the OpenSound Control (aka OSC) protocol, which is supported natively in SuperCollider. In squeak you can use the OSC package.

Here's a test which sets the 'freq' value of a SuperCollider SynthDef whose node id is 1000 to 440:

(OSCMessage for: {'/n_set'.1000.'\freq'.440})
	sendTo: (NetNameResolver localHostAddress)
	port: 57110.

But there's another, more powerful, solution: to launch the SuperCollider interpreter (sclang) as a process from within Squeak and pipe your code directly into the process STDIN. This requires the CommandShell package (for Squeak) which in turn depends on OSProcess. Once these are installed, you can launch the sclang interpreter with:

mysclangprocess _ PipeableOSProcess command: 'sclang'.

And kill it with:

mysclangprocess finalize.

To execute some code, e.g. for booting the synthesis server, evaluate:

mysclangprocess nextPutAll:
  's.sendMsg("/n_set", 1000, \freq, 440);', Character newPage asString.

If you want to see the standard output from Supercollider, evaluate:

Transcript show: mysclangprocess upToEnd withSqueakLineEndings.

Well, I'm excited. SuperCollider has a full fledged object oriented dynamic programming language, so you can program it interactively. Paired with Squeak, and especially its Morphic direct-manipulation User Interface, the possibilities are endless.