WIP: more beunsize map work
This commit is contained in:
parent
4dd4db6f65
commit
d79c6421e5
8 changed files with 222 additions and 47 deletions
|
|
@ -50,7 +50,6 @@ export class MidiControl<T extends MessageType> {
|
|||
this.device.input.setMaxListeners(50);
|
||||
|
||||
if (type === MessageType.NoteOnOff) {
|
||||
|
||||
this.addListener(MessageType.NoteOn)
|
||||
this.addListener(MessageType.NoteOff)
|
||||
} else {
|
||||
|
|
@ -90,7 +89,7 @@ export class MidiControl<T extends MessageType> {
|
|||
|
||||
const output = this.outputs[this.page];
|
||||
if (!output || output === undefined) return;
|
||||
output(data);
|
||||
output(outData);
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import osc from "osc";
|
|||
|
||||
interface IOSCEvent {
|
||||
address: string;
|
||||
handler: (message: osc.ResponseMessage<osc.MessageArg[]>) => void;
|
||||
handler: (data: string | number) => void;
|
||||
}
|
||||
|
||||
export class OSCDevice {
|
||||
|
|
@ -20,10 +20,17 @@ export class OSCDevice {
|
|||
this.port.on('error', (e) => { console.error('osc error', e) })
|
||||
|
||||
this.port.on('message', msg => {
|
||||
// console.log('msg', msg)
|
||||
for (const listener of this.listeners) {
|
||||
if (msg.address !== listener.address) continue;
|
||||
listener.handler(msg);
|
||||
if (msg.args[0] !== undefined) {
|
||||
let value: string | number | undefined;
|
||||
if (typeof msg.args[0] === 'object' && ['string', 'number'].includes(typeof msg.args[0].value)) value = msg.args[0].value as string | number;
|
||||
if (typeof msg.args[0] === 'string' || typeof msg.args[0] === 'number') value = msg.args[0];
|
||||
|
||||
if (value !== undefined) {
|
||||
listener.handler(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
|
@ -52,7 +59,7 @@ export class OSCDevice {
|
|||
this.port.send({ address });
|
||||
}
|
||||
|
||||
public addListener(address: string, handler: IOSCEvent['handler']): number {
|
||||
public addListener(address: string, handler: (data: string | number) => void): number {
|
||||
const newLength = this.listeners.push({
|
||||
address,
|
||||
handler
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue