code quality
This commit is contained in:
22
src/API.ts
22
src/API.ts
@ -16,6 +16,13 @@ import {
|
||||
// This is an LRU cache used for storing persistent patterns
|
||||
const cache = new LRUCache({max: 1000, ttl: 1000 * 60 * 5});
|
||||
|
||||
interface ControlChange {
|
||||
channel: number
|
||||
control: number
|
||||
value: number
|
||||
}
|
||||
|
||||
|
||||
interface Pattern<T> {
|
||||
pattern: any[];
|
||||
options: {
|
||||
@ -68,7 +75,7 @@ export class UserAPI {
|
||||
|
||||
get time(): number {
|
||||
/**
|
||||
* @returns The current time for the AudioContext
|
||||
* @returns the current AudioContext time (wall clock)
|
||||
*/
|
||||
return this.app.audioContext.currentTime;
|
||||
}
|
||||
@ -112,7 +119,7 @@ export class UserAPI {
|
||||
}
|
||||
s = this.script;
|
||||
|
||||
clearscript(script: number): void {
|
||||
clear_script(script: number): void {
|
||||
/**
|
||||
* Clears a local script
|
||||
*
|
||||
@ -124,9 +131,9 @@ export class UserAPI {
|
||||
evaluations: 0,
|
||||
};
|
||||
}
|
||||
cs = this.clearscript;
|
||||
cs = this.clear_script;
|
||||
|
||||
copyscript(from: number, to: number): void {
|
||||
copy_script(from: number, to: number): void {
|
||||
/**
|
||||
* Copy from a local script to another local script
|
||||
*
|
||||
@ -136,7 +143,7 @@ export class UserAPI {
|
||||
this.app.universes[this.app.selected_universe].locals[to] =
|
||||
this.app.universes[this.app.selected_universe].locals[from];
|
||||
}
|
||||
cps = this.copyscript;
|
||||
cps = this.copy_script;
|
||||
|
||||
// =============================================================
|
||||
// MIDI related functions
|
||||
@ -217,14 +224,15 @@ export class UserAPI {
|
||||
this.MidiConnection.sendMidiClock();
|
||||
}
|
||||
|
||||
public cc(control: number, value: number): void {
|
||||
|
||||
public control_change({ control= 20, value= 0, channel=0 }: ControlChange): void {
|
||||
/**
|
||||
* Sends a MIDI control change to the current MIDI output.
|
||||
*
|
||||
* @param control - The MIDI control to send
|
||||
* @param value - The value of the control
|
||||
*/
|
||||
this.MidiConnection.sendMidiControlChange(control, value);
|
||||
this.MidiConnection.sendMidiControlChange(control, value, channel);
|
||||
}
|
||||
|
||||
public midi_panic(): void {
|
||||
|
||||
17
src/Clock.ts
17
src/Clock.ts
@ -78,11 +78,22 @@ export class Clock {
|
||||
}
|
||||
|
||||
get beats_since_origin(): number {
|
||||
/**
|
||||
* Returns the number of beats since the origin.
|
||||
*
|
||||
* @returns number of beats since origin
|
||||
*/
|
||||
return (this.time_position.bar - 1) * this.beats_per_bar + this.time_position.beat;
|
||||
}
|
||||
|
||||
get pulses_since_origin(): number {
|
||||
/**
|
||||
* Returns the number of pulses since the origin.
|
||||
*
|
||||
* @returns number of pulses since origin
|
||||
*/
|
||||
return (this.beats_since_origin * this.ppqn) + this.time_position.pulse
|
||||
|
||||
}
|
||||
|
||||
get pulse_duration(): number {
|
||||
@ -100,7 +111,7 @@ export class Clock {
|
||||
}
|
||||
|
||||
|
||||
start(): void {
|
||||
public start(): void {
|
||||
/**
|
||||
* Starts the TransportNode (starts the clock).
|
||||
*/
|
||||
@ -113,14 +124,14 @@ export class Clock {
|
||||
}
|
||||
}
|
||||
|
||||
pause(): void {
|
||||
public pause(): void {
|
||||
/**
|
||||
* Pauses the TransportNode (pauses the clock).
|
||||
*/
|
||||
this.transportNode?.pause();
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
public stop(): void {
|
||||
/**
|
||||
* Stops the TransportNode (stops the clock).
|
||||
*/
|
||||
|
||||
@ -182,16 +182,17 @@ export class MidiConnection{
|
||||
}
|
||||
}
|
||||
|
||||
public sendMidiControlChange(controlNumber: number, value: number): void {
|
||||
public sendMidiControlChange(controlNumber: number, value: number, channel: number): void {
|
||||
/**
|
||||
* Sends a MIDI Control Change message to the currently selected MIDI output.
|
||||
*
|
||||
* @param controlNumber MIDI control number (0-127)
|
||||
* @param value MIDI control value (0-127)
|
||||
* @param channel MIDI channel (0-15)
|
||||
*/
|
||||
const output = this.midiOutputs[this.currentOutputIndex];
|
||||
if (output) {
|
||||
output.send([0xB0, controlNumber, value]); // Control Change
|
||||
output.send([0xB0 + channel, controlNumber, value]); // Control Change
|
||||
} else {
|
||||
console.error('MIDI output not available.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user