diff --git a/package.json b/package.json index 9c592a8..3ca5a72 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.26", "zzfx": "^1.2.0" } } diff --git a/src/API.ts b/src/API.ts index 012e7ec..9c067f7 100644 --- a/src/API.ts +++ b/src/API.ts @@ -16,6 +16,7 @@ import { // @ts-ignore } from "superdough"; import { Speaker } from "./StringExtensions"; +import { getScaleNotes } from "zifferjs"; interface ControlChange { channel: number; @@ -1512,6 +1513,7 @@ export class UserAPI { this._logMessage(message); }; + scale = getScaleNotes; rate = (rate: number): void => { rate = rate; 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 +)} + `; }; diff --git a/yarn.lock b/yarn.lock index a840f11..876c1e2 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.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"