Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #35683 > unrolled thread

Howto break selfreferensing loops "inbound maybe it is called?"

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2018-09-25 14:39 -0700
Last post2018-09-26 23:46 -0700
Articles 10 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  Howto break selfreferensing loops "inbound maybe it is called?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-25 14:39 -0700
    Re: Howto break selfreferensing loops "inbound maybe it is called?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-25 15:50 -0700
      Re: Howto break selfreferensing loops "inbound maybe it is called?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-26 00:19 -0700
        Re: Howto break selfreferensing loops "inbound maybe it is called?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-26 01:06 -0700
    Re: Howto break selfreferensing loops "inbound maybe it is called?" "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-09-26 19:45 -0700
      Re: Howto break selfreferensing loops "inbound maybe it is called?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-26 23:01 -0700
        Re: Howto break selfreferensing loops "inbound maybe it is called?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-26 23:02 -0700
          Re: Howto break selfreferensing loops "inbound maybe it is called?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-26 23:23 -0700
            Re: Howto break selfreferensing loops "inbound maybe it is called?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-26 23:28 -0700
              Re: Howto break selfreferensing loops "inbound maybe it is called?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-09-26 23:46 -0700

#35683 — Howto break selfreferensing loops "inbound maybe it is called?"

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-25 14:39 -0700
SubjectHowto break selfreferensing loops "inbound maybe it is called?"
Message-ID<760e6284-688a-44ee-a855-5e44c04c0f08@googlegroups.com>
if (copyEv.length) {
       if (playmidi==false) { break; }//***Get error message
      noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
      outportarr[outportindex].send(noteMessage);
      var waittime = copyEv.shift();
      midEvent++;
      setTimeout(doPlayup, waittime); 
    } 


***Uncaught SyntaxError: Illegal break statement

[toc] | [next] | [standalone]


#35686

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-25 15:50 -0700
Message-ID<5a7254ee-66d1-454a-8b7f-332a3a753fdc@googlegroups.com>
In reply to#35683
Den tisdag 25 september 2018 kl. 23:39:27 UTC+2 skrev Jonas Thörnvall:
> if (copyEv.length) {
>        if (playmidi==false) { break; }//***Get error message
>       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
>       outportarr[outportindex].send(noteMessage);
>       var waittime = copyEv.shift();
>       midEvent++;
>       setTimeout(doPlayup, waittime); 
>     } 
> 
> 
> ***Uncaught SyntaxError: Illegal break statement

Well solved it by copyEv.length=0;

But i have to think about howto pause, the player a bit.

[toc] | [prev] | [next] | [standalone]


#35688

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-26 00:19 -0700
Message-ID<74465e42-1463-4bf7-9cc5-e8173696395d@googlegroups.com>
In reply to#35686
Den onsdag 26 september 2018 kl. 00:50:32 UTC+2 skrev Jonas Thörnvall:
> Den tisdag 25 september 2018 kl. 23:39:27 UTC+2 skrev Jonas Thörnvall:
> > if (copyEv.length) {
> >        if (playmidi==false) { break; }//***Get error message
> >       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
> >       outportarr[outportindex].send(noteMessage);
> >       var waittime = copyEv.shift();
> >       midEvent++;
> >       setTimeout(doPlayup, waittime); 
> >     } 
> > 
> > 
> > ***Uncaught SyntaxError: Illegal break statement
> 
> Well solved it by copyEv.length=0;
> 
> But i have to think about howto pause, the player a bit.

Well i tried to pause play by set waittime=300000000;
And resume by set waittime=0; or the savewait at timestamp, but copyEv somehow "resets when loop breaks" so copyEv.length becomes zero, suggestions?

function doPlayup() {
    if (copyEv.length) {
      noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
      outportarr[outportindex].send(noteMessage);
      waittime = copyEv.shift();
      midEvent++;
      setTimeout(doPlayup, waittime); 
    } 
}

