Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34930
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2018-04-27 07:13 -0700 |
| References | <0e350c91-26c3-4ee3-838c-8873745b92f6@googlegroups.com> <XnsA8D07059C8B9Beejj99@194.109.6.166> <38e0bd1d-f418-418a-8d33-1a0ac2a868ad@googlegroups.com> |
| Message-ID | <ba71434b-e5b7-440c-a810-14dd2e91fb94@googlegroups.com> (permalink) |
| Subject | Re: Playup Event list hangs |
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
Den torsdag 26 april 2018 kl. 12:23:44 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 26 april 2018 kl. 11:03:28 UTC+2 skrev Evertjan.:
> > =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 26
> > Apr 2018 in comp.lang.javascript:
> >
> > > I have a list of timings where each time refer to playup of a midinotes.
> > > See noteOnMessage below.
> > >
> > > waitEv is a list of "wait times" between events, it is already
> > > precalculated i checked it is correct. I keep waitlists "timings" in
> > > sync with the events by simply step forward y++.
> > >
> > > I probably do not understand how the recursive call i tried to implement
> > > work, because it hangs after second event/note is played?
> >
> > Methinks you do not understand proper debugging,
> > as viewing the value of y in each recursion would have given it away.
> >
> > > function doPlayup(y) {
> > > if (waitEv.length) {
> > > var waittime = waitEv.shift();
> > > console.log("Waiting: " + waittime);
> > > noteOnMessage = [track[tracknr].midiMess[y].data0,
> > > track[tracknr].midiMess[y].data1,
> > > track[tracknr].midiMess[y].data2]; output.send(noteOnMessage);
> > > document.getElementById("keystream").value=waitEv[y];
> > > y++;
> > > setTimeout(doPlayup, waittime);
> > > }
> > >}
> >
> > Your function is not recursive in the sense of scope,
> > as the setTimeout() does not conduct the nonglobal y value.
> >
> > perhaps it would 'work' like this:
> >
> > let y=17;
> > doPlayup();
> >
> > function doPlayup() {
> > .....
> > };
> >
> > but then, global variables are prone to misconceptions.
> >
> > --
> > Evertjan.
> > The Netherlands.
> > (Please change the x'es to dots in my emailaddress)
>
> Thanks for the advice, Evertjan
>
> I am not used to these types of self referencing functions.
> And i try to figure out howto get ***the last note*** played?
> But it does not behave the way i expect.
>
> pyp=-1;
> doPlayup();
> noteOnMessage = [track[tracknr].midiMess[pyp].data0, track[tracknr].midiMess[pyp].data1, track[tracknr].midiMess[pyp].data2];
> output.send(noteOnMessage);
>
> function doPlayup() {
> if (waitEv.length) {
> var waittime = waitEv.shift();
> console.log("Waiting: " + waittime);
> 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);
> }
> }
Well of course i could use the ugly method adding a last note patch message, put a tail on it. Maybe shift just is not a good use in this case? What kind of loop is preferable for this type of problem?
And i am a bit curious how good programmers use shift in cases like this?
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-26 01:47 -0700
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-26 01:57 -0700
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-26 02:27 -0700
Re: Playup Event list hangs "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-04-26 11:02 +0200
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-26 03:23 -0700
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-27 07:13 -0700
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-27 07:25 -0700
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-27 07:30 -0700
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-29 12:59 -0700
Re: Playup Event list hangs "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-04-29 22:14 +0200
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-29 15:45 -0700
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-29 15:47 -0700
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-29 16:39 -0700
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-29 16:57 -0700
Re: Playup Event list hangs Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-04-29 17:06 -0700
csiph-web