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


Groups > comp.lang.javascript > #34977

Re: Bad timing

Newsgroups comp.lang.javascript
Date 2018-05-04 00:49 -0700
References (8 earlier) <8393b918-3835-4958-a8ac-0b48f58d4a46@googlegroups.com> <XnsA8D674D0F71ADeejj99@194.109.6.166> <b7abfe84-27f7-4cac-b6e9-dca76fccacdb@googlegroups.com> <423604bf-a765-44cb-9117-3cf535f44a0c@googlegroups.com> <0c11709c-6863-4aeb-a39f-33fe99e73706@googlegroups.com>
Message-ID <3499bc18-a698-4b77-86ef-068faa478431@googlegroups.com> (permalink)
Subject Re: Bad timing
From Jonas Thörnvall <jonas.thornvall@gmail.com>

Show all headers | View raw


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

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web