This commit is contained in:
2023-11-26 23:06:49 +01:00
parent fc47d598ac
commit 22508acb9f
21 changed files with 243 additions and 232 deletions

View File

@ -111,7 +111,7 @@ export class UserAPI {
}
this.app.settings.saveApplicationToLocalStorage(
this.app.universes,
this.app.settings
this.app.settings,
);
this.app.updateKnownUniversesView();
};
@ -203,7 +203,7 @@ export class UserAPI {
// @ts-ignore
this.errorTimeoutID = setTimeout(
() => this.app.interface.error_line.classList.add("hidden"),
2000
2000,
);
};
@ -217,7 +217,7 @@ export class UserAPI {
// @ts-ignore
this.printTimeoutID = setTimeout(
() => this.app.interface.error_line.classList.add("hidden"),
4000
4000,
);
};
@ -268,7 +268,7 @@ export class UserAPI {
*/
this.app.clock.tick = beat * this.app.clock.ppqn;
this.app.clock.time_position = this.app.clock.convertTicksToTimeposition(
beat * this.app.clock.ppqn
beat * this.app.clock.ppqn,
);
};
@ -325,7 +325,7 @@ export class UserAPI {
blinkScript(this.app, "local", arg);
tryEvaluate(
this.app,
this.app.universes[this.app.selected_universe].locals[arg]
this.app.universes[this.app.selected_universe].locals[arg],
);
}
});
@ -372,7 +372,7 @@ export class UserAPI {
delete this.app.universes[universe];
this.app.settings.saveApplicationToLocalStorage(
this.app.universes,
this.app.settings
this.app.settings,
);
this.app.updateKnownUniversesView();
};
@ -388,7 +388,7 @@ export class UserAPI {
};
this.app.settings.saveApplicationToLocalStorage(
this.app.universes,
this.app.settings
this.app.settings,
);
}
this.app.selected_universe = "Default";
@ -425,7 +425,7 @@ export class UserAPI {
value: number | number[] = 60,
velocity?: number | number[],
channel?: number | number[],
port?: number | string | number[] | string[]
port?: number | string | number[] | string[],
): MidiEvent => {
/**
* Sends a MIDI note to the current MIDI output.
@ -500,7 +500,7 @@ export class UserAPI {
};
public active_note_events = (
channel?: number
channel?: number,
): MidiNoteEvent[] | undefined => {
/**
* @returns A list of currently active MIDI notes
@ -637,7 +637,7 @@ export class UserAPI {
scale: number | string,
channel: number = 0,
port: number | string = this.MidiConnection.currentOutputIndex || 0,
soundOff: boolean = false
soundOff: boolean = false,
): void => {
/**
* Sends given scale to midi output for visual aid
@ -661,7 +661,7 @@ export class UserAPI {
// @ts-ignore
scale: number | string = 0,
channel: number = 0,
port: number | string = this.MidiConnection.currentOutputIndex || 0
port: number | string = this.MidiConnection.currentOutputIndex || 0,
): void => {
/**
* Hides all notes by sending all notes off to midi output
@ -676,7 +676,7 @@ export class UserAPI {
midi_notes_off = (
channel: number = 0,
port: number | string = this.MidiConnection.currentOutputIndex || 0
port: number | string = this.MidiConnection.currentOutputIndex || 0,
): void => {
/**
* Sends all notes off to midi output
@ -686,7 +686,7 @@ export class UserAPI {
midi_sound_off = (
channel: number = 0,
port: number | string = this.MidiConnection.currentOutputIndex || 0
port: number | string = this.MidiConnection.currentOutputIndex || 0,
): void => {
/**
* Sends all sound off to midi output
@ -713,7 +713,7 @@ export class UserAPI {
public z = (
input: string | Generator<number>,
options: InputOptions = {},
id: number | string = ""
id: number | string = "",
): Player => {
const zid = "z" + id.toString();
const key = id === "" ? this.generateCacheKey(input, options) : zid;
@ -790,7 +790,7 @@ export class UserAPI {
public counter = (
name: string | number,
limit?: number,
step?: number
step?: number,
): number => {
/**
* Returns the current value of a counter, and increments it by the step value.
@ -1297,8 +1297,8 @@ export class UserAPI {
const results: boolean[] = nArray.map(
(value) =>
(this.app.clock.pulses_since_origin - Math.floor(nudge * this.ppqn())) %
Math.floor(value * this.ppqn()) ===
0
Math.floor(value * this.ppqn()) ===
0,
);
return results.some((value) => value === true);
};
@ -1317,8 +1317,8 @@ export class UserAPI {
const results: boolean[] = nArray.map(
(value) =>
(this.app.clock.pulses_since_origin - nudgeInPulses) %
Math.floor(value * barLength) ===
0
Math.floor(value * barLength) ===
0,
);
return results.some((value) => value === true);
};
@ -1333,7 +1333,7 @@ export class UserAPI {
*/
const nArray = Array.isArray(n) ? n : [n];
const results: boolean[] = nArray.map(
(value) => (this.app.clock.pulses_since_origin - nudge) % value === 0
(value) => (this.app.clock.pulses_since_origin - nudge) % value === 0,
);
return results.some((value) => value === true);
};
@ -1342,7 +1342,7 @@ export class UserAPI {
public tick = (tick: number | number[], offset: number = 0): boolean => {
const nArray = Array.isArray(tick) ? tick : [tick];
const results: boolean[] = nArray.map(
(value) => this.app.clock.time_position.pulse === value + offset
(value) => this.app.clock.time_position.pulse === value + offset,
);
return results.some((value) => value === true);
};
@ -1391,7 +1391,7 @@ export class UserAPI {
public onbar = (
bars: number[] | number,
n: number = this.app.clock.time_signature[0]
n: number = this.app.clock.time_signature[0],
): boolean => {
let current_bar = (this.app.clock.time_position.bar % n) + 1;
return typeof bars === "number"
@ -1419,7 +1419,7 @@ export class UserAPI {
if (decimal_part <= 0)
decimal_part = decimal_part + this.ppqn() * this.nominator();
final_pulses.push(
integral_part === this.cbeat() && this.cpulse() === decimal_part
integral_part === this.cbeat() && this.cpulse() === decimal_part,
);
});
return final_pulses.some((p) => p == true);
@ -1501,7 +1501,7 @@ export class UserAPI {
iterator: number,
pulses: number,
length: number,
rotate: number = 0
rotate: number = 0,
): boolean => {
/**
* Returns a euclidean cycle of size length, with n pulses, rotated or not.
@ -1520,7 +1520,7 @@ export class UserAPI {
div: number,
pulses: number,
length: number,
rotate: number = 0
rotate: number = 0,
): boolean => {
return (
this.beat(div) && this._euclidean_cycle(pulses, length, rotate).beat(div)
@ -1530,7 +1530,7 @@ export class UserAPI {
_euclidean_cycle(
pulses: number,
length: number,
rotate: number = 0
rotate: number = 0,
): boolean[] {
if (pulses == length) return Array.from({ length }, () => true);
function startsDescent(list: number[], i: number): boolean {
@ -1541,7 +1541,7 @@ export class UserAPI {
if (pulses >= length) return [true];
const resList = Array.from(
{ length },
(_, i) => (((pulses * (i - 1)) % length) + length) % length
(_, i) => (((pulses * (i - 1)) % length) + length) % length,
);
let cycle = resList.map((_, i) => startsDescent(resList, i));
if (rotate != 0) {
@ -1660,7 +1660,7 @@ export class UserAPI {
triangle = (
freq: number = 1,
times: number = 1,
offset: number = 0
offset: number = 0,
): number => {
/**
* Returns a triangle wave between -1 and 1.
@ -1677,7 +1677,7 @@ export class UserAPI {
utriangle = (
freq: number = 1,
times: number = 1,
offset: number = 0
offset: number = 0,
): number => {
/**
* Returns a triangle wave between 0 and 1.
@ -1694,7 +1694,7 @@ export class UserAPI {
freq: number = 1,
times: number = 1,
offset: number = 0,
duty: number = 0.5
duty: number = 0.5,
): number => {
/**
* Returns a square wave with a specified duty cycle between -1 and 1.
@ -1714,7 +1714,7 @@ export class UserAPI {
freq: number = 1,
times: number = 1,
offset: number = 0,
duty: number = 0.5
duty: number = 0.5,
): number => {
/**
* Returns a square wave between 0 and 1.
@ -1774,7 +1774,7 @@ export class UserAPI {
*/
const sum = values.reduce(
(accumulator, currentValue) => accumulator + currentValue,
0
0,
);
return sum / values.length;
};
@ -1784,7 +1784,7 @@ export class UserAPI {
yMin: number,
yMax: number,
xMin: number,
xMax: number
xMax: number,
): number => {
const percent = (inputY - yMin) / (yMax - yMin);
const outputX = percent * (xMax - xMin) + xMin;
@ -1814,7 +1814,7 @@ export class UserAPI {
lang: string = "en-US",
voice: number = 0,
rate: number = 1,
pitch: number = 1
pitch: number = 1,
): void => {
/*
* Speaks the given text using the browser's speech synthesis API.
@ -1889,7 +1889,7 @@ export class UserAPI {
const elements = args.slice(1); // Get the rest of the arguments as an array
const timepos = this.app.clock.pulses_since_origin;
const slice_count = Math.floor(
timepos / Math.floor(chunk_size * this.ppqn())
timepos / Math.floor(chunk_size * this.ppqn()),
);
return elements[slice_count % elements.length];
};
@ -1917,7 +1917,7 @@ export class UserAPI {
// =============================================================
register = (name: string, operation: EventOperation<AbstractEvent>): void => {
AbstractEvent.prototype[name] = function(
AbstractEvent.prototype[name] = function (
this: AbstractEvent,
...args: any[]
) {
@ -2024,7 +2024,7 @@ export class UserAPI {
".cm-comment": {
fontFamily: commentFont,
},
})
}),
),
});
};