[chuck-users] different classes and files talking to each other

Julien Saint-Martin julien.saintmartin at googlemail.com
Wed Apr 18 04:33:45 EDT 2012


Hi Henrique and Welcome to ChucK world :o)

I think all you want to do is possible but their is different ways to do it
and limitations (but fortunately work around too!! )

Here is the method I use:
To centralize all my public classes, scripts and shared objects, I have a
top.ck file where I add each files in correct order with Machine.add()
command:

Machine.add ("tick_class.ck");
Machine.add ("beat_event_class.ck");
Machine.add ("beat_events.ck");
Machine.add ("play_tick_class.ck");
//Machine.add ("send.ck");
//Machine.add ("receive.ck");
Machine.add ("receive_tick.ck");
Machine.add ("rythm.ck");...



tick_class.ck is for example an extended Event class where I added some
extra info:

public class tick_event extends Event {

    int tick_nb;
    int is_meas_start;
    int is_super_meas_start;
    dur tick_dur;
}


One limitation of current chuck version is that you cannot have more than
one public class per file.


beat_events.ck contains another public class where static objects are
defined. There is a limitation here, you have to instantiate static objects
outside of class declaration. I use to do it in the same file as class
declaration:


public class beat_events {
    static beat_event @ ev1;

    static tick_event @ tick;

}

*tick_event Tick @=> beat_events.tick;
beat_event Ev1 @=> beat_events.ev1;
*



play_tick_class.ck : send Tick event with command
beat_events.tick.broadcast();
receive_tick.ck: Receive event with line:  beat_events.tick => now;



Have fun!
Ju


2012/4/18 [chriswicks] <crwicks at yahoo.com>

> If you're talking about defining your own object types via classes, you
> need to make sure that the .ck file containing your defined class gets
> added to the virtual machine first.  The best way to do this is to
> instantiate the VM in one terminal by using the comand chuck --loop.  After
> that, open another terminal and type chuck + Class.ck (replace class with
> whatever your filename is).  Then go ahead and add the client (whatever
> file is utilizing your defined class).  I'm not sure if this is what you're
> asking, and I'm new to ChucK myself, but hopefully this gets you started on
> the right track.  The other way is to just type "chuck Service.ck
> client.ck" or whatever (it is necessary that the class containing your
> user-defined object is first).  This works as well, but it's not as
> flexible on-the-fly as running chuck --loop.
>
>   ------------------------------
> *From:* henrique matias <hems.inlet at gmail.com>
> *To:* chuck-users at lists.cs.princeton.edu
> *Sent:* Tuesday, April 17, 2012 9:12 PM
> *Subject:* [chuck-users] different classes and files talking to each other
>
> Hello folks, hope everything is great over there! ( :
>
> Am new to chuck, needless to say am impressed!
>
> Am a bit confused how to share and control different classes and files
> from a central "machine".
>
> The first idea was to create a static Event var and put every class
> listening to this event, but unfortunately we still can't instantiate
> non-native objects as static.
>
> Would someone please point me to some basic structure/example?
>
> Thanks a lot! Happy chucking!
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20120418/c8761d1d/attachment.html>


More information about the chuck-users mailing list