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


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

Bad timing

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2018-04-29 17:27 -0700
Last post2018-04-30 06:20 -0700
Articles 20 on this page of 22 — 5 participants

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


Contents

  Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-29 17:27 -0700
    Re: Bad timing JJ <jj4public@vfemail.net> - 2018-04-30 10:43 +0700
      Re: Bad timing Julio Di Egidio <julio@diegidio.name> - 2018-04-30 00:24 -0700
        Re: Bad timing "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-04-30 13:01 -0700
          Re: Bad timing Julio Di Egidio <julio@diegidio.name> - 2018-04-30 17:04 -0700
            Re: Bad timing Julio Di Egidio <julio@diegidio.name> - 2018-05-01 04:33 -0700
          Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-30 18:24 -0700
            Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-30 18:32 -0700
              Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-30 18:44 -0700
                Re: Bad timing "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-05-01 10:29 +0200
                  Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-05-01 14:48 -0700
                  Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-05-01 14:54 -0700
                    Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-05-01 22:12 -0700
                    Re: Bad timing "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-05-02 11:29 +0200
                      Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-05-03 23:35 -0700
                        Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-05-03 23:38 -0700
                          Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-05-03 23:53 -0700
                            Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-05-04 00:49 -0700
                  Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-05-01 23:11 -0700
      Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-30 00:43 -0700
        Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-30 00:47 -0700
          Re: Bad timing Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-30 06:20 -0700

Page 1 of 2  [1] 2  Next page →


#34942 — Bad timing

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-04-29 17:27 -0700
SubjectBad timing
Message-ID<a26c44bd-b0d4-4b35-90cb-419d73f9f42c@googlegroups.com>
Is there a reason for the function below to have bad timing? 
The copyEv hold microseconds.

function doPlayup() {
    if (copyEv.length-1) {
      var waittime = copyEv.shift();
      if(pyp>-1) {
            noteOnMessage = [track[tracknr].midiMess[pyp].data0, track[tracknr].midiMess[pyp].data1, track[tracknr].midiMess[pyp].data2]; 
            output.send(noteOnMessage);
      } 
      pyp++;
      setTimeout(doPlayup, waittime); 
    } 
}

[toc] | [next] | [standalone]


#34943

FromJJ <jj4public@vfemail.net>
Date2018-04-30 10:43 +0700
Message-ID<4qa10u801489.jvohomgjs5av$.dlg@40tude.net>
In reply to#34942
On Sun, 29 Apr 2018 17:27:27 -0700 (PDT), Jonas Thörnvall wrote:
> Is there a reason for the function below to have bad timing? 
> The copyEv hold microseconds.
> 
> function doPlayup() {
>     if (copyEv.length-1) {
>       var waittime = copyEv.shift();
>       if(pyp>-1) {
>             noteOnMessage = [track[tracknr].midiMess[pyp].data0, track[tracknr].midiMess[pyp].data1, track[tracknr].midiMess[pyp].data2]; 
>             output.send(noteOnMessage);
>       } 
>       pyp++;
>       setTimeout(doPlayup, waittime); 
>     } 
> }

You should do that in a worker thread instead of the main thread, because
the main thread does many thing (e.g. DOM events, page rendering, etc.)
which may cause queued timer (including event) handler executions to be
postponed.

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


#34944

FromJulio Di Egidio <julio@diegidio.name>
Date2018-04-30 00:24 -0700
Message-ID<c55279ed-34c0-4d51-9805-a9c19984555f@googlegroups.com>
In reply to#34943
On Monday, 30 April 2018 05:43:13 UTC+2, JJ  wrote:
> On Sun, 29 Apr 2018 17:27:27 -0700 (PDT), Jonas Thörnvall wrote:
<snip>
> >       setTimeout(doPlayup, waittime); 
> >     } 
> > }
> 
> You should do that in a worker thread

There are no threads in JavaScript.

Julio

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


#34948

From"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>
Date2018-04-30 13:01 -0700
Message-ID<pc7sml$h0n$1@dont-email.me>
In reply to#34944
On 4/30/2018 12:24 AM, Julio Di Egidio wrote:
> On Monday, 30 April 2018 05:43:13 UTC+2, JJ  wrote:
>> On Sun, 29 Apr 2018 17:27:27 -0700 (PDT), Jonas Thörnvall wrote:
> <snip>
>>>        setTimeout(doPlayup, waittime);
>>>      }
>>> }
>>
>> You should do that in a worker thread
> 
> There are no threads in JavaScript.

Fwiw:

https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers

http://funwithfractals.atspace.cc/ct_root/ct_ui

The work is computed using another thread and the UI remains responsive.

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


#34949

FromJulio Di Egidio <julio@diegidio.name>
Date2018-04-30 17:04 -0700
Message-ID<973058b6-7ed6-49c6-9cd3-926c3d96a7fe@googlegroups.com>
In reply to#34948
On Monday, 30 April 2018 22:01:32 UTC+2, Chris M. Thomasson  wrote:
> On 4/30/2018 12:24 AM, Julio Di Egidio wrote:
> > On Monday, 30 April 2018 05:43:13 UTC+2, JJ  wrote:
> >> On Sun, 29 Apr 2018 17:27:27 -0700 (PDT), Jonas Thörnvall wrote:
> > <snip>
> >>>        setTimeout(doPlayup, waittime);
> >>>      }
> >>> }
> >>
> >> You should do that in a worker thread
> > 
> > There are no threads in JavaScript.
> 
> Fwiw:
> 
> https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
> 
> http://funwithfractals.atspace.cc/ct_root/ct_ui
> 
> The work is computed using another thread and the UI remains responsive.

