Introducing Slipmat for Java and Csound

Yesterday, I released the first public version of Slipmat, a Java-based modular computer music library built on top of the Csound API. You can download it at Sourceforge.

Let me back up a bit…

Ever since I started Csounding about a decade ago, I’ve heard people refer to the syntax of the Csound language as being very similar to that of Assembly on numerous occasions. I certainly see their point. Let’s face it, Csound is a Frankenstein of language, stitched together with duct tape and bubble gum. And like Frankenstein, it is both powerful, yet scary to those who judge it solely on its facade. Those who turn a blind eye to Csound’s frightening nature and learn to understand it for what it is are rewarded with an amazingly expressive computer music environment. Unfortunately, most people equate their first experience with ladling hot soup onto their laps. Did I mention Csound is afraid of fire?

Continuing with the Frankenstein metaphor a little longer, Slipmat is a Java abstraction layer that attempts to tame the monster. To teach it some manners and civility. If all goes well, Csound will be putting on the ritz in no time.

Let’s take a look at a simple Slipmat java program (included with the download.) The following plays every note in a 12 note octave between 440 and 880:

import com.thumbuki.slipmat.*;
import com.thumbuki.slipmat.module.*;

public class SimpleExample {
    public static void main(String[] args) {
        SynthRack synthRack = new SynthRack(false);
        SinePerc sinePerc = new SinePerc();
        Output output = new Output();

        for (int i = 0; i <= 12; i++)             sinePerc.playNote(i * 0.25, 0.9, 440 * Math.pow(2, i / 12.0));         synthRack.startCsound();                  try {             Thread.sleep(4000); /* Keep java running for four seconds */         }         catch(Exception ex) { }     } }

If we think of Slipmat as a high-level abstraction of Csound, which it is, then what happens behind the scenes is that Slipmat "compiles" Csound code, and then this code is fed to the Csound engine. This is sorta how Java produces bytecode that is executed by a Java Virtual Machine. The following is the code that is produced by the previous example:

csound -d -A -odevaudio null.csd
sr = 44100
kr = 4410
ksmps = 10
nchnls = 2

0dbfs = 1.0

gitable1 ftgen 1, 0, 8192, 10, 1.0

chn_a "chna0", 3

instr 1
aclear = 0.0
chnset aclear, "chna0"

instr 2
a1 oscil p4, p5, gitable1
aenv linseg 0, p3 * 0.05, 1, p3 * 0.95, 0
a1 = a1 * aenv
chnmix a1, "chna0"

instr 3
a1 chnget "chna0"
outs a1, a1

i 2 0.0 0.125 0.9 440.0
i 2 0.25 0.125 0.9 466.1637615180899
i 2 0.5 0.125 0.9 493.8833012561241
i 2 0.75 0.125 0.9 523.2511306011972
i 2 1.0 0.125 0.9 554.3652619537442
i 2 1.25 0.125 0.9 587.3295358348151
i 2 1.5 0.125 0.9 622.2539674441618
i 2 1.75 0.125 0.9 659.2551138257398
i 2 2.0 0.125 0.9 698.4564628660078
i 2 2.25 0.125 0.9 739.9888454232689
i 2 2.5 0.125 0.9 783.9908719634986
i 2 2.75 0.125 0.9 830.6093951598903
i 2 3.0 0.125 0.9 880.0
i 1 0 -1.0
i 3 0.0 -1.0


I know what you're thinking... What the hell am I looking at? Truth is, this code is not meant for human consumption. A person who regularly writes Csound code can write code that is more clear than this. Even then, compared to Java-Slipmat code, it can look like chicken scratch. Or my handwriting.

Since Slipmat is more or less a Java library built on top of the Java-Csound API, this means all of Java's and whistles are now available to use in conjunction with Csound. Want a reliable cross-platform GUI? Give swing a try. Want to integrate Processing with you Csound? You can. Want a tool that automagically hides all the grunt work from you, such as assigning instr numbers, tables, chn software busses, etc? More than anything else in life (personally speaking.)

I should warn you... Slipmat is currently pre-alpha. Which means everything is in a state of flux, and there isn't anything that resembles a specification at this point. Methods and classes are guaranteed to change drastically over the next few months. Tutorials on the way...