Updating ziffers and adding generator functions and tonnetz support
This commit is contained in:
@ -28,6 +28,7 @@
|
||||
"autoprefixer": "^10.4.14",
|
||||
"codemirror": "^6.0.1",
|
||||
"fflate": "^0.8.0",
|
||||
"jisg": "^0.9.7",
|
||||
"lru-cache": "^10.0.1",
|
||||
"marked": "^7.0.3",
|
||||
"postcss": "^8.4.27",
|
||||
@ -39,7 +40,7 @@
|
||||
"tone": "^14.8.49",
|
||||
"unique-names-generator": "^4.7.1",
|
||||
"vite-plugin-markdown": "^2.1.0",
|
||||
"zifferjs": "^0.0.34",
|
||||
"zifferjs": "^0.0.35",
|
||||
"zzfx": "^1.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
// ================================================================================
|
||||
|
||||
13
yarn.lock
13
yarn.lock
@ -927,6 +927,11 @@ iterate-object@^1.3.2:
|
||||
resolved "https://registry.yarnpkg.com/iterate-object/-/iterate-object-1.3.4.tgz#fa50b1d9e58e340a7dd6b4c98c8a5e182e790096"
|
||||
integrity sha512-4dG1D1x/7g8PwHS9aK6QV5V94+ZvyP4+d19qDv43EzImmrndysIl4prmJ1hWWIGCqrZHyaHBm6BSEWHOLnpoNw==
|
||||
|
||||
jisg@^0.9.7:
|
||||
version "0.9.7"
|
||||
resolved "https://registry.yarnpkg.com/jisg/-/jisg-0.9.7.tgz#d080655808d1f30ec22eb2be070e8a10d8ee097f"
|
||||
integrity sha512-JWoGHGgU3xxJnPCNm6FpgMl0791xYFZq2PsejV8guCbhNJGsMvImAENx9pMhp7HbqhJgkM4ZV5lRbh5zbmF9xw==
|
||||
|
||||
jiti@^1.18.2:
|
||||
version "1.19.3"
|
||||
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.19.3.tgz#ef554f76465b3c2b222dc077834a71f0d4a37569"
|
||||
@ -1451,10 +1456,10 @@ yaml@^2.1.1:
|
||||
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b"
|
||||
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==
|
||||
|
||||
zifferjs@^0.0.34:
|
||||
version "0.0.34"
|
||||
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.34.tgz#887fb2db1ec2aff21ff1742cbbbbc4621838588f"
|
||||
integrity sha512-q2eFi+j+yXkPTXU53at3Agrh67JmBJ5zloZ13kc5ObT9R8R9L/if21mbnFxpDJC6Sjugql40aM0Ko4p/zBTs4w==
|
||||
zifferjs@^0.0.35:
|
||||
version "0.0.35"
|
||||
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.35.tgz#0518a84d031d2ef19417bc1084c21b08666df067"
|
||||
integrity sha512-vtvyEO/hIPRboGinkb1IhqJu4iU5DdbkzrQX8Xg7n096fDi/PU72b5Nwxt0xt29D37CfOI99sjaLbtYPab1NoA==
|
||||
|
||||
zzfx@^1.2.0:
|
||||
version "1.2.0"
|
||||
|
||||
Reference in New Issue
Block a user