From c44ebf14ace9f5b10b5cb2f4eb93a1eb192bfdf3 Mon Sep 17 00:00:00 2001 From: davay Date: Thu, 14 Nov 2024 16:49:11 +0700 Subject: [PATCH] feat: 8 voices, sampler is off for now --- composables/useMidi.js | 13 +++++++++---- elements/_sampler.js | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/composables/useMidi.js b/composables/useMidi.js index c456e2e..ae30dad 100644 --- a/composables/useMidi.js +++ b/composables/useMidi.js @@ -1,5 +1,7 @@ import { WebMidi } from "webmidi"; -import { reactive, onMounted, shallowReactive } from 'vue'; +import { reactive, onMounted, shallowReactive, computed } from 'vue'; +import { Midi } from "tonal"; +import { Chord } from "tonal"; const inputs = shallowReactive({}) const outputs = shallowReactive({}) @@ -22,6 +24,11 @@ const activeNotes = reactive({}) const midiLog = shallowReactive([]) +export const guessChords = computed(() => { + const list = Object.entries(activeNotes).filter(([_, v]) => v).map(([n]) => Midi.midiToNoteName(Number(n), { sharps: true })); + return Chord.detect(list) +}) + export function useMidi() { onMounted(() => { if (midi.enabled || midi.enabled === null) return @@ -38,7 +45,7 @@ export function useMidi() { }) }).catch(e => midi.enabled = null) }) - return { midi, inputs, outputs, WebMidi, midiLog, midiNote, activeNotes } + return { midi, inputs, outputs, WebMidi, midiLog, midiNote, activeNotes, guessChords } } @@ -92,5 +99,3 @@ function initMidi() { }) } - - diff --git a/elements/_sampler.js b/elements/_sampler.js index f87c819..e3f68bc 100644 --- a/elements/_sampler.js +++ b/elements/_sampler.js @@ -1,6 +1,7 @@ import { midiFrequency } from "./index"; import { el } from "@elemaudio/core"; +// TODO: Find a way to embed the initial piano sample into html so this works at local file://:/index.html export const params = { on: { value: 1, min: 0, max: 1, step: 1, hidden: true, },