unsticking notes when they get stuck

This commit is contained in:
Yotam Mann 2016-11-14 16:35:36 -08:00
parent e2f4f5371d
commit 0b7012892f
3 changed files with 18 additions and 14 deletions

View File

@ -139,14 +139,12 @@ class KeyboardElement extends events.EventEmitter {
highlight.classList.remove('active')
setTimeout(() => highlight.remove(), 2000)
//and up on the roll
this._roll.keyUp(noteNum, ai)
} else {
// console.log(this._keys[noteNum].querySelector(query))
//try again without ai
//try again
this.keyUp(noteNum)
}
}
this._roll.keyUp(noteNum, ai)
}
_getNotePosition(key){

View File

@ -32,7 +32,7 @@ class Keyboard extends events.EventEmitter{
* The audio key keyboard
* @type {AudioKeys}
*/
this._keyboard = new AudioKeys({polyphony : 88, rows : 1, octaveControls : false})
this._keyboard = new AudioKeys({polyphony : 88, rows : 1, octaveControls : false, rootNote : 48})
this._keyboard.down((e) => {
this.keyDown(e.note)
this._emitKeyDown(e.note)
@ -45,7 +45,7 @@ class Keyboard extends events.EventEmitter{
/**
* The piano interface
*/
this._keyboardInterface = new KeyboardElement(container, 48, 2)
this._keyboardInterface = new KeyboardElement(container, 36, 2)
this._keyboardInterface.on('keyDown', (note) => {
this.keyDown(note)
this._emitKeyDown(note)
@ -138,7 +138,7 @@ class Keyboard extends events.EventEmitter{
const keyWidth = 24
let octaves = Math.round((window.innerWidth / keyWidth) / 12)
octaves = Math.max(octaves, 2)
this._keyboardInterface.resize(48, octaves)
this._keyboardInterface.resize(36, octaves)
}
activate(){

View File

@ -61,7 +61,10 @@ class Roll {
keyDown(midi, box, ai=false){
const selector = ai ? `ai${midi}` : midi
if (midi && box && !this._currentNotes.hasOwnProperty(selector)){
if (!this._currentNotes.hasOwnProperty(selector)){
this._currentNotes[selector] = []
}
if (midi && box){
//translate the box coords to this space
const initialScaling = 10000
const plane = new THREE.Mesh( geometry, ai ? aiMaterial : material )
@ -73,23 +76,26 @@ class Roll {
plane.position.y = this._element.clientHeight + this._camera.position.y + initialScaling / 2
this._scene.add(plane)
this._currentNotes[selector] = {
this._currentNotes[selector].push({
plane : plane,
position: this._camera.position.y
}
})
}
}
keyUp(midi, ai=false){
const selector = ai ? `ai${midi}` : midi
if (this._currentNotes[selector]){
const plane = this._currentNotes[selector].plane
const position = this._currentNotes[selector].position
delete this._currentNotes[selector]
if (this._currentNotes[selector] && this._currentNotes[selector].length){
const note = this._currentNotes[selector].shift()
const plane = note.plane
const position = note.position
// get the distance covered
plane.scale.y = Math.max(this._camera.position.y - position, 5)
plane.position.y = this._element.clientHeight + position + plane.scale.y / 2
} else {
// console.log(midi)
// setTimeout(() => this.keyUp(midi, ai), 100)
}
}