X-Received: by 2002:a24:d903:: with SMTP id p3-v6mr551758itg.41.1524838428354; Fri, 27 Apr 2018 07:13:48 -0700 (PDT) X-Received: by 2002:a9d:703:: with SMTP id 3-v6mr160700ote.11.1524838428163; Fri, 27 Apr 2018 07:13:48 -0700 (PDT) Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!k65-v6no390329ita.0!news-out.google.com!b185-v6ni552itb.0!nntp.google.com!k65-v6no390326ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.javascript Date: Fri, 27 Apr 2018 07:13:47 -0700 (PDT) In-Reply-To: <38e0bd1d-f418-418a-8d33-1a0ac2a868ad@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=84.217.164.223; posting-account=kxPkPAoAAACjJi8w0gL9bnyznPzdw9HW NNTP-Posting-Host: 84.217.164.223 References: <0e350c91-26c3-4ee3-838c-8873745b92f6@googlegroups.com> <38e0bd1d-f418-418a-8d33-1a0ac2a868ad@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Playup Event list hangs From: =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= Injection-Date: Fri, 27 Apr 2018 14:13:48 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 4389 X-Received-Body-CRC: 3108777354 Xref: csiph.com comp.lang.javascript:34930 Den torsdag 26 april 2018 kl. 12:23:44 UTC+2 skrev Jonas Th=C3=B6rnvall: > Den torsdag 26 april 2018 kl. 11:03:28 UTC+2 skrev Evertjan.: > > =3D?UTF-8?Q?Jonas_Th=3DC3=3DB6rnvall?=3D wr= ote on 26 > > Apr 2018 in comp.lang.javascript:=20 > >=20 > > > I have a list of timings where each time refer to playup of a midinot= es. > > > See noteOnMessage below. > > >=20 > > > 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++.=20 > > >=20 > > > I probably do not understand how the recursive call i tried to implem= ent > > > work, because it hangs after second event/note is played?=20 > >=20 > > Methinks you do not understand proper debugging, > > as viewing the value of y in each recursion would have given it away. > > =20 > > > function doPlayup(y) { > > > if (waitEv.length) { > > > var waittime =3D waitEv.shift(); > > > console.log("Waiting: " + waittime); > > > noteOnMessage =3D [track[tracknr].midiMess[y].data0, > > > track[tracknr].midiMess[y].data1, > > > track[tracknr].midiMess[y].data2]; output.send(noteOnMessage)= ;=20 > > > document.getElementById("keystream").value=3DwaitEv[y]; > > > y++;=20 > > > setTimeout(doPlayup, waittime); > > > }=20 > > >} > >=20 > > Your function is not recursive in the sense of scope, > > as the setTimeout() does not conduct the nonglobal y value. > >=20 > > perhaps it would 'work' like this: > >=20 > > let y=3D17; > > doPlayup(); > >=20 > > function doPlayup() { > > ..... > > }; > >=20 > > but then, global variables are prone to misconceptions. > >=20 > > --=20 > > Evertjan. > > The Netherlands. > > (Please change the x'es to dots in my emailaddress) >=20 > Thanks for the advice, Evertjan >=20 > 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. >=20 > pyp=3D-1; > doPlayup(); > noteOnMessage =3D [track[tracknr].midiMess[pyp].data0, track[trac= knr].midiMess[pyp].data1, track[tracknr].midiMess[pyp].data2];=20 > output.send(noteOnMessage); >=20 > function doPlayup() { > if (waitEv.length) { > var waittime =3D waitEv.shift(); > console.log("Waiting: " + waittime); > if (pyp>-1)=20 > { > noteOnMessage =3D [track[tracknr].midiMess[pyp].data0, track[trac= knr].midiMess[pyp].data1, track[tracknr].midiMess[pyp].data2];=20 > output.send(noteOnMessage);=20 > } > pyp++;=20 > setTimeout(doPlayup, waittime);=20 > }=20 > } 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 k= ind of loop is preferable for this type of problem?=20 And i am a bit curious how good programmers use shift in cases like this?