Skip to content

Commit

Permalink
Merge branch 'main' into new-theming
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubobubobubobubo authored Dec 16, 2023
2 parents 8739c3b + 02d8863 commit 57fe8a4
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 33 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@
<p rel="noopener noreferrer" id="docs_ziffers_syncing" class="doc_subheader">Syncing</p>
</div>
</details>

<p rel="noopener noreferrer" id="docs_variables" class="doc_header">Global Variables</p>
<p rel="noopener noreferrer" id="docs_lfos" class="doc_header">Low Freq Oscs.</p>
<p rel="noopener noreferrer" id="docs_probabilities" class="doc_header">Probabilities</p>
<p rel="noopener noreferrer" id="docs_chaining" class="doc_header">Chaining</p>
<p rel="noopener noreferrer" id="docs_functions" class="doc_header">Functions</p>
<p rel="noopener noreferrer" id="docs_generators" class="doc_header">Generators</p>
</div>
</details>
<details class="space-y-2" open>
Expand Down
14 changes: 7 additions & 7 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ export class UserAPI {
public randomGen = Math.random;
public currentSeed: string | undefined = undefined;
public localSeeds = new Map<string, Function>();
public patternCache = new LRUCache({ max: 1000, ttl: 1000 * 60 * 5 });
public tempCache = new LRUCache({ max: 1000, ttl: 1000 * 60 * 5 });
public patternCache = new LRUCache({ max: 10000, ttl: 10000 * 60 * 5 });
public invalidPatterns: {[key: string]: boolean} = {};
public cueTimes: { [key: string]: number } = {};
private errorTimeoutID: number = 0;
Expand Down Expand Up @@ -148,8 +147,8 @@ export class UserAPI {
? code
: (this.app.selectedExample as string);
}
this.clearPatternCache();
this.stop();
this.resetAllFromCache();
this.play();
};

Expand All @@ -160,6 +159,7 @@ export class UserAPI {
current_universe.example.candidate! = "";
current_universe.example.committed! = "";
}
this.clearPatternCache();
this.stop();
};

Expand All @@ -169,10 +169,10 @@ export class UserAPI {
current_universe.example.candidate! = "";
current_universe.example.committed! = "";
}
this.clearPatternCache();
this.stop();
this.play();
this.app.exampleIsPlaying = true;
this.resetAllFromCache();
evaluateOnce(this.app, code as string);
};

