Hi David,
Yeah, that's weird. I added these debug statements to 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];
<<< c, cells[name] >>>;
<<< c.o, cells[name].o, c.e, cells[name].e >>>;
<<< cells[name].o.isConnectedTo(cells[name].e) >>>;
<<< cells[name].e.isConnectedTo(dac) >>>;
}
function static void ad(string name, dur att,dur dec) {
cells[name] @=> Cell c;
<<< c, cells[name] >>>;
<<< c.o, cells[name].o, c.e, cells[name].e >>>;
<<< cells[name].o.isConnectedTo(cells[name].e) >>>;
<<< cells[name].e.isConnectedTo(dac) >>>;
1 => c.e.target;
att => c.e.duration => now;
0 => c.e.target;
dec => c.e.duration => now;
}
...
and get these results:
[chuck](VM): sporking incoming shred: 2 (ogborn_2)...
0x21c12010 0x21c12010
0x21c56060 0x21c56060 0x207f7a30 0x207f7a30
1 :(int)
1 :(int)
"public class Cells is still alive" : (string)
"public class Cells is still alive" : (string)
[chuck](VM): sporking incoming shred: 3 (ogborn_2)...
0x21c12010 0x21c12010
0x21c56060 0x21c56060 0x207f7a30 0x207f7a30
0 :(int)
0 :(int)
Seems to be the same object references but they are definitely not
connected by the time they get that call from the second shred.
Almost as if the UGen connections had scope...
-Mike
http://michaelclemow.com
http://semiotech.org
2012/2/23 David Ogborn
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
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users