From 616f98e3267af45b70dba118f8613b45a1a9b9af Mon Sep 17 00:00:00 2001 From: davay Date: Sun, 10 Nov 2024 11:26:40 +0700 Subject: [PATCH] cleaner --- src/useMidi.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/useMidi.js b/src/useMidi.js index 2e193dc..85e8e77 100644 --- a/src/useMidi.js +++ b/src/useMidi.js @@ -4,7 +4,6 @@ import { reactive, computed, watchEffect, onMounted, ref, watch, shallowReactive const inputs = shallowReactive({}) const outputs = shallowReactive({}) - const midi = reactive({ enabled: false, playing: false, @@ -39,7 +38,20 @@ function initMidi() { forwarder: input.addForwarder(), } input.removeListener(); - setupInputListeners(input); + Object.entries({ + start: () => { midi.playing = true; midi.stopped = false; }, + stop: () => { midi.playing = false; midi.stopped = Date.now(); }, + // clock: handleClock(input), + // midimessage: handleMidiMessage(input), + // noteon: ev => inputs[input.id].note = noteInOn(ev), + // noteoff: ev => inputs[input.id].note = noteInOn(ev), + // controlchange: handleControlChange(input), + // channelaftertouch: handleMonoAftertouch(input), + // keyaftertouch: handlePolyAftertouch(input), + // pitchbend: handlePitchBend(input), + }).forEach(([event, handler]) => { + input.addListener(event, handler); + }); }) WebMidi.outputs.forEach(output => { outputs[output.id] = { @@ -49,19 +61,5 @@ function initMidi() { }) } -function setupInputListeners(input) { - Object.entries({ - start: () => { midi.playing = true; midi.stopped = false; }, - stop: () => { midi.playing = false; midi.stopped = Date.now(); }, - // clock: handleClock(input), - // midimessage: handleMidiMessage(input), - // noteon: ev => inputs[input.id].note = noteInOn(ev), - // noteoff: ev => inputs[input.id].note = noteInOn(ev), - // controlchange: handleControlChange(input), - // channelaftertouch: handleMonoAftertouch(input), - // keyaftertouch: handlePolyAftertouch(input), - // pitchbend: handlePitchBend(input), - }).forEach(([event, handler]) => { - input.addListener(event, handler); - }); -} + +