function pauseplay(){
mode="Pause";
listMainSetting();
console.log("pauseplay");
savewait=waittime;
waittime=300000000;
copyEv.length=0;

}

function resumeplay(){
mode="Play";
listMainSetting();
waittime=savewait;
console.log("wait",waittime,"copyEV length",copyEv.length);
setTimeout(doPlayup, waittime);
}

[toc] | [prev] | [next] | [standalone]


#35689

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-26 01:06 -0700
Message-ID<d52aa5ad-3d54-4323-9f9e-687bde1a23a3@googlegroups.com>
In reply to#35688
Den onsdag 26 september 2018 kl. 09:20:01 UTC+2 skrev Jonas Thörnvall:
> Den onsdag 26 september 2018 kl. 00:50:32 UTC+2 skrev Jonas Thörnvall:
> > Den tisdag 25 september 2018 kl. 23:39:27 UTC+2 skrev Jonas Thörnvall:
> > > if (copyEv.length) {
> > >        if (playmidi==false) { break; }//***Get error message
> > >       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
> > >       outportarr[outportindex].send(noteMessage);
> > >       var waittime = copyEv.shift();
> > >       midEvent++;
> > >       setTimeout(doPlayup, waittime); 
> > >     } 
> > > 
> > > 
> > > ***Uncaught SyntaxError: Illegal break statement
> > 
> > Well solved it by copyEv.length=0;
> > 
> > But i have to think about howto pause, the player a bit.
> 
> Well i tried to pause play by set waittime=300000000;
> And resume by set waittime=0; or the savewait at timestamp, but copyEv somehow "resets when loop breaks" so copyEv.length becomes zero, suggestions?
> 
> function doPlayup() {
>     if (copyEv.length) {
>       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
>       outportarr[outportindex].send(noteMessage);
>       waittime = copyEv.shift();
>       midEvent++;
>       setTimeout(doPlayup, waittime); 
>     } 
> }
> 
> function pauseplay(){
> mode="Pause";
> listMainSetting();
> console.log("pauseplay");
> savewait=waittime;
> waittime=300000000;
> copyEv.length=0;
> 
> }
> 
> function resumeplay(){
> mode="Play";
> listMainSetting();
> waittime=savewait;
> console.log("wait",waittime,"copyEV length",copyEv.length);
> setTimeout(doPlayup, waittime);
> }

Is there a reason for the copyEv array to empty by just set waittime a long waittime? It is this kind of subtleties i do have a hard time to understand in Javascript, because i never figure out the reason for things that happens.

I can't see that it should? But yet....

Here is the full play playUp.js

waittime=0;

function startplay(){ 
  document.getElementById("keystream").value="";
  lastelement=track[0].midiMess.length; 
  //Check if anything to play
  if(lastelement!=0){
     tracknr=0;
     playmidi=true;
     mode="Play";
     listMainSetting();
     copyEv = waitEv.slice();
     last = copyEv[copyEv.length - 1]
     copyEv[copyEv.length]=last;
     var waittime = copyEv.shift();
     document.getElementById("keystream").value+="\n"+waittime+"\n";
     dot = 0; 
     midEvent=0;
     setTimeout(doPlayup, waittime);
  }
} 

function doPlayup() {
    if (copyEv.length) {
      noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
      outportarr[outportindex].send(noteMessage);
      waittime = copyEv.shift();
      midEvent++;
      setTimeout(doPlayup, waittime); 
    } 
}

function stopplay(){
console.log("stopplay");
copyEv.length=0;
mode="Listen";
listMainSetting();

}

function pauseplay(){
console.log("pauseplay");
savewait=waittime;
waittime=300000000;
copyEv.length=0;
mode="Pause";
listMainSetting();
}

function resumeplay(){
console.log("resumeplay");
mode="Play";
listMainSetting();
waittime=savewait;
console.log("wait",waittime,"copyEV_length",copyEv);
setTimeout(doPlayup, waittime);
}

