From 2a9b6ef0be04b5b5cacc47922e19c05d190d6ade Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sat, 26 Jul 2025 14:55:53 -0400 Subject: first stab at fretboard player. need to handle actual chord positions so everything isn't in 4, but otherwise works? --- main.mjs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'main.mjs') diff --git a/main.mjs b/main.mjs index 4108f5d..80e6524 100644 --- a/main.mjs +++ b/main.mjs @@ -2,22 +2,47 @@ import Fretboard from './fretboard.mjs'; import History from './history.mjs'; import KeyPicker from './key-picker.mjs'; import String from './string.mjs'; +import Player from './player.mjs'; +import { Note, toCents } from './scale.mjs'; function init() { console.debug('init()', this); String.register(); Fretboard.register(); - // KeyPicker.register(); - // History.register(); + KeyPicker.register(); + History.register(); + + let player = undefined; // todo: maybe just attach the listener to document? document.querySelectorAll(Fretboard.name).forEach(f => { f.addEventListener(f.saveEvent, e => { document.querySelectorAll(History.name).forEach(h => { + console.debug('h is', h, 'e is', e.detail); h.add(e.detail); }); }); + + f.addEventListener(f.playEvent, e => { + console.debug('got playEvent', e, e.detail.notes); + const a = Note.fromString('A'); + if (player) { + player.stop(); + } + player = new Player(e.detail.notes.filter(n => n !== 'x').map(n => { + // smoosh everything into 4 right now + return toCents([a, 4], [Note.fromString(n), 4]); + })); + player.start(); + }); + + f.addEventListener(f.stopEvent, e => { + console.debug('got stopEvent', e); + if (player) { + player.stop(); + } + }); }); } document.addEventListener('DOMContentLoaded', init); -- cgit v1.3