do loop

Discuss Lemur and share techniques.
joebataz
Regular
Posts: 154
Joined: 28 Feb 2012 16:50
Location: Anthem, AZ USA
Contact:

do loop

Post by joebataz »

Has anyone used a do loop and had it work?
This works, I get the 'bah' message and then the 'humbug' message:

timeMark = floor(time) + time%0.25;
lastTime = floor(time) + time%0.25 + 4;
AAmsg = 'bah';
while(timeMark < lastTime)
{
timeMark = floor(time) + time%0.2;
}
AAmsg = 'humbug';


I never get 'humbug' with this. Why not?

timeMark = floor(time) + time%0.25;
lastTime = floor(time) + time%0.25 + 4;
AAmsg = 'bah';
do
{
timeMark = floor(time) + time%0.2;
}
while(timeMark < lastTime);
AAmsg = 'humbug';
joebataz
Regular
Posts: 154
Joined: 28 Feb 2012 16:50
Location: Anthem, AZ USA
Contact:

Re: do loop

Post by joebataz »

And this never hits 'humbug' (changed lastTime to a local variable, removed the global)


decl lastTime;
AAmsg = 'bah';
lastTime = floor(time)+ time%.01 + 5;
while(1)
{
if(time>lastTime)break;
}
AAmsg = 'humbug';

Is this another Lemur bug that I spend hours (which I now have) banging my head against?
joebataz
Regular
Posts: 154
Joined: 28 Feb 2012 16:50
Location: Anthem, AZ USA
Contact:

Re: do loop

Post by joebataz »

OK 4 hours of trying to make a time loop work. Time to do something else.
There has got to be a bug or some sort of gotcha with this. :evil: :evil: :evil: :evil: :evil:
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: do loop

Post by Macciza »

Hi
The way I see it - while(timeMark < lastTime); - will always be true so it simply keeps iterating . . .
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
joebataz
Regular
Posts: 154
Joined: 28 Feb 2012 16:50
Location: Anthem, AZ USA
Contact:

Re: do loop

Post by joebataz »

How do you figure that???
for example:
timeMark = floor(time) + time%0.25; timeMark is now equal 100
lastTime = floor(time) + time%0.25 + 4; lastTime is now equal to 104
AAmsg = 'bah';
do
{
timeMark = floor(time) + time%0.2; <<<<<< --------shouldn't THIS increment timeMark? time is running isn't it
}
while(timeMark < lastTime);
AAmsg = 'humbug';

I have also tried this with the internal time variable as in:

lastTime = floor(time) + time%0.25 + 4;
AAmsg = 'bah';
do
{
<<doesn't really matter what goes here. this do loop is just killing time
}
while(time < lastTime);
AAmsg = 'humbug';

I have a monitor that is watching time and it most certainly goes past the lastTime variable so why is it still looping?
Could you give me an example of how to kill time?
bxsj
Regular
Posts: 116
Joined: 24 Dec 2011 06:47
Location: Vienna

Re: do loop

Post by bxsj »

Hi Joe,

It seems you are hitting a limit in regards to the number of times a loop is executed. Look at the attached example. The onchange script contains a "classic" endless loop. The variable count countes the number of times the loop is ececuted. In this case count shows the value of 11110 after execution. That leaves me to suspect that the Lemur has inbuilt limits to stop the execution of a script if an abnormal situation is encountered. But I may be totally wrong about that :roll:

Regarding your specific issue with the do loop, take a look at the attachement. Btw. Have you tried to increase the increment of the varialbe timeMark? Just for the giggles 8-)

Cheers,
B.
Attachments
endlessloop_test.jzml
(4.38 KiB) Downloaded 109 times
Win7 64, Ipad Lemur, Cubase6 and a bunch of Roland Synths and Samplers
joebataz
Regular
Posts: 154
Joined: 28 Feb 2012 16:50
Location: Anthem, AZ USA
Contact:

Re: do loop

Post by joebataz »

This is about the third time I've gotten REALLY disgusted with Lemur. I don't see how I can ask a simpler question than this and get an actual answer. I am including EXACTLY the code and the template. Here is the code:

AAmsg = 'start';
lastTime = floor(time)+time%.25+4;
timeMark = floor(time)+time%.25;
while(timeMark<lastTime)
{
timeMark = floor(time)+time%.25;
}
AAmsg = 'end';

