|
1 | 1 | <script> |
2 | | - import { Scale, Chord, Note, Midi } from "@tonaljs/tonal"; |
3 | | - import { createEventDispatcher, getContext } from "svelte"; |
| 2 | + import { Scale, Chord, Note, Midi } from "tonal"; |
| 3 | + import { getContext } from "svelte"; |
4 | 4 | import { tonic, tuning } from "./store"; |
5 | 5 |
|
6 | | - export let scale; |
| 6 | + let { scale, onchordchange } = $props(); |
7 | 7 |
|
8 | 8 | const lowestNote = Note.get($tuning[0]); |
9 | | - const dispatch = createEventDispatcher(); |
10 | 9 | const { player } = getContext("app"); |
11 | 10 |
|
12 | 11 | function handleMouseUp(event) { |
13 | 12 | const chordName = event.target.dataset.chord; |
14 | 13 | const rootNote = Note.get( |
15 | | - `${$tonic}${$tonic === "C" ? lowestNote.oct + 1 : lowestNote.oct}` |
| 14 | + `${$tonic}${$tonic === "C" ? lowestNote.oct + 1 : lowestNote.oct}`, |
16 | 15 | ); |
17 | 16 | const startNote = |
18 | 17 | rootNote.height < lowestNote.height |
19 | 18 | ? Note.get(`${rootNote.name}${rootNote.oct + 1}`) |
20 | 19 | : rootNote; |
21 | 20 |
|
22 | 21 | const chord = Chord.getChord(chordName, startNote); |
23 | | - const midi = chord.notes.map(Midi.toMidi); |
| 22 | + const notesWithOctaves = Chord.notes(chordName, startNote); |
| 23 | + const midi = notesWithOctaves.map(Midi.toMidi); |
24 | 24 | player.play(midi, 15); |
25 | 25 |
|
26 | | - dispatch("chordchange", chord); |
| 26 | + onchordchange?.(chord); |
27 | 27 | } |
28 | 28 | </script> |
29 | 29 |
|
|
0 commit comments