-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The CSS Update Part 3 - A bunch of fixes and tweaks
yeah
- Loading branch information
Showing
19 changed files
with
351 additions
and
251 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @enum {string} | ||
*/ | ||
export const keybinds = { | ||
synthesizerUIShow: "s", | ||
settingsShow: "r", | ||
|
||
blackMidiMode: "b", | ||
midiPanic: "backspace", | ||
|
||
playPause: " ", | ||
toggleLoop: "l", | ||
toggleLyrics: "t", | ||
seekBackwards: "arrowleft", | ||
seekForwards: "arrowright", | ||
previousSong: "[", | ||
nextSong: "]", | ||
|
||
cinematicMode: "c", | ||
videoMode: "v" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { isMobile } from '../utils/is_mobile.js' | ||
|
||
/** | ||
* @this {MidiKeyboard} | ||
* @private | ||
*/ | ||
export function _handlePointers() | ||
{ | ||
// POINTER HANDLING | ||
const userNoteOff = note => { | ||
this.pressedKeys.delete(note) | ||
this.releaseNote(note, this.channel); | ||
this.synth.noteOff(this.channel, note); | ||
} | ||
|
||
const userNoteOn = (note, clientY) => { | ||
// user note on | ||
this.pressedKeys.add(note); | ||
|
||
let velocity; | ||
if (isMobile) | ||
{ | ||
// ignore precise key velocity on mobile (keys are too small anyways) | ||
velocity = 127; | ||
} | ||
else | ||
{ | ||
// determine velocity. lower = more velocity | ||
const keyElement = this.keys[note]; | ||
const rect = keyElement.getBoundingClientRect(); | ||
// Handle both mouse and touch events | ||
const relativeMouseY = clientY - rect.top; | ||
const keyHeight = rect.height; | ||
velocity = Math.floor(relativeMouseY / keyHeight * 127); | ||
} | ||
this.synth.noteOn(this.channel, note, velocity, this.enableDebugging); | ||
} | ||
|
||
/** | ||
* @param e {MouseEvent|TouchEvent} | ||
*/ | ||
const moveHandler = e => { | ||
// all currently pressed keys are stored in this.pressedKeys | ||
/** | ||
* @type {Touch[]|MouseEvent[]} | ||
*/ | ||
const touches = e.touches ? Array.from(e.touches) : [e]; | ||
/** | ||
* @type {Set<number>} | ||
*/ | ||
const currentlyTouchedKeys = new Set(); | ||
touches.forEach(touch => { | ||
const targetKey = document.elementFromPoint(touch.clientX, touch.clientY); | ||
const midiNote = parseInt(targetKey.id.replace("note", "")); | ||
currentlyTouchedKeys.add(midiNote); | ||
if(isNaN(midiNote) || midiNote < 0 || this.pressedKeys.has(midiNote)) | ||
{ | ||
// pressed outside of bounds or already pressed | ||
return; | ||
} | ||
userNoteOn(midiNote, touch.clientY); | ||
}); | ||
this.pressedKeys.forEach(key => { | ||
if(!currentlyTouchedKeys.has(key)) | ||
{ | ||
userNoteOff(key); | ||
} | ||
}); | ||
}; | ||
|
||
// mouse | ||
document.addEventListener("mousedown", e => { | ||
this.mouseHeld = true; | ||
moveHandler(e); | ||
}); | ||
document.addEventListener("mouseup", () => { | ||
this.mouseHeld = false; | ||
this.pressedKeys.forEach(key => { | ||
userNoteOff(key); | ||
}); | ||
}); | ||
this.keyboard.onmousemove = e => { | ||
if(this.mouseHeld) moveHandler(e); | ||
}; | ||
this.keyboard.onmouseleave = () => { | ||
this.pressedKeys.forEach(key => { | ||
userNoteOff(key); | ||
}); | ||
} | ||
|
||
// touch | ||
this.keyboard.ontouchstart = e => { | ||
moveHandler(e); | ||
}; | ||
this.keyboard.ontouchend = () => { | ||
this.pressedKeys.forEach(key => { | ||
userNoteOff(key); | ||
}); | ||
}; | ||
this.keyboard.addEventListener("touchmove", e => { | ||
moveHandler(e); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.