Skip to content

Commit

Permalink
Pixel-perfect line note style. #18 @ask-compu
Browse files Browse the repository at this point in the history
  • Loading branch information
PoneyClairDeLune committed Oct 20, 2023
1 parent 7bfd3f9 commit c90ff92
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/cambiare/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const metaNames = {
"XfSongBt",
"XfSngIns"
];
const lineDash = [[], [4, 4], [2, 2]];
const portPos = [{l: 0, t: 0}, {l: 0, t: 416}, {l: 960, t: 0}, {l: 960, t: 416}];

let createElement = function (tag, classes, details = {}) {
Expand Down Expand Up @@ -107,14 +108,17 @@ let classOn = function (target, classes) {
});
};

// Cache for CC register display heights
let heightCache = new Array(128).fill(0);
heightCache.forEach((e, i, a) => {
a[i] = Math.floor(24 * i / 12.7) / 10;
});
// Cache for panpot display widths
let widthCache = new Array(128).fill(0);
widthCache.forEach((e, i, a) => {
a[i] = Math.abs(Math.round(48 * (i - 64) / 12.7) / 10);
});
// Cache for the scale segments
let leftCache = new Array(11).fill(null);
leftCache.forEach((e, i, a) => {
a[i] = `${Math.round(i * 12 / 0.0128) / 100}%`;
Expand Down Expand Up @@ -192,13 +196,23 @@ let Cambiare = class extends RootDisplay {
border = range == 1 ? 3 : 1;
break;
};
case "line": {
let originPitch = note - pitch;
if (Math.abs(pitch) > 2) {
originPitch = note - Math.sign(pitch) * 2;
};
ex = Math.round((note + 0.5) * width / 128);
sx = Math.round((originPitch + 0.5) * width / 128);
};
default: {
// Nothing yet
};
};
// Colours
context.fillStyle = `#${isBlackKey ? (upThis.#accent) : "ffffff"}${((velo << 1) | (velo >> 6)).toString(16).padStart(2, "0")}`;
context.strokeStyle = context.fillStyle;
context.lineWidth = range == 1 ? 4 : 2;
context.lineDashOffset = 0;
// Draw calls
switch (upThis.#style) {
case "block": {
Expand Down Expand Up @@ -226,6 +240,32 @@ let Cambiare = class extends RootDisplay {
};
break;
};
case "line": {
if (isHeld) {
context.setLineDash(lineDash[range == 1 ? 1 : 2]);
switch (range) {
case 4: {
context.lineDashOffset = -1;
break;
};
default: {
context.lineDashOffset = 0;
};
};
} else {
context.setLineDash(lineDash[0]);
if (range != 4) {
sx += 0.5;
ex += 0.5;
};
};
context.beginPath();
context.moveTo(sx, (range == 4 || !isHeld) ? 2 : 1);
context.lineTo(ex, (height >> 1) + 2);
context.lineTo(sx, height + 2);
context.stroke();
break;
};
default: {
// Nothing yet
};
Expand Down

5 comments on commit c90ff92

@ask-compu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have been pinged

@PoneyClairDeLune
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have been pinged

The MegaMID-like line-styled notes are now present. Could you please check if they work correctly?

@ask-compu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do i go to check that?

@PoneyClairDeLune
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do i go to check that?

https://gh.ltgc.cc/octavia/test/cambiare.htm

Select "line" in note styles, and choose any demo to play. Demo c, g and demo 2 should be the most obvious ones.

@ask-compu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to be working, still need a way to sync the midi visuals with the audio file playback tho

Please sign in to comment.