Author |
Message |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Sat Feb 02, 2008 9:24 am Post subject:
Breaking an infinite loop using an event.. |
 |
|
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
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Sat Feb 02, 2008 9:44 am Post subject:
|
 |
|
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
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Sat Feb 02, 2008 10:24 am Post subject:
|
 |
|
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
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Tue Feb 05, 2008 3:34 pm Post subject:
Re: Breaking an infinite loop using an event.. |
 |
|
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
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Wed Feb 06, 2008 7:30 am Post subject:
|
 |
|
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
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Feb 06, 2008 11:55 am Post subject:
|
 |
|
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
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Wed Feb 06, 2008 12:32 pm Post subject:
|
 |
|
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. ( *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
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Feb 06, 2008 7:28 pm Post subject:
|
 |
|
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
|
|
 |
|