Add missing bar function + documentation

This commit is contained in:
2023-10-13 16:42:13 +02:00
parent ad9962848c
commit 2edbb577d0
2 changed files with 158 additions and 137 deletions

View File

@ -63,7 +63,7 @@ export class UserAPI {
private errorTimeoutID: number = 0;
private printTimeoutID: number = 0;
public MidiConnection: MidiConnection;
public scale_aid: string|number|undefined = undefined;
public scale_aid: string | number | undefined = undefined;
load: samples;
constructor(public app: Editor) {
@ -588,54 +588,54 @@ export class UserAPI {
};
public show_scale = (
root: number|string,
scale: number|string,
channel: number = 0,
port: number|string = (this.MidiConnection.currentOutputIndex || 0),
root: number | string,
scale: number | string,
channel: number = 0,
port: number | string = (this.MidiConnection.currentOutputIndex || 0),
soundOff: boolean = false): void => {
/**
* Sends given scale to midi output for visual aid
*/
if (!this.scale_aid || scale !== this.scale_aid) {
this.hide_scale(root,scale,channel,port);
this.hide_scale(root, scale, channel, port);
const scaleNotes = getAllScaleNotes(scale, root);
// Send each scale note to current midi out
scaleNotes.forEach(note => {
this.MidiConnection.sendMidiOn(note, channel, 1, port);
if(soundOff) this.MidiConnection.sendAllSoundOff(channel, port);
});
this.MidiConnection.sendMidiOn(note, channel, 1, port);
if (soundOff) this.MidiConnection.sendAllSoundOff(channel, port);
});
this.scale_aid = scale;
}
}
public hide_scale = (
// @ts-ignore
root: number|string=0,
root: number | string = 0,
// @ts-ignore
scale: number|string=0,
channel: number = 0,
port: number|string = (this.MidiConnection.currentOutputIndex || 0)): void => {
scale: number | string = 0,
channel: number = 0,
port: number | string = (this.MidiConnection.currentOutputIndex || 0)): void => {
/**
* Hides all notes by sending all notes off to midi output
*/
const allNotes = Array.from(Array(128).keys());
// Send each scale note to current midi out
allNotes.forEach(note => {
this.MidiConnection.sendMidiOff(note, channel, port);
});
this.scale_aid = undefined;
const allNotes = Array.from(Array(128).keys());
// Send each scale note to current midi out
allNotes.forEach(note => {
this.MidiConnection.sendMidiOff(note, channel, port);
});
this.scale_aid = undefined;
}
midi_notes_off = (channel: number = 0, port: number|string = (this.MidiConnection.currentOutputIndex || 0)): void => {
midi_notes_off = (channel: number = 0, port: number | string = (this.MidiConnection.currentOutputIndex || 0)): void => {
/**
* Sends all notes off to midi output
*/
this.MidiConnection.sendAllNotesOff(channel, port);
}
midi_sound_off = (channel: number = 0, port: number|string = (this.MidiConnection.currentOutputIndex || 0)): void => {
midi_sound_off = (channel: number = 0, port: number | string = (this.MidiConnection.currentOutputIndex || 0)): void => {
/**
* Sends all sound off to midi output
*/
@ -1269,6 +1269,17 @@ export class UserAPI {
};
b = this.beat;
public bar = (...n: number[]): boolean => {
const results: boolean[] = n.map(
(value) =>
this.app.clock.pulses_since_origin % Math.floor((value * this.ppqn()) * this.app.clock.time_signature[1]) ===
0
);
return results.some((value) => value === true);
};
B = this.bar;
public pulse = (...n: number[]): boolean => {
const results: boolean[] = n.map(
(value) => this.app.clock.pulses_since_origin % value === 0