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


Groups > comp.lang.javascript > #36172

Re: Realtime pianoroll "scroll" logic

Newsgroups comp.lang.javascript
Date 2019-03-26 07:46 -0700
References (4 earlier) <98c398bb-ec87-4bd5-9d2d-6d1a1ce363c3@googlegroups.com> <7o6i9e1l8t5ak76vg04rf4e90vu3k80775@4ax.com> <f7ea2627-ae14-4a9e-8179-ea9c3cd4b421@googlegroups.com> <7aaefad9-a42b-4720-aa12-2121f143fe44@googlegroups.com> <a7177c3f-b901-4a04-bd66-fa180a5d4007@googlegroups.com>
Message-ID <91c62d4b-1395-4f2c-a681-fbcd31e6ee33@googlegroups.com> (permalink)
Subject Re: Realtime pianoroll "scroll" logic
From Jonas Thörnvall <jonas.thornvall@gmail.com>

Show all headers | View raw


Den tisdag 26 mars 2019 kl. 15:25:01 UTC+1 skrev Jonas Thörnvall:
> Den tisdag 26 mars 2019 kl. 10:04:51 UTC+1 skrev Jonas Thörnvall:
> > Den tisdag 26 mars 2019 kl. 08:17:14 UTC+1 skrev Jonas Thörnvall:
> > > Den måndag 25 mars 2019 kl. 19:17:25 UTC+1 skrev John G Harris:
> > > > On Mon, 25 Mar 2019 06:04:58 -0700 (PDT), Jonas Thörnvall
> > > > <jonas.thornvall@gmail.com> wrote:
> > > > 
> > > >   <snip>
> > > > >what happen if you read thru array in loop in one thread and at same time insert elements into it with unshift() in another trhead???
> > > > 
> > > > If the threads can really interleave then chaos.
> > > > 
> > > > If they can't then you might not know whether reading or updating will
> > > > be done first.
> > > > 
> > > >   John
> > > 
> > > I guess one can not insert elements from start keeping the indexes, because that would mean element with negative index. Can arrays in javascript have indexes with negative values, where the first element negative?
> > > 
> > > An array is a stack of indexes and pointers?
> > > If you create an array and start to insert elements at index 7, is index 0-6 there anyway holding null pointers?
> > 
> > Well the change was just a unshift to push got first case working.
> > 
> > var midiEv=0;
> > var xFrontStart=[];
> > var FRONTOFFSET=[];
> > var xBarLength=[];
> > var keyreleased=[]; 
> > backStuck=50;
> > for (var p=0;p<3000;p++) {xFrontStart[p]=0;FRONTOFFSET[p]=0;keyreleased[p]=false;}
> > 
> > function pianoSCROLL(){
> > 
> > nbrOfEv = pianoroll.length;
> >  
> >   while (nbrOfEv>0){
> >      midiEv=nbrOfEv-1;
> >      
> >      //p.stop();
> >     // When still holding key only front moves
> >     // While key not released back is stuck at start of pianoroll "stroke not released still going"
> >     if(pianoroll[midiEv].data0==NOTE_ON && keyreleased[midiEv]==false){
> >         console.log("nbrOfEv="+nbrOfEv); 
> >         console.log("frontmove");
> >         ctm.fillStyle = "magenta";
> >         ctm.fillRect(backStuck,(PistartX+keyHeight*88)-(keyHeight*(pianoroll[midiEv].data1-8)), xFrontStart[midiEv],keyHeight);
> >         //When ***A NEW*** key pressed a startpoint relative the scrollbar created ***FRONTOFFSET***
> >         if(FRONTOFFSET[midiEv]==0) {FRONTOFFSET[midiEv]=scrollBarPos;}
> >         xFrontStart[midiEv]=scrollBarPos-FRONTOFFSET[midiEv];
> >         console.log("FRONTOFFSET[midiEv]="+FRONTOFFSET[midiEv]+" midiEv="+midiEv);
> >    
> >     //These events should have a moving backend  in sync with the moving front because NOTE_ON midiEv AND keyreleased[midiev]=true
> >     //So midiEv *fixed* barlength has been calculated below
> >     } 
> >     /* else  if (pianoroll[midiEv].data0==NOTE_ON && keyreleased[midiEv]==true) {
> >       console.log("bothmove");
> >       ctm.fillStyle = "black";
> >       ctm.fillRect(backStuck, (PistartX+keyHeight*88)-(keyHeight*(pianoroll[midiEv].data1-8)), Mwidth, keyHeight+2);
> >       //Math.round(all the values); maybe not needed
> >       moveFront=scrollBarPos-FRONTOFFSET[midiEv];
> >       moveBack=moveFront-xBarLength[midiEv];
> >       ctm.fillStyle = "orange";
> >       ctm.fillRect(moveBack,(PistartX+keyHeight*88)-(keyHeight*(pianoroll[midiEv].data1-8)),moveFront,keyHeight);
> >    
> >     //If a KEY EVENT Equal **released***, must find the matching KEYPRESS by looking forward 
> >     //KEYPRESS should be after the keyrelease in array because "current time" insert from start.... 
> >     //Q ***should*** be the not
> > 
> >     } else if(pianoroll[midiEv].data0==NOTE_OFF && keyreleased[midiEv]==false){
> >       console.log("keyreleased!");
> >       for(var q=0;q<midiEv;q++){ 
> >            if(pianoroll[q].data1==pianoroll[midiEv].data1) { keyreleased[q]=true; xBarLength[q]=xFrontStart[midiEv]-backStuck; }
> >       }
> >     keyreleased[midiEv]=true;
> >    } 
> >   */
> >   nbrOfEv--; 
> >   }
> > 
> > }
> 
> Well except for strikingout painted keystrokes on same note, there is just the logical conundrum left.
> 
>    moveFront=scrollBarPos-FRONTOFFSET[midiEv];
>    moveBack=moveFront-xBarLength[midiEv];
> 
> If scrollBarPos is a moving target each call, and FRONTOFFSET is a constant xBarlength is a constant.
> 
> How could possibly the length of rectangle created by moveBack and moveFront vary.
> I can't wrap my head around it.
> 
>  ctm.fillRect(moveBack,(PistartX+keyHeight*88)-(keyHeight*(pianoroll[midiEv].data1-8)),moveFront,keyHeight);
> 
> 
> http://midisequenser.000webhostapp.com

https://www.youtube.com/watch?v=mnTX2p22CWs

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


Thread

Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-24 15:38 -0700
  Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-24 22:06 -0700
    Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-25 02:44 -0700
  Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-25 04:59 -0700
    Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-25 05:29 -0700
      Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-25 05:33 -0700
        Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-25 06:04 -0700
          Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-25 06:10 -0700
          Re: Realtime pianoroll "scroll" logic John G Harris <niam@jghnorth.org.uk.invalid> - 2019-03-25 18:17 +0000
            Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-26 00:17 -0700
              Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-26 02:04 -0700
                Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-26 07:24 -0700
                Re: Realtime pianoroll "scroll" logic Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-26 07:46 -0700
              Re: Realtime pianoroll "scroll" logic John G Harris <niam@jghnorth.org.uk.invalid> - 2019-03-26 19:17 +0000

csiph-web