Refactor object mangling and add midi support
This commit is contained in:
30
src/API.ts
30
src/API.ts
@ -9,7 +9,7 @@ import { tryEvaluate, evaluateOnce } from "./Evaluator";
|
||||
import { DrunkWalk } from "./Utils/Drunk";
|
||||
import { Editor } from "./main";
|
||||
import { SoundEvent } from "./classes/SoundEvent";
|
||||
import { MidiEvent } from "./classes/MidiEvent";
|
||||
import { MidiEvent, MidiParams } from "./classes/MidiEvent";
|
||||
import { LRUCache } from "lru-cache";
|
||||
import { InputOptions, Player } from "./classes/ZPlayer";
|
||||
import {
|
||||
@ -390,9 +390,10 @@ export class UserAPI {
|
||||
};
|
||||
|
||||
public midi = (
|
||||
value: number | object = 60,
|
||||
velocity?: number,
|
||||
channel?: number
|
||||
value: number | number[] = 60,
|
||||
velocity?: number | number[],
|
||||
channel?: number | number[],
|
||||
port?: number | string | number[] | string[]
|
||||
): MidiEvent => {
|
||||
/**
|
||||
* Sends a MIDI note to the current MIDI output.
|
||||
@ -402,24 +403,9 @@ export class UserAPI {
|
||||
* { 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;
|
||||
}
|
||||
const event = {note: value, velocity, channel, port} as MidiParams
|
||||
|
||||
if (channel !== undefined) {
|
||||
if (typeof value === "number") {
|
||||
value = { note: value };
|
||||
}
|
||||
// @ts-ignore
|
||||
value["channel"] = channel;
|
||||
}
|
||||
|
||||
return new MidiEvent(value, this.app);
|
||||
return new MidiEvent(event, this.app);
|
||||
};
|
||||
|
||||
public sysex = (data: Array<number>): void => {
|
||||
@ -1893,7 +1879,7 @@ export class UserAPI {
|
||||
// Trivial functions
|
||||
// =============================================================
|
||||
|
||||
sound = (sound: string | object) => {
|
||||
sound = (sound: string | string[]) => {
|
||||
return new SoundEvent(sound, this.app);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user