blink background

This commit is contained in:
2023-08-02 21:10:07 +02:00
parent 72dba1a581
commit 035328cf13
2 changed files with 49 additions and 8 deletions

View File

@ -18,6 +18,7 @@ const sound = (value: any) => ({
export class UserAPI {
variables: { [key: string]: any } = {}
iterators: { [key: string]: any } = {}
MidiConnection: MidiConnection = new MidiConnection()
strudelSound = webaudioOutput()
load: samples
@ -100,6 +101,34 @@ export class UserAPI {
this.MidiConnection.panic()
}
// =============================================================
// Iterator related functions
// =============================================================
public iterator(name: string, limit?: number, step?: number) {
// Check if iterator already exists
if (!(name in this.iterators)) {
// Create new iterator with default step of 1
this.iterators[name] = {
value: 0,
step: step ?? 1,
limit
};
} else {
// Increment existing iterator by step value
this.iterators[name].value += this.iterators[name].step;
// Check for limit overshoot
if (this.iterators[name].limit !== undefined &&
this.iterators[name].value > this.iterators[name].limit) {
this.iterators[name].value = 0;
}
}
// Return current iterator value
return this.iterators[name].value;
}
// =============================================================
// Variable related functions
// =============================================================