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


Groups > comp.lang.javascript > #36151

Realtime pianoroll "scroll" logic

Newsgroups comp.lang.javascript
Date 2019-03-24 15:38 -0700
Message-ID <efe5cd64-b4ae-4553-8ad9-77422f159bcf@googlegroups.com> (permalink)
Subject Realtime pianoroll "scroll" logic
From Jonas Thörnvall <jonas.thornvall@gmail.com>

Show all headers | View raw


Recording, I now buffer the key strokes "note on and off" in an array. But the logic for a pianoroll isn't as plain and easy as i thought.

Now this is only a visual thingy so no ***exact time*** is needed for the calculation of pianoroll keystrokes "only position".

I can't see i missed any case, but the pianoroll does not behave as i expect.

CASE 1 KEY PRESSED STILL NOT RELEASED, FRONTEND MOVE INDEPENDENT OF LOCKED STARTPOINT "CALCULATE  FRONTEND RELATIVE SCROLLBAR ENTRYPOINT

CASE 2 KEY IS RELEASED, ***FIXED LENGTH*** OF KEYSTROKE CALCULATED

CASE 3 BOTH FRONTEND AND BACKEND MOVING synchronus, frontend calculated using offset relative scrollbar "same as CASE1", backend calculated using "LENGTH CASE 2" relative the frontend

I know it is hard to read others logic but i tried keep complexity to a minimum, maybe someone done something similar comoving thingy and have a good eye for logics.

http://midisequenser.000webhostapp.com/

var xKeylength=0;
var midiEv=0;
var xFrontStart=[];
var FRONTOFFSET=[];
var backStuck=0;
var keyreleased=[];
for (var p=0;p<300;p++) {xFrontStart[p]=0;FRONTOFFSET[p]=0;keyreleased[p]=false;}

function pianoSCROLL(){
console.log(pianoroll.length); 
var nbrOfEv = pianoroll.length;
  while (midiEv<nbrOfEv){
    
    // Pianoroll Array Events reversed last event "keypress" ***IS FIRST***, 
    
    // CASE one 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){
        backStuck=keylength;
        ctm.fillStyle = "magenta";
        ctm.fillRect(backStuck,(PistartX+keyHeight*88)-(keyHeight*(pianoroll[midiEv].data1-8)), xFrontStart[midiEv],keyHeight);
        //When key pressed a startpoint, relative scrollbar created ***FRONTOFFSET***
        if(FRONTOFFSET[midiEv]==0) {FRONTOFFSET[midiEv]=scrollBarPos;}
        xFrontStart[midiEv]=scrollBarPos-FRONTOFFSET[midiEv];
    
    //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.... 

    } else if(pianoroll[midiEv]==NOTE_OFF && keyreleased[midiEv]==false){
       console.log("keyreleased!");
       for(var q=midiEv+1;q<nbrOfEv;q++){
       if(pianoroll[q].data1==pianoroll[midiEv].data1) {keyreleased[q]=true; xBarLength[q]=xFrontStart[q]-xBackEnd;}
       }
    
    //These events should have a moving backend  in sync with the moving front

    } else  if (pianoroll[midiEv]==NOTE_OFF && keyreleased[midiEv]==true) {
      console.log("bothmove");
      ctm.fillStyle = "black";
      ctm.fillRect(keylength, (PistartX+keyHeight*88)-(keyHeight*(pianoroll[midiEv]-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]-8)),moveFront,keyHeight);
    }

  midiEv++; 
  }
  midiEv=0; 
}

Back to comp.lang.javascript | Previous | Next — 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