[toc] | [prev] | [next] | [standalone]


#35707

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2018-09-26 19:45 -0700
Message-ID<ddf8f6a7-bea8-4ecd-848c-e3a529b7d657@googlegroups.com>
In reply to#35683
Jonas Thörnvall wrote:
> if (copyEv.length) {
>        if (playmidi==false) { break; }//***Get error message
>       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
>       outportarr[outportindex].send(noteMessage);
>       var waittime = copyEv.shift();
>       midEvent++;
>       setTimeout(doPlayup, waittime); 
>     } 
> 
> 
> ***Uncaught SyntaxError: Illegal break statement


You've failed the Turing Test.

[toc] | [prev] | [next] | [standalone]


#35709

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-26 23:01 -0700
Message-ID<379d95fc-4644-472a-b5c2-da40c19985b8@googlegroups.com>
In reply to#35707
Den torsdag 27 september 2018 kl. 04:46:04 UTC+2 skrev Michael Haufe (TNO):
> Jonas Thörnvall wrote:
> > if (copyEv.length) {
> >        if (playmidi==false) { break; }//***Get error message
> >       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
> >       outportarr[outportindex].send(noteMessage);
> >       var waittime = copyEv.shift();
> >       midEvent++;
> >       setTimeout(doPlayup, waittime); 
> >     } 
> > 
> > 
> > ***Uncaught SyntaxError: Illegal break statement
> 
> 
> You've failed the Turing Test.

No the ***stop*** test i passed by. 
copyEv.length=0; 
It is the ***pause*** test that is alot harder.
I tried to set waittime to some high value and was thinking that it would resume from pause once i set it back or to zero. But it does not.

If you have any smart idea howto pause the loop tell me, because when i set pause waittime to 30000000, and later try resume by setting it to 0, copyEv.length for some to me unknown reason zero. 
http://anybase.co.nf/index.html 

[toc] | [prev] | [next] | [standalone]


#35710

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-26 23:02 -0700
Message-ID<47a829d4-1ae2-4b76-aa9a-52ca467138b7@googlegroups.com>
In reply to#35709
Den torsdag 27 september 2018 kl. 08:01:14 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 27 september 2018 kl. 04:46:04 UTC+2 skrev Michael Haufe (TNO):
> > Jonas Thörnvall wrote:
> > > if (copyEv.length) {
> > >        if (playmidi==false) { break; }//***Get error message
> > >       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
> > >       outportarr[outportindex].send(noteMessage);
> > >       var waittime = copyEv.shift();
> > >       midEvent++;
> > >       setTimeout(doPlayup, waittime); 
> > >     } 
> > > 
> > > 
> > > ***Uncaught SyntaxError: Illegal break statement
> > 
> > 
> > You've failed the Turing Test.
> 
> No the ***stop*** test i passed by. 
> copyEv.length=0; 
> It is the ***pause*** test that is alot harder.
> I tried to set waittime to some high value and was thinking that it would resume from pause once i set it back or to zero. But it does not.
> 
> If you have any smart idea howto pause the loop tell me, because when i set pause waittime to 30000000, and later try resume by setting it to 0, copyEv.length for some to me unknown reason zero. 
> http://anybase.co.nf/index.html

Oops shit happens when you copy and rename, unknown reason not so unknown...

unction pauseplay(){ 
console.log("pauseplay"); 
savewait=waittime; 
waittime=300000000; 
****copyEv.length=0;**** 
mode="Pause"; 
listMainSetting(); 
}

[toc] | [prev] | [next] | [standalone]


