[Haskell-cafe] Re: getting started with hsc (supercollider)

Rohan Drape rd at slavepianos.org
Sat Jan 27 19:49:02 EST 2007

Hello Alex,

alex <alex at slab.org> writes:
| Would anyone have some illustrative example code, and perhaps a
| couple of tips for how to get things working well in emacs?

Noting that Hsc is still experimental and not completely nailed down,
though I think now quite close, and assuming that SuperCollider and
ghc and emacs and the standard haskell emacs mode [1] are all
installed and working, the following should get you started.

* get hsc, or update if you have it (important, recent fixes required)

  darcs get http://slavepianos.org/rd/sw/sw-69

* compile it

  cd sw-69
  runhaskell Setup.hs configure --prefix ~
  runhaskell Setup.hs build
  runhaskell Setup.hs install --user

  (or there is a Makefile to do these three steps...)

* add an appropriately modified variant of the following to ~/.emacs

  (push "/home/rohan/sw/sw-69/emacs" load-path)
  (setq hsc-interpreter "ghci")
  (setq hsc-help-directory "/home/rohan/sw/sw-69/Help/")
  (require 'hsc)

* start the supercollider server

  scsynth -u 57110

That ought to be the end of premilinaries, this message is a 'literate
SuperCollider Haskell file', save it with a .lhs extension, open it in
emacs, make sure the Hsc menu comes up and read on.

You can start ghci and load Sound.SC3 by typing C-cC-s (Hsc -> Haskell
-> Start haskell).

If the ghci output window becomes obscured you can see it again by
typing C-cC-g (Hsc -> Haskell -> See output).

The SuperCollider convention is that ordinary graph nodes are placed
in a group with identifier 1, this node is not created when scsynth
starts, so initially we will have to make it.

The simplest way is to run the following line, and the simplest way to
run a line is to put point on the line and type C-cC-c (Hsc ->
Expression -> Run line).

> withSC3 reset

Doing this is so common there is a keybinding for it, C-cC-k (Hsc ->
SCSynth -> Reset scsynth).

To make a test sound run the following:

> audition (sinOsc AR 440 0 * 0.1)

This ought to play a quiet sine oscillator at A440.

To see the server status type C-cC-w (Hsc -> SCSynth -> Display

To stop the sound reset the server, ie. type C-cC-k.

For expressions that don't fit on one line select the region and type
C-cC-e (Hsc -> Expression -> Run region).  This writes the region in a
do block in a main procedure to a temporary file [2], loads the file
and then runs main.

> let f = sinOsc AR (xLine KR 1 1000 9 RemoveSynth) 0 * 200 + 800
> audition (sinOsc AR f 0 * 0.1)

(To select a region use the mouse or place point at one end, type
C-Space and move point to the other end.)

To find help on a UGen or on a SuperCollider server command put point
over the identifier and type C-cC-h (Hsc -> Help -> Hsc help).  This
opens the help file, which ought to have working examples in it, the
above graph is in the sinOsc help file.

To stop ghci type C-cC-x (Hsc -> Haskell -> Quit haskell).

It may have been a mistake to just use .lhs as the extension, however
it is not a disaster because the Hsc mode is a derivative of the
haskell mode.  Perhaps it ought to be changed to .hsc.

Hope this is clear-ish, please send through any questions, bug reports
or patches!


[1] To get this loaded I have the following in ~/.emacs:

  (push "~/ext/src/haskell/fptools/fptools/CONTRIB/haskell-modes/emacs" load-path)
  (load "haskell-site-file.el")      
  (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
  (add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
  (add-hook 'haskell-mode-hook 'turn-on-haskell-ghci)))

[2] The file is written to /tmp/hsc.lhs, the preamble imports
    the following modules, this is enough to run the help file 

    import Sound.OpenSoundControl
    import Sound.SC3
    import Control.Monad
    import System.Random

More information about the Haskell-Cafe mailing list