From 3c663a9d20c90f43e3512dd573f1ef2f9e44d632 Mon Sep 17 00:00:00 2001 From: Miika Alonen Date: Thu, 21 Sep 2023 22:11:03 +0300 Subject: [PATCH 1/3] Added z0-z16 as string prototypes --- src/StringExtensions.ts | 92 ++++++++++++++++++++++++++++++++++-- src/documentation/ziffers.ts | 14 ++++++ 2 files changed, 103 insertions(+), 3 deletions(-) diff --git a/src/StringExtensions.ts b/src/StringExtensions.ts index 65931c5..b1a3261 100644 --- a/src/StringExtensions.ts +++ b/src/StringExtensions.ts @@ -5,7 +5,6 @@ export {}; // Extend String prototype declare global { interface String { - z(): Player; speak(): void; rate(speed: number): string; pitch(pitch: number): string; @@ -13,6 +12,24 @@ declare global { voice(voice: number): string; lang(language: string): string; options(): SpeechOptions; + 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; } } @@ -59,9 +76,78 @@ export const makeStringExtensions = (api: UserAPI) => { return stringObject(this.valueOf(), {voice: voice}); }; - String.prototype.z = function () { - return api.z(this.valueOf()); + String.prototype.z = function (options: {[key: string]: any} = {}) { + return api.z(this.valueOf(), options); }; + + String.prototype.z0 = function (options: {[key: string]: any} = {}) { + return api.z0(this.valueOf(), options); + }; + + String.prototype.z1 = function (options: {[key: string]: any} = {}) { + return api.z1(this.valueOf(), options); + }; + + String.prototype.z2 = function (options: {[key: string]: any} = {}) { + return api.z2(this.valueOf(), options); + }; + + String.prototype.z3 = function (options: {[key: string]: any} = {}) { + return api.z3(this.valueOf(), options); + }; + + String.prototype.z4 = function (options: {[key: string]: any} = {}) { + return api.z4(this.valueOf(), options); + }; + + String.prototype.z5 = function (options: {[key: string]: any} = {}) { + return api.z5(this.valueOf(), options); + }; + + String.prototype.z6 = function (options: {[key: string]: any} = {}) { + return api.z6(this.valueOf(), options); + }; + + String.prototype.z7 = function (options: {[key: string]: any} = {}) { + return api.z7(this.valueOf(), options); + }; + + String.prototype.z8 = function (options: {[key: string]: any} = {}) { + return api.z8(this.valueOf(), options); + }; + + String.prototype.z9 = function (options: {[key: string]: any} = {}) { + return api.z9(this.valueOf(), options); + }; + + String.prototype.z10 = function (options: {[key: string]: any} = {}) { + return api.z10(this.valueOf(), options); + }; + + String.prototype.z11 = function (options: {[key: string]: any} = {}) { + return api.z11(this.valueOf(), options); + }; + + String.prototype.z12 = function (options: {[key: string]: any} = {}) { + return api.z12(this.valueOf(), options); + }; + + String.prototype.z13 = function (options: {[key: string]: any} = {}) { + return api.z13(this.valueOf(), options); + }; + + String.prototype.z14 = function (options: {[key: string]: any} = {}) { + return api.z14(this.valueOf(), options); + }; + + String.prototype.z15 = function (options: {[key: string]: any} = {}) { + return api.z15(this.valueOf(), options); + }; + + String.prototype.z16 = function (options: {[key: string]: any} = {}) { + return api.z16(this.valueOf(), options); + }; + } type SpeechOptions = { diff --git a/src/documentation/ziffers.ts b/src/documentation/ziffers.ts index d0e06ea..460d71b 100644 --- a/src/documentation/ziffers.ts +++ b/src/documentation/ziffers.ts @@ -409,5 +409,19 @@ z1('q (0 3 1 5)+(2 5) e (0 5 2)*(2 3) (0 5 2)>>(2 3) (0 5 2)%(2 3)').sound('sine true )} +## String prototypes + +You can also use string prototypes as an alternative syntax for creating Ziffers patterns + +${makeExample( + "String prototypes", + ` + "q 0 e 5 2 6 2 q 3".z0().sound('sine').out() + "q 2 7 8 6".z1().octave(-1).sound('sine').out() + "q 2 7 8 6".z2({key: "C2", scale: "aeolian"}).sound('sine').scale("minor").out() +`, + true +)} + `; }; From b14411d58d89084ee91868db5dc1a56c13c43850 Mon Sep 17 00:00:00 2001 From: Miika Alonen Date: Thu, 21 Sep 2023 22:48:31 +0300 Subject: [PATCH 2/3] New scale methods from zifferjs --- package.json | 2 +- src/API.ts | 4 ++-- yarn.lock | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 6cea638..bf614c6 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "tone": "^14.8.49", "unique-names-generator": "^4.7.1", "vite-plugin-markdown": "^2.1.0", - "zifferjs": "^0.0.24", + "zifferjs": "^0.0.25", "zzfx": "^1.2.0" } } diff --git a/src/API.ts b/src/API.ts index 871b99e..6d30454 100644 --- a/src/API.ts +++ b/src/API.ts @@ -2,7 +2,6 @@ import { seededRandom } from "zifferjs"; import { MidiConnection } from "./IO/MidiConnection"; import { tryEvaluate, evaluateOnce } from "./Evaluator"; import { DrunkWalk } from "./Utils/Drunk"; -import { scale } from "./Scales"; import { Editor } from "./main"; import { SoundEvent } from "./classes/SoundEvent"; import { MidiEvent } from "./classes/MidiEvent"; @@ -17,6 +16,7 @@ import { // @ts-ignore } from "superdough"; import { Speaker } from "./StringExtensions"; +import { getScaleNotes } from "zifferjs"; interface ControlChange { channel: number; @@ -1513,7 +1513,7 @@ export class UserAPI { this._logMessage(message); }; - scale = scale; + scale = getScaleNotes rate = (rate: number): void => { rate = rate; diff --git a/yarn.lock b/yarn.lock index b25765a..c198d7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1451,10 +1451,10 @@ yaml@^2.1.1: resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b" integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ== -zifferjs@^0.0.24: - version "0.0.24" - resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.24.tgz#073f606086ed7977a8c5cd6cc2f9d6c897415281" - integrity sha512-pTUM2i3pTBsINiflBym48pzQnEmw93Xf9GVq0FUnnWwLBirwJJsOxJeZZG/c7DVf4EnV7oC1Ik/R5ULt2sVtug== +zifferjs@^0.0.25: + version "0.0.25" + resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.25.tgz#939d170e4c263974d002e2c125c29b54ddbcd8dc" + integrity sha512-3cOvt7hYAUGM/qZ7IexrQxA8N2QrYF1ZEly1KqZiD5qPXSUb2lkhtBXqAoO0maSCDO6+C6MnTVuWft/VI+uM/g== zzfx@^1.2.0: version "1.2.0" From 0816356dc766b26d5f981976f26e509bfa516dcb Mon Sep 17 00:00:00 2001 From: Miika Alonen Date: Thu, 21 Sep 2023 23:36:51 +0300 Subject: [PATCH 3/3] New zifferjs version --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index bf614c6..992a81b 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "tone": "^14.8.49", "unique-names-generator": "^4.7.1", "vite-plugin-markdown": "^2.1.0", - "zifferjs": "^0.0.25", + "zifferjs": "^0.0.26", "zzfx": "^1.2.0" } } diff --git a/yarn.lock b/yarn.lock index c198d7d..177b073 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1451,10 +1451,10 @@ yaml@^2.1.1: resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b" integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ== -zifferjs@^0.0.25: - version "0.0.25" - resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.25.tgz#939d170e4c263974d002e2c125c29b54ddbcd8dc" - integrity sha512-3cOvt7hYAUGM/qZ7IexrQxA8N2QrYF1ZEly1KqZiD5qPXSUb2lkhtBXqAoO0maSCDO6+C6MnTVuWft/VI+uM/g== +zifferjs@^0.0.26: + version "0.0.26" + resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.26.tgz#a137543b4f4bea19f06cf14bb5c75ae70015d372" + integrity sha512-7UkazHovtVlgvjMZXeAG5KyR4FBKbkXhhaq38K/dmluEI08BeDJCKjspbYdxgS59x3SzhjlTJO7De4oB22CyhQ== zzfx@^1.2.0: version "1.2.0"