Expand Down Expand Up @@ -725,7 +725,7 @@ export class UserAPI {

maybeToNumber = (something: any): number|any => {
// If something is BigInt
if(something && typeof something === "bigint") {
if(typeof something === "bigint") {
return Number(something);
} else {
return something;
Expand All @@ -744,7 +744,7 @@ export class UserAPI {
if(isGenerator(value)) {
if(this.patternCache.has(key)) {
const cachedValue = (this.patternCache.get(key) as Generator<any>).next().value
if(!cachedValue) {
if(cachedValue!==0 && !cachedValue) {
const generator = value as unknown as Generator<any>
this.patternCache.set(key, generator);
return this.maybeToNumber(generator.next().value);
Expand All @@ -758,7 +758,7 @@ export class UserAPI {
} else if(isGeneratorFunction(value)) {
if(this.patternCache.has(key)) {
const cachedValue = (this.patternCache.get(key) as Generator<any>).next().value;
if(cachedValue) {
if(cachedValue || cachedValue===0 || cachedValue===0n) {
return this.maybeToNumber(cachedValue);
} else {
const generator = value();
Expand Down
2 changes: 2 additions & 0 deletions src/Documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { midi } from "./documentation/learning/midi";
import { osc } from "./documentation/learning/osc";
import { patterns } from "./documentation/patterns/patterns";
import { functions } from "./documentation/patterns/functions";
import { generators } from "./documentation/patterns/generators";
import { variables } from "./documentation/patterns/variables";
import { probabilities } from "./documentation/patterns/probabilities";
import { lfos } from "./documentation/patterns/lfos";
Expand Down Expand Up @@ -106,6 +107,7 @@ export const documentation_factory = (application: Editor) => {
variables: variables(application),
probabilities: probabilities(application),
functions: functions(application),
generators: generators(application),
shortcuts: shortcuts(application),
amplitude: amplitude(application),
effects: effects(application),
Expand Down
1 change: 1 addition & 0 deletions src/InterfaceLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ export const installInterfaceLogic = (app: Editor) => {
"midi",
"osc",
"functions",
"generators",
"lfos",
"probabilities",
"variables",
Expand Down
41 changes: 23 additions & 18 deletions src/classes/AbstractEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { SkipEvent } from "./SkipEvent";
import { SoundParams } from "./SoundEvent";
import { centsToSemitones, edoToSemitones, ratiosToSemitones } from "zifferjs/src/scale";
import { safeMod } from "zifferjs/src/utils";

export type EventOperation<T> = (instance: T, ...args: any[]) => void;

Expand Down Expand Up @@ -210,9 +211,14 @@ export class AbstractEvent {
* @param func - The function to be applied to the Event
* @returns The transformed Event
*/
return this.modify(func);
return this.modify(func).update();
};

mod = (value: number): AbstractEvent => {
this.values.originalPitch = safeMod(this.values.originalPitch, value);
return this.update();
}

noteLength = (
value: number | number[],
...kwargs: number[]
Expand Down Expand Up @@ -297,8 +303,7 @@ export abstract class AudibleEvent extends AbstractEvent {
this.values["pitch"] = value;
this.values["originalPitch"] = value;
this.defaultPitchKeyScale();
this.update();
return this;
return this.update();
};

pc = this.pitch;
Expand All @@ -317,8 +322,10 @@ export abstract class AudibleEvent extends AbstractEvent {
this.values.key &&
(this.values.pitch || this.values.pitch === 0) &&
this.values.parsedScale
)
this.update();
) {
return this.update();
}

return this;
};

Expand All @@ -335,8 +342,10 @@ export abstract class AudibleEvent extends AbstractEvent {
if (
(this.values.pitch || this.values.pitch === 0) &&
this.values.parsedScale
)
this.update();
) {
return this.update();
}

return this;
};

Expand Down Expand Up @@ -364,40 +373,35 @@ export abstract class AudibleEvent extends AbstractEvent {
this.values.parsedScale = value.map((v) => safeScale(v));
}
this.defaultPitchKeyScale();
this.update();
return this;
return this.update();
};

semitones(values: number|number[], ...rest: number[]) {
const scaleValues = typeof values === "number" ? [values, ...rest] : values;
this.values.parsedScale = safeScale(scaleValues);
this.defaultPitchKeyScale();
this.update();
return this;
return this.update();
}
steps = this.semitones;

cents(values: number|number[], ...rest: number[]) {
const scaleValues = typeof values === "number" ? [values, ...rest] : values;
this.values.parsedScale = safeScale(centsToSemitones(scaleValues));
this.defaultPitchKeyScale();
this.update();
return this;
return this.update();
}

ratios(values: number|number[], ...rest: number[]) {
const scaleValues = typeof values === "number" ? [values, ...rest] : values;
this.values.parsedScale = safeScale(ratiosToSemitones(scaleValues));
this.defaultPitchKeyScale();
this.update();
return this;
return this.update();
}

edo(value: number, intervals: string|number[] = new Array(value).fill(1)) {
this.values.parsedScale = edoToSemitones(value, intervals);
this.defaultPitchKeyScale();
this.update();
return this;
return this.update();
}

protected updateValue<T>(key: string, value: T | T[] | null): this {
Expand Down Expand Up @@ -498,8 +502,9 @@ export abstract class AudibleEvent extends AbstractEvent {
return this;
};

update = (): void => {
update = (): this => {
// Overwrite in subclasses
return this;
};

cue = (functionName: string|Function): this => {
Expand Down
6 changes: 3 additions & 3 deletions src/classes/MidiEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export class MidiEvent extends AudibleEvent {
return funcResult;
} else {
func(this.values);
this.update();
return this;
return this.update();
}
};

Expand All @@ -83,7 +82,7 @@ export class MidiEvent extends AudibleEvent {
return this;
};

update = (): void => {
update = (): this => {
const filteredValues = filterObject(this.values, [
"key",
"pitch",
Expand Down Expand Up @@ -112,6 +111,7 @@ export class MidiEvent extends AudibleEvent {

this.values.note = newArrays.note;
if (newArrays.bend) this.values.bend = newArrays.bend;
return this;
};

out = (): void => {
Expand Down
7 changes: 3 additions & 4 deletions src/classes/SoundEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,11 @@ export class SoundEvent extends AudibleEvent {
if (funcResult instanceof Object) return funcResult;
else {
func(this.values);
this.update();
return this;
return this.update();
}
};

update = (): void => {
update = (): this => {
const filteredValues = filterObject(this.values, [
"key",
"pitch",
Expand Down Expand Up @@ -419,7 +418,7 @@ export class SoundEvent extends AudibleEvent {
this.values.pitch = newArrays.pitch;
this.values.octave = newArrays.octave;
this.values.pitchOctave = newArrays.pitchOctave;

return this;
};

out = (orbit?: number | number[]): void => {
Expand Down
3 changes: 3 additions & 0 deletions src/documentation/basics/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Topos is made to be controlled entirely with a keyboard. It is recommanded to st
|Force Eval|${key_shortcut(
"Ctrl + Shift + Enter",
)}|Force evaluation of the current script|
|Clear cache & Eval|${key_shortcut(
"Ctrl + Shift + Backspace (Delete)",
)}|Clears cache and forces evaluation to update cached scripts|
### Special
Expand Down
Loading

0 comments on commit 57fe8a4

Please sign in to comment.