[chuck-users] Sharing Instantiated Objects Thru Shreds
ssalazar at CS.Princeton.EDU
Wed Oct 11 20:25:41 EDT 2006
There is no explicit mechanism for sharing data between multiple
shreds, but using public classes and static data members, you can
create and use global data. For example, if you defined the
following public class:
public class GlobalData
// ChucK doesn't support static
// objects which aren't references
static Event @ theEvent;
// initialize our global data -
// this starts out as an empty reference
Event e @=> GlobalData.theEvent;
// end of GlobalData.ck
You could then access the same event in any other shreds like so:
GlobalData.theEvent => now;
// do something
// end of 1.ck
// end of 2.ck
You can put as many static data members as you need of whichever
types into a single or multiple public classes, and share those
single instances of these data members between all running shreds.
The one trick is that if you want to use a static member variable
that is an object (ie, not an int, float, dur, or time), it has to be
an _explicit reference_ to that object. Then you have to make sure
to initialize that object before you use it.
Feel free to ask questions if any of this is too confusing.
hope this helps,
On Oct 11, 2006, at 4:48 PM, Piero B. Contezini wrote:
> Maybe i'm missing something, but I need to share a instantiated
> object between my shreds, as this object will control the music
> flow, I need all my shreds to share this instance.
> It works like this:
> Shred 1 controls the basic bass sequence
> Shred 2 controls the fx sequence
> There is a common class between them notifying each shred when they
> must change their random parameters (for sequencing everything in
> the right compasses), but the class itself doesn't work if it has
> no instance controlling the time poll interval, so in a programming
> language I should implement a shared memory area with mutexes to
> control the access of the main object, anyone had this problem before?
> I'm still figuring out how to put my ideas on Chuck, maybe i'm just
> doing something that's already done. Basicly i'm thinking this way
> because of the common way eletronic music is built on (8 beats as a
> word, 32 beats as phrase, and so on)
> In this way, I can't just add a new shred to the machine without
> being in the right compass (in a new phrase) , I could use timing,
> but I still want to make breaks (with effects of course) live,
> where I just set the main object to stop allowing the shreds to
> processes its next words/phrases , play the hole effect, and leave
> the control of the machine to the old shreds again.
> Is this just insane?
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
More information about the chuck-users