a little debugging help for frozen VM!
Hey, all. I'm attempting to build something that shifts layers of ChucK files based on OSC events, and I hit a snag really early on. I'm a relatively new programmer, so hopefully this isn't too stupid of a question, but I've got an issue that freezes the virtual machine and doesn't play any sound or send any OSC events. Nothing happens..the VM shows that the shreds are added, and then it just freezes and I have to force quit...it won't take a --removeall or --kill command or anything. Individually, each file works as it should, aside from the file whose code I am including here. I think I may be missing a key concept as to the way Machine.add works and how it assigns the value of the shred to an int, but I'm just not sure. If anyone can give me some direction here as to what might be happening I'd appreciate it! I've tried advancing time in various places, setting my initial pedCount to various values, all to no avail. Thanks very much, and please let me know if this is unclear in any way. //begincode Machine.add("justa.ck"); //class of frequency definitions Machine.add("pedestrianSender.ck"); //OSC sender of int values OscRecv receiver; //OSC receiver object 6449 => receiver.port; receiver.listen(); receiver.event("weather/pedestrian, int") @=> OscEvent pedEvent; -1 => int b3base1; //int to store a shred ID -1 => int b3base2; //ditto 25 => int pedCount; //int to store pedCount sent via OSC while (true) { //if the pedCount is greater than 20 (a value which will be sent via OSC) and b3base1 is equal to -1, i.e. the shred isn't currently running, //add both shreds to the VM and assign their shred ID to the b3base1 and b3base2 if (pedCount > 20 && b3base1 == -1) { Machine.add("b3base.ck") => b3base1; Machine.add("b3base.ck") => b3base2; } else { //if the pedCount is less than 20, remove both shreds from the VM and assign -1 to their value so that if the pedCount goes back above 20 they //meet the conditional. if (pedCount < 20 && b3base1 != -1) { Machine.remove(b3base1); Machine.remove(b3base2); -1 => b3base1; -1 => b3base2; } } while( pedEvent.nextMsg() != 0) { pedEvent.getInt() => pedCount; 2::second => now; } } //endcode
On Fri, May 25, 2012 at 12:32:35PM -0700, [chriswicks] wrote:
Hey, all. I'm attempting to build something that shifts layers of ChucK files based on OSC events, and I hit a snag really early on. I'm a relatively new programmer, so hopefully this isn't too stupid of a question,
That one I could answer before considering the code; if you looked yourself and considered the docs (which I'm sure you did) then there are no stupid questions. Great, having established that, let's look at the next issue;
but I've got an issue that freezes the virtual machine and doesn't play any sound or send any OSC events. Nothing happens..the VM shows that the shreds are added, and then it just freezes and I have to force quit...it won't take a --removeall or --kill command or anything. Individually, each file works as it should, aside from the file whose code I am including here. I think I may be missing a key concept as to the way Machine.add works and how it assigns the value of the shred to an int, but I'm just not sure. If anyone can give me some direction here as to what might be happening I'd appreciate it! I've tried advancing time in various places, setting my initial pedCount to various values, all to no avail. Thanks very much, and please let me know if this is unclear in any way.
Yes, I see. When this happens it most of the time means that you have a infinite loop that doesn't advance time. That turns out to be the case here, but it is a bit hard to see because yours is a quite involved loop that does advance time, but only under some conditions. Particularly; only when pedEvent.nextMsg() equals zero. When this happens the shred will keep racing through the loop, without yielding the cpu to other shreds. When this happens and nothing changes the parameters tested for it will never get out of that state. I expect you'll see a improvement in your code's behaviour by simply adding "second => now;" as the last like of the "while(true)" loop. I suspect that after that more improvements could be made because quite likely your intention will be to go through the loop every time OSC messages arrive to change the sitiation. In that case it would be better to "chucK' that OSC event to now, instead of a rbitrary amount of time like a second. That way you guarantee that you'll go thorugh the loop when -and only when- such a message arrives. This is explained in more detail in the documentation in the section on events. Best of luck; looks like a ambitious structure for a "new programmer" which is of course the best way to get rid of the "new" clause :-). Yours, Kas.
Kassen - Thanks! This helped me get out of the frozen VM situation, but now for some reason my loop doesn't seem to be executing after the first runthrough. I've modified the code as follows, chucking the event to now at the end of the loop. This works, and b3base gets added twice to the VM as it should in the first runthrough. I have it printing out the value for pedCount at the beginning, and it only does so once...so, it prints out the value 25 for pedCount and then I never see it printing again after that, just the OSC values ticking by (I currently have my OSC sender set to send values from 25 down to 6, then resetting back to 25, every 2 seconds, and it prints to the VM every time it sends a value so I can see that that part, at least, is working). Interestingly, I also don't get any response from the VM when I send it a 'chuck ^' command...the OSC values keep on ticking by, and the audio keeps playing as it should, it just doesn't send out a response. It does, however, respond to --kill and --removeall commands. Something's not working as it should, and pedCount never seems to get updated with the OSC value, which is strange, because I have VERY similar code (almost identical) sending and receiving float values in OSC (in other parts of this piece) and they work just fine. I think that perhaps somewhere the loop is getting tripped up and running infinitely without doing anything, but I can't pinpoint where or why this is happening. Basically, what this code should do is take an OSC value, and if it's greater than 20 and the shreds aren't already present, add them to the VM. If it's less than 20 and the shreds are present, it should remove them from the VM. I thought I had it nailed but something's wonky. Thanks again for any help as I trudge through this stuff! //begincode Machine.add("justa.ck"); Machine.add("pedestrianSender.ck"); OscRecv receiver; 6449 => receiver.port; receiver.listen(); receiver.event("weather/pedestrian, int") @=> OscEvent pedEvent; -1 => int b3base1; -1 => int b3base2; 25 => int pedCount; while (true) { <<<"Pedestrian ct: ", pedCount>>>; if (pedCount > 20 && b3base1 == -1) { Machine.add("b3base.ck") => b3base1; Machine.add("b3base.ck") => b3base2; } else { if (pedCount < 20 && b3base1 != -1) { Machine.remove(b3base1); Machine.remove(b3base2); -1 => b3base1; -1 => b3base2; } } while( pedEvent.nextMsg() != 0) { pedEvent.getInt() => pedCount; } pedEvent => now; } //endcode
On Sat, May 26, 2012 at 09:22:47AM -0700, [chriswicks] wrote:
Kassen -
Thanks! This helped me get out of the frozen VM situation, but now for some reason my loop doesn't seem to be executing after the first runthrough.
First of all; happy to have been of help. As for the rest, the first thing I notice is that when pedcount equals exactly 20 neither of the two paths will be taken. You may want to verify whether that is what you want. Another way in which I could see this code getting stuck is if pedEvent.nextMsg() would always return non-zero values, in that case your last nested loop would keep looping and the outer loop would never return to it's start. Finally it could be that pedEvent never gets send again, that would also make it all stop looping. It is a bit hard to say without the rest and at the risk of sounding rude; I don't feel like sorting through a larger code-base right now as it is quite hot here :-)
I've modified the code as follows, chucking the event to now at the end of the loop. This works, and b3base gets added twice to the VM as it should in the first runthrough. I have it printing out the value for pedCount at the beginning, and it only does so once...so, it prints out the value 25 for pedCount and then I never see it printing again after that, just the OSC values ticking by (I currently have my OSC sender set to send values from 25 down to 6, then resetting back to 25, every 2 seconds, and it prints to the VM every time it sends a value so I can see that that part, at least, is working). Interestingly, I also don't get any response from the VM when I send it a 'chuck ^' command...the OSC values keep on ticking by, and the audio keeps playing as it should, it just doesn't send out a response. It does, however, respond to --kill and --removeall commands.
That is a very good strategy; to add lines that print the value of your variables. You can also add print commants at various parts in the code to see how execution flows. If that doesn't help I'd try simplifying the situation in some temporary copies of my files. This may well take longer than writing the code did, such is the of a programmer. The good news is you'll learn. Yours, Kas.
Problem solved!
I was discussing this problem in a conversation with my brother last night, and had him take a look at the code on his Mac. Lo and behold, the code worked as I had intended it to. I rebooted into my Linux partition, and again, the code works perfectly. Same code, 3 operating systems tested, and for some reason Windows doesn't behave properly. He suggested that this may be an issue with Windows firewall, but I don't have problems with any of the other OSC stuff (all running on the same port). On the Linux end I have a source-built version of ChucK for JACK, and on the Windows end I'm using precompiled binaries (both downloaded on the same day from the ChucK website). Just thought I'd let it be known here FWIW. Thanks very much for the help Kassen! Take care.
-chris wicks
________________________________
From: Kassen
Kassen -
Thanks! This helped me get out of the frozen VM situation, but now for some reason my loop doesn't seem to be executing after the first runthrough.
First of all; happy to have been of help. As for the rest, the first thing I notice is that when pedcount equals exactly 20 neither of the two paths will be taken. You may want to verify whether that is what you want. Another way in which I could see this code getting stuck is if pedEvent.nextMsg() would always return non-zero values, in that case your last nested loop would keep looping and the outer loop would never return to it's start. Finally it could be that pedEvent never gets send again, that would also make it all stop looping. It is a bit hard to say without the rest and at the risk of sounding rude; I don't feel like sorting through a larger code-base right now as it is quite hot here :-)
I've modified the code as follows, chucking the event to now at the end of the loop. This works, and b3base gets added twice to the VM as it should in the first runthrough. I have it printing out the value for pedCount at the beginning, and it only does so once...so, it prints out the value 25 for pedCount and then I never see it printing again after that, just the OSC values ticking by (I currently have my OSC sender set to send values from 25 down to 6, then resetting back to 25, every 2 seconds, and it prints to the VM every time it sends a value so I can see that that part, at least, is working). Interestingly, I also don't get any response from the VM when I send it a 'chuck ^' command...the OSC values keep on ticking by, and the audio keeps playing as it should, it just doesn't send out a response. It does, however, respond to --kill and --removeall commands.
That is a very good strategy; to add lines that print the value of your variables. You can also add print commants at various parts in the code to see how execution flows. If that doesn't help I'd try simplifying the situation in some temporary copies of my files. This may well take longer than writing the code did, such is the of a programmer. The good news is you'll learn. Yours, Kas.
Just to (hopefully) wrap this issue up for good...the strangest thing is, upon booting back into my Windows partition today, the program is now working in Windows as well as Linux. Go figure.
-chris wicks
________________________________
From: [chriswicks]
Kassen -
Thanks! This helped me get out of the frozen VM situation, but now for some reason my loop doesn't seem to be executing after the first runthrough.
First of all; happy to have been of help. As for the rest, the first thing I notice is that when pedcount equals exactly 20 neither of the two paths will be taken. You may want to verify whether that is what you want. Another way in which I could see this code getting stuck is if pedEvent.nextMsg() would always return non-zero values, in that case your last nested loop would keep looping and the outer loop would never return to it's start. Finally it could be that pedEvent never gets send again, that would also make it all stop looping. It is a bit hard to say without the rest and at the risk of sounding rude; I don't feel like sorting through a larger code-base right now as it is quite hot here :-)
I've modified the code as follows, chucking the event to now at the end of the loop. This works, and b3base gets added twice to the VM as it should in the first runthrough. I have it printing out the value for pedCount at the beginning, and it only does so once...so, it prints out the value 25 for pedCount and then I never see it printing again after that, just the OSC values ticking by (I currently have my OSC sender set to send values from 25 down to 6, then resetting back to 25, every 2 seconds, and it prints to the VM every time it sends a value so I can see that that part, at least, is working). Interestingly, I also don't get any response from the VM when I send it a 'chuck ^' command...the OSC values keep on ticking by, and the audio keeps playing as it should, it just doesn't send out a response. It does, however, respond to --kill and --removeall commands.
That is a very good strategy; to add lines that print the value of your variables. You can also add print commants at various parts in the code to see how execution flows. If that doesn't help I'd try simplifying the situation in some temporary copies of my files. This may well take longer than writing the code did, such is the of a programmer. The good news is you'll learn. Yours, Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Your code never gets out of the first while-loop. Among other things,
that means that you never make it to the pedEvent handler. I'm not
entirely sure what you're trying to do, but I think you want something
more like this:
//begincode
Machine.add("justa.ck"); //class of frequency definitions
Machine.add("pedestrianSender.ck"); //OSC sender of int values
OscRecv receiver; //OSC receiver object
6449 => receiver.port;
receiver.listen();
receiver.event("weather/pedestrian, int") @=> OscEvent pedEvent;
-1 => int b3base1; //int to store a shred ID
-1 => int b3base2; //ditto
25 => int pedCount; //int to store pedCount sent via OSC
while (pedEvent.nextMsg() != 0) {
pedEvent.getInt() => pedCount;
//if the pedCount is greater than 20 (a value which will be sent via
OSC) and b3base1 is equal to -1, i.e. the shred isn't currently
running,
//add both shreds to the VM and assign their shred ID to the b3base1
and b3base2
if (pedCount > 20 && b3base1 == -1) {
Machine.add("b3base.ck") => b3base1;
Machine.add("b3base.ck") => b3base2;
}
else {
//if the pedCount is less than 20, remove both shreds from the VM
and assign -1 to their value so that if the pedCount goes back above
20 they
//meet the conditional.
if (pedCount < 20 && b3base1 != -1) {
Machine.remove(b3base1);
Machine.remove(b3base2);
-1 => b3base1;
-1 => b3base2;
}
}
while( pedEvent.nextMsg() != 0) {
pedEvent.getInt() => pedCount;
2::second => now;
}
}
//endcode
If you need to run through the loop once when you start then you could
use a do-while-loop instead of a while-loop
(http://chuck.cs.princeton.edu/doc/language/ctrl.html#while).
andy
On Fri, May 25, 2012 at 3:32 PM, [chriswicks]
Hey, all. I'm attempting to build something that shifts layers of ChucK files based on OSC events, and I hit a snag really early on. I'm a relatively new programmer, so hopefully this isn't too stupid of a question, but I've got an issue that freezes the virtual machine and doesn't play any sound or send any OSC events. Nothing happens..the VM shows that the shreds are added, and then it just freezes and I have to force quit...it won't take a --removeall or --kill command or anything. Individually, each file works as it should, aside from the file whose code I am including here. I think I may be missing a key concept as to the way Machine.add works and how it assigns the value of the shred to an int, but I'm just not sure. If anyone can give me some direction here as to what might be happening I'd appreciate it! I've tried advancing time in various places, setting my initial pedCount to various values, all to no avail. Thanks very much, and please let me know if this is unclear in any way.
//begincode
Machine.add("justa.ck"); //class of frequency definitions Machine.add("pedestrianSender.ck"); //OSC sender of int values
OscRecv receiver; //OSC receiver object 6449 => receiver.port; receiver.listen(); receiver.event("weather/pedestrian, int") @=> OscEvent pedEvent;
-1 => int b3base1; //int to store a shred ID -1 => int b3base2; //ditto
25 => int pedCount; //int to store pedCount sent via OSC
while (true) {
//if the pedCount is greater than 20 (a value which will be sent via OSC) and b3base1 is equal to -1, i.e. the shred isn't currently running, //add both shreds to the VM and assign their shred ID to the b3base1 and b3base2
if (pedCount > 20 && b3base1 == -1) { Machine.add("b3base.ck") => b3base1; Machine.add("b3base.ck") => b3base2; }
else {
//if the pedCount is less than 20, remove both shreds from the VM and assign -1 to their value so that if the pedCount goes back above 20 they //meet the conditional.
if (pedCount < 20 && b3base1 != -1) { Machine.remove(b3base1); Machine.remove(b3base2); -1 => b3base1; -1 => b3base2; } }
while( pedEvent.nextMsg() != 0) { pedEvent.getInt() => pedCount; 2::second => now; } }
//endcode
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Hi,
I have often wondered if this behaviour should be detected by the
compiler / VM and cause an error to occur
I have actually used this behaviour to illustrate a wider security
concern in a paper accepted to the upcoming ICMC
And that is a cool first ChucK problem Chris!!
On Fri, May 25, 2012 at 8:57 PM, Andrew Turley
Your code never gets out of the first while-loop. Among other things, that means that you never make it to the pedEvent handler. I'm not entirely sure what you're trying to do, but I think you want something more like this:
//begincode
Machine.add("justa.ck"); //class of frequency definitions Machine.add("pedestrianSender.ck"); //OSC sender of int values
OscRecv receiver; //OSC receiver object 6449 => receiver.port; receiver.listen(); receiver.event("weather/pedestrian, int") @=> OscEvent pedEvent;
-1 => int b3base1; //int to store a shred ID -1 => int b3base2; //ditto
25 => int pedCount; //int to store pedCount sent via OSC
while (pedEvent.nextMsg() != 0) { pedEvent.getInt() => pedCount;
//if the pedCount is greater than 20 (a value which will be sent via OSC) and b3base1 is equal to -1, i.e. the shred isn't currently running, //add both shreds to the VM and assign their shred ID to the b3base1 and b3base2
if (pedCount > 20 && b3base1 == -1) { Machine.add("b3base.ck") => b3base1; Machine.add("b3base.ck") => b3base2; }
else {
//if the pedCount is less than 20, remove both shreds from the VM and assign -1 to their value so that if the pedCount goes back above 20 they //meet the conditional.
if (pedCount < 20 && b3base1 != -1) { Machine.remove(b3base1); Machine.remove(b3base2); -1 => b3base1; -1 => b3base2; } }
while( pedEvent.nextMsg() != 0) { pedEvent.getInt() => pedCount; 2::second => now; } }
//endcode
If you need to run through the loop once when you start then you could use a do-while-loop instead of a while-loop (http://chuck.cs.princeton.edu/doc/language/ctrl.html#while).
andy
On Fri, May 25, 2012 at 3:32 PM, [chriswicks]
wrote: Hey, all. I'm attempting to build something that shifts layers of ChucK files based on OSC events, and I hit a snag really early on. I'm a relatively new programmer, so hopefully this isn't too stupid of a question, but I've got an issue that freezes the virtual machine and doesn't play any sound or send any OSC events. Nothing happens..the VM shows that the shreds are added, and then it just freezes and I have to force quit...it won't take a --removeall or --kill command or anything. Individually, each file works as it should, aside from the file whose code I am including here. I think I may be missing a key concept as to the way Machine.add works and how it assigns the value of the shred to an int, but I'm just not sure. If anyone can give me some direction here as to what might be happening I'd appreciate it! I've tried advancing time in various places, setting my initial pedCount to various values, all to no avail. Thanks very much, and please let me know if this is unclear in any way.
//begincode
Machine.add("justa.ck"); //class of frequency definitions Machine.add("pedestrianSender.ck"); //OSC sender of int values
OscRecv receiver; //OSC receiver object 6449 => receiver.port; receiver.listen(); receiver.event("weather/pedestrian, int") @=> OscEvent pedEvent;
-1 => int b3base1; //int to store a shred ID -1 => int b3base2; //ditto
25 => int pedCount; //int to store pedCount sent via OSC
while (true) {
//if the pedCount is greater than 20 (a value which will be sent via OSC) and b3base1 is equal to -1, i.e. the shred isn't currently running, //add both shreds to the VM and assign their shred ID to the b3base1 and b3base2
if (pedCount > 20 && b3base1 == -1) { Machine.add("b3base.ck") => b3base1; Machine.add("b3base.ck") => b3base2; }
else {
//if the pedCount is less than 20, remove both shreds from the VM and assign -1 to their value so that if the pedCount goes back above 20 they //meet the conditional.
if (pedCount < 20 && b3base1 != -1) { Machine.remove(b3base1); Machine.remove(b3base2); -1 => b3base1; -1 => b3base2; } }
while( pedEvent.nextMsg() != 0) { pedEvent.getInt() => pedCount; 2::second => now; } }
//endcode
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
On Sat, May 26, 2012 at 12:56:42AM +0100, Scott Hewitt wrote:
Hi,
I have often wondered if this behaviour should be detected by the compiler / VM and cause an error to occur
Wait, did I miss something? Maybe I sohould have looked more carefully but this just looked to me like a infinite loop that doesn't advance time, which is a example of the halting problem which is famously and provably unsolvable. In that kind of case you can guess that the VM may have halted, as the "watchdog" functionality that causes the popup in such cases in the MiniAudicle does, but you can't -in the general case- be sure. http://en.wikipedia.org/wiki/Halting_problem Yours, Kas.
hi,
No I dont think you missed anything just saying that it would be
useful if zero time loops could be intercepted before they are run so
as to protect the VM
Scott
On Sat, May 26, 2012 at 1:12 AM, Kassen
On Sat, May 26, 2012 at 12:56:42AM +0100, Scott Hewitt wrote:
Hi,
I have often wondered if this behaviour should be detected by the compiler / VM and cause an error to occur
Wait, did I miss something? Maybe I sohould have looked more carefully but this just looked to me like a infinite loop that doesn't advance time, which is a example of the halting problem which is famously and provably unsolvable.
In that kind of case you can guess that the VM may have halted, as the "watchdog" functionality that causes the popup in such cases in the MiniAudicle does, but you can't -in the general case- be sure.
http://en.wikipedia.org/wiki/Halting_problem
Yours, Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
On Sat, May 26, 2012 at 01:12:07PM +0100, Scott Hewitt wrote:
hi,
No I dont think you missed anything just saying that it would be useful if zero time loops could be intercepted before they are run so as to protect the VM
Got it. I think there are some issues with this though. "Zero time" loops can be useful. For example; I might be playing back a wave-file and at some point desire to know when the next zero crossing in it is. For that I'd use a loop and this loop wouldn't advance time and would run until either the next such point or at worst the end of the wave-file. In this case you and I know that the loop will terminate but ChucK doesn't. Those two types of loops are non-trivial to sort; it would need to happen in the parser yet also take the state of the VM into account; anything that uses me.yield() may be safe, but only if there is at least one other shred running, for example. We do have the popup in the Mini and I think that "watchdog" functionality is also there in the CLI version but it could be made more accessible there, for example by printing a message when a halted VM is suspected. That's quite close to what you propose in practice, I think, and workable. Imho parser/compilation errors leading to segfaults are a bigger danger to the VM but my perception might be slanted by my own use patterns. As a final point; the worst loss of the VM is in the Mini where a loss of the VM typically also means a loss of the contents of unsaved buffers. There auto-saving buffers to a special directory would decrease the risks by decreasing the consequences. To me those two solutions seem like a decent remedy for some of the risks that powertools like detailed control over execution create. ChucK is probably not the right tool for high-security or high-risk applications and a bit of risk does add some excitement ;-). IMHO, IMHO and IMHO, respectively. Trying to solve the halting problem is primarily like designing a perpetuum mobile; great fun. Kas.
Hi,
I have often wondered if this behaviour should be detected by the
compiler / VM and cause an error to occur
I have actually used this behaviour to illustrate a wider security
concern in a paper accepted to the upcoming ICMC
And that is a cool first ChucK problem Chris!!
On Fri, May 25, 2012 at 8:57 PM, Andrew Turley
Your code never gets out of the first while-loop. Among other things, that means that you never make it to the pedEvent handler. I'm not entirely sure what you're trying to do, but I think you want something more like this:
//begincode
Machine.add("justa.ck"); //class of frequency definitions Machine.add("pedestrianSender.ck"); //OSC sender of int values
OscRecv receiver; //OSC receiver object 6449 => receiver.port; receiver.listen(); receiver.event("weather/pedestrian, int") @=> OscEvent pedEvent;
-1 => int b3base1; //int to store a shred ID -1 => int b3base2; //ditto
25 => int pedCount; //int to store pedCount sent via OSC
while (pedEvent.nextMsg() != 0) { pedEvent.getInt() => pedCount;
//if the pedCount is greater than 20 (a value which will be sent via OSC) and b3base1 is equal to -1, i.e. the shred isn't currently running, //add both shreds to the VM and assign their shred ID to the b3base1 and b3base2
if (pedCount > 20 && b3base1 == -1) { Machine.add("b3base.ck") => b3base1; Machine.add("b3base.ck") => b3base2; }
else {
//if the pedCount is less than 20, remove both shreds from the VM and assign -1 to their value so that if the pedCount goes back above 20 they //meet the conditional.
if (pedCount < 20 && b3base1 != -1) { Machine.remove(b3base1); Machine.remove(b3base2); -1 => b3base1; -1 => b3base2; } }
while( pedEvent.nextMsg() != 0) { pedEvent.getInt() => pedCount; 2::second => now; } }
//endcode
If you need to run through the loop once when you start then you could use a do-while-loop instead of a while-loop (http://chuck.cs.princeton.edu/doc/language/ctrl.html#while).
andy
On Fri, May 25, 2012 at 3:32 PM, [chriswicks]
wrote: Hey, all. I'm attempting to build something that shifts layers of ChucK files based on OSC events, and I hit a snag really early on. I'm a relatively new programmer, so hopefully this isn't too stupid of a question, but I've got an issue that freezes the virtual machine and doesn't play any sound or send any OSC events. Nothing happens..the VM shows that the shreds are added, and then it just freezes and I have to force quit...it won't take a --removeall or --kill command or anything. Individually, each file works as it should, aside from the file whose code I am including here. I think I may be missing a key concept as to the way Machine.add works and how it assigns the value of the shred to an int, but I'm just not sure. If anyone can give me some direction here as to what might be happening I'd appreciate it! I've tried advancing time in various places, setting my initial pedCount to various values, all to no avail. Thanks very much, and please let me know if this is unclear in any way.
//begincode
Machine.add("justa.ck"); //class of frequency definitions Machine.add("pedestrianSender.ck"); //OSC sender of int values
OscRecv receiver; //OSC receiver object 6449 => receiver.port; receiver.listen(); receiver.event("weather/pedestrian, int") @=> OscEvent pedEvent;
-1 => int b3base1; //int to store a shred ID -1 => int b3base2; //ditto
25 => int pedCount; //int to store pedCount sent via OSC
while (true) {
//if the pedCount is greater than 20 (a value which will be sent via OSC) and b3base1 is equal to -1, i.e. the shred isn't currently running, //add both shreds to the VM and assign their shred ID to the b3base1 and b3base2
if (pedCount > 20 && b3base1 == -1) { Machine.add("b3base.ck") => b3base1; Machine.add("b3base.ck") => b3base2; }
else {
//if the pedCount is less than 20, remove both shreds from the VM and assign -1 to their value so that if the pedCount goes back above 20 they //meet the conditional.
if (pedCount < 20 && b3base1 != -1) { Machine.remove(b3base1); Machine.remove(b3base2); -1 => b3base1; -1 => b3base2; } }
while( pedEvent.nextMsg() != 0) { pedEvent.getInt() => pedCount; 2::second => now; } }
//endcode
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (4)
-
[chriswicks]
-
Andrew Turley
-
Kassen
-
Scott Hewitt