electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks GalleryGallery 
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
30 Days of ChucK
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [14 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Stochastic



Joined: Feb 25, 2008
Posts: 16
Location: Vancouver

PostPosted: Tue Apr 01, 2008 7:10 pm    Post subject: 30 Days of ChucK Reply with quote  Mark this post and the followings unread

Just thought I'd let people know,

I've signed up for the www.thirtydaysproject.com and as my project theme I'm teaching myself chuck by doing one 'song' a day.

You can view my codes and songs at http://www.sfu.ca/~edh2/april/

any feedback would be great, but keep in mind I'm new to all this so don't expect awesome programming skills

oh, and out of curiosity, is there a way to kill sporked shreds on command?
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 5961
Location: The Hague, NL
G2 patch files: 3

PostPosted: Tue Apr 01, 2008 7:42 pm    Post subject: Reply with quote  Mark this post and the followings unread

Great! Looking forward to seeing how this develops.

About killing shreds; assuming you want to kill them using code (and not manual commands) the most straightforward way would be

Machine.remove( foo );

where foo is a integer that's the id of the shred you want to kill. There are more ways but this will probably do for now. It's treated in the manual in the section on the "machine" namespace and of course there are sections on shreds.

Good luck!

_________________
while(!machine.crash() ) <<<"all is well">>>;
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Inventor



Joined: Oct 13, 2007
Posts: 825
Location: Florida, USA
Audio files: 37

PostPosted: Tue Apr 01, 2008 7:51 pm    Post subject: Re: 30 Days of ChucK Reply with quote  Mark this post and the followings unread

Stochastic wrote:
JI've signed up for the www.thirtydaysproject.com and as my project theme I'm teaching myself chuck by doing one 'song' a day.

oh, and out of curiosity, is there a way to kill sporked shreds on command?


ACK! Thirty deadlines in thirty days! Well, that's one way to push yourself. It will be interesting to hear your songs, I remember writing some fun/good/OK stuff when I first started ChucKing so you can too.

The sporked shreads trick is one i have just discovered. You make a variable called int shred_id or similar and at the beginning of the shred's function definition you say "my.id () => shred_id;", then when you want to stop the shred you say "Machine.remove (shred_id);". It's a bit of a trick, but it works for me. I have a program that sporks or unsporks hundreds of shreds every "play" button push and it works fine there.

You can also reset shred_id to zero when you remove the shred and that way you can examine shred_id to see if the shred is launched, should you need that.

Good luck with your project and have fun learning ChucK!

_________________
@(ºoº)@ ><}}}º> ~(^.^) <:3 )~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Stochastic



Joined: Feb 25, 2008
Posts: 16
Location: Vancouver

PostPosted: Tue Apr 01, 2008 7:54 pm    Post subject: Reply with quote  Mark this post and the followings unread

hmm I was trying to get the id of a sporked shred, by doing:

spork ~ foo() => int id;
or
spork ~ foo() => Shred @ int id; (as the manual kinda suggested)
or
spork ~ foo() => Shred @=> int id; (as the compiler then suggested)

but the compiler was having troubles resolving types.
Back to top
View user's profile Send private message
Inventor



Joined: Oct 13, 2007
Posts: 825
Location: Florida, USA
Audio files: 37

PostPosted: Tue Apr 01, 2008 8:08 pm    Post subject: Reply with quote  Mark this post and the followings unread

try this:


Code:
// define the int
int id;

// define the function
function void shredder () {
    // save the id
    my.id () => id;
}

// spork the shred
spork ~ shredder ();
// wait
10::second => now;

// remove the shred
Machine.remove (id);
0 => id;


or something like that, didn't test it.

_________________
@(ºoº)@ ><}}}º> ~(^.^) <:3 )~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Stochastic



Joined: Feb 25, 2008
Posts: 16
Location: Vancouver

PostPosted: Tue Apr 01, 2008 9:34 pm    Post subject: Reply with quote  Mark this post and the followings unread

The problem I have with that method is that I have various instances of the same function being sporked and my interest was in killing the older of the shreds.

Though I guess with a few adjustments it would be workable.
Back to top
View user's profile Send private message
Inventor



Joined: Oct 13, 2007
Posts: 825
Location: Florida, USA
Audio files: 37

PostPosted: Tue Apr 01, 2008 9:51 pm    Post subject: Reply with quote  Mark this post and the followings unread

Well, we are limited by the fact that the ChucK spork command does not report the shred id. The Machine.add (string path); function does however return the shred's id value. So I guess you could put your shred in a separate external file and then run it with Machine.add if you want. That's another option.
_________________
@(ºoº)@ ><}}}º> ~(^.^) <:3 )~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Stochastic



Joined: Feb 25, 2008
Posts: 16
Location: Vancouver

PostPosted: Tue Apr 01, 2008 10:13 pm    Post subject: Reply with quote  Mark this post and the followings unread

So where they talk here: http://chuck.cs.princeton.edu/doc/language/spork.html#spork
about storing a reference to the shred in offspring, what does that mean?
offspring isn't declared anywhere so I don't know what type it is (not listed in reserved words either).
Back to top
View user's profile Send private message
Inventor



Joined: Oct 13, 2007
Posts: 825
Location: Florida, USA
Audio files: 37

PostPosted: Tue Apr 01, 2008 10:48 pm    Post subject: Reply with quote  Mark this post and the followings unread

I think you're referring to this:

Code:
    // spork another, store reference to new shred in offspring
    spork ~ go() => Shred @ offspring;


I dunno about that, I've never understood it. Maybe someone can explain it? I think it's sending an image of itself to a variable called offspring that is defined as type Shred or something, but this is way advanced ChucK for me, lol.

_________________
@(ºoº)@ ><}}}º> ~(^.^) <:3 )~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Stochastic



Joined: Feb 25, 2008
Posts: 16
Location: Vancouver

PostPosted: Tue Apr 01, 2008 11:50 pm    Post subject: Reply with quote  Mark this post and the followings unread

Oh, wait, I think I understand this. It stores a reference (see wikipedia) to the location of the Shred. This is much different than the ID number of the shred in the VM. I'm not sure of what this would be good for doing, but I'm no comp sci prof.
Back to top
View user's profile Send private message
Inventor



Joined: Oct 13, 2007
Posts: 825
Location: Florida, USA
Audio files: 37

PostPosted: Wed Apr 02, 2008 12:58 am    Post subject: Reply with quote  Mark this post and the followings unread

Yes, I think it is a a reference thingie. References dazzle and confuse me. I have yet to cozy up on them.
_________________
@(ºoº)@ ><}}}º> ~(^.^) <:3 )~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Inventor



Joined: Oct 13, 2007
Posts: 825
Location: Florida, USA
Audio files: 37

PostPosted: Wed Apr 02, 2008 12:59 am    Post subject: Reply with quote  Mark this post and the followings unread

Yes, I think it is a a reference thingie. References dazzle and confuse me. I have yet to cozy up on them.
_________________
@(ºoº)@ ><}}}º> ~(^.^) <:3 )~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frostburn



Joined: Dec 12, 2007
Posts: 166
Location: Finland
Audio files: 5

PostPosted: Wed Apr 02, 2008 1:17 am    Post subject: Reply with quote  Mark this post and the followings unread

Is this what you're after (using references to get the id for removal):
Code:
fun void sporky(){
        <<<"Sporky","go!">>>;
        second => now;
        <<<"Sporky","leave...">>>;
}
spork~sporky();

2::second => now;

Shred shredReference;

spork~sporky() @=> shredReference;

0.5::second => now;
shredReference.id() => Machine.remove;
<<<"Sporky","killed.">>>;

3::second => now;
<<<"Have","a","nice",day>>>;


I don't know why shredReference.exit(); doesn't work... Maybe a bug...

_________________
In Serendipity We Trust
Back to top
View user's profile Send private message
Inventor



Joined: Oct 13, 2007
Posts: 825
Location: Florida, USA
Audio files: 37

PostPosted: Thu Apr 24, 2008 11:29 pm    Post subject: Reply with quote  Mark this post and the followings unread

Stochastic, how did your thirty days project go? I believe it has been more than thirty days since you started. Did you learn to ChucK or abandon the project?
_________________
@(ºoº)@ ><}}}º> ~(^.^) <:3 )~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [14 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003, 2004, 2005, 2006 and 2007 by electro-music.com