Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaning up for a release.

  • Loading branch information...
commit 2227ad28e71196c9625e13ea6141700c03d556ce 1 parent fc12d44
@jacobjoaquin authored
View
141 README
@@ -1,2 +1,141 @@
-'Csoundo' is a Processing library for Csound.
+'Csoundo' is a Csound library for Processing.
+
+Copyright (c) 2010 Jacob Joaquin
+jacobjoaquin@gmail.com
+http://csoundblog.com/
+
+Note
+----
+Csoundo development is in early Alpha. Though people have been successful in running Csoundo on Linux, OS X and Windows, there are still many issues that are preventing people from getting Csoundo to work on their computers. For example, Csoundo only works with the floats version of Csoundo, not doubles. (see "Known Issues" at the end)
+
+
+
+What is Processing?
+-------------------
+
+"Processing is an open source programming language and environment for people who want to create images, animations, and interactions. Initially developed to serve as a software sketchbook and to teach fundamentals of computer programming within a visual context, Processing also has evolved into a tool for generating finished professional work. Today, tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning, prototyping, and production."
+
+http://processing.org/
+
+
+
+What is Csound?
+---------------
+
+"Csound is a sound and music synthesis system, providing facilities for composition and performance over a wide range of platforms. It is not restricted to any style of music, having been used for many years in the creation of classical, pop, techno, ambient, experimental, and (of course) computer music, as well as music for film and television."
+
+http://csound.sourceforge.net/
+
+
+
+Running on OS X
+---------------
+1) Install Csound.
+
+Only one version of the pre-built Csound binaries has been confirmed to work on OS X, and only confirmed to work on Intel machines:
+
+csound5.12.4-OSX10.5-Universal.dmg
+http://sourceforge.net/projects/csound/files/csound5/csound5.12/csound5.12.4-OSX10.5-Universal.dmg/download
+
+
+2) Copy the Csoundo folder into your Processing 'libraries' folder. See instructions at Processing.org:
+
+http://wiki.processing.org/w/How_to_Install_a_Contributed_Library
+
+
+3) Copy or make a symlink to the csnd.jar file. The csnd.jar is located here:
+
+/Library/Frameworks/CsoundLib.framework/Resources/Java/csnd.jar
+
+Make a copy of csnd.jar in this folder:
+
+yoursketchbook/libraries/csoundo/library
+
+Alternatively, you can create a symbolic link using the terminal app.
+
+$ cd yoursketchbook/libraries/csoundo/library
+$ ln -s /Library/Frameworks/CsoundLib.framework/Resources/Java/csnd.jar csnd.jar
+
+
+
+Running on Linux
+----------------
+
+I do not have linux installed. If you have better instructions, please email me, and I will incorporate them into the Csoundo knowledge base.
+
+1) Install Csound:
+
+http://csound.sourceforge.net/
+
+
+2) Copy the Csoundo folder into your Processing 'libraries' folder. See instructions at Processing.org:
+
+http://wiki.processing.org/w/How_to_Install_a_Contributed_Library
+
+
+3) Copy or make a symlink to the csnd.jar here:
+
+yoursketchbook/libraries/csoundo/library
+
+To create a symbolic link:
+
+$ cd yoursketchbook/libraries/csoundo/library
+$ ln -s /Library/Frameworks/CsoundLib.framework/Resources/Java/csnd.jar csnd.jar
+
+
+4) Make modifications to the 'processing' lauch script.
+
+There is currently one known method for running Csoundo on linux. That is, to make to modifications to the 'processing' launcher script in the root folder of Processing.
+
+A. Towards the very end, right before the line "# Start Processing in the same directory as this script", add this code (your csound plugins folder may vary):
+
+#make sure that OPCODEDIR is set..
+export OPCODEDIR=/usr/local/lib/csound/plugins
+log OPCODEDIR
+
+B. Replace the last line "java processing.app.Base "$SKETCH" &" to the following:
+
+java -Djava.library.path=/usr/local/lib processing.app.Base "$SKETCH" &
+
+
+Thanks to Rory Walsh for this info.
+
+
+
+Running on Windows
+------------------
+
+There have been reports of Csoundo working on various versions of Windows. I do not have Windows installed. If you have better instructions, please email me, and I will incorporate them into the Csoundo knowledge base.
+
+1) Install Csound:
+
+http://csound.sourceforge.net/
+
+
+2) Copy the Csoundo folder into your Processing 'libraries' folder. See instructions at Processing.org:
+
+http://wiki.processing.org/w/How_to_Install_a_Contributed_Library
+
+
+3) Copy the csnd.jar here:
+
+yoursketchbook/libraries/csoundo/library
+
+
+
+Known Issues
+------------
+
+* Csound Doubles is not yet supported. To find out which version you are running, run csound, and about 5 lines down, you'll get a message like this: "Csound version 5.12 (float samples) Jun 4 2010"
+
+To track other issues, go here:
+
+http://github.com/jacobjoaquin/Csoundo/issues
+
+
+
+
+
+
+
View
13 examples/chnInOut/chnInOut.pde
@@ -1,3 +1,10 @@
+/*
+ * Demonstrates writing data to a csound channel (chn) bus then reading
+ * back the data. Move the mouse pointer around the screen.
+ *
+ * Example by Jacob Joaquin
+ */
+
import csoundo.*;
Csoundo cs;
@@ -7,18 +14,18 @@ void setup() {
frameRate(30);
smooth();
- cs = new Csoundo(this, sketchPath("data/synth.csd"));
+ cs = new Csoundo(this, "data/synth.csd");
cs.run();
}
void draw() {
background(0);
- /* Send mouse position to Csound chn busses */
+ // Send mouse position to Csound chn busses
cs.setChn("mouse_x", mouseX / (float) width);
cs.setChn("mouse_y", (1 - (mouseY / (float) height)));
- /* Read chn busses */
+ // Read chn busses
float mx = cs.getChn("mouse_x");
float my = cs.getChn("mouse_y");
View
2  examples/chnInOut/temp.csd
@@ -1,6 +1,6 @@
<CsoundSynthesizer>
<CsOptions>
--d -odac /Users/clu/Documents/workspace/Csoundo/examples/chnInOut/temp.csd
+-g -odac /Users/clu/Documents/workspace/Csoundo/examples/chnInOut/temp.csd
</CsOptions>
<CsInstruments>
sr = 44100
View
27 examples/devScratchPad/data/synth.csd
@@ -1,37 +1,24 @@
<CsoundSynthesizer>
<CsInstruments>
sr = 44100
-kr = 1470
-ksmps = 30
+kr = 4410
+ksmps = 10
nchnls = 1
0dbfs = 1
-gi_sin ftgen 1, 0, 8192, 10, 1
+chn_k "elapsed", 1
-chn_k "amp", 1
-
-chnset 0.5, "amp"
+chnset 0, "elapsed"
instr 1
- ; Keep Csound running
-endin
-
-instr 2
- idur = p3
- iamp = p4
- ifreq = p5
+ k1 chnget "elapsed"
+ chnset k1 + 1, "elapsed"
- k2 chnget "amp"
-
- k1 line iamp, idur, 0
- a1 oscil k1 * k2, ifreq, gi_sin
-
- out a1
endin
</CsInstruments>
<CsScore>
i 1 0 [60 * 60 * 24]
-i 2 0 4 0.5 262
+
</CsScore>
</CsoundSynthesizer>
View
25 examples/devScratchPad/devScratchPad.pde
@@ -1,30 +1,21 @@
-import csoundo.*;
+/*
+ * Developer scratch pad. This isn't an example, just a place to try things.
+ */
+
+ import csoundo.*;
Csoundo cs;
void setup() {
size(720, 480);
- frameRate(30);
- smooth();
+ noLoop();
cs = new Csoundo(this, "data/synth.csd");
cs.run();
- println("perf status: " + cs.getPerfStatus());
- cs.tableSet(1, 2048, -1.0);
}
void draw() {
background(0);
- noStroke();
- fill(random(255));
- ellipseMode(RADIUS);
- ellipse(width / 2, height / 2, 50, 50);
-
- cs.kLock();
- if (frameCount % 30 == 0) {
- cs.event("i 2 0 0.3 0.5 440");
- cs.event("i 2 0.1 0.3 0.5 880");
- }
- cs.kUnlock();
-
+ println(cs.get0dBFS());
+ println(cs.getOptions());
}
View
29 examples/devScratchPad/temp.csd
@@ -1,41 +1,28 @@
<CsoundSynthesizer>
<CsOptions>
--d -odac /Users/clu/Documents/workspace/Csoundo/examples/devScratchPad/temp.csd
+-g -odac /Users/clu/Documents/workspace/Csoundo/examples/devScratchPad/temp.csd
</CsOptions>
<CsInstruments>
sr = 44100
-kr = 1470
-ksmps = 30
+kr = 4410
+ksmps = 10
nchnls = 1
0dbfs = 1
-gi_sin ftgen 1, 0, 8192, 10, 1
+chn_k "elapsed", 1
-chn_k "amp", 1
-
-chnset 0.5, "amp"
+chnset 0, "elapsed"
instr 1
- ; Keep Csound running
-endin
-
-instr 2
- idur = p3
- iamp = p4
- ifreq = p5
+ k1 chnget "elapsed"
+ chnset k1 + 1, "elapsed"
- k2 chnget "amp"
-
- k1 line iamp, idur, 0
- a1 oscil k1 * k2, ifreq, gi_sin
-
- out a1
endin
</CsInstruments>
<CsScore>
i 1 0 [60 * 60 * 24]
-i 2 0 4 0.5 262
+
</CsScore>
</CsoundSynthesizer>
View
13 examples/drawTables/drawTables.pde
@@ -1,3 +1,14 @@
+/*
+ * Demonstrates reading values from an f-table and how to format f-tables
+ * into nice looking graphics. Perfect for the class room, papers and blogs.
+ *
+ * This example can be modified to output scalable vector graphics (SVG)
+ * to use in programs such as illustrator. See the PDF Library for details.
+ *
+ * Example by Jacob Joaquin
+ */
+
+
import csoundo.*;
Csoundo cs;
@@ -7,7 +18,7 @@ void setup() {
smooth();
noLoop();
- cs = new Csoundo(this, sketchPath("data/synth.csd"));
+ cs = new Csoundo(this, "data/synth.csd");
cs.run();
}
View
2  examples/drawTables/temp.csd
@@ -1,6 +1,6 @@
<CsoundSynthesizer>
<CsOptions>
--d -odac /Users/clu/Documents/workspace/Csoundo/examples/drawTables/temp.csd
+-g -odac /Users/clu/Documents/workspace/Csoundo/examples/drawTables/temp.csd
</CsOptions>
<CsInstruments>
sr = 44100
View
9 examples/events/events.pde
@@ -1,3 +1,10 @@
+/*
+ * Create i-events using the cs.event() method. For example:
+ * cs.event("i 2 0 0.25 0.4 880");
+ *
+ * Example by Jacob Joaquin
+ */
+
import csoundo.*;
Csoundo cs;
@@ -10,7 +17,7 @@ void setup() {
background(0);
noStroke();
- cs = new Csoundo(this, sketchPath("data/synth.csd"));
+ cs = new Csoundo(this, "data/synth.csd");
cs.run();
}
View
2  examples/events/temp.csd
@@ -1,6 +1,6 @@
<CsoundSynthesizer>
<CsOptions>
--d -odac /Users/clu/Documents/workspace/Csoundo/examples/events/temp.csd
+-g -odac /Users/clu/Documents/workspace/Csoundo/examples/events/temp.csd
</CsOptions>
<CsInstruments>
sr = 44100
View
10 examples/experiment_1/experiment_1.pde
@@ -1,4 +1,10 @@
-import csoundo.*;
+/*
+ * Something between a lava lamp and a wind chime.
+ *
+ * Example by Jacob Joaquin
+ */
+
+ import csoundo.*;
Net net;
Csoundo cs;
@@ -25,7 +31,7 @@ void setup() {
net = new Net(N_NODES, MIN_NODE_SIZE, MAX_NODE_SIZE);
if (IS_SOUND_ON) {
- cs = new Csoundo(this, sketchPath("data/synth.csd"));
+ cs = new Csoundo(this, "data/synth.csd");
cs.run();
}
}
View
2  examples/experiment_1/temp.csd
@@ -1,6 +1,6 @@
<CsoundSynthesizer>
<CsOptions>
--d -odac /Users/clu/Documents/workspace/Csoundo/examples/experiment_1/temp.csd
+-g -odac /Users/clu/Documents/workspace/Csoundo/examples/experiment_1/temp.csd
</CsOptions>
<CsInstruments>
sr = 44100
View
13 examples/headerInfo/headerInfo.pde
@@ -1,4 +1,10 @@
-import csoundo.*;
+/*
+ * Demonstrates how to use information about a running Csound process.
+ *
+ * Example by Jacob Joaquin
+ */
+
+ import csoundo.*;
Csoundo cs;
PFont font;
@@ -16,10 +22,11 @@ void setup() {
}
void draw() {
- translate(30, height - 150);
+ translate(30, height - 180);
text("Sample rate: " + cs.sr(), 0, 0);
text("Control rate: " + cs.kr(), 0, 30);
text("Ksmps: " + cs.ksmps(), 0, 60);
text("Channels: " + cs.nchnls(), 0, 90);
- text("0dBfs: " + cs.get0dBFS(), 0, 120);
+ text("0dBfs: " + cs.get0dBFS(), 0, 120);
+ text("Options: " + cs.getOptions(), 0, 150);
}
View
2  examples/headerInfo/temp.csd
@@ -1,6 +1,6 @@
<CsoundSynthesizer>
<CsOptions>
--d -odac /Users/clu/Documents/workspace/Csoundo/examples/headerInfo/temp.csd
+-g -odac /Users/clu/Documents/workspace/Csoundo/examples/headerInfo/temp.csd
</CsOptions>
<CsInstruments>
sr = 44100
View
12 examples/playMessage/playMessage.pde
@@ -1,9 +1,15 @@
+/*
+ * Demonstrates running a Csound composition.
+ *
+ * Message From Another Planet by Jacob Joaquin
+ */
+
import csoundo.*;
Csoundo cs;
void setup() {
- size(1600, 1200);
+ size(740, 480);
background(0);
noLoop();
@@ -11,6 +17,4 @@ void setup() {
cs.run();
}
-void draw() {
-
-}
+void draw() { }
View
2  examples/playMessage/temp.csd
@@ -1,6 +1,6 @@
<CsoundSynthesizer>
<CsOptions>
--d -odac /Users/clu/Documents/workspace/Csoundo/examples/playMessage/temp.csd
+-g -odac /Users/clu/Documents/workspace/Csoundo/examples/playMessage/temp.csd
</CsOptions>
<CsInstruments>
sr = 44100
View
48 examples/protectedTable/protectedTable.pde
@@ -1,3 +1,16 @@
+/*
+ * Not an example, but a test to make sure table data is protected.
+ *
+ * Every frame, a new Csound table is generated, overwriting the existing
+ * table. Each value is replaced with a sine + noise value, and then read
+ * from the table and used for drawing an animation.
+ *
+ * Some indicators that the test fails at times, where it reads a value
+ * before it has been properly set.
+ *
+ * !Example by Jacob Joaquin
+ */
+
import csoundo.*;
Csoundo cs;
@@ -6,43 +19,30 @@ void setup() {
size(740, 480);
frameRate(30);
smooth();
- background(0);
-// noLoop();
+ noFill();
+ ellipseMode(RADIUS);
cs = new Csoundo(this, "data/synth.csd");
cs.run();
-
}
void draw() {
- fill(0, 16);
- rect(0, 0, width, height);
- ellipseMode(RADIUS);
- noStroke();
+ background(0);
-// float r = random(255.0);
-// fill(r, r, 196);
-
- println("before");
- float size = pow(2, 7);
- println(size);
+ float size = pow(2, 13);
cs.event("f 20 0 " + size + " 10 0");
- println("after");
int length = cs.tableLength(20);
float phase = (float) (frameCount % 120) / 120 * TWO_PI;
+
for (int i = 0; i < length; i++) {
float r = random(255.0);
- fill(r, r, 255, 196);
+ stroke(r, r, 255);
+
+ // Intentionally read backwards
cs.tableSet(20, length - i - 1, sin(2 * PI * (float) i *
- (random(0.2) + 1.0) / (float) length + phase));
- float v = cs.tableGet(20, length - i - 1);
+ (random(0.2) + 2.0) / (float) length + phase));
- float r1 = random(2.0);
- float r2 = random(2.0);
-
- ellipse((float) i / (float) length * (float) width,
- height / 2.0 + height / 2.0 * v, r1, r1);
+ float v = cs.tableGet(20, length - i - 1);
+ point((float) i / (float) length * (float) width, height / 2.0 + height / 2.0 * v);
}
-// float v = cs.tableGet(20, (length - 1));
-// print("done " + v);
}
View
2  examples/protectedTable/temp.csd
@@ -1,6 +1,6 @@
<CsoundSynthesizer>
<CsOptions>
--d -odac /Users/clu/Documents/workspace/Csoundo/examples/protectedTable/temp.csd
+-g -odac /Users/clu/Documents/workspace/Csoundo/examples/protectedTable/temp.csd
</CsOptions>
<CsInstruments>
sr = 44100
View
8 examples/random/random.pde
@@ -1,4 +1,8 @@
-/* Example by Rory Walsh */
+/*
+ * Randomly generated visuals synchronized with audio.
+ *
+ * Example by Rory Walsh
+ */
import csoundo.*;
@@ -11,7 +15,7 @@ void setup() {
size(740, 480);
frameRate(10);
smooth();
- cs = new Csoundo(this, sketchPath("data/test.csd"));
+ cs = new Csoundo(this, "data/test.csd");
cs.run();
}
View
2  examples/random/temp.csd
@@ -1,6 +1,6 @@
<CsoundSynthesizer>
<CsOptions>
--d -odac /Users/clu/Documents/workspace/Csoundo/examples/random/temp.csd
+-g -odac /Users/clu/Documents/workspace/Csoundo/examples/random/temp.csd
</CsOptions>
<CsInstruments>
sr = 44100
View
14 examples/sliders/sliders.pde
@@ -1,4 +1,14 @@
-import controlP5.*;
+/*
+ * A bank of seven sliders controlling an FM synthesizer (foscil). The
+ * sliders are generated using the controlP5 library by Andreas Schlegel.
+ * Great for old school lasers and UFOs.
+ *
+ * Downlaod controlP5: http://www.sojamo.de/libraries/controlP5/
+ *
+ * Example by Jacob Joaquin
+ */
+
+ import controlP5.*;
import csoundo.*;
ControlP5 controlP5;
@@ -10,7 +20,7 @@ void setup() {
smooth();
controlP5 = new ControlP5(this);
- cs = new Csoundo(this, sketchPath("data/synth.csd"));
+ cs = new Csoundo(this, "data/synth.csd");
cs.run();
// Set default values in Csound chn bus memory
View
2  examples/sliders/temp.csd
@@ -1,6 +1,6 @@
<CsoundSynthesizer>
<CsOptions>
--d -odac /Users/clu/Documents/workspace/Csoundo/examples/sliders/temp.csd
+-g -odac /Users/clu/Documents/workspace/Csoundo/examples/sliders/temp.csd
</CsOptions>
<CsInstruments>
sr = 44100
View
81 src/csoundo/Csoundo.java
@@ -33,7 +33,7 @@
*/
-public class Csoundo {
+public class Csoundo{
PApplet myParent;
public final static String VERSION = "##version##";
@@ -45,7 +45,6 @@
private Engine engine;
private Csound csound;
private CsoundPerformanceThread perfThread;
-// private SWIGTYPE_p_CSOUND_ csound_p;
private Mutex mutex;
/**
@@ -89,7 +88,9 @@ public void dispose() {
public void pre() { }
- public void post() { }
+ public void post() {
+ mutex.cleanup(); // Closes any mutex locks left open from lock()
+ }
private void welcome() {
System.out.println("##name## ##version## by ##author##");
@@ -103,7 +104,7 @@ private void welcome() {
public static String version() {
return VERSION;
}
-
+
/**
* Creates a Csound score event.
*
@@ -111,11 +112,18 @@ public static String version() {
*/
public void event(String s) {
if (!isRunning) return;
+ // TODO: Is mutex needed if csoundPerformanceThread.InputMessage()
+ // is already thread safe? Does it use mutex?
mutex.lock();
perfThread.InputMessage(s);
mutex.unlock();
}
+ /**
+ * Returns the 0dbfs value, set in the orchestra header.
+ *
+ * @return 0dbfs
+ */
public float get0dBFS() {
if (!isRunning) return 0;
return csound.Get0dBFS();
@@ -134,20 +142,29 @@ public float getChn(String chn) {
return value;
}
+ /**
+ * Returns the command-line options string.
+ *
+ * @return command-line options
+ */
+ public String getOptions() {
+ return engine.options;
+ }
+
+ /**
+ * Returns the status of csoundPerformanceThread.
+ *
+ * NOTE: This is for Csoundo development and is likely to disappear
+ * or be renamed.
+ *
+ * @return status
+ */
public int getPerfStatus() {
+ // TODO: Make ENUMS, not magic numbers
if (!isRunning) return -99999;
return perfThread.GetStatus();
}
-
- public void kLock() {
- mutex.lock();
- }
-
- public void kUnlock() {
- mutex.unlock();
- }
-
/**
* Return the control rate.
*
@@ -164,10 +181,18 @@ public float kr() {
* @return ksmps
*/
public float ksmps() {
+ // TODO: Throw exceptions, not magic numbers.
if (!isRunning) return 0;
return csound.GetKsmps();
}
+ /**
+ * Lock mutex. Experimental.
+ */
+ public void lock() {
+ mutex.lock();
+ }
+
/**
* Return the number or audio output channels.
*
@@ -188,7 +213,7 @@ public void run() {
System.out.println("Waiting for csoundPerformanceThread");
}
csound = engine.csound;
- mutex = new Mutex();
+ mutex = engine.mutex;
isRunning = engine.isRunning;
}
@@ -228,6 +253,19 @@ public void setChnTest(String chn, float value) {
}
*/
+ /**
+ * Overwrites the Csound options.
+ *
+ * Default options are '-g -odac' where -g sets graphics to display
+ * as ascii characters in the console output and -odac means to send
+ * audio to the default digital-audio-converter.
+ *
+ * @param Command-line string
+ */
+ public void setOptions(String s) {
+ engine.options = s;
+ }
+
/**
* Return the samplerate.
*
@@ -282,13 +320,10 @@ public void tableSet(int t, int i, float v) {
mutex.unlock();
}
+ /**
+ * Unlock mutex. Experimental.
+ */
+ public void unlock() {
+ mutex.unlock();
+ }
}
-
-
-
-
-
-
-
-
-
View
63 src/csoundo/Engine.java
@@ -28,35 +28,40 @@
import java.io.*;
import csnd.*;
+/**
+ * This class is for getting Csound up and running.
+ */
public class Engine {
private String csd;
private String path;
+ public String options = "-g -odac";
public boolean isRunning = false;
-// public CppSound csound;
public Csound csound;
public CsoundFile csoundFile;
public CsoundPerformanceThread perfThread;
public SWIGTYPE_p_void v;
public SWIGTYPE_p_CSOUND_ csound_p;
-// SWIGTYPE_p_void mutex;
+ public Mutex mutex;
/**
* The Engine constructor, usually called in the setup() method in your
* sketch to initialize and start the library.
*
- * @param theParent The PApplet. Usually pass 'this'
- * @param f The Csound file to run. Requires full absolute path.
+ * @param _csd The name of the csd file
+ * @param _path The path to the csd
*/
public Engine(String _csd, String _path) {
-// csound = new CppSound();
csound = new Csound();
csd = _csd;
path = _path;
}
+ /**
+ * Setup the Csound engine and play it.
+ */
private void csoundPerf() {
// TODO: Make sure csound isn't already running
if (true) {
@@ -71,7 +76,7 @@ private void csoundPerf() {
// TODO: csd should get unique names, in case of multiple
// instances.
String tempCSD = "temp.csd";
- csoundFile.setCommand("-d -odac " + path + tempCSD);
+ csoundFile.setCommand(options + " " + path + tempCSD);
csoundFile.exportForPerformance();
int compile = csound.Compile(path + tempCSD);
@@ -81,7 +86,7 @@ private void csoundPerf() {
isRunning = true;
perfThread = new CsoundPerformanceThread(csound_p);
perfThread.Play();
- //mutex = csnd.csoundCreateMutex(1);
+ mutex = new Mutex();
}
}
}
@@ -109,48 +114,10 @@ private String fileToString(String path) {
return sb.toString();
}
+ /**
+ * Start Csound.
+ */
public void start() {
-// cppSoundPerf();
csoundPerf();
}
}
-
-/*
-private void cppSoundPerf() {
- // TODO: Make sure csound isn't already running
- if (true) {
- csnd.csoundInitialize(null, null,
- csnd.CSOUNDINIT_NO_SIGNAL_HANDLER);
-
- csound = new CppSound();
- csound_p = csound.getCsound();
-
- csoundFile = csound.getCsoundFile();
- csoundFile.setCSD(fileToString(csd));
-
- // TODO: csd should get unique names, in case of multiple
- // instances.
- String tempCSD = "temp.csd";
- csoundFile.setCommand("-d -odac " + path + tempCSD);
-
- csoundFile.exportForPerformance();
- int compile = csound.compile();
- System.out.println("compile status: " + compile);
-
- if (compile == 0) {
- isRunning = true;
- perfThread = new CsoundPerformanceThread(csound_p);
- perfThread.Play();
- mutex = csnd.csoundCreateMutex(1);
- }
- }
-}
-*/
-
-
-
-
-
-
-
-
View
40 src/csoundo/Mutex.java
@@ -27,39 +27,47 @@
import csnd.*;
+/**
+ * Experimental class for thread locking/memory protection.
+ */
public class Mutex {
+ // FIXME: My tests have confirmed that I have no idea what I'm doing
+ // here.
+
+ SWIGTYPE_p_void m; // Mutex
+ private int locks = 0; // Number of active locks
+ private boolean useLocks = true; // Use locks?
- SWIGTYPE_p_void m;
- int instances = 0;
- private boolean useThreads = true;
-
+ public Mutex() {
+ m = csnd.csoundCreateMutex(1);
+ }
+
+ public int activeThreads() {
+ return locks;
+ }
+
public void cleanup() {
- if (!useThreads) return;
- while (instances > 0) {
+ if (!useLocks) return;
+ while (locks > 0) {
unlock();
}
}
- public Mutex() {
- m = csnd.csoundCreateMutex(1);
- }
-
public void lock() {
- if (!useThreads) return;
+ if (!useLocks) return;
csnd.csoundLockMutex(m);
- instances++;
+ locks++;
}
public void unlock() {
- if (!useThreads) return;
- if (instances > 0) {
- instances--;
+ if (!useLocks) return;
+ if (locks > 0) {
+ locks--;
csnd.csoundUnlockMutex(m);
} else {
System.out.println("Warning: Mutex trying to unlock imaginary threads.");
}
}
-
}
Please sign in to comment.
Something went wrong with that request. Please try again.