diff options
| author | Brian Cully <bjc@spork.org> | 2025-07-28 08:52:51 -0400 |
|---|---|---|
| committer | Brian Cully <bjc@spork.org> | 2025-07-28 08:52:51 -0400 |
| commit | 77f5e81d0a1adc497040eaa89095635f3de3924e (patch) | |
| tree | 4ad6a00edf5cfe3c5c2bf0090ba80f8d13c143cc /main.mjs | |
| parent | 2d12e407ccac850dd2e1ce133a2f335677a2ef29 (diff) | |
| download | chords-77f5e81d0a1adc497040eaa89095635f3de3924e.tar.gz chords-77f5e81d0a1adc497040eaa89095635f3de3924e.zip | |
attach octave values to frets
sometimes just do the simple thing
Diffstat (limited to 'main.mjs')
| -rw-r--r-- | main.mjs | 70 |
1 files changed, 38 insertions, 32 deletions
@@ -5,6 +5,41 @@ import String from './string.mjs'; import Player from './player.mjs'; import { Note, toCents } from './scale.mjs'; +let player = undefined; + +function save(e) { + document.querySelectorAll(History.name).forEach(h => { + console.debug('h is', h, 'e is', e.detail); + h.add(e.detail); + }); +} + +function play(e) { + console.debug('got playEvent', e, e.detail.notes); + if (player) { + player.stop(); + } + + const played = e.detail.notes.map((n, i) => { + if (n !== 'x') { + return [Note.fromString(n), e.detail.octaves[i]]; + } + }).filter(n => n); + + const a = Note.fromString('A'); + player = new Player(played.map(([n, o]) => { + return toCents([a, 4], [n, o]); + })); + player.start(); +} + +function stop(e) { + console.debug('got stopEvent', e); + if (player) { + player.stop(); + } +} + function init() { console.debug('init()', this); @@ -13,40 +48,11 @@ function init() { 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(); - } - const played = e.detail.notes.map((n, i) => { - if (n !== 'x') { - return [Note.fromString(n), e.detail.octaves[i]] - } - }).filter(n => n); - player = new Player(played.map(([n, o]) => { - return toCents([a, 4], [n, o]); - })); - player.start(); - }); - - f.addEventListener(f.stopEvent, e => { - console.debug('got stopEvent', e); - if (player) { - player.stop(); - } - }); + f.addEventListener(f.saveEvent, save); + f.addEventListener(f.playEvent, play); + f.addEventListener(f.stopEvent, stop); }); } document.addEventListener('DOMContentLoaded', init); |
