Updating ziffers and adding generator functions and tonnetz support
This commit is contained in:
18
src/API.ts
18
src/API.ts
@ -1,5 +1,5 @@
|
||||
import { EditorView } from '@codemirror/view';
|
||||
import { getAllScaleNotes, seededRandom } from "zifferjs";
|
||||
import { getAllScaleNotes, nearScales, seededRandom } from "zifferjs";
|
||||
import {
|
||||
MidiCCEvent,
|
||||
MidiConnection,
|
||||
@ -25,7 +25,7 @@ import {
|
||||
soundMap,
|
||||
// @ts-ignore
|
||||
} from "superdough";
|
||||
import { Speaker } from "./StringExtensions";
|
||||
import { Speaker } from "./extensions/StringExtensions";
|
||||
import { getScaleNotes } from "zifferjs";
|
||||
import { OscilloscopeConfig, blinkScript } from "./AudioVisualisation";
|
||||
import { SkipEvent } from './classes/SkipEvent';
|
||||
@ -675,8 +675,12 @@ export class UserAPI {
|
||||
this.patternCache.forEach((player) => (player as Player).reset());
|
||||
}
|
||||
|
||||
public removePatternFromCache = (id: string): void => {
|
||||
this.patternCache.delete(id);
|
||||
}
|
||||
|
||||
public z = (
|
||||
input: string,
|
||||
input: string | Generator<number>,
|
||||
options: InputOptions = {},
|
||||
id: number | string = ""
|
||||
): Player => {
|
||||
@ -687,7 +691,7 @@ export class UserAPI {
|
||||
|
||||
if (this.app.api.patternCache.has(key)) {
|
||||
player = this.app.api.patternCache.get(key) as Player;
|
||||
if (player.input !== input) {
|
||||
if (typeof input === "string" && player.input !== input) {
|
||||
player = undefined;
|
||||
}
|
||||
}
|
||||
@ -697,6 +701,10 @@ export class UserAPI {
|
||||
this.app.api.patternCache.set(key, player);
|
||||
}
|
||||
|
||||
if(player.ziffers.generator && player.ziffers.generatorDone) {
|
||||
this.removePatternFromCache(key);
|
||||
}
|
||||
|
||||
if (typeof id === "number") player.zid = zid;
|
||||
|
||||
player.updateLastCallTime();
|
||||
@ -1895,6 +1903,8 @@ export class UserAPI {
|
||||
|
||||
scale = getScaleNotes;
|
||||
|
||||
nearScales = nearScales;
|
||||
|
||||
rate = (rate: number): void => {
|
||||
rate = rate;
|
||||
// TODO: Implement this. This function should change the rate at which the global script
|
||||
|
||||
@ -10,7 +10,7 @@ import { arrayOfObjectsToObjectWithArrays } from "../Utils/Generic";
|
||||
export type InputOptions = { [key: string]: string | number };
|
||||
|
||||
export class Player extends Event {
|
||||
input: string;
|
||||
input: string|number;
|
||||
ziffers: Ziffers;
|
||||
initCallTime: number = 0;
|
||||
startCallTime: number = 0;
|
||||
@ -25,15 +25,23 @@ export class Player extends Event {
|
||||
skipIndex = 0;
|
||||
|
||||
constructor(
|
||||
input: string,
|
||||
input: string|number|Generator<number>,
|
||||
options: InputOptions,
|
||||
public app: Editor,
|
||||
zid: string = ""
|
||||
) {
|
||||
super(app);
|
||||
this.input = input;
|
||||
this.options = options;
|
||||
this.ziffers = new Ziffers(input, options);
|
||||
if (typeof input === "string") {
|
||||
this.input = input;
|
||||
this.ziffers = new Ziffers(input, options);
|
||||
} else if (typeof input === "number") {
|
||||
this.input = input;
|
||||
this.ziffers = Ziffers.fromNumber(input,options);
|
||||
} else {
|
||||
this.ziffers = Ziffers.fromGenerator(input,options);
|
||||
this.input = this.ziffers.input;
|
||||
}
|
||||
this.zid = zid;
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { type UserAPI } from "./API";
|
||||
import { type UserAPI } from "../API";
|
||||
import { safeScale, stepsToScale } from "zifferjs";
|
||||
export { };
|
||||
|
||||
98
src/extensions/NumberExtensions.ts
Normal file
98
src/extensions/NumberExtensions.ts
Normal file
@ -0,0 +1,98 @@
|
||||
import { type UserAPI } from "../API";
|
||||
import { Player } from "../classes/ZPlayer";
|
||||
|
||||
declare global {
|
||||
interface Number {
|
||||
z(): Player;
|
||||
z0(): Player;
|
||||
z1(): Player;
|
||||
z2(): Player;
|
||||
z3(): Player;
|
||||
z4(): Player;
|
||||
z5(): Player;
|
||||
z6(): Player;
|
||||
z7(): Player;
|
||||
z8(): Player;
|
||||
z9(): Player;
|
||||
z10(): Player;
|
||||
z11(): Player;
|
||||
z12(): Player;
|
||||
z13(): Player;
|
||||
z14(): Player;
|
||||
z15(): Player;
|
||||
z16(): Player;
|
||||
note(): number;
|
||||
}
|
||||
}
|
||||
|
||||
export const makeNumberExtensions = (api: UserAPI) => {
|
||||
|
||||
Number.prototype.z0 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z0(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z1 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z1(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z2 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z2(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z3 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z3(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z4 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z4(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z5 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z5(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z6 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z6(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z7 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z7(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z8 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z8(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z9 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z9(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z10 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z10(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z11 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z11(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z12 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z12(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z13 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z13(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z14 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z14(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z15 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z15(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
Number.prototype.z16 = function (options: {[key: string]: any} = {}) {
|
||||
return api.z16(this.valueOf().toString().split("").join(), options);
|
||||
};
|
||||
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
import { noteNameToMidi } from "zifferjs";
|
||||
import { type UserAPI } from "./API";
|
||||
import { Player } from "./classes/ZPlayer";
|
||||
import { type UserAPI } from "../API";
|
||||
import { Player } from "../classes/ZPlayer";
|
||||
export {};
|
||||
|
||||
// Extend String prototype
|
||||
18
src/main.ts
18
src/main.ts
@ -16,16 +16,19 @@ import { documentation_factory } from "./Documentation";
|
||||
import { EditorView } from "codemirror";
|
||||
import { Clock } from "./Clock";
|
||||
import { loadSamples, UserAPI } from "./API";
|
||||
import { makeArrayExtensions } from "./ArrayExtensions";
|
||||
import * as oeis from 'jisg'
|
||||
import * as zpatterns from 'zifferjs/src/patterns.ts'
|
||||
import { makeArrayExtensions } from "./extensions/ArrayExtensions";
|
||||
import "./style.css";
|
||||
import { Universes, File, template_universes } from "./FileManagement";
|
||||
import { tryEvaluate } from "./Evaluator";
|
||||
// @ts-ignore
|
||||
import showdown from "showdown";
|
||||
import { makeStringExtensions } from "./StringExtensions";
|
||||
import { makeStringExtensions } from "./extensions/StringExtensions";
|
||||
import { installInterfaceLogic } from "./InterfaceLogic";
|
||||
import { installWindowBehaviors } from "./WindowBehavior";
|
||||
import { drawEmptyBlinkers } from "./AudioVisualisation";
|
||||
import { makeNumberExtensions } from "./extensions/NumberExtensions";
|
||||
|
||||
export class Editor {
|
||||
// Universes and settings
|
||||
@ -120,12 +123,23 @@ export class Editor {
|
||||
this.api = new UserAPI(this);
|
||||
makeArrayExtensions(this.api);
|
||||
makeStringExtensions(this.api);
|
||||
makeNumberExtensions(this.api);
|
||||
|
||||
// Passing the API to the User
|
||||
Object.entries(this.api).forEach(([name, value]) => {
|
||||
(globalThis as Record<string, any>)[name] = value;
|
||||
});
|
||||
|
||||
// Passing OEIS generators to the User
|
||||
Object.entries(oeis).forEach(([name, value]) => {
|
||||
(globalThis as Record<string, any>)[name] = value;
|
||||
});
|
||||
|
||||
// Passing ziffers sequences to the User
|
||||
Object.entries(zpatterns).forEach(([name, value]) => {
|
||||
(globalThis as Record<string, any>)[name] = value;
|
||||
});
|
||||
|
||||
// ================================================================================
|
||||
// Building Documentation
|
||||
// ================================================================================
|
||||
|
||||
Reference in New Issue
Block a user