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


Groups > comp.lang.javascript > #35247

Re: Pair matching algorithm "hard?"

Newsgroups comp.lang.javascript
Date 2018-06-20 10:19 -0700
References <81af6402-843a-4d3a-a888-81d9776e6bbe@googlegroups.com> <1740bf3f-993a-4546-8e60-1f246499e39e@googlegroups.com> <13th7ihqnys6m.1py2jfza3m6y2.dlg@40tude.net>
Message-ID <374aa467-b685-49a8-b1a4-6c2cd52689fa@googlegroups.com> (permalink)
Subject Re: Pair matching algorithm "hard?"
From Jonas Thörnvall <jonas.thornvall@gmail.com>

Show all headers | View raw


Den onsdag 20 juni 2018 kl. 15:31:28 UTC+2 skrev JJ:
> On Wed, 20 Jun 2018 03:31:03 -0700 (PDT), Jonas Thörnvall wrote:
> 
> > Den onsdag 20 juni 2018 kl. 12:26:26 UTC+2 skrev Jonas Thörnvall:
> >> I have a two valued pair. One value is data let say characters. The other value denotes if it a start or end value. A value can not restart until it ended.
> >> 
> >> I have written an algorithm that match up the start and ends, but i think i got it overly complicated. In reality the start and end values also carry time, but it is not necessary for the actual algorithm. So it is a stepthru algorithm, you can think of the values as an array arr[].ch and arr[].temporal
> >> 
> >> C start
> >> Z start
> >> C end
> >> B start
> >> Z end
> >> B end
> >> C start
> >> K start
> >> R start
> >> R end
> >> K end
> >> C end
> > 
> > Does this look alright?
> > 
> > function listTrackEvents(z){
> >   eventlist="";
> >   for (var i=0;i<track[z].midiMess.length;i++){
> >    //Generate textstring eventlist
> >    if(track[z].midiMess[i].data0=="128"){ }
> >    else if(track[z].midiMess[i].data0=="144"){
> >        notenumber=track[z].midiMess[i].data1;
> >        note=getNote(notenumber);
> >        eventlist+=note;
> >        eventlist+=" t="+track[z].midiMess[i].time.toFixed(3)+"\n"; 
> >        j=i+1;
> >        while(track[z].midiMess[j].data1!=notenumber){
> >          j++;       
> >        }
> >        duration=track[z].midiMess[j].time-track[z].midiMess[i].time;
> >        eventlist+=" Duration "+duration+"\n";
> >        eventlist+=" Vel "+track[z].midiMess[i].data2+"\n";
> >     } 
> >    }
> >   document.getElementById("events").value=eventlist;
> > }
> 
> You forgot to take account of the MIDI channel.
> 
> Use an "note" cache for all 16 MIDI channels. e.g.
> 
>   var noteCache = [
>     {}, {}, {}, {}, {}, {}, {}, {},
>     {}, {}, {}, {}, {}, {}, {}, {}
>   ];
> 
> When encountering a Channel event, store the event's channel number to e.g.
> `channelNum` variable.
> 
> When encountering a NoteOn event, store it in the cache. e.g.
> 
>   if (message.event === msgNoteOn) {
>     noteCache[channelNum][message.noteNumber] = message.time;
>   }
> 
> When encountering a NoteOff event, check it from the "note" cache. If found,
> calculate the duration, then remove it from the cache. e.g.
> 
>   if (message.event === msgNoteOff) {
>     if (message.noteNumber in noteCache[channelNum]) {
>       duration = message.time - noteCache[channelNum][message.noteNumber];
>       delete noteCache[channelNum][message.noteNumber];
>     }
>   }

Oh this is just **listing** maybe later for the editor. I list the notes in order, and find the note off. So these are already recorded notes.

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


Thread

Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 03:26 -0700
  Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 03:31 -0700
    Re: Pair matching algorithm "hard?" Wally W. <ww84wa@aim.com> - 2018-06-20 08:45 -0400
      Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 10:16 -0700
    Re: Pair matching algorithm "hard?" JJ <jj4public@vfemail.net> - 2018-06-20 20:31 +0700
      Re: Pair matching algorithm "hard?" JJ <jj4public@vfemail.net> - 2018-06-20 20:37 +0700
        Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 10:22 -0700
        Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 10:55 -0700
          Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 11:26 -0700
            Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 13:12 -0700
              Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 13:15 -0700
                Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 13:20 -0700
                Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 13:26 -0700
        Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-24 09:17 -0700
          Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-24 09:27 -0700
      Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 10:19 -0700
      Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 10:28 -0700
        Re: Pair matching algorithm "hard?" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-20 10:37 -0700

csiph-web