OCTAVE: ${octaves[this.octave]}
NOTE: ${this.note}
`;
}
onKeyUp = () => {};
findNote(mouse: THREE.Vector2) {
this.raycaster.setFromCamera(mouse, this.camera);
const intersects = this.raycaster.intersectObjects(
this.scene.children,
true
);
const obj = intersects.length > 0 ? intersects[0] : null;
if (obj?.object?.userData) {
if (obj.object instanceof THREE.Mesh) {
obj.object.material.color.set("gray");
const { note } = obj.object.userData;
this.playNote(note, (color) => {
// @ts-ignore
obj?.object?.material.color.set(color);
});
}
}
}
playNote(note: string, update: (color: string) => void) {
this.note = note;
const color = note.includes("#") ? "black" : "white";
this.synth.triggerAttackRelease(note, "8n");
this.onKeyUp = () => {
update(color);
};
}
findNode(
note: string,
nodes: THREE.Object3D[]
): THREE.Mesh