They asked for it, they get it...  Use with care.

As for my UI's, those are responsive since about 1995.  :)

Note that HTML5 is the only really new thing in town...

HTH,

Julio

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


#34957

FromJulio Di Egidio <julio@diegidio.name>
Date2018-05-01 04:33 -0700
Message-ID<3bbaa19d-29c9-453f-8951-a3e191a5b489@googlegroups.com>
In reply to#34949
On Tuesday, 1 May 2018 02:04:13 UTC+2, Julio Di Egidio  wrote:
> On Monday, 30 April 2018 22:01:32 UTC+2, Chris M. Thomasson  wrote:
> > On 4/30/2018 12:24 AM, Julio Di Egidio wrote:
> > > On Monday, 30 April 2018 05:43:13 UTC+2, JJ  wrote:
> > >> On Sun, 29 Apr 2018 17:27:27 -0700 (PDT), Jonas Thörnvall wrote:
> > > <snip>
> > >>>        setTimeout(doPlayup, waittime);
> > >>>      }
> > >>> }
> > >>
> > >> You should do that in a worker thread
> > > 
> > > There are no threads in JavaScript.
> > 
> > Fwiw:
> > 
> > https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
> > 
> > http://funwithfractals.atspace.cc/ct_root/ct_ui
> > 
> > The work is computed using another thread and the UI remains responsive.
> 
> They asked for it, they get it...  Use with care.
> 
> As for my UI's, those are responsive since about 1995.  :)
> 
> Note that HTML5 is the only really new thing in town...

P.S.  A lot of knowledge is really being lost in those operations:
E.g. an aspect of JavaScript, indeed the runtime model, is that it is
a so called event-driven paradigm, which by the way too contributes to
the great modularity (also at system level) along with the outstanding
simplicity.  But of course if all one knows is a hammer...

Julio

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


#34950

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-04-30 18:24 -0700
Message-ID<9cc97d1c-9625-47c0-9fa4-acbc3a8f4a19@googlegroups.com>
In reply to#34948
Den måndag 30 april 2018 kl. 22:01:32 UTC+2 skrev Chris M. Thomasson:
> On 4/30/2018 12:24 AM, Julio Di Egidio wrote:
> > On Monday, 30 April 2018 05:43:13 UTC+2, JJ  wrote:
> >> On Sun, 29 Apr 2018 17:27:27 -0700 (PDT), Jonas Thörnvall wrote:
> > <snip>
> >>>        setTimeout(doPlayup, waittime);
> >>>      }
> >>> }
> >>
> >> You should do that in a worker thread
> > 
> > There are no threads in JavaScript.
> 
> Fwiw:
> 
> https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
> 
> http://funwithfractals.atspace.cc/ct_root/ct_ui
> 
> The work is computed using another thread and the UI remains responsive.

Well i found the problem of the slipping notes "bad programming of events", but it is good to know howto find a solution that is more accurate under rendering.

I do not quite understand shift() i guess it remove first item in array.

It seem the last note "timing" in array is removed before the last call, what is the solution to this problem?

I am just used to work with loops, these backcalls with shift() are confusing.

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


#34951

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-04-30 18:32 -0700
Message-ID<8b31acbd-5858-4496-9698-4aaf934ff452@googlegroups.com>
In reply to#34950
Den tisdag 1 maj 2018 kl. 03:25:00 UTC+2 skrev Jonas Thörnvall:
> Den måndag 30 april 2018 kl. 22:01:32 UTC+2 skrev Chris M. Thomasson:
> > On 4/30/2018 12:24 AM, Julio Di Egidio wrote:
> > > On Monday, 30 April 2018 05:43:13 UTC+2, JJ  wrote:
> > >> On Sun, 29 Apr 2018 17:27:27 -0700 (PDT), Jonas Thörnvall wrote:
> > > <snip>
> > >>>        setTimeout(doPlayup, waittime);
> > >>>      }
> > >>> }
> > >>
> > >> You should do that in a worker thread
> > > 
> > > There are no threads in JavaScript.
> > 
> > Fwiw:
> > 
> > https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
> > 
> > http://funwithfractals.atspace.cc/ct_root/ct_ui
> > 
> > The work is computed using another thread and the UI remains responsive.
> 
> Well i found the problem of the slipping notes "bad programming of events", but it is good to know howto find a solution that is more accurate under rendering.
> 
> I do not quite understand shift() i guess it remove first item in array.
> 
> It seem the last note "timing" in array is removed before the last call, what is the solution to this problem?
> 
> I am just used to work with loops, these backcalls with shift() are confusing.

last note never reached?
Because i never reach last timing in array copyEv, i guess i remove it before "i should" do the last call to doPlayup?

I've been thinking for two days now and i do not see howto resolve it.
But there must be a standard solution handling this? I can't see it.

doPlayup();

