Skip to content

Commit

Permalink
feat(devicePrototype): Add new control listener generator with embedd…
Browse files Browse the repository at this point in the history
…ed filtering
  • Loading branch information
bamdadfr committed Apr 3, 2022
1 parent 8b98f8f commit 30675bb
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/app/devices/device/device.prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,34 @@ devicePrototype.addControlListener = function(listener, isToggle = false): void
);
};

interface AddControlListenerNewOptions {
note: number;
callback;
isToggle: boolean;
}

devicePrototype.addControlListener_NEW = function({
note,
callback,
isToggle = false,
}: AddControlListenerNewOptions) {
const message = 'controlchange';
const channel = this.settings.channels.input;
const handler = (e) => {
if (note !== e.controller.number) {
return;
}

if (isToggle && e.value !== 127) {
return;
}

callback(e);
};

this.device.input.addListener(message, channel, handler);
};

/**
* Utility function to remove an input event from the device
*/
Expand Down

0 comments on commit 30675bb

Please sign in to comment.