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


Groups > comp.lang.javascript > #34511

Re: Accessing clock for playup of timed events, "sequenser"

Newsgroups comp.lang.javascript
Date 2018-01-08 00:50 -0800
References <206a2e6b-9262-45f2-8bcd-52494069d2cb@googlegroups.com> <72e5b95b-c999-4a2d-a676-ede95207427c@googlegroups.com> <e160f530-8a8a-4007-aea0-b69ec59cf10a@googlegroups.com> <4b10686b-7a80-4a9d-8185-235ea3042be7@googlegroups.com>
Message-ID <a0f647c2-0e05-4e68-b22e-bda937b54fa1@googlegroups.com> (permalink)
Subject Re: Accessing clock for playup of timed events, "sequenser"
From Jonas Thörnvall <jonas.thornvall@gmail.com>

Show all headers | View raw


Den måndag 8 januari 2018 kl. 08:33:36 UTC+1 skrev Jonas Thörnvall:
> Den måndag 8 januari 2018 kl. 07:34:20 UTC+1 skrev Jonas Thörnvall:
> > Den måndag 8 januari 2018 kl. 07:24:26 UTC+1 skrev Jonas Thörnvall:
> > > Den måndag 8 januari 2018 kl. 07:20:19 UTC+1 skrev Jonas Thörnvall:
> > > > I have timed events stored, in an "object?" that did get the clock using performance.now(), however now i need a running timer that send these events.
> > > > 
> > > > And i am clueless about both how one deal with timecritical events both in general and in javascript. Should i "poll/request?" the timer/clock again and again?
> > > 
> > > In principle is this the approach, or is there most sophisticated ways?
> > > 
> > > function refresh() {
> > >     // make Ajax call here, inside the callback call:
> > >     setTimeout(refresh, 5000);
> > >     // ...
> > > }
> > > 
> > > // initial call, or just call refresh directly
> > > setTimeout(refresh, 5000);
> > 
> > Something like this?
> > 
> > function play()
> >   while(playmidi){
> >   time=performance.now();
> > //How big is the chance that multiple event have same value should i compare                //with as many values as the polyphony of device?
> > //comparisson with time in array and then...
> >   output.send(noteOnMessage);
> >   }
> 
> 
> function makeTrack()
> {
>    for (var m = 0; m < 16; m ++ )
>    {
>      track[m] ={
>      tid:[],
>      data0:[],
>      data1:[],
>      data2:[]
>    };
>    }
>    return track;
> }
> 
> I think my object maybe has wrong structure for the purpose, but It seem to work this way to?
> I want the time object to hold the data messages "i think?" so i can pop a full message or, or maybe a message that hold them all? I mean i can't pop the track?
> But i am really unsure about the convention for howto create javascript objects.
> 
> function makeTrack()
> {
> 
>    track[] ={
>         message[]={
>              tid:0,
>              data0:0,
>              data1:0,
>              data2:0
>         };
>    }
>    return track;
> }
> 
> How should such an object look like and howto access it, is the above correct? time=track[x].message[y].tid;
> 
> Will this have worse access time then the former?

Well this is the playback of the recorded event i came up with any suggestions for improvement welcome. I do realise that one probably would reset the ***recorded*** events to t0=0, but since this only is recorded in memory i don't care. I was a bit worried about losing polyphony playing up this way but to check if the recorded event time is less then clock seems to work nice.

function play(){
  lastelement=track[1].time.length;
  var x=0;var time=0; var starttime=0; var clock=0;
  var time=performance.now();
  starttime=time;
  while(x<lastelement){
    var time=performance.now();
    clock=time-starttime; 
    if(track[1].time[x]<=clock){
        var noteOnMessage = [track[1].data0[x],track[1].data1[x],track[1].data2[x]];
        output.send(noteOnMessage);  
     x++;
    }
 
  }
}

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


Thread

Accessing clock for playup of timed events, "sequenser" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-07 22:20 -0800
  Re: Accessing clock for playup of timed events, "sequenser" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-07 22:24 -0800
    Re: Accessing clock for playup of timed events, "sequenser" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-07 22:34 -0800
      Re: Accessing clock for playup of timed events, "sequenser" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-07 23:33 -0800
        Re: Accessing clock for playup of timed events, "sequenser" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-08 00:50 -0800
          Re: Accessing clock for playup of timed events, "sequenser" Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-08 00:52 -0800

csiph-web