#35711

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-26 23:23 -0700
Message-ID<a895a7c1-1a78-4272-a61a-0d9042110570@googlegroups.com>
In reply to#35710
Den torsdag 27 september 2018 kl. 08:03:04 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 27 september 2018 kl. 08:01:14 UTC+2 skrev Jonas Thörnvall:
> > Den torsdag 27 september 2018 kl. 04:46:04 UTC+2 skrev Michael Haufe (TNO):
> > > Jonas Thörnvall wrote:
> > > > if (copyEv.length) {
> > > >        if (playmidi==false) { break; }//***Get error message
> > > >       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
> > > >       outportarr[outportindex].send(noteMessage);
> > > >       var waittime = copyEv.shift();
> > > >       midEvent++;
> > > >       setTimeout(doPlayup, waittime); 
> > > >     } 
> > > > 
> > > > 
> > > > ***Uncaught SyntaxError: Illegal break statement
> > > 
> > > 
> > > You've failed the Turing Test.
> > 
> > No the ***stop*** test i passed by. 
> > copyEv.length=0; 
> > It is the ***pause*** test that is alot harder.
> > I tried to set waittime to some high value and was thinking that it would resume from pause once i set it back or to zero. But it does not.
> > 
> > If you have any smart idea howto pause the loop tell me, because when i set pause waittime to 30000000, and later try resume by setting it to 0, copyEv.length for some to me unknown reason zero. 
> > http://anybase.co.nf/index.html
> 
> Oops shit happens when you copy and rename, unknown reason not so unknown...
> 
> unction pauseplay(){ 
> console.log("pauseplay"); 
> savewait=waittime; 
> waittime=300000000; 
> ****copyEv.length=0;**** 
> mode="Pause"; 
> listMainSetting(); 
> }

But then it will not pause...

[toc] | [prev] | [next] | [standalone]


#35712

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-26 23:28 -0700
Message-ID<2775bf2c-ed06-468e-9876-9f13d169d24f@googlegroups.com>
In reply to#35711
Den torsdag 27 september 2018 kl. 08:23:08 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 27 september 2018 kl. 08:03:04 UTC+2 skrev Jonas Thörnvall:
> > Den torsdag 27 september 2018 kl. 08:01:14 UTC+2 skrev Jonas Thörnvall:
> > > Den torsdag 27 september 2018 kl. 04:46:04 UTC+2 skrev Michael Haufe (TNO):
> > > > Jonas Thörnvall wrote:
> > > > > if (copyEv.length) {
> > > > >        if (playmidi==false) { break; }//***Get error message
> > > > >       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
> > > > >       outportarr[outportindex].send(noteMessage);
> > > > >       var waittime = copyEv.shift();
> > > > >       midEvent++;
> > > > >       setTimeout(doPlayup, waittime); 
> > > > >     } 
> > > > > 
> > > > > 
> > > > > ***Uncaught SyntaxError: Illegal break statement
> > > > 
> > > > 
> > > > You've failed the Turing Test.
> > > 
> > > No the ***stop*** test i passed by. 
> > > copyEv.length=0; 
> > > It is the ***pause*** test that is alot harder.
> > > I tried to set waittime to some high value and was thinking that it would resume from pause once i set it back or to zero. But it does not.
> > > 
> > > If you have any smart idea howto pause the loop tell me, because when i set pause waittime to 30000000, and later try resume by setting it to 0, copyEv.length for some to me unknown reason zero. 
> > > http://anybase.co.nf/index.html
> > 
> > Oops shit happens when you copy and rename, unknown reason not so unknown...
> > 
> > unction pauseplay(){ 
> > console.log("pauseplay"); 
> > savewait=waittime; 
> > waittime=300000000; 
> > ****copyEv.length=0;**** 
> > mode="Pause"; 
> > listMainSetting(); 
> > }
> 
> But then it will not pause...

Anyone have a good idea for howto **pause** the loop in doPlayup() from pauseplay()

function doPlayup() {
    if (copyEv.length) {
      noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
      outportarr[outportindex].send(noteMessage);
      waittime = copyEv.shift();
      midEvent++;
      setTimeout(doPlayup, waittime); 
    } else {stopplay();}
}