function doPlayup() {
    if (copyEv.length) {
      var waittime = copyEv.shift();
      if(pyp>-1) {
            noteOnMessage = [track[tracknr].midiMess[pyp].data0, track[tracknr].midiMess[pyp].data1, track[tracknr].midiMess[pyp].data2]; 
            output.send(noteOnMessage);
           
      } 
      document.getElementById("keystream").value+=waittime+"\n";
      pyp++;
      setTimeout(doPlayup, waittime); 
    } 
}

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


#34952

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-04-30 18:44 -0700
Message-ID<809123f9-7988-438e-baf0-9c79ce06f3e0@googlegroups.com>
In reply to#34951
Den tisdag 1 maj 2018 kl. 03:32:27 UTC+2 skrev Jonas Thörnvall:
> Den tisdag 1 maj 2018 kl. 03:25:00 UTC+2 skrev Jonas Thörnvall:
> > Den måndag 30 april 2018 kl. 22:01:32 UTC+2 skrev Chris M. Thomasson:
> > > On 4/30/2018 12:24 AM, Julio Di Egidio wrote:
> > > > On Monday, 30 April 2018 05:43:13 UTC+2, JJ  wrote:
> > > >> On Sun, 29 Apr 2018 17:27:27 -0700 (PDT), Jonas Thörnvall wrote:
> > > > <snip>
> > > >>>        setTimeout(doPlayup, waittime);
> > > >>>      }
> > > >>> }
> > > >>
> > > >> You should do that in a worker thread
> > > > 
> > > > There are no threads in JavaScript.
> > > 
> > > Fwiw:
> > > 
> > > https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
> > > 
> > > http://funwithfractals.atspace.cc/ct_root/ct_ui
> > > 
> > > The work is computed using another thread and the UI remains responsive.
> > 
> > Well i found the problem of the slipping notes "bad programming of events", but it is good to know howto find a solution that is more accurate under rendering.
> > 
> > I do not quite understand shift() i guess it remove first item in array.
> > 
> > It seem the last note "timing" in array is removed before the last call, what is the solution to this problem?
> > 
> > I am just used to work with loops, these backcalls with shift() are confusing.
> 
> last note never reached?
> Because i never reach last timing in array copyEv, i guess i remove it before "i should" do the last call to doPlayup?
> 
> I've been thinking for two days now and i do not see howto resolve it.
> But there must be a standard solution handling this? I can't see it.
> 
> doPlayup();
> 
> function doPlayup() {
>     if (copyEv.length) {
>       var waittime = copyEv.shift();
>       if(pyp>-1) {
>             noteOnMessage = [track[tracknr].midiMess[pyp].data0, track[tracknr].midiMess[pyp].data1, track[tracknr].midiMess[pyp].data2]; 
>             output.send(noteOnMessage);
>            
>       } 
>       document.getElementById("keystream").value+=waittime+"\n";
>       pyp++;
>       setTimeout(doPlayup, waittime); 
>     } 
> }

The last midiMess is never played i guess it is inherent to the use of 
if array.length and shift()

And if i do write if (copyEv.length+1), it play last but i get undefined which i guess is from try to shift something that isn't there.... Correct?

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


#34954

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2018-05-01 10:29 +0200
Message-ID<XnsA8D56AAC37D86eejj99@194.109.6.166>
In reply to#34952
=?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 01
May 2018 in comp.lang.javascript: 

> The last midiMess is never played i guess it is inherent to the use of 
> if array.length and shift()
> 
> And if i do write if (copyEv.length+1), it play last but i get undefined
> which i guess is from try to shift something that isn't there....
> Correct? 
> 

Methinks you guess 'wrongly', to quote Trumpian.

Instead of guessing, you should modularly debug your code:

<script type='text/javascript'> 'use strict'

let pyp = 0;
let copyEv = [2001,2002,2003,2004];

doPlayup();

function doPlayup() {
    if (copyEv.length) {
      var waittime = copyEv.shift();
      if(pyp>-1) {
            //noteOnMessage = [....]; 
            //output.send(noteOnMessage);
           console.log(pyp, waittime);
      }; 
      //document.getElementById("keystream").value+=waittime+"\n";
      pyp++;
      setTimeout(doPlayup, waittime); 
    };
};
</script>

console output:

test.html:17 0 2001
test.html:17 1 2002
test.html:17 2 2003
test.html:17 3 2004

So shift is not the culprit.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

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


#34960

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-05-01 14:48 -0700
Message-ID<335c1431-c937-44cb-9a97-3370dc3035d9@googlegroups.com>
In reply to#34954
Den tisdag 1 maj 2018 kl. 10:29:16 UTC+2 skrev Evertjan.:
> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 01
> May 2018 in comp.lang.javascript: 
> 
> > The last midiMess is never played i guess it is inherent to the use of 
> > if array.length and shift()
> > 
> > And if i do write if (copyEv.length+1), it play last but i get undefined
> > which i guess is from try to shift something that isn't there....
> > Correct? 
> > 
> 
> Methinks you guess 'wrongly', to quote Trumpian.
> 
> Instead of guessing, you should modularly debug your code:
> 
> <script type='text/javascript'> 'use strict'
> 
> let pyp = 0;
> let copyEv = [2001,2002,2003,2004];
> 
> doPlayup();
> 
> function doPlayup() {
>     if (copyEv.length) {
>       var waittime = copyEv.shift();
>       if(pyp>-1) {
>             //noteOnMessage = [....]; 
>             //output.send(noteOnMessage);
>            console.log(pyp, waittime);
>       }; 
>       //document.getElementById("keystream").value+=waittime+"\n";
>       pyp++;
>       setTimeout(doPlayup, waittime); 
>     };
> };
> </script>
> 
> console output:
> 
> test.html:17 0 2001
> test.html:17 1 2002
> test.html:17 2 2003
> test.html:17 3 2004
> 
> So shift is not the culprit.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

