From ae59afa4e29d80b751320fbc3e75c88d334bae90 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Fri, 25 Aug 2023 20:38:15 +0200 Subject: [PATCH] support different syntax for midi notes --- src/API.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/API.ts b/src/API.ts index 8ed69f7..3e65971 100644 --- a/src/API.ts +++ b/src/API.ts @@ -391,7 +391,11 @@ export class UserAPI { } }; - public midi = (value: number | object = 60): NoteEvent => { + public midi = ( + value: number | object = 60, + velocity?: number, + channel?: number + ): NoteEvent => { /** * Sends a MIDI note to the current MIDI output. * @@ -399,6 +403,24 @@ export class UserAPI { * @param options - an object containing options for that note * { channel: 0, velocity: 100, duration: 0.5 } */ + + if (velocity !== undefined) { + // Check if value is of type number + if (typeof value === "number") { + value = { note: value }; + } + // @ts-ignore + value["velocity"] = velocity; + } + + if (channel !== undefined) { + if (typeof value === "number") { + value = { note: value }; + } + // @ts-ignore + value["channel"] = channel; + } + return new NoteEvent(value, this.app); };