Skip to content

Commit 3d0b299

Browse files
authored
Merge pull request #9 from caged/update-tonal
Update tonal to v5
2 parents 71beb3e + af220bf commit 3d0b299

12 files changed

Lines changed: 122 additions & 258 deletions

package-lock.json

Lines changed: 97 additions & 235 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"type": "module",
77
"dependencies": {
88
"@tailwindcss/forms": "^0.5.10",
9-
"@tonaljs/tonal": "^4.6.5",
109
"d3": "^7.3.0",
1110
"d3-scale-chromatic": "^3.0.0",
1211
"howler": "^2.2.1",
1312
"svelte": "^5.45.8",
14-
"svelte-select": "^5.8.3"
13+
"svelte-select": "^5.8.3",
14+
"tonal": "^6.4.2"
1515
},
1616
"devDependencies": {
1717
"@sveltejs/vite-plugin-svelte": "^5.0.4",

src/app/App.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { Chord, Note } from "@tonaljs/tonal";
2+
import { Chord, Note } from "tonal";
33
import { scale as getScale, tnps, pentatonic } from "../frets/index";
44
import KeySelector from "./KeySelector.svelte";
55
import ScaleSelector from "./ScaleSelector.svelte";
@@ -17,8 +17,8 @@
1717
let position;
1818
let chordName;
1919
20-
function handleChordChange(event) {
21-
chordName = event.detail;
20+
function handleChordChange(chord) {
21+
chordName = chord;
2222
}
2323
2424
$: scaleName = `${$tonic} ${scaleLabel}`;
@@ -93,7 +93,7 @@
9393
</div>
9494
<div class="p-5 hidden lg:block w-2/3">
9595
<h3 class="font-bold">Chords</h3>
96-
<ScaleChords on:chordchange={handleChordChange} {scale} />
96+
<ScaleChords onchordchange={handleChordChange} {scale} />
9797
</div>
9898
</div>
9999
{/if}

src/app/Metronome.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import { delay } from "./utils";
44
import Volume from "./Volume.svelte";
55
import { bpm } from "./store";
6+
import metronomeUrl from "../metronome.mp3?url";
67
78
let volume = 0.5;
89
let playing = false;
910
1011
var sound = new Howl({
11-
src: "metronome.mp3",
12+
src: metronomeUrl,
1213
sprite: {
1314
a: [0, 500],
1415
b: [500, 500],

src/app/NotePlayer.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script>
2-
import { Chord, Range } from "@tonaljs/tonal";
2+
import { Chord, Range } from "tonal";
33
import { Howl, Howler } from "howler";
44
import { delay as pauseFor } from "./utils";
5+
import guitarNotesUrl from "../guitar-notes.mp3?url";
56
67
export let notes = "";
78
export let delay = 20;
@@ -17,7 +18,7 @@
1718
const allNotes = { ...sharps, ...flats };
1819
1920
var sound = new Howl({
20-
src: "guitar-notes.mp3",
21+
src: guitarNotesUrl,
2122
sprite: allNotes,
2223
});
2324
sound.volume(0.2);

src/app/ScaleChords.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<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";
44
import { tonic, tuning } from "./store";
55
6-
export let scale;
6+
let { scale, onchordchange } = $props();
77
88
const lowestNote = Note.get($tuning[0]);
9-
const dispatch = createEventDispatcher();
109
const { player } = getContext("app");
1110
1211
function handleMouseUp(event) {
1312
const chordName = event.target.dataset.chord;
1413
const rootNote = Note.get(
15-
`${$tonic}${$tonic === "C" ? lowestNote.oct + 1 : lowestNote.oct}`
14+
`${$tonic}${$tonic === "C" ? lowestNote.oct + 1 : lowestNote.oct}`,
1615
);
1716
const startNote =
1817
rootNote.height < lowestNote.height
1918
? Note.get(`${rootNote.name}${rootNote.oct + 1}`)
2019
: rootNote;
2120
2221
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);
2424
player.play(midi, 15);
2525
26-
dispatch("chordchange", chord);
26+
onchordchange?.(chord);
2727
}
2828
</script>
2929

src/app/ScaleSelector.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
22
import Select from "svelte-select";
3-
import { ScaleType } from "@tonaljs/tonal";
3+
import { ScaleType } from "tonal";
44
55
export let value;
66

src/app/player.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Howl } from "howler";
2-
import { Range } from "@tonaljs/tonal";
3-
import { delay as pauseFor } from "./utils";
2+
import { Range } from "tonal";
43
import noteCrescendoUrl from "../note-crescendo.mp3?url";
4+
import { delay as pauseFor } from "./utils";
55

66
export default function player() {
77
function player() {}

src/frets/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Note, Range } from "@tonaljs/tonal";
1+
import { Note, Range } from "tonal";
22
export { default as tnps } from "./system/tnps";
33
export { default as pentatonic } from "./system/pentatonic";
44
export { default as scale } from "./scale";

src/frets/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Note, Range } from "@tonaljs/tonal";
1+
import { Note, Range } from "tonal";
22
import { frets, tnps, pentatonic, scale } from "./";
33
import { assert } from "chai";
44

0 commit comments

Comments
 (0)