WHY does this loop not end? maccazia said something about timeMark never getting larger than lastTime. WHY NOT???? Isn't it incremented being set to the value of time in the while loop? And if not why not? I get absolutely frustrated when I'm spending hours and hours trying to make a simple loop work and it all comes down to WHY specifically does this never get to 'end'. I am including a simple template which I would appreciate someone modifying to show me how to get to 'end'.
Attachments
dirtSimple.jzml
(4.34 KiB) Downloaded 85 times
Macciza
Regular
Posts: 1315
Joined: 07 Dec 2011 04:57
Location: Sydney, Australia.

Re: do loop

Post by Macciza »

Hi
Sorry - I focused on the wrong part of my answer and got it wrong, scope and execution issues didn't help either . . .
But I overlooked the crucial issue - for 'time' to have passed, particularly 240 frames, we can't still be executing . . .
Damn even bxsj comment should have 'thrown the switch' - I am pretty sure there has always been an 'escape clause' to avoid those issues.
Remember we are not in a 'realtime rate' but instead a 'frame rate' environment and that sometimes that changes things drastically.
In 'realtime' the do whiles etc recipes you used work, but the can be used in the framed Lemur environment
Within the operation time of the script your test is not fulfilled and I think it's execution abandoned to avoid hanging

So what I did was give timeMark it definition at global level so it is always giving current time via your function
Custom Button.RunA - lastTime = timeMark+4; - sets lastTime to some value and that is all it does.
message -the Monitor object- has a script added
ie disp()

if(floor(timeMark)<lastTime)
AAmsg = 'start';

else
AAmsg = 'end';

The floor(timeMark) was needed to avoid bounce due to the modulo

Hope that makes sense.
MM
Attachments
dirtySimple.jzml
(4.44 KiB) Downloaded 88 times
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]
joebataz
Regular
Posts: 154
Joined: 28 Feb 2012 16:50
Location: Anthem, AZ USA
Contact:

Re: do loop

Post by joebataz »

I sort of understand what you mean but I still can't get this to work.
Here is the task I need.
I have 2 sequences of midi notes (anywhere from 0 to 31) in two arrays. For each pair of those notes I have a set number(time) as in:
A_SeqBank = {0,3,10,0,3,10,0,3,10,6,9,11}
A_SeqPreset = {3,1,1,6,2,2,9,3,3,2,8,6}
A_SeqTime = {1,1,1,2,2,2,3,3,3,4,4,4}

I need to fire the notes in a set a minimum of 40ms apart so I press a custom button for set 1 and I need the following to happen
noteout(0,0,127,15);
delay
noteout(0,3,127,16);
delay
noteout(0,3,127,15);
delay
noteout(0,1,127,16);
delay
noteout(0,10,127,15);
delay
noteout(0,1,127,16);

Of course the above happens in a loop (which is the whole point of this loop stuff) and I just can't ever get this to work. Here's what the code should look like:
if(A_CurFrame < sizeof(A_SeqBank))
{
if(A_CurFrame == 0)
{
noteout(0,A_SeqBank[A_CurFrame],127,15);
DELAY GOES HERE!!
noteout(0,A_SeqPreset[A_CurFrame],127,16);
DELAY GOES HERE!!
A_CurFrame++;
}
do
{
noteout(0,A_SeqBank[A_CurFrame],127,15);
DELAY GOES HERE!!
noteout(0,A_SeqPreset[A_CurFrame],127,16);
DELAY GOES HERE!!
A_CurFrame++;
}
while ((A_SeqTime[A_CurFrame-1] == A_SeqTime[A_CurFrame]) && (A_CurFrame < sizeof(A_SeqBank)));
}

Does that make sense? Everything else I sent in the last template is now working (with a few added functions). And it works extremely well. Just need a better way to save the sequences once I get past this timing issue.

Thanks,

joeb
joebataz
Regular
Posts: 154
Joined: 28 Feb 2012 16:50
Location: Anthem, AZ USA
Contact:

Re: do loop

Post by joebataz »

it is absolutely beyond frustrating that it is so hard to get a 40ms delay between 2 events, frame based or whatever. I'm done with banging my head against this. 5 days of roughly 16 hours a day. I have come to the conclusion that Lemur CAN'T control everything. Understand I have spent several weeks setting up an enormous amount of DMX scenes based on being able to turn them on in sets or individually. The whole silly things works EXCEPT I can't get playing to work because of an inability to get midi to come out in 40ms intervals. Since I can't do that I'm going to have to go back in and reset all my DMX work to individual scenes instead of mixing masked scenes. This means taking the 260 or so DMX scenes and changing them to several thousand scenes. What a HUGE price to pay for 40ms.
Post Reply