tisdag 26 oktober 2021 kl. 07:38:21 UTC+2 skrev Jonas Thörnvall:http://jtmidi.000webhostapp.com/
I have this function drawNotesCanvas that behave different depending on else leg although the same call to function as other leg?
What i want todo is draw out all tracks if track is zero, track zero is the "downmix of all tracks", used during playup.
But even if i hardcode channel and remove loop, it does not to what the other "single channel" else leg do. It has gotten me bewilderd for months "years".
snippet
============
if (activetrack==0){
//for (var i=1;i<=maxtrack;i++){
drawtrack=1; //1,2,3 or whatever channel do not do same as other leg notePlot();
// }
} else {
drawtrack=activetrack;
notePlot();
}
}
fullcode
==================
var graphNotePosX= [];
var graphNotePosY= [];
var graphNoteLength= [];
var graphNoteHeight= [];
var graphNoteEvent= [];
var trColor=[];
trColor[0]="yellow";
trColor[1]="magenta";
trColor[2]="lightgrey";
trColor[3]="skyblue";
trColor[4]="yellow";
trColor[5]="fuchsia";
trColor[6]="pink";
trColor[7]="magenta";
trColor[8]="orange";
trColor[9]="cyan";
trColor[10]="white";
trColor[11]="lightgreen";
trColor[12]="silver";
trColor[13]="lightblue";
trColor[14]="olive";
trColor[15]="red";
trColor[16]="aqua";
// CLEAR NOTES ON CANVAS
function delRenderedNotes() {
ctm.fillStyle = "black";
ctm.fillRect(46, 24, Mwidth, Mheight);
}
// FETCH VALUES WHERE TO DRAW IN VIEW MODE
function drawNotesCanvas(){
startPoint=0;
endPoint=Mwidth;
editSPos=document.getElementById("SB").value; editEPos=document.getElementById("EB").value; TimeSPos=document.getElementById("EditStart").value; TimeSPos=parseInt(TimeSPos); TimeEPos=document.getElementById("EditEnd").value; TimeEPos=parseInt(TimeEPos);
if (activetrack==0){
for (var i=1;i<=maxtrack;i++){
drawtrack=i;
notePlot();
}
} else {
drawtrack=activetrack;
notePlot();
}
}
// DRAWOUT NOTES ON MAIN CANVAS WHEN PAGE VIEW CHANGE
function notePlot(){
//console.log("NOTEPLOT TRACK="+drawtrack+" midiMess length="+track[drawtrack].midiMess.length);
var plotRightSide=0;var plotLeftSide=0;
var x=0;var z=0;var i=0;
nbrOfEV = track[drawtrack].midiMess.length; distanceTotal=Mwidth-keylength;
TimeTotal=TimeEPos-TimeSPos;
while (x<nbrOfEV-1){
if (track[drawtrack].midiMess[x].time>TimeSPos && track[drawtrack].midiMess[x].time<TimeEPos && track[drawtrack].midiMess[x].data0==NOTE_ON){
TimeOnLeft=track[drawtrack].midiMess[x].time-TimeSPos; TimePerc=TimeOnLeft/TimeTotal;
plotLeftSide=TimePerc*distanceTotal;
z=x+1;
TimeOnRight=TimeTotal-(TimeEPos-track[drawtrack].midiMess[z].time); TimePerc=TimeOnRight/TimeTotal;
plotRightSide=TimePerc*distanceTotal; recLength=plotRightSide-plotLeftSide;
ctm.fillStyle = trColor[drawtrack]; ctm.fillRect(50+plotLeftSide,(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8)),recLength,keyHeight-1);
//Saving the values of note graphic to array to compare with mouse graphNotePosX[i]=50+plotLeftSide; graphNotePosY[i]=(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8));By the way when i look at the code i wrote some/ a year ago i think there must be dark sorcery going on. It manages to draw out notelength just using the noteOn event, or maybe it doesn't....
graphNoteLength[i]=recLength;
graphNoteHeight[i]=keyHeight-1;
graphNoteEvent[i]=x;
i++;
}
x++;
}
}
Well i adjusted it apparently i thought i could just look at next event "or was lazy"....
function notePlot(){
//console.log("NOTEPLOT TRACK="+drawtrack+" midiMess length="+track[drawtrack].midiMess.length);
var plotRightSide=0;var plotLeftSide=0;
var x=0;var z=0;var i=0;
nbrOfEV = track[drawtrack].midiMess.length;
distanceTotal=Mwidth-keylength;
TimeTotal=TimeEPos-TimeSPos;
while (x<nbrOfEV-1){
if (track[drawtrack].midiMess[x].time>TimeSPos && track[drawtrack].midiMess[x].time<TimeEPos && track[drawtrack].midiMess[x].data0==NOTE_ON){
TimeOnLeft=track[drawtrack].midiMess[x].time-TimeSPos; TimePerc=TimeOnLeft/TimeTotal;
plotLeftSide=TimePerc*distanceTotal;
////////////////////////////////////
//THIS CODE FIND THE NOTE OFF EVENT
var q=x+1;
findNote=track[drawtrack].midiMess[x].data1;
while (track[drawtrack].midiMess[q].data1!=findNote) {
q++;
}
/////////////////////////////////// TimeOnRight=TimeTotal-(TimeEPos-track[drawtrack].midiMess[q].time); TimePerc=TimeOnRight/TimeTotal;
plotRightSide=TimePerc*distanceTotal;
recLength=plotRightSide-plotLeftSide;
ctm.fillStyle = trColor[drawtrack]; ctm.fillRect(50+plotLeftSide,(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8)),recLength,keyHeight-1);
//Saving the values of note graphic to array to compare with mouse graphNotePosX[i]=50+plotLeftSide; graphNotePosY[i]=(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8));
graphNoteLength[i]=recLength;
graphNoteHeight[i]=keyHeight-1;
graphNoteEvent[i]=x;
i++;
}
x++;
}
So i fixed "drawout" for note lengths "note off" but the multitrack draw at track zero, remain unsolved anyone got any idea?
I have this function drawNotesCanvas that behave different depending on else leg although the same call to function as other leg?By the way when i look at the code i wrote some/ a year ago i think there must be dark sorcery going on. It manages to draw out notelength just using the noteOn event, or maybe it doesn't....
What i want todo is draw out all tracks if track is zero, track zero is the "downmix of all tracks", used during playup.
But even if i hardcode channel and remove loop, it does not to what the other "single channel" else leg do. It has gotten me bewilderd for months "years".
snippet
============
if (activetrack==0){
//for (var i=1;i<=maxtrack;i++){
drawtrack=1; //1,2,3 or whatever channel do not do same as other leg notePlot();
// }
} else {
drawtrack=activetrack;
notePlot();
}
}
fullcode
==================
var graphNotePosX= [];
var graphNotePosY= [];
var graphNoteLength= [];
var graphNoteHeight= [];
var graphNoteEvent= [];
var trColor=[];
trColor[0]="yellow";
trColor[1]="magenta";
trColor[2]="lightgrey";
trColor[3]="skyblue";
trColor[4]="yellow";
trColor[5]="fuchsia";
trColor[6]="pink";
trColor[7]="magenta";
trColor[8]="orange";
trColor[9]="cyan";
trColor[10]="white";
trColor[11]="lightgreen";
trColor[12]="silver";
trColor[13]="lightblue";
trColor[14]="olive";
trColor[15]="red";
trColor[16]="aqua";
// CLEAR NOTES ON CANVAS
function delRenderedNotes() {
ctm.fillStyle = "black";
ctm.fillRect(46, 24, Mwidth, Mheight);
}
// FETCH VALUES WHERE TO DRAW IN VIEW MODE
function drawNotesCanvas(){
startPoint=0;
endPoint=Mwidth;
editSPos=document.getElementById("SB").value; editEPos=document.getElementById("EB").value; TimeSPos=document.getElementById("EditStart").value; TimeSPos=parseInt(TimeSPos); TimeEPos=document.getElementById("EditEnd").value; TimeEPos=parseInt(TimeEPos);
if (activetrack==0){
for (var i=1;i<=maxtrack;i++){
drawtrack=i;
notePlot();
}
} else {
drawtrack=activetrack;
notePlot();
}
}
// DRAWOUT NOTES ON MAIN CANVAS WHEN PAGE VIEW CHANGE
function notePlot(){
//console.log("NOTEPLOT TRACK="+drawtrack+" midiMess length="+track[drawtrack].midiMess.length);
var plotRightSide=0;var plotLeftSide=0;
var x=0;var z=0;var i=0;
nbrOfEV = track[drawtrack].midiMess.length;
distanceTotal=Mwidth-keylength;
TimeTotal=TimeEPos-TimeSPos;
while (x<nbrOfEV-1){
if (track[drawtrack].midiMess[x].time>TimeSPos && track[drawtrack].midiMess[x].time<TimeEPos && track[drawtrack].midiMess[x].data0==NOTE_ON){
TimeOnLeft=track[drawtrack].midiMess[x].time-TimeSPos; TimePerc=TimeOnLeft/TimeTotal;
plotLeftSide=TimePerc*distanceTotal;
z=x+1;
TimeOnRight=TimeTotal-(TimeEPos-track[drawtrack].midiMess[z].time); TimePerc=TimeOnRight/TimeTotal;
plotRightSide=TimePerc*distanceTotal;
recLength=plotRightSide-plotLeftSide;
ctm.fillStyle = trColor[drawtrack]; ctm.fillRect(50+plotLeftSide,(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8)),recLength,keyHeight-1);
//Saving the values of note graphic to array to compare with mouse graphNotePosX[i]=50+plotLeftSide; graphNotePosY[i]=(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8));
graphNoteLength[i]=recLength;
graphNoteHeight[i]=keyHeight-1;
graphNoteEvent[i]=x;
i++;
}
x++;
}
}
tisdag 26 oktober 2021 kl. 08:24:13 UTC+2 skrev Jonas Thörnvall:To be honest i am probably just silly about estethics, having all tracks up is probably just confusing but i wanted sort of a graphical overview of full song all tracks in different color just when loaded.
tisdag 26 oktober 2021 kl. 07:38:21 UTC+2 skrev Jonas Thörnvall:
I have this function drawNotesCanvas that behave different depending on else leg although the same call to function as other leg?
What i want todo is draw out all tracks if track is zero, track zero is the "downmix of all tracks", used during playup.
But even if i hardcode channel and remove loop, it does not to what the other "single channel" else leg do. It has gotten me bewilderd for months "years".
snippet
============
if (activetrack==0){
//for (var i=1;i<=maxtrack;i++){
drawtrack=1; //1,2,3 or whatever channel do not do same as other leg notePlot();
// }
} else {
drawtrack=activetrack;
notePlot();
}
}
fullcode
==================
var graphNotePosX= [];
var graphNotePosY= [];
var graphNoteLength= [];
var graphNoteHeight= [];
var graphNoteEvent= [];
var trColor=[];
trColor[0]="yellow";
trColor[1]="magenta";
trColor[2]="lightgrey";
trColor[3]="skyblue";
trColor[4]="yellow";
trColor[5]="fuchsia";
trColor[6]="pink";
trColor[7]="magenta";
trColor[8]="orange";
trColor[9]="cyan";
trColor[10]="white";
trColor[11]="lightgreen";
trColor[12]="silver";
trColor[13]="lightblue";
trColor[14]="olive";
trColor[15]="red";
trColor[16]="aqua";
// CLEAR NOTES ON CANVAS
function delRenderedNotes() {
ctm.fillStyle = "black";
ctm.fillRect(46, 24, Mwidth, Mheight);
}
// FETCH VALUES WHERE TO DRAW IN VIEW MODE
function drawNotesCanvas(){
startPoint=0;
endPoint=Mwidth;
editSPos=document.getElementById("SB").value; editEPos=document.getElementById("EB").value; TimeSPos=document.getElementById("EditStart").value; TimeSPos=parseInt(TimeSPos); TimeEPos=document.getElementById("EditEnd").value; TimeEPos=parseInt(TimeEPos);
if (activetrack==0){
for (var i=1;i<=maxtrack;i++){
drawtrack=i;
notePlot();
}
} else {
drawtrack=activetrack;
notePlot();
}
}
// DRAWOUT NOTES ON MAIN CANVAS WHEN PAGE VIEW CHANGE
function notePlot(){
//console.log("NOTEPLOT TRACK="+drawtrack+" midiMess length="+track[drawtrack].midiMess.length);
var plotRightSide=0;var plotLeftSide=0;
var x=0;var z=0;var i=0;
nbrOfEV = track[drawtrack].midiMess.length; distanceTotal=Mwidth-keylength;
TimeTotal=TimeEPos-TimeSPos;
while (x<nbrOfEV-1){
if (track[drawtrack].midiMess[x].time>TimeSPos && track[drawtrack].midiMess[x].time<TimeEPos && track[drawtrack].midiMess[x].data0==NOTE_ON){
TimeOnLeft=track[drawtrack].midiMess[x].time-TimeSPos; TimePerc=TimeOnLeft/TimeTotal;
plotLeftSide=TimePerc*distanceTotal;
z=x+1; TimeOnRight=TimeTotal-(TimeEPos-track[drawtrack].midiMess[z].time); TimePerc=TimeOnRight/TimeTotal;
plotRightSide=TimePerc*distanceTotal; recLength=plotRightSide-plotLeftSide;
ctm.fillStyle = trColor[drawtrack]; ctm.fillRect(50+plotLeftSide,(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8)),recLength,keyHeight-1);
//Saving the values of note graphic to array to compare with mouse graphNotePosX[i]=50+plotLeftSide; graphNotePosY[i]=(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8));By the way when i look at the code i wrote some/ a year ago i think there must be dark sorcery going on. It manages to draw out notelength just using the noteOn event, or maybe it doesn't....
graphNoteLength[i]=recLength;
graphNoteHeight[i]=keyHeight-1;
graphNoteEvent[i]=x;
i++;
}
x++;
}
}
Well i adjusted it apparently i thought i could just look at next event "or was lazy"....
function notePlot(){
//console.log("NOTEPLOT TRACK="+drawtrack+" midiMess length="+track[drawtrack].midiMess.length);
var plotRightSide=0;var plotLeftSide=0;
var x=0;var z=0;var i=0;
nbrOfEV = track[drawtrack].midiMess.length; distanceTotal=Mwidth-keylength;
TimeTotal=TimeEPos-TimeSPos;
while (x<nbrOfEV-1){
if (track[drawtrack].midiMess[x].time>TimeSPos && track[drawtrack].midiMess[x].time<TimeEPos && track[drawtrack].midiMess[x].data0==NOTE_ON){
TimeOnLeft=track[drawtrack].midiMess[x].time-TimeSPos; TimePerc=TimeOnLeft/TimeTotal;
plotLeftSide=TimePerc*distanceTotal;
////////////////////////////////////
//THIS CODE FIND THE NOTE OFF EVENT
var q=x+1;
findNote=track[drawtrack].midiMess[x].data1;
while (track[drawtrack].midiMess[q].data1!=findNote) {
q++;
}
/////////////////////////////////// TimeOnRight=TimeTotal-(TimeEPos-track[drawtrack].midiMess[q].time); TimePerc=TimeOnRight/TimeTotal;
plotRightSide=TimePerc*distanceTotal; recLength=plotRightSide-plotLeftSide;
ctm.fillStyle = trColor[drawtrack]; ctm.fillRect(50+plotLeftSide,(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8)),recLength,keyHeight-1);
//Saving the values of note graphic to array to compare with mouse graphNotePosX[i]=50+plotLeftSide; graphNotePosY[i]=(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8));http://jtmidi.000webhostapp.com/
graphNoteLength[i]=recLength;
graphNoteHeight[i]=keyHeight-1;
graphNoteEvent[i]=x;
i++;
}
x++;
}
So i fixed "drawout" for note lengths "note off" but the multitrack draw at track zero, remain unsolved anyone got any idea?
//Saving the values of note graphic to array to compare with mouse graphNotePosX[i]=50+plotLeftSide; graphNotePosY[i]=(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8));
graphNoteLength[i]=recLength;
graphNoteHeight[i]=keyHeight-1;
graphNoteEvent[i]=x;
On Tuesday, October 26, 2021 at 12:38:21 AM UTC-5, jonas.t...@gmail.com wrote:Yeah you are probably correct, but of course that is really just a region of "graphics" that is compared with mouse to be able to know if you clicked inside or outside object.
//Saving the values of note graphic to array to compare with mouse graphNotePosX[i]=50+plotLeftSide; graphNotePosY[i]=(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8));I (and others) have tried suggesting better abstraction to make your code more readable.
graphNoteLength[i]=recLength;
graphNoteHeight[i]=keyHeight-1;
graphNoteEvent[i]=x;
I think this block might be a good isolated example to try again.
This code just looks wrong. It's not the best use of data structure organization.
The graph note should be an object. All the named parts should be properties of
the object. And then since you need and array of them, make an array of them.
Consider if the code were rewritten like this (with corresponding changes to the data structure):
graphNote[i].PosX=50+plotLeftSide; graphNote[i].PosY=(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8));
graphNote[i].Length=recLength;
graphNote[i].Height=keyHeight-1;
graphNote[i].Event=x;
If this is the initialization of a new object, that could be made clearer by combining all the lines
into a single assignment of a new object.
graphNote[i] = {
PosX=50+plotLeftSide, PosY=(PistartX+keyHeight*88)-(keyHeight*(track[drawtrack].midiMess[x].data1-8)),
Length=recLength,
Height=keyHeight-1,
Event=x,
};
Or, you could go still further and wrap it in a function with a descriptive name:
save_new_graph_note( i, drawtrack, x );
Abstraction lets you write less code overall, have less code to read and debug, isolate changes
to small parts of the program, and improve organization and efficiency. As a bonus,
it makes the code easier for others to understand if they want to offer help.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 438 |
Nodes: | 16 (2 / 14) |
Uptime: | 241:49:35 |
Calls: | 9,145 |
Calls today: | 1 |
Files: | 13,432 |
D/L today: |
1 files (2,685K bytes) |
Messages: | 6,039,750 |