//midi input - note, velocity //variable input - widthVar, padding, spaceBtwn, lengthCrop, overlap inlets = 10; var note1 = 0; var prevnote1 = 0; var velocity1 = 0; var prevelocity1 = 0; var note2 = 0; var prevnote2 = 0; var velocity2 = 0; var prevelocity2 = 0; var note3 = 0; var prevnote3 = 0; var velocity3 = 0; var prevelocity3 = 0; var note4 = 0; var prevnote4 = 0; var velocity4 = 0; var prevelocity4 = 0; var widthVar = 0; var padding = 0; var spaceBtwn = 12.2; var lengthCrop = 0; var overlap = 0; var keyMax = 71; var keyWidth; var keyHeightMax = 573; var keyHeightMin = 186; var maxOverlap = -80; var minOverlap = -33; var keyHeight = 0; var lower = true; var keyIndex = 0; var width = 2500; var height = 1500; var origin = width/2; var noteval = new Array(); var x1 = new Array(); var y1 = new Array(); var x2 = new Array(); var y2 = new Array(); var noteIndex = 24; var mode = false; var prevmode = false; var sketch = new JitterObject("jit.gl.sketch","marimba"); var handle = new JitterObject("jit.gl.handle","marimba"); sketch.glenable("blend"); //input variables function msg_float(a) { switch(inlet) { case(0): note1 = a; break; case(1): velocity1 = a; break; case(2): note2 = a; break; case(3): velocity2 = a; break; case(4): note3 = a; break; case(5): velocity3 = a; break; case(4): note4 = a; break; case(5): velocity4 = a; break; case(8): spaceBtwn = a; break; case(9): mode = a; break; } bang(); } function bang() { sketch.reset(); origin = width/2; noteIndex = 24; for (var current=1; current<=keyMax; current++) { getKeyWidth(current); keyHeight = map(current, 1, 71, keyHeightMax, keyHeightMin); overlap = map(current, 1, 71, maxOverlap, minOverlap); //up or down? if (current%2!=0) { //if odd, on bottom x1[noteIndex] = map(keyIndex,0.,width,-1.,1.); y1[noteIndex] = map(origin, 0.,width,-1.,1.); x2[noteIndex] = map(keyIndex + keyWidth,0.,width,-1.,1.); y2[noteIndex] = map(origin+overlap-keyHeight,0.,width,-1.,1.); noteIndex++; //sketch.glrect(keyIndex, origin, keyIndex + keyWidth, origin-keyHeight); } else { //if even, on top if ((current!=6) && (current!=14) && (current !=20) && (current !=28) && (current !=34) && (current !=42) && (current !=48) && (current !=56) && (current !=62) && (current !=70)) { //DRAW TOP ROW x1[noteIndex] = map(keyIndex,0.,width,-1.,1.); y1[noteIndex] = map(origin+overlap,0.,width,-1.,1.); x2[noteIndex] = map(keyIndex + keyWidth,0.,width,-1.,1.); y2[noteIndex] = map(origin+overlap+keyHeight,0.,width,-1.,1.); noteIndex++; //sketch.glrect(keyIndex, origin+overlap, keyIndex + keyWidth, origin+overlap - keyHeight); } } keyIndex = keyIndex + keyWidth/2 + spaceBtwn; } keyIndex = 0; //noteIndex = 24; for (var current=1; current<=keyMax; current++) { getKeyWidth(current); keyHeight = map(current, 1, 71, keyHeightMax, keyHeightMin); overlap = map(current, 1, 71, 80, 33); //up or down? set rectmode and origin keyIndex = keyIndex + keyWidth/2 + spaceBtwn; } updateColor(); draw(); keyIndex = 0; sketch.glcolor(0.,0.,0.,1.); sketch.glrect(-1.5,-1.5,1.5,1.5); } function updateColor(){ if(mode==true){ for(var i = 24; i<85; i++){ noteval[i] = 1.; } prevmode = true; } if(mode==false){ if(prevmode == true){ for(var i = 24; i<85; i++){ noteval[i] = 0.; prevmode = false; } } if((velocity1!=prevelocity1) || (note1!=prevnote1)){ noteval[note1]=map(velocity1,0.,127.,0.,1.); noteval[prevnote1] = 0.; prevelocity1 = velocity1; prevnote1 = note1; } if((velocity2!=prevelocity2) || (note2!=prevnote2)){ noteval[note2]=map(velocity2,0.,127.,0.,1.); noteval[prevnote2] = 0.; prevelocity2 = velocity2; prevnote2 = note2; } if((velocity3!=prevelocity3) || (note3!=prevnote3)){ noteval[note3]=map(velocity3,0.,127.,0.,1.); noteval[prevnote3] = 0.; prevelocity3 = velocity3; prevnote3 = note3; } if((velocity4!=prevelocity4) || (note4!=prevnote4)){ noteval[note4]=map(velocity4,0.,127.,0.,1.); noteval[prevnote4] = 0.; prevelocity4 = velocity4; prevnote4 = note4; } } } function draw(){ for(var i = 24; i<85; i++){ sketch.glcolor(noteval[i],noteval[i],noteval[i],1.); sketch.glrect(x1[i],y1[i],x2[i],y2[i]); } } function getKeyWidth(counter){ //set width according to current //1-4 = 71 if(counter>=1 && counter<=4){ keyWidth = 71 + widthVar; } //5-18 = 66 if(counter>=5 && counter<=18){ keyWidth = 66 + widthVar; } //19-21 = 61 if(counter>=19 && counter<=21){ keyWidth = 61 + widthVar; } //22-27 = 57 if(counter>=22 && counter<=27){ keyWidth = 57 + widthVar; } //29-35 = 52 if(counter>=29 && counter<=35){ keyWidth = 52 + widthVar; } //36-48 = 47 if(counter>=36 && counter<=48){ keyWidth = 47 + widthVar; } //49-63 = 43 if(counter>=49 && counter<=63){ keyWidth = 43 + widthVar; } //64-71 = 39 if(counter>=64 && counter<=71){ keyWidth = 39 + widthVar; } } function map(num, curlow, curhigh, destlow, desthigh) { var newvalue; newvalue = (((num - curlow) * (desthigh - destlow)) / (curhigh - curlow)) + destlow; return newvalue; }