function pauseplay(){
mode="Pause";
listMainSetting();
console.log("pauseplay");
savewait=waittime;
waittime=3000.0
}

[toc] | [prev] | [next] | [standalone]


#35713

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-09-26 23:46 -0700
Message-ID<d11025c2-c49f-4903-ab0a-cc3c282925df@googlegroups.com>
In reply to#35712
Den torsdag 27 september 2018 kl. 08:28:27 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 27 september 2018 kl. 08:23:08 UTC+2 skrev Jonas Thörnvall:
> > Den torsdag 27 september 2018 kl. 08:03:04 UTC+2 skrev Jonas Thörnvall:
> > > Den torsdag 27 september 2018 kl. 08:01:14 UTC+2 skrev Jonas Thörnvall:
> > > > Den torsdag 27 september 2018 kl. 04:46:04 UTC+2 skrev Michael Haufe (TNO):
> > > > > Jonas Thörnvall wrote:
> > > > > > if (copyEv.length) {
> > > > > >        if (playmidi==false) { break; }//***Get error message
> > > > > >       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
> > > > > >       outportarr[outportindex].send(noteMessage);
> > > > > >       var waittime = copyEv.shift();
> > > > > >       midEvent++;
> > > > > >       setTimeout(doPlayup, waittime); 
> > > > > >     } 
> > > > > > 
> > > > > > 
> > > > > > ***Uncaught SyntaxError: Illegal break statement
> > > > > 
> > > > > 
> > > > > You've failed the Turing Test.
> > > > 
> > > > No the ***stop*** test i passed by. 
> > > > copyEv.length=0; 
> > > > It is the ***pause*** test that is alot harder.
> > > > I tried to set waittime to some high value and was thinking that it would resume from pause once i set it back or to zero. But it does not.
> > > > 
> > > > If you have any smart idea howto pause the loop tell me, because when i set pause waittime to 30000000, and later try resume by setting it to 0, copyEv.length for some to me unknown reason zero. 
> > > > http://anybase.co.nf/index.html
> > > 
> > > Oops shit happens when you copy and rename, unknown reason not so unknown...
> > > 
> > > unction pauseplay(){ 
> > > console.log("pauseplay"); 
> > > savewait=waittime; 
> > > waittime=300000000; 
> > > ****copyEv.length=0;**** 
> > > mode="Pause"; 
> > > listMainSetting(); 
> > > }
> > 
> > But then it will not pause...
> 
> Anyone have a good idea for howto **pause** the loop in doPlayup() from pauseplay()
> 
> function doPlayup() {
>     if (copyEv.length) {
>       noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
>       outportarr[outportindex].send(noteMessage);
>       waittime = copyEv.shift();
>       midEvent++;
>       setTimeout(doPlayup, waittime); 
>     } else {stopplay();}
> }
> 
> function pauseplay(){
> mode="Pause";
> listMainSetting();
> console.log("pauseplay");
> savewait=waittime;
> waittime=3000.0
> }

Solved! nicely?
function doPlayup() {
  if(keepGoing){
    if (copyEv.length) {
      noteMessage = [track[0].midiMess[midEvent].data0, track[0].midiMess[midEvent].data1, track[0].midiMess[midEvent].data2]; 
      outportarr[outportindex].send(noteMessage);
      waittime = copyEv.shift();
      midEvent++;
      setTimeout(doPlayup, waittime); 
    } else {stopplay();}
 }
}

function stopplay(){
console.log("stopplay");
copyEv.length=0;
mode="Listen";
listMainSetting();
}

function pauseplay(){
mode="Pause";
listMainSetting();
console.log("pauseplay");
savewait=waittime;
keepGoing=false;
}

function resumeplay(){
keepGoing=true;
console.log("resumeplay");
mode="Play";
listMainSetting();
waittime=savewait;
console.log("wait",waittime,"copyEV_length",copyEv);
setTimeout(doPlayup, waittime);
}

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web