electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
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 
 Forum index » DIY Hardware and Software » ChucK programming language
Trouble Breaking Out of a Loop Using MIDI events.
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
sir honey



Joined: Aug 04, 2006
Posts: 36
Location: NY

PostPosted: Sat Mar 10, 2007 10:13 pm    Post subject: Trouble Breaking Out of a Loop Using MIDI events. Reply with quote  Mark this post and the followings unread

Hi,

I'd like to trigger record my samples with MIDI events, and make use of variable length sampling. So I have this framework (not fully functional yet)
Code:

// yada yada yada.

MidiIn min;
MidiMsg msg;
min.open(2);


fun void sampler(int y)
{
   0 => int seconds;
   while(y == 1)
   {
      <<<seconds>>>;
      1::second => now;
      seconds++;
   }
}

spork ~ sampler(0);   

while(true)
{
   min => now;
   while(min.recv(msg))
   {
      if(msg.data1 == 176 && msg.data2 == 64 && msg.data3 == 127)
      {
         <<<"sampling">>>;
         sampler(1);
      }
         
      if(msg.data1 == 176 && msg.data2 == 64 && msg.data3 == 0)
      {
         <<<"done sampling">>>;
         sampler(0);
      }
   }
}


The only real problem I'm having is that once I trigger the sample loop, I can't break back out of it. I'm not sure how to get sampler() to listen to the 0 command I'm sending via my footswitch to stop recording. Any suggestions?

Thanks!
jack Very Happy
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: Sun Mar 11, 2007 12:35 pm    Post subject: Re: Trouble Breaking Out of a Loop Using MIDI events. Reply with quote  Mark this post and the followings unread

sir honey wrote:

fun void sampler(int y)
{
0 => int seconds;
while(y == 1)
{
<<<seconds>>>;
1::second => now;
seconds++;
}
}

spork ~ sampler(0);


I don't think this will work. Let's trace what will happen.

As soon as you spork this function and it has initated it's "Seconds" variable it will see wether Y equals 1. Well; it doesn't since you just defined it as being 0 so that loop isn't going to run. Execution will continue below that loop. Whoops! Below that loop there is no more code so that shred will asume it's done and drift up to shred-heaven.

From there on it will be called again in your main loop, this time as a normal inline function. However; at that point Y will be 1 so that function won't ever return execution to the main loop so the main loop will be stuck while your function keeps endlessly looping.

I'd move "y" out of that function to the main shred. You could then spork the function where you now call it for the first time in your main loop. Where you call it for the second time you could move "Y" back to 0 which should make the sporked shred stop execting, hopefully having completed it's task by that time.

Note that function can be sporked to seperate shreds but can also be used to repalce a block of code you would like to use in-line several times with just a call for compactness-sake. Those uses are quite different; one is in paralel, the other serial. Int his case you accidentally used them in series where one of the elements in the series won't ever end. You can verify this by using ChucK --status froma second window once it's gotten stuck; you should only see one shred.

Good question; managing concurency is at the core of ChucKing so I hope this helped.

_________________
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 [2 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


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use