SuperCollider: drawing UGen graph
Many people find it useful to see graphically the network of unit generators in their SynthDefs. There is a Quark that will create a Graphviz .dot file from your SuperCollider code.
First, install Graphviz (of course). There are downloads for OSX, Linux, and others.
Then you need to install the rd_dot Quark. If you’ve never dealt with Quarks before, it is rather simple to install them. In your SuperCollider interpreter, type this:
1 |
Quarks.gui; |
You will get a GUI window of all the available Quarks. The first time you run this the list will probably be empty. Press the Update Quark Listing button. Depending on your security settings, you may be prompted to accept their certificate. There will be a local listing written to your ~/Library/Application Support/SuperCollider/quarks directory. You might not get the listing refreshed immediately in your GUI windows after the process is finished. Simple kill the GUI and start it again.
Then, find the rd_dot quark. Click on the icon to the left of the name so it now reads +. Now press the Apply button in the “toolbar”. The rd_dot quark will be installed in your quarks directory.
Recompile your class library. It’s on the Language menu. Rebooting the interpreter will do it.
Try it out by changing the play method in your hacks to draw. Here’s a simple sine wave:
1 |
{SinOsc.ar()}.play; |
Change play to draw:
1 |
{SinOsc.ar()}.draw; |
When you interpret this now, you will get this displayed in Graphviz:
Possible glitch
If you have Word installed (I had a shotgun aimed at me), the file will open in Word since .dot files are associated with Word. The rd_dot quark writes a Graphviz .dot file to your tmp directory. An easy way to fix the association is to open any .dot file in the Finder inspector. Select it in Finder and press cmd-I. One of the sections in the inspector is Open With. Select SuperCollider from the option menu and apply to all.
If you want Word to remain associated with .dot files, you’ll have to hack the rd_dot code. It uses a simple call to open without any parameters, which is why Word is used. Change the open call to
1 |
open -a /Applications/SuperCollider/SuperCollider.app/ |
Great, thanks! Minor comment concerning the problem with Word opening the *.dot files: you want Graphviz to open these files, not SuperCollider, as you said above 🙂