SuperCollider with Emacs on OSX
SuperCollider (Github) has a decent IDE these days. But perhaps you’d like to use an actual editor like Emacs.
Sam Aaron published an article on this, but it is badly outdated. It was also overly complicated including copying several core directories out of the app. He’s probably too busy doing his good work with Overtone to update it. You should check out Overtone, by the way.
You need to get the current source for scmode. There is no separate repo, so you need the whole SuperCollider repo. Once you clone the repo, the scmode code is under supercollider/editors/scel. The contents of the sc directory needs to be copied to the Extensions directory of your application support directory. You can discover the location of your application support directory by evaluating this in the SuperCollider interpreter:
1 |
Platform.userAppSupportDir; |
On OSX that will be ~/Library/Application Support/SuperCollider, so copy scel to ~/Library/Application Support/SuperCollider/Extensions, creating the directory if it doesn’t already exist.
1 2 3 4 |
git clone https://github.com/supercollider/supercollider.git cd supercollider/editors/scel sudo mkdir ~/Library/Application\ Support/SuperCollider/Extensions sudo cp -r sc ~/Library/Application\ Support/SuperCollider/Extensions |
You need to add the contents of supercollider/editors/scel/el to your load path. You can just point to where you cloned the git repo, but I prefer to have my emacs lisp in a logical place. I copied the el directory to ~/.emacs.d/vendor/scel/el directory.
Add this to your init file:
1 2 |
(add-to-list 'load-path "~/.emacs.d/vendor/scel/el") (require 'sclang) |
You need to set your path within Emacs also. The sclang program is located in /Applications/SuperCollider/SuperCollider.app/Contents/Resources, so that needs to be in your path.
(For hacking in iTerm, I’ve also added it to my PATH in my bash startup file).
1 2 |
(setenv "PATH" (concat (getenv "PATH") ":/Applications/SuperCollider:/Applications/SuperCollider/SuperCollider.app/Contents/Resources")) (setq exec-path (append exec-path '("/Applications/SuperCollider" "/Applications/SuperCollider/SuperCollider.app/Contents/Resources" ))) |
Launch Emacs. When the dust settles, type
1 |
M-x sclang-start |
The interpreter will start in a buffer named SCLang:PostBuffer and you will be presented with a new buffer named SCLang:Workspace.
Start the server in the workspace.
1 2 |
s = Server.local; s.boot; |
There will be a SCLang menu and you can execute commands from there. You’ll see the C-x C-f will evaluate the entire document. (Or type C-c C-p b to boot. Of course you can type C-h m to get the help for sclang mode).
Create a simple noisemaker.
1 |
{[SinOsc.ar(440, 0, 0.2), SinOsc.ar(442, 0, 0.2)]}.play; |
C-c C-s will stop playing.
Have fun!
Awesome, thank you! I wasn’t doing two things exactly right and this post was the missing link among all the various bits of emacs-supercollider info out there.
Two notes that may be helpful to others, or may simply be the result of mistakes on my part:
1. In my scel/el directory, there was a file with a .in ending (specifically “sclang-vars.el.in”) that was causing a problem.
It has something to do with cmake, I’ve inferred, but I simply just changed to the file ending to “.el” and I stopped getting the error.
2. Apparently, there were/are two “Document.sc” files (one in Supercollider/extensions directory and one buried in the SCClassLibrary/Common/GUI directory); that caused an error. I simply removed the one from the Supercollider/extensions (they appeared to hold the same contents) and, voilá/voilà!
Thanks again for spelling things out nicely. Will try to check back and dig the other things on your blog!
Thanks for the info, Cicero.
Thanks for the thorough guide to ‘collide’ SC to Emacs.
I am not sure this meant to be only for a specific OS so apologies to jump in.
For MacOS note that the ‘exec-path’ line must amend to (setq exec-path (append exec-path ‘(“/Applications/SuperCollider” “/Applications/SuperCollider/SuperCollider.app/Contents/MacOS” )))
And that seems to solve the problem.
Thanks again for the guide!
Best
K.
I think I found the problem, as of 3.7 sclang is in MacOS folder, instead of the Resources folder. However, I try to change that with MacOS folder but when I try to start sclang by sclang-start I am getting an error that says it can’t find the sclang file or directory, and what is strange is that still uses the old path instead the one I am putting here: (setenv “PATH” (concat (getenv “PATH”) “:/Applications/SuperCollider:/Applications/SuperCollider/SuperCollider.app/Contents/Resources”))
(setq exec-path (append exec-path ‘(“/Applications/SuperCollider” “/Applications/SuperCollider/SuperCollider.app/Contents/Resources” )))
Any tips?
Best
K.
I haven’t updated yet. I’ll bang on it later this week and get back to you.
Thanks,
looking forward I have spent some significant time to find some workaround, alas nothing!
Would be great to make it work on SC3.7.
Regards
K.
Any progress on this? It just doesn’t work to change the path to ‘…/Contents/MacOS’ instead of ‘…/Contents/Resources’ in .emacs or within sclang-customize, I still get:
/usr/local/Cellar/emacs/24.5/Emacs.app/Contents/MacOS/Emacs: /Applications/SuperCollider/SuperCollider.app/Contents/Resources/sclang: No such file or directory
*** SCLang exited abnormally with code 127 ***
I just downloaded the current version – 3.6.6 – and here it is.
Thank you for the clear info, but we’re talking about 3.7, not 3.6, I’m afraid. As far as I understand, that is the version of SC Konstantinos was referring to, and what I also have trouble with. So I was wondering if you guys had made any progress on the matter. Anyway, many thanks! The search goes on!
All the best,
D.
D’Oh! I didn’t see 3.7 on the download page. I’ll try to find it after work.
In 3.7.0 beta 1, sclang, scsynth, and SuperCollider are under MacOS now instead of Resources.
Beta 1 of 3.7.0
Yes, exactly. And it doesn’t work changing it by customizing sclang path in emacs scel. For some reason it looks for the executables in the Resources folder instead, no matter what. So, it would be great if we could figure out why and where it looks for the sc path.
.
By the way, it’ll be fixed in the release of 3.7.0, according to the issue created the other day: https://github.com/supercollider/supercollider/issues/1860. So, I’ll stop filling your blog post with further clutter about the bug.
All the best,
D.
Thanks for all the info.
I was just using 3.6 and had no idea there was a problem with 3.7, so I’m glad to know what’s going on.