rsc3/doc/tutorials/rsc3-tutorial.html

187 lines
8.3 KiB
HTML
Raw Normal View History

2022-08-24 13:53:18 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<title>rd: rsc3-texts/md/rsc3-tutorial.md</title>
<meta name="description" content="rsc3-texts/md/rsc3-tutorial.md" />
<meta name="author" content="ROHAN DRAPE" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" media="all" href="css/rd.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/aaaakshat/cm-web-fonts@latest/fonts.css" />
<link rel="icon" type="image/png" href="https://rohandrape.net/data/png/rd.512.png" />
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=yes" />
<meta name="google-site-verification" content="FRRDSM4lyfU-s4Pw9tAjg4mz_27hNAgSgGQuC2I-Hkc" />
</head>
<body class="rsc3-texts/md/rsc3-tutorial.md">
<div class="main">
<nav class="menu">
<div class="menu">
rd:
<span class="menu" id="work">
<a href="?t=work" class="not-here">work</a>
</span>
<span class="menu-separator"> | </span>
<span class="menu" id="about">
<a href="?t=about" class="not-here">about</a>
</span>
<span class="menu-separator"> | </span>
<span class="menu" id="contact">
<a href="?t=contact" class="not-here">contact</a>
</span>
</div>
</nav>
<div class="rd-md"><h1>Scheme SuperCollider, a Tutorial</h1>
<h2>Prerequisites</h2>
<p>Scheme SuperCollider
(<a href="http://rohandrape.net/?t=rsc3">rsc3</a>)
requires that both the
<a href="http://www.audiosynth.com/">SuperCollider</a>,
synthesiser and a scheme interpreter
(either
<a href="https://launchpad.net/ikarus/">Ikarus</a>
or
<a href="https://www.scheme.com/">Chez</a>
or
<a href="https://www.gnu.org/software/guile/">Guile</a>)
are all installed and working properly.</p>
<p>The interaction environment is ordinarily
<a href="http://www.gnu.org/software/emacs/">Emacs</a>.</p>
<h2>Setting up Scheme SuperCollider</h2>
<p>Scheme SuperCollider is currently only available as a set of
<a href="http://darcs.net/">darcs</a>
repositories, the basic system is called <code>rsc3</code> and
requires the rhs and sosc libraries. A simple build utility is also
required.</p>
<pre><code>$ darcs get http://rohandrape.net/sw/mk-r6rs
$ darcs get http://rohandrape.net/sw/rhs
$ darcs get http://rohandrape.net/sw/sosc
$ darcs get http://rohandrape.net/sw/rsc3
</code></pre>
<p>To build ensure that the <code>mk-r6rs</code> library is on the scheme library
path and run the below in each project.</p>
<pre><code>$ (cd mk; make prefix=~/opt)
</code></pre>
<p>This installs the r6rs libraries to <code>~/opt/lib/r6rs</code>.</p>
<!--
If using `PLT` scheme the following steps are also required:
$ plt-r6rs --install ~/opt/lib/r6rs/rhs.sls
$ plt-r6rs --install ~/opt/lib/r6rs/sosc.mzscheme.sls
$ plt-r6rs --install ~/opt/lib/r6rs/rsc3.mzscheme.sls
-->
<h2>Setting up the Scheme SuperCollider Emacs mode</h2>
<p>Add an appropriately modified variant of the following to <code>~/.emacs</code></p>
<pre><code>(push &quot;/home/rohan/sw/rsc3/emacs&quot; load-path)
(setq rsc3-help-directory &quot;/home/rohan/sw/rsc3/help/&quot;)
(setq rsc3-interpreter (list &quot;ikarus&quot; &quot;/home/rohan/.rsc3&quot;))
(require 'rsc3)
</code></pre>
<p>The rsc3 emacs mode associates itself with files having the extensions
<code>.scm</code> and <code>.lisp</code>. When the <code>rsc3</code> emacs mode is active there
is a <code>Scheme SuperCollider</code> menu available.</p>
<p>Ordinarily the <code>~/.rsc3</code> file will load a standard set of modules.</p>
<pre><code>(import (rhs core)) ; rhs
(import (sosc core)) ; sosc
(import (rsc3 core) (rsc3 server) (rsc3 ugen)) ; rsc3
(import (rsc3 arf) (rsc3 dot) (rsc3 lang)) ; rsc3-arf rsc3-dot rsc3-lang
</code></pre>
<h2>Documentation</h2>
<p>The documentation for Scheme SuperCollider, including this tutorial,
is written in plain text as ordinary scheme source files.</p>
<p>Unlike ordinary programs the Scheme SuperCollider help files cannot be
compiled to executables. Each help file contains multiple independant
examples that can be evaluated using editor commands, either by
selecting from the <code>Scheme SuperCollider</code> menu or using the associated
keybinding.</p>
<h2>Interpreter Interaction</h2>
<p>To start the scheme interpreter use <code>C-cC-&gt;</code> (Scheme SuperCollider →
Scheme → See scheme).</p>
<p>Starting the interpreter splits the current window into two windows.
If the scheme output window becomes obscured during a session you can
see it again by typing <code>C-cC-s</code> again.</p>
<p>To stop scheme type <code>C-cC-q</code> (Scheme SuperCollider → Scheme
→ Quit scheme).</p>
<h2>Starting the SuperCollider server</h2>
<p>The SuperCollider server can be started from the command
line. The help files assume that scsynth is listening for
UDP connections at the standard port on the local machine.</p>
<pre><code>$ scsynth -u 57110
</code></pre>
<h2>Basic SuperCollider Interaction</h2>
<p>The SuperCollider server manages a graph of nodes with
integer identifiers. The root node has ID zero. By
convention ordinary graph nodes are placed in a group with
identifier 1, however this node is not created when scsynth
starts.</p>
<p>To create this node we need to send an OSC message to the
server, the expression to do this is written below. To
evaluate an expression move the cursor to the closing
parenthesis and type <code>C-cC-e</code> (Scheme SuperCollider →
Expression → Evaluate).</p>
<pre><code>(withSc3 (lambda (fd) (sendMessage fd (g_new1 1 addToTail 0))))
</code></pre>
<p>We can then audition a quiet sine oscillator at A440 by typing
<code>C-cC-a</code> (Scheme SuperCollider → Expression → Play).</p>
<pre><code>(Mul (SinOsc 440 0) 0.1)
</code></pre>
<p>To stop the sound we can delete the group it is a part of,
the audition function places the synthesis node into the
group node with ID 1, the expression below deletes that
group.</p>
<pre><code>(withSc3 (lambda (fd) (sendMessage fd (n_free1 1))))
</code></pre>
<p>In order to audition another graph we need to re-create a group with
ID 1. rsc3 includes a function <code>reset</code> that sequences these two
actions, first deleting the group node, then re-creating a new empty
group.</p>
<pre><code>(withSc3 reset)
</code></pre>
<p>Using this command is so common there is a keybinding for it, <code>C-cC-k</code>
(Scheme SuperCollider → SCSynth → Reset scsynth). After a reset we
can audition a new graph.</p>
<pre><code>(Mul (SinOsc 220 0) 0.1)
</code></pre>
<p>To see the server status type <code>C-cC-p</code> (Scheme SuperCollider → SCSynth
→ Status), which sends:</p>
<pre><code>(withSc3 displayServerStatus)
</code></pre>
<p>This prints a table indicating server activity to the scheme output
window.</p>
<pre><code>***** SuperCollider Server Status *****
# Ugens 0
# Synths 0
# Groups 2
# Instruments 0
% CPU (Average) 1.2261821031570435
% CPU (Peak) 1.2635631561279297
Sample Rate (Nominal) 44100.0
Sample Rate (Actual) 44098.31557093504
</code></pre>
<h2>Multiple line expressions</h2>
<p>Multiple line expressions are evaluated using the same mechanism as
single line expressions, so <code>C-cC-a</code> will play the expression below:</p>
<pre><code>(let* ((f1 (XLine 1 1000 9 removeSynth))
(f2 (MulAdd (SinOsc f1 0) 200 800)))
(Mul (SinOsc f2 0) 0.1))
</code></pre>
<h2>Help Files</h2>
<p>To find help on a Ugen or on a SuperCollider server command place the
cursor over the identifier and type <code>C-cC-h</code> (Scheme SuperCollider →
Help → Scheme SuperCollider help). This opens the help file, which
ought to have working examples in it, the above graph is in the
<code>SinOsc</code> help file.</p>
<p>There is also a collection of Ugen graphs,
for instance <code>help/graph/jmcc-analog-bubbles.lisp</code>.</p>
<h2>Monitoring incoming server messages</h2>
<p>To monitor what OSC messages scsynth is receiving use the <code>dumpOSC</code>
server command to request that scsynth print text traces of incoming
messages to its standard output.</p>
<pre><code>(withSc3 (lambda (fd) (sendMessage fd (dumpOSC 1))))
</code></pre>
<p>To end printing send:</p>
<pre><code>(withSc3 (lambda (fd) (sendMessage fd (dumpOSC 0))))
</code></pre>
</div>
</div>
</body>
</html>