I think you avoid the problem Evertjan, first call nothing should be rendered out, because the first message can only be rendered out after waiting.

Think of it like the recording wait 3 seconds before first note is played.
So pyp must necessarily be -1 first call because it should not render any output.

We just happen to be in the actual function a little early LoL

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


#34961

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-05-01 14:54 -0700
Message-ID<8393b918-3835-4958-a8ac-0b48f58d4a46@googlegroups.com>
In reply to#34954
Den tisdag 1 maj 2018 kl. 10:29:16 UTC+2 skrev Evertjan.:
> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 01
> May 2018 in comp.lang.javascript: 
> 
> > The last midiMess is never played i guess it is inherent to the use of 
> > if array.length and shift()
> > 
> > And if i do write if (copyEv.length+1), it play last but i get undefined
> > which i guess is from try to shift something that isn't there....
> > Correct? 
> > 
> 
> Methinks you guess 'wrongly', to quote Trumpian.
> 
> Instead of guessing, you should modularly debug your code:
> 
> <script type='text/javascript'> 'use strict'
> 
> let pyp = 0;
> let copyEv = [2001,2002,2003,2004];
> 
> doPlayup();
> 
> function doPlayup() {
>     if (copyEv.length) {
>       var waittime = copyEv.shift();
>       if(pyp>-1) {
>             //noteOnMessage = [....]; 
>             //output.send(noteOnMessage);
>            console.log(pyp, waittime);
>       }; 
>       //document.getElementById("keystream").value+=waittime+"\n";
>       pyp++;
>       setTimeout(doPlayup, waittime); 
>     };
> };
> </script>
> 
> console output:
> 
> test.html:17 0 2001
> test.html:17 1 2002
> test.html:17 2 2003
> test.html:17 3 2004
> 
> So shift is not the culprit.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

I probably should/can render a dummy "note off" at time zero, maybe that is what you suggest?

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


