[chuck-users] public class connections mystery

David Ogborn ogbornd at mcmaster.ca
Thu Feb 23 20:44:12 EST 2012


Hello again Chuckists,

This is the second time today that I harangue the list with a question about some unexpected behaviour from code (unexpected to me, anyways!).  This one is a bit more complicated…

I declare a public class that maintains a static array of oscillators and envelopes (through a helper class).  A function in the public class creates a new oscillator and envelope, and connects them both to the dac.  Another function in the public class makes the envelope "go".

Now here's the funny thing, to my mind: 

(1) If I call the creation function and the "go" function from the same (second) shred, everything works.

(2) If I call the creation function in one shred and the "go" function in another shred, there is no sound - and a little investigation seems to reveal that the ugens all exist and are accessible, but are no longer connected to each other.

(3) If I call a special "connect" function - _from any shred_ - that simply reestablishes the connections, then the "go" function works when called _from any shred.

Here is an example of "calling shreds" and below that is the public class code:

// one possible shred…
Cells.sinOsc("low",28);

// I want this to work from a separate shred but there is no sound/connections
Cells.ad("low",5::ms,5::ms);

// However, the above starts to work again if this is called from any shred
Cells.connect("low");

// public class code in a separate file and shred

class Cell {
    Osc o;
    Envelope e;
}

public class Cells {
    
    static Cell @cells[];
    
    function static void sinOsc(string name, float nn) {
        Cell c;
        new SinOsc @=> c.o;
        nn => Std.mtof => c.o.freq;
        new Envelope @=> c.e;
        c.o => c.e => dac;
        c @=> cells[name];
    }
    
    function static void ad(string name, dur att,dur dec) {
        cells[name] @=> Cell c;
        1 => c.e.target;
        att => c.e.duration => now;
        0 => c.e.target;
        dec => c.e.duration => now;
    }
    
    // the function below shouldn't be necessary, I don't think
    // but it is… unless connect is called on a given cell from
    // a shred other than the shred that calls sinOsc, the 
    // ugens are not connected to the dac! ???
    function static void connect(string name) {
        cells[name] @=> Cell c;
        c.o => c.e => dac;
    }
    
    function static void note(string name, float nn) {
        nn => Std.mtof => cells[name].o.freq;
    }

}

Cell theCells[0] @=> Cells.cells;

while(true) {
    <<< "public class Cells is still alive" >>>;
    10::second => now; 
}

// Thanks for any help!
// Yours truly,
// David

-------------------------------------------------------------------
Dr. David Ogborn, Assistant Professor
Communication Studies & Multimedia
Director, Cybernetic Orchestra & ESP Studio
McMaster University, Hamilton, Canada

ogbornd --at-- mcmaster.ca
http://davidogborn.net
http://twitter.com/ogbornd
http://esp.mcmaster.ca (Cybernetic Orchestra)
1-905-525-9140 ext 27603






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20120223/b0c0ff36/attachment.htm>


More information about the chuck-users mailing list