WIP: APC mini mk2
This commit is contained in:
parent
d79c6421e5
commit
2efeb55543
4 changed files with 224 additions and 34 deletions
|
|
@ -2,7 +2,7 @@ import osc from "osc";
|
|||
|
||||
interface IOSCEvent {
|
||||
address: string;
|
||||
handler: (data: string | number) => void;
|
||||
handler: (data: Array<string | number>) => void;
|
||||
}
|
||||
|
||||
export class OSCDevice {
|
||||
|
|
@ -22,15 +22,21 @@ export class OSCDevice {
|
|||
this.port.on('message', msg => {
|
||||
for (const listener of this.listeners) {
|
||||
if (msg.address !== listener.address) continue;
|
||||
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 (!msg.args.length) continue;
|
||||
|
||||
if (value !== undefined) {
|
||||
listener.handler(value);
|
||||
const argValues = msg.args.map(arg => {
|
||||
if (typeof arg === 'object' && ['string', 'number'].includes(typeof arg.value)) {
|
||||
return arg.value as string | number;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof arg === 'number' || typeof arg === 'string') {
|
||||
return arg;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}).filter(v => v !== undefined);
|
||||
|
||||
listener.handler(argValues);
|
||||
}
|
||||
|
||||
})
|
||||
|
|
@ -59,7 +65,7 @@ export class OSCDevice {
|
|||
this.port.send({ address });
|
||||
}
|
||||
|
||||
public addListener(address: string, handler: (data: string | number) => void): number {
|
||||
public addListener(address: string, handler: (data: Array<string | number>) => void): number {
|
||||
const newLength = this.listeners.push({
|
||||
address,
|
||||
handler
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue