electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
Live streaming at radio.electro-music.com

  host / artist show at your time

poster

Please visit the chat
 Forum index » DIY Hardware and Software » ChucK programming language
Breaking an infinite loop using an event..
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [8 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Dr. Spankenstein



Joined: Mar 03, 2007
Posts: 136
Location: Cambridge
Audio files: 1

PostPosted: Sat Feb 02, 2008 9:24 am    Post subject: Breaking an infinite loop using an event.. Reply with quote  Mark this post and the followings unread

Code:


Event Off;

spork ~ count() @=> Shred @ countShred;

do
{
   while(true)
   {
        for(1 => int i; i < 30; i++)
      {
         <<<"I =",i>>>;
          }   
      10::second => now;
   }
}
until (Off => now);
<<<"EXITING">>>;
me.exit();

fun void count()
{
   5::second => now;
   <<<"Signaling!">>>;
   Off.signal();
}



How can I have a for loop running in another while loop until a signal is received. I'm currently using an infinite loop, which doesnt allow for the signal to stop whatever is going on inside it.

Unfortunately I need the for loop to keep running until the signal occurs.

Any suggestions?

Rhys
Back to top
View user's profile Send private message
Frostburn



Joined: Dec 12, 2007
Posts: 255
Location: Finland
Audio files: 9

PostPosted: Sat Feb 02, 2008 9:44 am    Post subject: Reply with quote  Mark this post and the followings unread

Try making a new shred out the while loop.
Then you can let the main shred wait for the event because it's not doing anything special.
Code:
Event Off;

spork ~ count() @=> Shred @ countShred;

fun void sporkable_while_for_loop(){
   while(true)
   {
        for(1 => int i; i < 30; i++)
        {
         <<<"I =",i>>>;
        }   
      10::second => now;
   }
}

spork~sporkable_while_for_loop(); //Making a new shred out of what you want to do gives control back to the main shred
Off => now; //When the main shred has the control it can wait for events
<<<"EXITING">>>;
me.exit();

fun void count()
{
   5::second => now;
   <<<"Signaling!">>>;
   Off.signal();
}

_________________
To boldly go where no man has bothered to go before.
Back to top
View user's profile Send private message
Dr. Spankenstein



Joined: Mar 03, 2007
Posts: 136
Location: Cambridge
Audio files: 1

PostPosted: Sat Feb 02, 2008 10:24 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks Frosty!

I shall try that and see how I get on.

Though it seems incredibly logical, that way didn't occur to me.

Rhys
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


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

PostPosted: Tue Feb 05, 2008 3:34 pm    Post subject: Re: Breaking an infinite loop using an event.. Reply with quote  Mark this post and the followings unread

Dr. Spankenstein wrote:

How can I have a for loop running in another while loop until a signal is received.


Well..... call me naive, but what about this?


Code:

int my_signal;

fun void my_fun()
{
until(my_signal)
  {
  do.stuff();
  some_time => now;
  }
}

spork ~ my_fun();

minute => now;

//a poor man's event :¬)
1 => signal;
do.moreStuff();


Of course, if it really has to be a event, for example because you need the housekeeping facilities that ".signal()" has to offer then Frosty (cute nicknames are cute!) has the solution (and it's clever too!) but I think in most cases this would be enough?

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frostburn



Joined: Dec 12, 2007
Posts: 255
Location: Finland
Audio files: 9

PostPosted: Wed Feb 06, 2008 7:30 am    Post subject: Reply with quote  Mark this post and the followings unread

To make Kassy's (cute nicknames are cute) example more general. You also use a reference to an array that only has a single member.
Allthough I would propably do this by creating a class with a member int signal and then use that to control it's inner workings.
Code:

int my_signal[1];
int your_signal[1];

fun void my_fun( int termination_signal[] )
{
until( termination_signal[0] )
  {
  do.stuff();
  some_time => now;
  }
}

spork ~ my_fun( my_signal );
spork ~ my_fun( your_signal );

minute => now;

//a poor man's event :¬)
true => my_signal[0]; //Signal the one sporked first
do.moreStuff();
minute => now;
true => your_signal[0]; //Signal the second one.

_________________
To boldly go where no man has bothered to go before.
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


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

PostPosted: Wed Feb 06, 2008 11:55 am    Post subject: Reply with quote  Mark this post and the followings unread

Oh, mr. Burn, I hope you weren't offended by the nick-namification incident?

Seriously, another case of wraping things in objects to be able to reference them. I'm starting to think we may have a need for a more general and less cludged way of forcing things into "objectness". Very clever indeed, your solution, my compliments

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Frostburn



Joined: Dec 12, 2007
Posts: 255
Location: Finland
Audio files: 9

PostPosted: Wed Feb 06, 2008 12:32 pm    Post subject: Reply with quote  Mark this post and the followings unread

Quote:
Oh, mr. Burn, I hope you weren't offended by the nick-namification incident?

Oh not at all. Nick names are nice... I mean Frostburn is a nick already so why not spice it up a little:)
I was about me acting to get upset in a friendly manner... I just don't know what smiley to use for such things. ( Mad albino *haha, kidding* )

Quote:
I'm starting to think we may have a need for a more general and less cludged way of forcing things into "objectness".

I've recently discovered the power of making classes. I've made a resonable workaround for extending UGens and made a usefull Instrument base class out of it. It's all still in the works but I will release it with our next Math Project song.

_________________
To boldly go where no man has bothered to go before.
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


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

PostPosted: Wed Feb 06, 2008 7:28 pm    Post subject: Reply with quote  Mark this post and the followings unread

Cool. I suspected you took it in that vein. Let me say again how much I liked your take on forcing references to integers.
_________________
Kassen
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 [8 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
e-m mkii

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 through 2009 by electro-music.com - Conditions Of Use