This post originated from an RSS feed registered with Ruby Buzz
by Sam Aaron.
Original Post: Hooking SuperCollider up to Emacs on OS X
Feed Title: Communicatively Speaking
Feed URL: http://sam.aaron.name/feed/atom.xml
Feed Description: Sam Aaron's blog. Here you'll find interesting discussions on matters such as communicative programming, domain specific languages and music.
I think that SuperCollider is one of the most exciting music technologies currently available. It’s super powerful, Open Source, and has even got a separate server and language runtime giving everyone the opportunity to experiment with different approaches. I’m very excited to see where we go with it, and how I can utilise it with my Polynome project.
However, despite the fact that it comes shipping with a very nice live-coding enabled interface, I use Emacs, and well, I love using Emacs for editing text of all kinds. I therefore wanted to have the convenience of the live editing with the powerful text manipulation features that Emacs offers. Luckily there’s an Emacs mode for SuperCollider and I just finished hooking it all up. Unfortunately I couldn’t find a nice tutorial for doing it, but I did manage to piece together a process that finally worked for me. It wasn’t a fun time, so I’m documenting it here in the hope that someone else might benefit from my pain.
Caveat and Context
Now, I need to issue a major caveat: there’s lots of moving parts in this situation, and your parts might not even be the same as mine. So, just to be clear - this might not work for you, but hopefully it’ll get you a major part of the distance. The more similar our setups, the more likely this will help, so for clarity I’m using:
Cocoa Emacs 23.1.50 Git 2010-02-09 (the latest nightly build at the time of writing)
I’m also assuming that you have already installed Emacs and SuperCollider and that you have a basic working knowledge of Emacs configuration, and general UNIX hockery pokery1.
Update your Path (UNIX-style)
First up open your shell config file (~/.zshrc in my case) with your favourite editor2 and append /Applications/SuperCollider to your PATH. Check to see if it worked:
λ sclang -h
Usage:
sclang [options] [file..] [-]
Options:
-d <path> Set runtime directory
-D Enter daemon mode (no input)
-g <memory-growth>[km] Set heap growth (default 256k)
-h Display this message and exit
-l <path> Set library configuration file
-m <memory-space>[km] Set initial heap size (default 2m)
-r Call Main.run on startup
-s Call Main.stop on shutdown
-u <network-port-number> Set UDP listening port (default 57120)
In a fresh terminal update the OS X plist version of the PATH to match your newly updated version: defaults write $HOME/.MacOSX/environment PATH "$PATH" and restart your machine.
In your emacs config explicitly create a PATH variable: (setq path "/Applications/SuperCollider:/rest/of/PATH")(setenv "PATH" path)
Again, in your Emacs config, add SuperCollider to your exec-path: (push "/Applications/SuperCollider" exec-path)
Not all of these may be necessary; I did the the last two.
Creating a Fresh SCClassLibrary
Create a new place for a fresh copy of SCClassLibrary:
mkdir ~/.sclang
Copy the SCClassLibrary from your SuperCollider install into this new place:
/Applications/SuperCollider/README\ SCLang\ OSX advises you to edit the startup method in ~/.sclang/SCClassLibrary/Platform/osx/OSXPlatform.sc. Open it up and find the startup method. Delete everything from startup { to the closing } and replace it with the following:
Now we’re ready to power up Emacs with SuperCollider goodness. I found a copy of scel on github that contained a few issues that I ironed out in my own clone3. Feel free to grab it and add it to your own emacs config. That might be as simple as downloading the tarball, or if you manage your config with git (which, by the way, is a great idea) then you could just add it as a submodule. I happen to have based my config on Phil Hagelberg’s wonderful emacs starter kit. So this can be as simple as:
cd ~/.emacs.d
git submodule add git://github.com:samaaron/scel.git vendor/supercollider
Copy scel’s sc files to your new SCClassLibrary
For scel to work correctly it has a number of SC Class files that need to be compiled and loaded when sclang is started. In order to achieve this copy the sc files from scel’s sc directory into your new SCClassLibrary:
Finally, you need to tell it where to find your SCClassLibrary and other bits and bobs. scel advises you to use M-x sclang-customize, however I just set the variables by hand:
OK, well done for making it so far. I’m praying for you that things went hunky-dory. At this stage I simply restarted Emacs and hit M-x sclang-start and BOOM entered the SC Workbench. If this seems to work, and you see two buffers, a workbench and a log, try typing "Hello from Emacs".postln; in the buffer and with the cursor over it hit M-x
sclang-eval-line. You should see the message pop up in the log.
Go grab a cup of tea, you’ve earned it.
Please note that not all these steps may be necessary. It’s possible I accidentally slipped in some cargo-culting along the way. Please feel free to let me know if there are smarter and wiser ways of getting this to work!_
I still can’t faithfully communicate how absolutely amazing github is. The fact that it enabled this process (find library, clone library, fix library, share library) in such a frictionless manner is outstanding.