#34963

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-05-01 22:12 -0700
Message-ID<c621f3b6-eba4-406e-b16c-ca7f12572b7f@googlegroups.com>
In reply to#34961
Den tisdag 1 maj 2018 kl. 23:55:00 UTC+2 skrev Jonas Thörnvall:
> Den tisdag 1 maj 2018 kl. 10:29:16 UTC+2 skrev Evertjan.:
> > =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 01
> > May 2018 in comp.lang.javascript: 
> > 
> > > The last midiMess is never played i guess it is inherent to the use of 
> > > if array.length and shift()
> > > 
> > > And if i do write if (copyEv.length+1), it play last but i get undefined
> > > which i guess is from try to shift something that isn't there....
> > > Correct? 
> > > 
> > 
> > Methinks you guess 'wrongly', to quote Trumpian.
> > 
> > Instead of guessing, you should modularly debug your code:
> > 
> > <script type='text/javascript'> 'use strict'
> > 
> > let pyp = 0;
> > let copyEv = [2001,2002,2003,2004];
> > 
> > doPlayup();
> > 
> > function doPlayup() {
> >     if (copyEv.length) {
> >       var waittime = copyEv.shift();
> >       if(pyp>-1) {
> >             //noteOnMessage = [....]; 
> >             //output.send(noteOnMessage);
> >            console.log(pyp, waittime);
> >       }; 
> >       //document.getElementById("keystream").value+=waittime+"\n";
> >       pyp++;
> >       setTimeout(doPlayup, waittime); 
> >     };
> > };
> > </script>
> > 
> > console output:
> > 
> > test.html:17 0 2001
> > test.html:17 1 2002
> > test.html:17 2 2003
> > test.html:17 3 2004
> > 
> > So shift is not the culprit.
> > 
> > -- 
> > Evertjan.
> > The Netherlands.
> > (Please change the x'es to dots in my emailaddress)
> 
> I probably should/can render a dummy "note off" at time zero, maybe that is what you suggest?

It could serve as a start marker.

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


#34965

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2018-05-02 11:29 +0200
Message-ID<XnsA8D674D0F71ADeejj99@194.109.6.166>
In reply to#34961
=?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 01
May 2018 in comp.lang.javascript: 

> Den tisdag 1 maj 2018 kl. 10:29:16 UTC+2 skrev Evertjan.:
>> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on
>> 01 May 2018 in comp.lang.javascript: 
>> 
>> > The last midiMess is never played i guess it is inherent to the use
>> > of if array.length and shift()
>> > 
>> > And if i do write if (copyEv.length+1), it play last but i get
>> > undefined which i guess is from try to shift something that isn't
>> > there.... Correct? 
>> > 
>> 
>> Methinks you guess 'wrongly', to quote Trumpian.
>> 
>> Instead of guessing, you should modularly debug your code:
>> 
>> <script type='text/javascript'> 'use strict'
>> 
>> let pyp = 0;
>> let copyEv = [2001,2002,2003,2004];
>> 
>> doPlayup();
>> 
>> function doPlayup() {
>>     if (copyEv.length) {
>>       var waittime = copyEv.shift();
>>       if(pyp>-1) {
>>             //noteOnMessage = [....]; 
>>             //output.send(noteOnMessage);
>>            console.log(pyp, waittime);
>>       }; 
>>       //document.getElementById("keystream").value+=waittime+"\n";
>>       pyp++;
>>       setTimeout(doPlayup, waittime); 
>>     };
>> };
>> </script>
>> 
>> console output:
>> 
>> test.html:17 0 2001
>> test.html:17 1 2002
>> test.html:17 2 2003
>> test.html:17 3 2004
>> 
>> So shift is not the culprit.
> 
> I probably should/can render a dummy "note off" at time zero, maybe that
> is what you suggest? 

No!

I suggested that you debug your modules seperately,
intead of guessing how it works.

Then, if you are satisfied, you treat them as black boxes, and debug only 
the input and output paramreters [and other effects like midi].

I see you now understand more about thee module [function] in question,
but don't even realize the step you made.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

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


#34972

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-05-03 23:35 -0700
Message-ID<b7abfe84-27f7-4cac-b6e9-dca76fccacdb@googlegroups.com>
In reply to#34965
Den onsdag 2 maj 2018 kl. 11:29:07 UTC+2 skrev Evertjan.:
> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 01
> May 2018 in comp.lang.javascript: 
> 
> > Den tisdag 1 maj 2018 kl. 10:29:16 UTC+2 skrev Evertjan.:
> >> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on
> >> 01 May 2018 in comp.lang.javascript: 
> >> 
> >> > The last midiMess is never played i guess it is inherent to the use
> >> > of if array.length and shift()
> >> > 
> >> > And if i do write if (copyEv.length+1), it play last but i get
> >> > undefined which i guess is from try to shift something that isn't
> >> > there.... Correct? 
> >> > 
> >> 
> >> Methinks you guess 'wrongly', to quote Trumpian.
> >> 
> >> Instead of guessing, you should modularly debug your code:
> >> 
> >> <script type='text/javascript'> 'use strict'
> >> 
> >> let pyp = 0;
> >> let copyEv = [2001,2002,2003,2004];
> >> 
> >> doPlayup();
> >> 
> >> function doPlayup() {
> >>     if (copyEv.length) {
> >>       var waittime = copyEv.shift();
> >>       if(pyp>-1) {
> >>             //noteOnMessage = [....]; 
> >>             //output.send(noteOnMessage);
> >>            console.log(pyp, waittime);
> >>       }; 
> >>       //document.getElementById("keystream").value+=waittime+"\n";
> >>       pyp++;
> >>       setTimeout(doPlayup, waittime); 
> >>     };
> >> };
> >> </script>
> >> 
> >> console output:
> >> 
> >> test.html:17 0 2001
> >> test.html:17 1 2002
> >> test.html:17 2 2003
> >> test.html:17 3 2004
> >> 
> >> So shift is not the culprit.
> > 
> > I probably should/can render a dummy "note off" at time zero, maybe that
> > is what you suggest? 
> 
> No!
> 
> I suggested that you debug your modules seperately,
> intead of guessing how it works.
> 
> Then, if you are satisfied, you treat them as black boxes, and debug only 
> the input and output paramreters [and other effects like midi].
> 
> I see you now understand more about thee module [function] in question,
> but don't even realize the step you made.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

The logic behind what is going on in the function fails me.
Could you give an advice all the values get print out but the last note is not played. Somehow the reason fails me.

var waittime = copyEv.shift();
document.getElementById("keystream").value+="\n"+waittime+"\n";
setTimeout(doPlayup, waittime);

function doPlayup() {
    if (copyEv.length) {
      noteMessage = [track[0].midiMess[pyp].data0, track[0].midiMess[pyp].data1, track[0].midiMess[pyp].data2]; 
      output.send(noteMessage);
      var waittime = copyEv.shift();
      document.getElementById("keystream").value+=waittime+"\n";
      pyp++;
      setTimeout(doPlayup, waittime); 
    } 
}

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


#34973

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-05-03 23:38 -0700
Message-ID<423604bf-a765-44cb-9117-3cf535f44a0c@googlegroups.com>
In reply to#34972
Den fredag 4 maj 2018 kl. 08:35:36 UTC+2 skrev Jonas Thörnvall:
> Den onsdag 2 maj 2018 kl. 11:29:07 UTC+2 skrev Evertjan.:
> > =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 01
> > May 2018 in comp.lang.javascript: 
> > 
> > > Den tisdag 1 maj 2018 kl. 10:29:16 UTC+2 skrev Evertjan.:
> > >> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on
> > >> 01 May 2018 in comp.lang.javascript: 
> > >> 
> > >> > The last midiMess is never played i guess it is inherent to the use
> > >> > of if array.length and shift()
> > >> > 
> > >> > And if i do write if (copyEv.length+1), it play last but i get
> > >> > undefined which i guess is from try to shift something that isn't
> > >> > there.... Correct? 
> > >> > 
> > >> 
> > >> Methinks you guess 'wrongly', to quote Trumpian.
> > >> 
> > >> Instead of guessing, you should modularly debug your code:
> > >> 
> > >> <script type='text/javascript'> 'use strict'
> > >> 
> > >> let pyp = 0;
> > >> let copyEv = [2001,2002,2003,2004];
> > >> 
> > >> doPlayup();
> > >> 
> > >> function doPlayup() {
> > >>     if (copyEv.length) {
> > >>       var waittime = copyEv.shift();
> > >>       if(pyp>-1) {
> > >>             //noteOnMessage = [....]; 
> > >>             //output.send(noteOnMessage);
> > >>            console.log(pyp, waittime);
> > >>       }; 
> > >>       //document.getElementById("keystream").value+=waittime+"\n";
> > >>       pyp++;
> > >>       setTimeout(doPlayup, waittime); 
> > >>     };
> > >> };
> > >> </script>
> > >> 
> > >> console output:
> > >> 
> > >> test.html:17 0 2001
> > >> test.html:17 1 2002
> > >> test.html:17 2 2003
> > >> test.html:17 3 2004
> > >> 
> > >> So shift is not the culprit.
> > > 
> > > I probably should/can render a dummy "note off" at time zero, maybe that
> > > is what you suggest? 
> > 
> > No!
> > 
> > I suggested that you debug your modules seperately,
> > intead of guessing how it works.
> > 
> > Then, if you are satisfied, you treat them as black boxes, and debug only 
> > the input and output paramreters [and other effects like midi].
> > 
> > I see you now understand more about thee module [function] in question,
> > but don't even realize the step you made.
> > 
> > -- 
> > Evertjan.
> > The Netherlands.
> > (Please change the x'es to dots in my emailaddress)
> 
> The logic behind what is going on in the function fails me.
> Could you give an advice all the values get print out but the last note is not played. Somehow the reason fails me.
> 
> var waittime = copyEv.shift();
> document.getElementById("keystream").value+="\n"+waittime+"\n";
> setTimeout(doPlayup, waittime);
> 
> function doPlayup() {
>     if (copyEv.length) {
>       noteMessage = [track[0].midiMess[pyp].data0, track[0].midiMess[pyp].data1, track[0].midiMess[pyp].data2]; 
>       output.send(noteMessage);
>       var waittime = copyEv.shift();
>       document.getElementById("keystream").value+=waittime+"\n";
>       pyp++;
>       setTimeout(doPlayup, waittime); 
>     } 
> }

Meanwhile i put the dummy note in there because that is the only way i see it done play all notes without undefined at end.

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


#34974

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-05-03 23:53 -0700
Message-ID<0c11709c-6863-4aeb-a39f-33fe99e73706@googlegroups.com>
In reply to#34973
Den fredag 4 maj 2018 kl. 08:38:37 UTC+2 skrev Jonas Thörnvall:
> Den fredag 4 maj 2018 kl. 08:35:36 UTC+2 skrev Jonas Thörnvall:
> > Den onsdag 2 maj 2018 kl. 11:29:07 UTC+2 skrev Evertjan.:
> > > =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 01
> > > May 2018 in comp.lang.javascript: 
> > > 
> > > > Den tisdag 1 maj 2018 kl. 10:29:16 UTC+2 skrev Evertjan.:
> > > >> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on
> > > >> 01 May 2018 in comp.lang.javascript: 
> > > >> 
> > > >> > The last midiMess is never played i guess it is inherent to the use
> > > >> > of if array.length and shift()
> > > >> > 
> > > >> > And if i do write if (copyEv.length+1), it play last but i get
> > > >> > undefined which i guess is from try to shift something that isn't
> > > >> > there.... Correct? 
> > > >> > 
> > > >> 
> > > >> Methinks you guess 'wrongly', to quote Trumpian.
> > > >> 
> > > >> Instead of guessing, you should modularly debug your code:
> > > >> 
> > > >> <script type='text/javascript'> 'use strict'
> > > >> 
> > > >> let pyp = 0;
> > > >> let copyEv = [2001,2002,2003,2004];
> > > >> 
> > > >> doPlayup();
> > > >> 
> > > >> function doPlayup() {
> > > >>     if (copyEv.length) {
> > > >>       var waittime = copyEv.shift();
> > > >>       if(pyp>-1) {
> > > >>             //noteOnMessage = [....]; 
> > > >>             //output.send(noteOnMessage);
> > > >>            console.log(pyp, waittime);
> > > >>       }; 
> > > >>       //document.getElementById("keystream").value+=waittime+"\n";
> > > >>       pyp++;
> > > >>       setTimeout(doPlayup, waittime); 
> > > >>     };
> > > >> };
> > > >> </script>
> > > >> 
> > > >> console output:
> > > >> 
> > > >> test.html:17 0 2001
> > > >> test.html:17 1 2002
> > > >> test.html:17 2 2003
> > > >> test.html:17 3 2004
> > > >> 
> > > >> So shift is not the culprit.
> > > > 
> > > > I probably should/can render a dummy "note off" at time zero, maybe that
> > > > is what you suggest? 
> > > 
> > > No!
> > > 
> > > I suggested that you debug your modules seperately,
> > > intead of guessing how it works.
> > > 
> > > Then, if you are satisfied, you treat them as black boxes, and debug only 
> > > the input and output paramreters [and other effects like midi].
> > > 
> > > I see you now understand more about thee module [function] in question,
> > > but don't even realize the step you made.
> > > 
> > > -- 
> > > Evertjan.
> > > The Netherlands.
> > > (Please change the x'es to dots in my emailaddress)
> > 
> > The logic behind what is going on in the function fails me.
> > Could you give an advice all the values get print out but the last note is not played. Somehow the reason fails me.
> > 
> > var waittime = copyEv.shift();
> > document.getElementById("keystream").value+="\n"+waittime+"\n";
> > setTimeout(doPlayup, waittime);
> > 
> > function doPlayup() {
> >     if (copyEv.length) {
> >       noteMessage = [track[0].midiMess[pyp].data0, track[0].midiMess[pyp].data1, track[0].midiMess[pyp].data2]; 
> >       output.send(noteMessage);
> >       var waittime = copyEv.shift();
> >       document.getElementById("keystream").value+=waittime+"\n";
> >       pyp++;
> >       setTimeout(doPlayup, waittime); 
> >     } 
> > }
> 
> Meanwhile i put the dummy note in there because that is the only way i see it done play all notes without undefined at end.

I admit i am a bit clueless about what is going on in the function, if anyone got the time to explain i am all ears.

I did know pretty much from the start howto resolve it though, a bit laughable maybe, but i can't see what is failing or rather howto adjust the behaviour of shift to fit the purpose.
Anyhow here is my patch/solution to the problem ;)

last = copyEv[copyEv.length - 1]
copyEv[copyEv.length]=last;
var waittime = copyEv.shift();
document.getElementById("keystream").value+="\n"+waittime+"\n";
setTimeout(doPlayup, waittime);

function doPlayup() {
    if (copyEv.length) {
      noteMessage = [track[0].midiMess[pyp].data0, track[0].midiMess[pyp].data1, track[0].midiMess[pyp].data2]; 
      output.send(noteMessage);
      var waittime = copyEv.shift();
      document.getElementById("keystream").value+=waittime+"\n";
      pyp++;
      setTimeout(doPlayup, waittime); 
    } 
}

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


#34977

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-05-04 00:49 -0700
Message-ID<3499bc18-a698-4b77-86ef-068faa478431@googlegroups.com>
In reply to#34974
Den fredag 4 maj 2018 kl. 08:53:25 UTC+2 skrev Jonas Thörnvall:
> Den fredag 4 maj 2018 kl. 08:38:37 UTC+2 skrev Jonas Thörnvall:
> > Den fredag 4 maj 2018 kl. 08:35:36 UTC+2 skrev Jonas Thörnvall:
> > > Den onsdag 2 maj 2018 kl. 11:29:07 UTC+2 skrev Evertjan.:
> > > > =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 01
> > > > May 2018 in comp.lang.javascript: 
> > > > 
> > > > > Den tisdag 1 maj 2018 kl. 10:29:16 UTC+2 skrev Evertjan.:
> > > > >> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on
> > > > >> 01 May 2018 in comp.lang.javascript: 
> > > > >> 
> > > > >> > The last midiMess is never played i guess it is inherent to the use
> > > > >> > of if array.length and shift()
> > > > >> > 
> > > > >> > And if i do write if (copyEv.length+1), it play last but i get
> > > > >> > undefined which i guess is from try to shift something that isn't
> > > > >> > there.... Correct? 
> > > > >> > 
> > > > >> 
> > > > >> Methinks you guess 'wrongly', to quote Trumpian.
> > > > >> 
> > > > >> Instead of guessing, you should modularly debug your code:
> > > > >> 
> > > > >> <script type='text/javascript'> 'use strict'
> > > > >> 
> > > > >> let pyp = 0;
> > > > >> let copyEv = [2001,2002,2003,2004];
> > > > >> 
> > > > >> doPlayup();
> > > > >> 
> > > > >> function doPlayup() {
> > > > >>     if (copyEv.length) {
> > > > >>       var waittime = copyEv.shift();
> > > > >>       if(pyp>-1) {
> > > > >>             //noteOnMessage = [....]; 
> > > > >>             //output.send(noteOnMessage);
> > > > >>            console.log(pyp, waittime);
> > > > >>       }; 
> > > > >>       //document.getElementById("keystream").value+=waittime+"\n";
> > > > >>       pyp++;
> > > > >>       setTimeout(doPlayup, waittime); 
> > > > >>     };
> > > > >> };
> > > > >> </script>
> > > > >> 
> > > > >> console output:
> > > > >> 
> > > > >> test.html:17 0 2001
> > > > >> test.html:17 1 2002
> > > > >> test.html:17 2 2003
> > > > >> test.html:17 3 2004
> > > > >> 
> > > > >> So shift is not the culprit.
> > > > > 
> > > > > I probably should/can render a dummy "note off" at time zero, maybe that
> > > > > is what you suggest? 
> > > > 
> > > > No!
> > > > 
> > > > I suggested that you debug your modules seperately,
> > > > intead of guessing how it works.
> > > > 
> > > > Then, if you are satisfied, you treat them as black boxes, and debug only 
> > > > the input and output paramreters [and other effects like midi].
> > > > 
> > > > I see you now understand more about thee module [function] in question,
> > > > but don't even realize the step you made.
> > > > 
> > > > -- 
> > > > Evertjan.
> > > > The Netherlands.
> > > > (Please change the x'es to dots in my emailaddress)
> > > 
> > > The logic behind what is going on in the function fails me.
> > > Could you give an advice all the values get print out but the last note is not played. Somehow the reason fails me.
> > > 
> > > var waittime = copyEv.shift();
> > > document.getElementById("keystream").value+="\n"+waittime+"\n";
> > > setTimeout(doPlayup, waittime);
> > > 
> > > function doPlayup() {
> > >     if (copyEv.length) {
> > >       noteMessage = [track[0].midiMess[pyp].data0, track[0].midiMess[pyp].data1, track[0].midiMess[pyp].data2]; 
> > >       output.send(noteMessage);
> > >       var waittime = copyEv.shift();
> > >       document.getElementById("keystream").value+=waittime+"\n";
> > >       pyp++;
> > >       setTimeout(doPlayup, waittime); 
> > >     } 
> > > }
> > 
> > Meanwhile i put the dummy note in there because that is the only way i see it done play all notes without undefined at end.
> 
> I admit i am a bit clueless about what is going on in the function, if anyone got the time to explain i am all ears.
> 
> I did know pretty much from the start howto resolve it though, a bit laughable maybe, but i can't see what is failing or rather howto adjust the behaviour of shift to fit the purpose.
> Anyhow here is my patch/solution to the problem ;)
> 
> last = copyEv[copyEv.length - 1]
> copyEv[copyEv.length]=last;
> var waittime = copyEv.shift();
> document.getElementById("keystream").value+="\n"+waittime+"\n";
> setTimeout(doPlayup, waittime);
> 
> function doPlayup() {
>     if (copyEv.length) {
>       noteMessage = [track[0].midiMess[pyp].data0, track[0].midiMess[pyp].data1, track[0].midiMess[pyp].data2]; 
>       output.send(noteMessage);
>       var waittime = copyEv.shift();
>       document.getElementById("keystream").value+=waittime+"\n";
>       pyp++;
>       setTimeout(doPlayup, waittime); 
>     } 
> }

https://www.youtube.com/watch?v=dsUXAEzaC3Q

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


#34964

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-05-01 23:11 -0700
Message-ID<9b6ee184-1465-4eb8-b7e6-527a78fbae12@googlegroups.com>
In reply to#34954
Den tisdag 1 maj 2018 kl. 10:29:16 UTC+2 skrev Evertjan.:
> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 01
> May 2018 in comp.lang.javascript: 
> 
> > The last midiMess is never played i guess it is inherent to the use of 
> > if array.length and shift()
> > 
> > And if i do write if (copyEv.length+1), it play last but i get undefined
> > which i guess is from try to shift something that isn't there....
> > Correct? 
> > 
> 
> Methinks you guess 'wrongly', to quote Trumpian.
> 
> Instead of guessing, you should modularly debug your code:
> 
> <script type='text/javascript'> 'use strict'
> 
> let pyp = 0;
> let copyEv = [2001,2002,2003,2004];
> 
> doPlayup();
> 
> function doPlayup() {
>     if (copyEv.length) {
>       var waittime = copyEv.shift();
>       if(pyp>-1) {
>             //noteOnMessage = [....]; 
>             //output.send(noteOnMessage);
>            console.log(pyp, waittime);
>       }; 
>       //document.getElementById("keystream").value+=waittime+"\n";
>       pyp++;
>       setTimeout(doPlayup, waittime); 
>     };
> };
> </script>
> 
> console output:
> 
> test.html:17 0 2001
> test.html:17 1 2002
> test.html:17 2 2003
> test.html:17 3 2004
> 
> So shift is not the culprit.
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Should i put a wait outside function, before doing the first call maybe?
I just want to know how it is generally solved, because i guess there must be a worked out method to approach these type of problem?
It seem they must be common? 

In my mind two approaches appear, either you fake an event, or init the first wait outside the function.

But to be honest both those methods really seem like workarounds to me.

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


#34945

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-04-30 00:43 -0700
Message-ID<01218288-76d8-4db0-bded-fe9e831653c3@googlegroups.com>
In reply to#34943
Den måndag 30 april 2018 kl. 05:43:13 UTC+2 skrev JJ:
> On Sun, 29 Apr 2018 17:27:27 -0700 (PDT), Jonas Thörnvall wrote:
> > Is there a reason for the function below to have bad timing? 
> > The copyEv hold microseconds.
> > 
> > function doPlayup() {
> >     if (copyEv.length-1) {
> >       var waittime = copyEv.shift();
> >       if(pyp>-1) {
> >             noteOnMessage = [track[tracknr].midiMess[pyp].data0, track[tracknr].midiMess[pyp].data1, track[tracknr].midiMess[pyp].data2]; 
> >             output.send(noteOnMessage);
> >       } 
> >       pyp++;
> >       setTimeout(doPlayup, waittime); 
> >     } 
> > }
> 
> You should do that in a worker thread instead of the main thread, because
> the main thread does many thing (e.g. DOM events, page rendering, etc.)
> which may cause queued timer (including event) handler executions to be
> postponed.



Well i never experience any timing issues when i just echo the the signal to port "play live". It is just one condition, one shift and one counter add.

Of course there is a possibility that the timing issues comes from the recording path i have no external sequenser, so it is hard to check.

function record(message){
 clock=clock+rs;
 midievent++;
   track[tracknr].midiMess.push({time:clock,data0:message.data[0],data1:message.data[1],data2:message.data[2]});
  x++; 
 console.log("Track="+tracknr);
}

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


Page 1 of 2  [1] 2  Next page →

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


csiph-web