Fix MIDI input logging
This commit is contained in:
parent
a0291e8a42
commit
ee326c709e
1 changed files with 6 additions and 9 deletions
|
|
@ -5,7 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { WebMidi } from 'webmidi';
|
import { WebMidi } from 'webmidi';
|
||||||
import { ref } from '@strudel/core';
|
import { logger, ref } from '@strudel/core';
|
||||||
import { getDevice } from './util.mjs';
|
import { getDevice } from './util.mjs';
|
||||||
|
|
||||||
export class MidiInput {
|
export class MidiInput {
|
||||||
|
|
@ -15,7 +15,7 @@ export class MidiInput {
|
||||||
*/
|
*/
|
||||||
constructor(input) {
|
constructor(input) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.stateKey = typeof input === 'string' ? input : undefined;
|
this.stateKey = typeof input === 'string' ? input : undefined; // Saved state is not tracked for numeric index inputs
|
||||||
|
|
||||||
this._refs = {};
|
this._refs = {};
|
||||||
this._refsByChan = {};
|
this._refsByChan = {};
|
||||||
|
|
@ -37,9 +37,6 @@ export class MidiInput {
|
||||||
|
|
||||||
_startDeviceListener() {
|
_startDeviceListener() {
|
||||||
const initialDevice = getDevice(this.input, WebMidi.inputs);
|
const initialDevice = getDevice(this.input, WebMidi.inputs);
|
||||||
if (!initialDevice) {
|
|
||||||
console.warn(`midiin: device "${this.input}" not found`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Background connection loop
|
// Background connection loop
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
@ -51,8 +48,6 @@ export class MidiInput {
|
||||||
device = await this._waitForDevice();
|
device = await this._waitForDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('midiin: device connected:', device.name);
|
|
||||||
|
|
||||||
// Wait a bit for device to be ready to receive last state
|
// Wait a bit for device to be ready to receive last state
|
||||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||||
|
|
||||||
|
|
@ -68,9 +63,7 @@ export class MidiInput {
|
||||||
|
|
||||||
await this._waitForDeviceDisconnect(device);
|
await this._waitForDeviceDisconnect(device);
|
||||||
|
|
||||||
console.warn('midiin: device disconnected:', device.name);
|
|
||||||
device.removeListener('midimessage', midiListener);
|
device.removeListener('midimessage', midiListener);
|
||||||
|
|
||||||
device = null; // Clear var to trigger wait for connection
|
device = null; // Clear var to trigger wait for connection
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
@ -83,6 +76,8 @@ export class MidiInput {
|
||||||
const connListener = () => {
|
const connListener = () => {
|
||||||
const device = getDevice(this.input, WebMidi.inputs);
|
const device = getDevice(this.input, WebMidi.inputs);
|
||||||
if (device) {
|
if (device) {
|
||||||
|
logger(`[midi] device reconnected: ${device.name}`);
|
||||||
|
|
||||||
WebMidi.removeListener('connected', connListener);
|
WebMidi.removeListener('connected', connListener);
|
||||||
resolve(device);
|
resolve(device);
|
||||||
}
|
}
|
||||||
|
|
@ -96,6 +91,8 @@ export class MidiInput {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const disconnListener = (e) => {
|
const disconnListener = (e) => {
|
||||||
if (e.port.name === device.name) {
|
if (e.port.name === device.name) {
|
||||||
|
logger(`[midi] device disconnected: ${device.name}`);
|
||||||
|
|
||||||
WebMidi.removeListener('disconnected', disconnListener);
|
WebMidi.removeListener('disconnected', disconnListener);
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue