@blibliki/engine
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -0,1 +1,2 @@ | ||
import MidiDeviceManager from "./MidiDeviceManager"; | ||
import { ModuleType } from "./Module"; | ||
@@ -13,5 +14,7 @@ import { AudioModule } from "./Module"; | ||
declare class Engine { | ||
midiDeviceManager: MidiDeviceManager; | ||
private static instance; | ||
private _master; | ||
private context; | ||
private propsUpdateCallbacks; | ||
modules: { | ||
@@ -72,2 +75,4 @@ [Identifier: string]: AudioModule; | ||
}; | ||
onPropsUpdate(callback: (id: string, props: any) => void): void; | ||
_triggerPropsUpdate(id: string, props: any): void; | ||
updatePropsModule(id: string, props: any): { | ||
@@ -111,7 +116,8 @@ id: string; | ||
}; | ||
triggerKey(noteName: string, type: string): void; | ||
triggerVirtualMidi(id: string, noteName: string, type: string): void; | ||
dispose(): void; | ||
findById(id: string): AudioModule; | ||
private applyRoutesRequired; | ||
} | ||
declare const _default: Engine; | ||
export default _default; |
import { Context, setContext } from "tone"; | ||
import MidiDeviceManager from "./MidiDeviceManager"; | ||
import MidiEvent from "./MidiEvent"; | ||
import { ModuleType } from "./Module"; | ||
@@ -7,5 +9,7 @@ import { createModule } from "./Module"; | ||
class Engine { | ||
midiDeviceManager; | ||
static instance; | ||
_master; | ||
context; | ||
propsUpdateCallbacks; | ||
modules; | ||
@@ -16,2 +20,3 @@ routes; | ||
this.routes = {}; | ||
this.propsUpdateCallbacks = []; | ||
} | ||
@@ -28,2 +33,3 @@ static getInstance() { | ||
this.context.transport.start(); | ||
this.midiDeviceManager = new MidiDeviceManager(); | ||
return { | ||
@@ -44,8 +50,13 @@ master: this.master, | ||
} | ||
onPropsUpdate(callback) { | ||
this.propsUpdateCallbacks.push(callback); | ||
} | ||
_triggerPropsUpdate(id, props) { | ||
this.propsUpdateCallbacks.forEach((callback) => callback(id, props)); | ||
} | ||
updatePropsModule(id, props) { | ||
const audioModule = this.findById(id); | ||
const polyNumber = audioModule instanceof VoiceScheduler && audioModule.polyNumber; | ||
const applyRoutesRequired = this.applyRoutesRequired(audioModule, props); | ||
audioModule.props = props; | ||
const { polyNumber: newPolyNumber } = props; | ||
if (polyNumber !== newPolyNumber) | ||
if (applyRoutesRequired) | ||
applyRoutes(Object.values(this.routes)); | ||
@@ -72,3 +83,6 @@ return audioModule.serialize(); | ||
} | ||
triggerKey(noteName, type) { } | ||
triggerVirtualMidi(id, noteName, type) { | ||
const virtualMidi = this.findById(id); | ||
virtualMidi.sendMidi(MidiEvent.fromNote(noteName, type)); | ||
} | ||
dispose() { | ||
@@ -89,4 +103,11 @@ Object.values(this.modules).forEach((m) => { | ||
} | ||
applyRoutesRequired(audioModule, props) { | ||
if (!props.polyNumber) | ||
return false; | ||
if (!(audioModule instanceof VoiceScheduler)) | ||
return false; | ||
return props.polyNumber !== audioModule.polyNumber; | ||
} | ||
} | ||
export default Engine.getInstance(); | ||
//# sourceMappingURL=Engine.js.map |
@@ -24,3 +24,3 @@ import MidiEvent from "./MidiEvent"; | ||
removeEventListener(callback: EventListerCallback): void; | ||
_processEvent(e: MIDIMessageEvent): void; | ||
private processEvent; | ||
} |
@@ -20,3 +20,3 @@ import MidiEvent from "./MidiEvent"; | ||
return; | ||
this._processEvent(e); | ||
this.processEvent(e); | ||
}; | ||
@@ -35,5 +35,5 @@ } | ||
removeEventListener(callback) { | ||
this.eventListerCallbacks = this.eventListerCallbacks.filter((c) => c === callback); | ||
this.eventListerCallbacks = this.eventListerCallbacks.filter((c) => c !== callback); | ||
} | ||
_processEvent(e) { | ||
processEvent(e) { | ||
const event = new MidiEvent(e); | ||
@@ -40,0 +40,0 @@ switch (event.type) { |
import MidiDevice from "./MidiDevice"; | ||
declare class MidiDeviceManager { | ||
private devices; | ||
private static instance; | ||
static getInstance(): MidiDeviceManager; | ||
fetchDevices(): Promise<MidiDevice[]>; | ||
find(id: string): Promise<MidiDevice>; | ||
_inputs(): Promise<MIDIInput[]>; | ||
onStateChange(callback: Function): Promise<void>; | ||
export default class MidiDeviceManager { | ||
devices: { | ||
[Key: string]: MidiDevice; | ||
}; | ||
private initialized; | ||
constructor(); | ||
find(id: string): MidiDevice; | ||
onStateChange(callback: (device: MidiDevice) => void): void; | ||
private listenChanges; | ||
private initializeDevices; | ||
private inputs; | ||
} | ||
declare const _default: MidiDeviceManager; | ||
export default _default; |
import MidiDevice from "./MidiDevice"; | ||
class MidiDeviceManager { | ||
devices; | ||
static instance; | ||
static getInstance() { | ||
if (!MidiDeviceManager.instance) { | ||
MidiDeviceManager.instance = new MidiDeviceManager(); | ||
} | ||
return MidiDeviceManager.instance; | ||
export default class MidiDeviceManager { | ||
devices = {}; | ||
initialized = false; | ||
constructor() { | ||
this.initializeDevices().then(() => { | ||
this.listenChanges(); | ||
this.initialized = true; | ||
}); | ||
} | ||
async fetchDevices() { | ||
if (this.devices) | ||
return this.devices; | ||
this.devices = (await this._inputs()).map((input) => new MidiDevice(input)); | ||
return this.devices; | ||
} | ||
async find(id) { | ||
const device = (await this.fetchDevices()).find((dev) => dev.id === id); | ||
find(id) { | ||
const device = this.devices[id]; | ||
if (!device) | ||
throw Error(`Midie device with id ${id} not found`); | ||
throw Error(`Midi device with id ${id} not found`); | ||
return device; | ||
} | ||
async _inputs() { | ||
onStateChange(callback) { | ||
navigator.requestMIDIAccess().then((access) => { | ||
access.onstatechange = (e) => { | ||
const isMidiEvent = e instanceof MIDIConnectionEvent; | ||
if (!isMidiEvent) | ||
return; | ||
if (e.port instanceof MIDIOutput) | ||
return; | ||
const input = e.port; | ||
const midi = new MidiDevice(input); | ||
callback(midi); | ||
}; | ||
}); | ||
} | ||
listenChanges() { | ||
this.onStateChange((device) => { | ||
if (device.state === "disconnected") { | ||
device.disconnect(); | ||
delete this.devices[device.id]; | ||
} | ||
else { | ||
this.devices[device.id] = device; | ||
} | ||
}); | ||
} | ||
async initializeDevices() { | ||
if (this.initialized) | ||
return Object.values(this.devices); | ||
(await this.inputs()).forEach((input) => { | ||
if (this.devices[input.id]) | ||
return; | ||
this.devices[input.id] = new MidiDevice(input); | ||
}); | ||
return Object.values(this.devices); | ||
} | ||
async inputs() { | ||
const inputs = []; | ||
@@ -29,18 +58,3 @@ const access = await navigator.requestMIDIAccess(); | ||
} | ||
async onStateChange(callback) { | ||
const access = await navigator.requestMIDIAccess(); | ||
await this.fetchDevices(); | ||
access.onstatechange = (e) => { | ||
const isMidiEvent = e instanceof MIDIConnectionEvent; | ||
if (!isMidiEvent) | ||
return; | ||
if (e.port instanceof MIDIOutput) | ||
return; | ||
const input = e.port; | ||
const midi = new MidiDevice(input); | ||
callback(midi); | ||
}; | ||
} | ||
} | ||
export default MidiDeviceManager.getInstance(); | ||
//# sourceMappingURL=MidiDeviceManager.js.map |
import Note from "./Note"; | ||
export default class MidiEvent { | ||
note?: Note; | ||
triggeredAt: number; | ||
readonly triggeredAt: number; | ||
_type: string; | ||
private data; | ||
private _type; | ||
private _event; | ||
private event; | ||
static fromNote(noteName: string, type: string): MidiEvent; | ||
constructor(event: MIDIMessageEvent); | ||
@@ -9,0 +10,0 @@ get type(): string; |
import { now } from "tone"; | ||
import Note from "./Note"; | ||
const EvenType = { | ||
const EventType = { | ||
8: "noteOff", | ||
@@ -10,7 +10,13 @@ 9: "noteOn", | ||
triggeredAt; | ||
_type; | ||
data; | ||
_type; | ||
_event; | ||
event; | ||
static fromNote(noteName, type) { | ||
const event = new MidiEvent(new MIDIMessageEvent("", { data: new Uint8Array([0, 0, 0]) })); | ||
event.note = new Note(noteName); | ||
event._type = type; | ||
return event; | ||
} | ||
constructor(event) { | ||
this._event = event; | ||
this.event = event; | ||
this.triggeredAt = now(); | ||
@@ -23,3 +29,3 @@ this.data = event.data; | ||
return this._type; | ||
let type = EvenType[this.data[0] >> 4]; | ||
let type = EventType[this.data[0] >> 4]; | ||
if (type === "noteOn" && this.data[2] === 0) { | ||
@@ -36,5 +42,5 @@ type = "noteOff"; | ||
return; | ||
this.note = new Note(this._event); | ||
this.note = new Note(this.event); | ||
} | ||
} | ||
//# sourceMappingURL=MidiEvent.js.map |
@@ -14,2 +14,3 @@ import { InputNode } from "tone"; | ||
MidiSelector = "midiSelector", | ||
VirtualMidi = "virtualMidi", | ||
Volume = "monoVolume" | ||
@@ -16,0 +17,0 @@ } |
@@ -14,2 +14,3 @@ import { v4 as uuidv4 } from "uuid"; | ||
ModuleType["MidiSelector"] = "midiSelector"; | ||
ModuleType["VirtualMidi"] = "virtualMidi"; | ||
ModuleType["Volume"] = "monoVolume"; | ||
@@ -16,0 +17,0 @@ })(ModuleType || (ModuleType = {})); |
@@ -12,2 +12,3 @@ import Module, { Connectable } from "./Base"; | ||
import Volume, { PolyVolume } from "./Volume"; | ||
import VirtualMidi from "./VirtualMidi"; | ||
export { default, ModuleType } from "./Base"; | ||
@@ -21,2 +22,2 @@ export { default as PolyModule, PolyModuleType } from "./PolyModule"; | ||
export declare function createModule(name: string, type: string, props: any): AudioModule; | ||
export declare function moduleClassFromType(type: string): typeof Oscillator | typeof PolyOscillator | typeof Envelope | typeof PolyEnvelope | typeof AmpEnvelope | typeof PolyAmpEnvelope | typeof Filter | typeof PolyFilter | typeof Master | typeof VoiceScheduler | typeof Voice | typeof MidiSelector | typeof Volume | typeof PolyVolume; | ||
export declare function moduleClassFromType(type: string): typeof VirtualMidi | typeof Oscillator | typeof PolyOscillator | typeof Envelope | typeof PolyEnvelope | typeof AmpEnvelope | typeof PolyAmpEnvelope | typeof Filter | typeof PolyFilter | typeof Master | typeof VoiceScheduler | typeof Voice | typeof MidiSelector | typeof Volume | typeof PolyVolume; |
@@ -13,2 +13,3 @@ import { ModuleType } from "./Base"; | ||
import Volume, { PolyVolume } from "./Volume"; | ||
import VirtualMidi from "./VirtualMidi"; | ||
export { default, ModuleType } from "./Base"; | ||
@@ -57,2 +58,4 @@ export { default as PolyModule, PolyModuleType } from "./PolyModule"; | ||
return MidiSelector; | ||
case ModuleType.VirtualMidi: | ||
return VirtualMidi; | ||
default: | ||
@@ -59,0 +62,0 @@ throw Error("Unknown module type"); |
@@ -1,3 +0,1 @@ | ||
import MidiDevice from "../MidiDevice"; | ||
import MidiEvent from "../MidiEvent"; | ||
import Module, { DummnyInternalModule } from "./Base"; | ||
@@ -13,5 +11,5 @@ import { Output } from "./IO"; | ||
set selectedId(value: string | null); | ||
onMidiEvent: (midiEvent: MidiEvent) => void; | ||
availableDevices(): Promise<MidiDevice[]>; | ||
private registerOutputs; | ||
private onMidiEvent; | ||
private addEventListener; | ||
} |
@@ -1,2 +0,2 @@ | ||
import MidiDeviceManager from "../MidiDeviceManager"; | ||
import Engine from "../Engine"; | ||
import Module, { ModuleType, DummnyInternalModule } from "./Base"; | ||
@@ -15,2 +15,3 @@ const InitialProps = { | ||
this.registerOutputs(); | ||
this.addEventListener(this.selectedId); | ||
} | ||
@@ -22,13 +23,11 @@ get selectedId() { | ||
if (this.selectedId) { | ||
MidiDeviceManager.find(this.selectedId).then((midiDevice) => { | ||
midiDevice.removeEventListener(this.onMidiEvent); | ||
}); | ||
const prevMidiDevice = Engine.midiDeviceManager.find(this.selectedId); | ||
prevMidiDevice.removeEventListener(this.onMidiEvent); | ||
} | ||
this._props = { ...this.props, selectedId: value }; | ||
if (!value) | ||
return; | ||
MidiDeviceManager.find(value).then((midiDevice) => { | ||
midiDevice.addEventListener(this.onMidiEvent); | ||
}); | ||
this.addEventListener(value); | ||
} | ||
registerOutputs() { | ||
this.midiOutput = this.registerOutput({ name: "midi out" }); | ||
} | ||
onMidiEvent = (midiEvent) => { | ||
@@ -39,9 +38,9 @@ this.midiOutput.connections.forEach((input) => { | ||
}; | ||
async availableDevices() { | ||
return MidiDeviceManager.fetchDevices(); | ||
addEventListener(midiId) { | ||
if (!this.onMidiEvent || !midiId) | ||
return; // Ugly hack because of weird super bug | ||
const midiDevice = Engine.midiDeviceManager.find(midiId); | ||
midiDevice.addEventListener(this.onMidiEvent); | ||
} | ||
registerOutputs() { | ||
this.midiOutput = this.registerOutput({ name: "midi out" }); | ||
} | ||
} | ||
//# sourceMappingURL=MidiSelector.js.map |
{ | ||
"name": "@blibliki/engine", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"main": "build/index.js", | ||
@@ -5,0 +5,0 @@ "types": "build/index.d.ts", |
import { Context, setContext } from "tone"; | ||
import MidiDeviceManager from "./MidiDeviceManager"; | ||
import MidiEvent from "./MidiEvent"; | ||
@@ -6,2 +8,3 @@ import { ModuleType } from "./Module"; | ||
import Master from "./Module/Master"; | ||
import VirtualMidi from "./Module/VirtualMidi"; | ||
import VoiceScheduler from "./Module/VoiceScheduler"; | ||
@@ -22,5 +25,7 @@ import { applyRoutes, createRoute, RouteInterface, RouteProps } from "./routes"; | ||
class Engine { | ||
midiDeviceManager: MidiDeviceManager; | ||
private static instance: Engine; | ||
private _master: Master; | ||
private context: Context; | ||
private propsUpdateCallbacks: { (id: string, props: any): void }[]; | ||
@@ -38,2 +43,3 @@ modules: { | ||
this.routes = {}; | ||
this.propsUpdateCallbacks = []; | ||
} | ||
@@ -53,2 +59,3 @@ | ||
this.context.transport.start(); | ||
this.midiDeviceManager = new MidiDeviceManager(); | ||
@@ -76,12 +83,17 @@ return { | ||
onPropsUpdate(callback: (id: string, props: any) => void) { | ||
this.propsUpdateCallbacks.push(callback); | ||
} | ||
_triggerPropsUpdate(id: string, props: any) { | ||
this.propsUpdateCallbacks.forEach((callback) => callback(id, props)); | ||
} | ||
updatePropsModule(id: string, props: any) { | ||
const audioModule = this.findById(id); | ||
const polyNumber = | ||
audioModule instanceof VoiceScheduler && audioModule.polyNumber; | ||
const applyRoutesRequired = this.applyRoutesRequired(audioModule, props); | ||
audioModule.props = props; | ||
const { polyNumber: newPolyNumber } = props; | ||
if (applyRoutesRequired) applyRoutes(Object.values(this.routes)); | ||
if (polyNumber !== newPolyNumber) applyRoutes(Object.values(this.routes)); | ||
return audioModule.serialize(); | ||
@@ -118,4 +130,8 @@ } | ||
triggerKey(noteName: string, type: string) {} | ||
triggerVirtualMidi(id: string, noteName: string, type: string) { | ||
const virtualMidi = this.findById(id) as VirtualMidi; | ||
virtualMidi.sendMidi(MidiEvent.fromNote(noteName, type)); | ||
} | ||
dispose() { | ||
@@ -139,4 +155,11 @@ Object.values(this.modules).forEach((m) => { | ||
} | ||
private applyRoutesRequired(audioModule: AudioModule, props: any) { | ||
if (!props.polyNumber) return false; | ||
if (!(audioModule instanceof VoiceScheduler)) return false; | ||
return props.polyNumber !== audioModule.polyNumber; | ||
} | ||
} | ||
export default Engine.getInstance(); |
@@ -34,3 +34,3 @@ import MidiEvent from "./MidiEvent"; | ||
this._processEvent(e); | ||
this.processEvent(e); | ||
}; | ||
@@ -55,7 +55,7 @@ } | ||
this.eventListerCallbacks = this.eventListerCallbacks.filter( | ||
(c) => c === callback | ||
(c) => c !== callback | ||
); | ||
} | ||
_processEvent(e: MIDIMessageEvent) { | ||
private processEvent(e: MIDIMessageEvent) { | ||
const event = new MidiEvent(e); | ||
@@ -62,0 +62,0 @@ |
import MidiDevice from "./MidiDevice"; | ||
class MidiDeviceManager { | ||
private devices: Array<MidiDevice>; | ||
private static instance: MidiDeviceManager; | ||
export default class MidiDeviceManager { | ||
devices: { [Key: string]: MidiDevice } = {}; | ||
private initialized: boolean = false; | ||
public static getInstance(): MidiDeviceManager { | ||
if (!MidiDeviceManager.instance) { | ||
MidiDeviceManager.instance = new MidiDeviceManager(); | ||
} | ||
return MidiDeviceManager.instance; | ||
constructor() { | ||
this.initializeDevices().then(() => { | ||
this.listenChanges(); | ||
this.initialized = true; | ||
}); | ||
} | ||
async fetchDevices(): Promise<MidiDevice[]> { | ||
if (this.devices) return this.devices; | ||
find(id: string): MidiDevice { | ||
const device = this.devices[id]; | ||
this.devices = (await this._inputs()).map((input) => new MidiDevice(input)); | ||
if (!device) throw Error(`Midi device with id ${id} not found`); | ||
return this.devices; | ||
return device; | ||
} | ||
async find(id: string): Promise<MidiDevice> { | ||
const device = (await this.fetchDevices()).find( | ||
(dev: MidiDevice) => dev.id === id | ||
); | ||
onStateChange(callback: (device: MidiDevice) => void) { | ||
navigator.requestMIDIAccess().then((access: MIDIAccess) => { | ||
access.onstatechange = (e) => { | ||
const isMidiEvent = e instanceof MIDIConnectionEvent; | ||
if (!device) throw Error(`Midie device with id ${id} not found`); | ||
if (!isMidiEvent) return; | ||
if (e.port instanceof MIDIOutput) return; | ||
return device; | ||
} | ||
const input = e.port as MIDIInput; | ||
async _inputs() { | ||
const inputs: Array<MIDIInput> = []; | ||
const midi = new MidiDevice(input); | ||
const access = await navigator.requestMIDIAccess(); | ||
access.inputs.forEach((input) => inputs.push(input)); | ||
callback(midi); | ||
}; | ||
}); | ||
} | ||
return inputs; | ||
private listenChanges() { | ||
this.onStateChange((device) => { | ||
if (device.state === "disconnected") { | ||
device.disconnect(); | ||
delete this.devices[device.id]; | ||
} else { | ||
this.devices[device.id] = device; | ||
} | ||
}); | ||
} | ||
async onStateChange(callback: Function) { | ||
const access: MIDIAccess = await navigator.requestMIDIAccess(); | ||
await this.fetchDevices(); | ||
private async initializeDevices() { | ||
if (this.initialized) return Object.values(this.devices); | ||
access.onstatechange = (e) => { | ||
const isMidiEvent = e instanceof MIDIConnectionEvent; | ||
(await this.inputs()).forEach((input) => { | ||
if (this.devices[input.id]) return; | ||
if (!isMidiEvent) return; | ||
if (e.port instanceof MIDIOutput) return; | ||
this.devices[input.id] = new MidiDevice(input); | ||
}); | ||
const input = e.port as MIDIInput; | ||
return Object.values(this.devices); | ||
} | ||
const midi = new MidiDevice(input); | ||
private async inputs() { | ||
const inputs: Array<MIDIInput> = []; | ||
callback(midi); | ||
}; | ||
const access = await navigator.requestMIDIAccess(); | ||
access.inputs.forEach((input) => inputs.push(input)); | ||
return inputs; | ||
} | ||
} | ||
export default MidiDeviceManager.getInstance(); |
import { now } from "tone"; | ||
import Note from "./Note"; | ||
const EvenType: { [key: number]: string } = { | ||
const EventType: { [key: number]: string } = { | ||
8: "noteOff", | ||
@@ -11,9 +11,19 @@ 9: "noteOn", | ||
note?: Note; | ||
triggeredAt: number; | ||
readonly triggeredAt: number; | ||
_type: string; | ||
private data: Uint8Array; | ||
private _type: string; | ||
private _event: MIDIMessageEvent; | ||
private event: MIDIMessageEvent; | ||
static fromNote(noteName: string, type: string) { | ||
const event = new MidiEvent( | ||
new MIDIMessageEvent("", { data: new Uint8Array([0, 0, 0]) }) | ||
); | ||
event.note = new Note(noteName); | ||
event._type = type; | ||
return event; | ||
} | ||
constructor(event: MIDIMessageEvent) { | ||
this._event = event; | ||
this.event = event; | ||
this.triggeredAt = now(); | ||
@@ -27,3 +37,3 @@ this.data = event.data; | ||
let type = EvenType[this.data[0] >> 4]; | ||
let type = EventType[this.data[0] >> 4]; | ||
@@ -44,4 +54,4 @@ if (type === "noteOn" && this.data[2] === 0) { | ||
this.note = new Note(this._event); | ||
this.note = new Note(this.event); | ||
} | ||
} |
@@ -17,2 +17,3 @@ import { v4 as uuidv4 } from "uuid"; | ||
MidiSelector = "midiSelector", | ||
VirtualMidi = "virtualMidi", | ||
Volume = "monoVolume", | ||
@@ -19,0 +20,0 @@ } |
@@ -13,2 +13,3 @@ import Module, { Connectable, ModuleType } from "./Base"; | ||
import Volume, { PolyVolume } from "./Volume"; | ||
import VirtualMidi from "./VirtualMidi"; | ||
@@ -76,2 +77,4 @@ export { default, ModuleType } from "./Base"; | ||
return MidiSelector; | ||
case ModuleType.VirtualMidi: | ||
return VirtualMidi; | ||
default: | ||
@@ -78,0 +81,0 @@ throw Error("Unknown module type"); |
@@ -1,3 +0,2 @@ | ||
import MidiDevice from "../MidiDevice"; | ||
import MidiDeviceManager from "../MidiDeviceManager"; | ||
import Engine from "../Engine"; | ||
import MidiEvent from "../MidiEvent"; | ||
@@ -29,2 +28,3 @@ import Module, { ModuleType, DummnyInternalModule } from "./Base"; | ||
this.registerOutputs(); | ||
this.addEventListener(this.selectedId); | ||
} | ||
@@ -38,5 +38,4 @@ | ||
if (this.selectedId) { | ||
MidiDeviceManager.find(this.selectedId).then((midiDevice: MidiDevice) => { | ||
midiDevice.removeEventListener(this.onMidiEvent); | ||
}); | ||
const prevMidiDevice = Engine.midiDeviceManager.find(this.selectedId); | ||
prevMidiDevice.removeEventListener(this.onMidiEvent); | ||
} | ||
@@ -46,10 +45,10 @@ | ||
if (!value) return; | ||
this.addEventListener(value); | ||
} | ||
MidiDeviceManager.find(value).then((midiDevice: MidiDevice) => { | ||
midiDevice.addEventListener(this.onMidiEvent); | ||
}); | ||
private registerOutputs() { | ||
this.midiOutput = this.registerOutput({ name: "midi out" }); | ||
} | ||
onMidiEvent = (midiEvent: MidiEvent) => { | ||
private onMidiEvent = (midiEvent: MidiEvent) => { | ||
this.midiOutput.connections.forEach((input) => { | ||
@@ -60,9 +59,8 @@ input.pluggable(midiEvent); | ||
async availableDevices(): Promise<MidiDevice[]> { | ||
return MidiDeviceManager.fetchDevices(); | ||
} | ||
private addEventListener(midiId: string | null) { | ||
if (!this.onMidiEvent || !midiId) return; // Ugly hack because of weird super bug | ||
private registerOutputs() { | ||
this.midiOutput = this.registerOutput({ name: "midi out" }); | ||
const midiDevice = Engine.midiDeviceManager.find(midiId); | ||
midiDevice.addEventListener(this.onMidiEvent); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
168203
95
3943