Updated zifferjs and added edo scales
This commit is contained in:
@ -43,7 +43,7 @@
|
|||||||
"tone": "^14.8.49",
|
"tone": "^14.8.49",
|
||||||
"unique-names-generator": "^4.7.1",
|
"unique-names-generator": "^4.7.1",
|
||||||
"vite-plugin-markdown": "^2.1.0",
|
"vite-plugin-markdown": "^2.1.0",
|
||||||
"zifferjs": "^0.0.53",
|
"zifferjs": "^0.0.54",
|
||||||
"zyklus": "^0.1.4",
|
"zyklus": "^0.1.4",
|
||||||
"zzfx": "^1.2.0"
|
"zzfx": "^1.2.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -146,6 +146,7 @@ export class UserAPI {
|
|||||||
: (this.app.selectedExample as string);
|
: (this.app.selectedExample as string);
|
||||||
}
|
}
|
||||||
this.stop();
|
this.stop();
|
||||||
|
this.resetAllFromCache();
|
||||||
this.play();
|
this.play();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -168,6 +169,7 @@ export class UserAPI {
|
|||||||
this.stop();
|
this.stop();
|
||||||
this.play();
|
this.play();
|
||||||
this.app.exampleIsPlaying = true;
|
this.app.exampleIsPlaying = true;
|
||||||
|
this.resetAllFromCache();
|
||||||
evaluateOnce(this.app, code as string);
|
evaluateOnce(this.app, code as string);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import {
|
|||||||
} from "zifferjs";
|
} from "zifferjs";
|
||||||
import { SkipEvent } from "./SkipEvent";
|
import { SkipEvent } from "./SkipEvent";
|
||||||
import { SoundParams } from "./SoundEvent";
|
import { SoundParams } from "./SoundEvent";
|
||||||
import { centsToSemitones, ratiosToSemitones } from "zifferjs/src/scale";
|
import { centsToSemitones, edoToSemitones, ratiosToSemitones } from "zifferjs/src/scale";
|
||||||
|
|
||||||
export type EventOperation<T> = (instance: T, ...args: any[]) => void;
|
export type EventOperation<T> = (instance: T, ...args: any[]) => void;
|
||||||
|
|
||||||
@ -295,7 +295,9 @@ export abstract class AudibleEvent extends AbstractEvent {
|
|||||||
value = Array.isArray(value) ? value.concat(kwargs) : [value, ...kwargs];
|
value = Array.isArray(value) ? value.concat(kwargs) : [value, ...kwargs];
|
||||||
}
|
}
|
||||||
this.values["pitch"] = value;
|
this.values["pitch"] = value;
|
||||||
if (this.values.key && this.values.parsedScale) this.update();
|
this.values["originalPitch"] = value;
|
||||||
|
this.defaultPitchKeyScale();
|
||||||
|
this.update();
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -310,7 +312,7 @@ export abstract class AudibleEvent extends AbstractEvent {
|
|||||||
if (kwargs.length > 0) {
|
if (kwargs.length > 0) {
|
||||||
value = Array.isArray(value) ? value.concat(kwargs) : [value, ...kwargs];
|
value = Array.isArray(value) ? value.concat(kwargs) : [value, ...kwargs];
|
||||||
}
|
}
|
||||||
this.values["octave"] = value;
|
this.values["paramOctave"] = value;
|
||||||
if (
|
if (
|
||||||
this.values.key &&
|
this.values.key &&
|
||||||
(this.values.pitch || this.values.pitch === 0) &&
|
(this.values.pitch || this.values.pitch === 0) &&
|
||||||
@ -338,6 +340,12 @@ export abstract class AudibleEvent extends AbstractEvent {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
defaultPitchKeyScale() {
|
||||||
|
if (!this.values.key) this.values.key = 60;
|
||||||
|
if (!(this.values.pitch || this.values.pitch === 0)) this.values.pitch = 0;
|
||||||
|
if (!this.values.parsedScale) this.values.parsedScale = safeScale("major");
|
||||||
|
}
|
||||||
|
|
||||||
scale = (
|
scale = (
|
||||||
value: string | number | (number | string)[],
|
value: string | number | (number | string)[],
|
||||||
...kwargs: (string | number)[]
|
...kwargs: (string | number)[]
|
||||||
@ -355,21 +363,15 @@ export abstract class AudibleEvent extends AbstractEvent {
|
|||||||
} else if (Array.isArray(value)) {
|
} else if (Array.isArray(value)) {
|
||||||
this.values.parsedScale = value.map((v) => safeScale(v));
|
this.values.parsedScale = value.map((v) => safeScale(v));
|
||||||
}
|
}
|
||||||
if (this.values.key && (this.values.pitch || this.values.pitch === 0)) {
|
this.defaultPitchKeyScale();
|
||||||
this.update();
|
this.update();
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
updateKeyAndPitch() {
|
|
||||||
if (!this.values.key) this.values.key = 60;
|
|
||||||
if (!(this.values.pitch || this.values.pitch === 0)) this.values.pitch = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
semitones(values: number|number[], ...rest: number[]) {
|
semitones(values: number|number[], ...rest: number[]) {
|
||||||
const scaleValues = typeof values === "number" ? [values, ...rest] : values;
|
const scaleValues = typeof values === "number" ? [values, ...rest] : values;
|
||||||
this.values.parsedScale = safeScale(scaleValues);
|
this.values.parsedScale = safeScale(scaleValues);
|
||||||
this.updateKeyAndPitch();
|
this.defaultPitchKeyScale();
|
||||||
this.update();
|
this.update();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -378,7 +380,7 @@ export abstract class AudibleEvent extends AbstractEvent {
|
|||||||
cents(values: number|number[], ...rest: number[]) {
|
cents(values: number|number[], ...rest: number[]) {
|
||||||
const scaleValues = typeof values === "number" ? [values, ...rest] : values;
|
const scaleValues = typeof values === "number" ? [values, ...rest] : values;
|
||||||
this.values.parsedScale = safeScale(centsToSemitones(scaleValues));
|
this.values.parsedScale = safeScale(centsToSemitones(scaleValues));
|
||||||
this.updateKeyAndPitch();
|
this.defaultPitchKeyScale();
|
||||||
this.update();
|
this.update();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -386,7 +388,14 @@ export abstract class AudibleEvent extends AbstractEvent {
|
|||||||
ratios(values: number|number[], ...rest: number[]) {
|
ratios(values: number|number[], ...rest: number[]) {
|
||||||
const scaleValues = typeof values === "number" ? [values, ...rest] : values;
|
const scaleValues = typeof values === "number" ? [values, ...rest] : values;
|
||||||
this.values.parsedScale = safeScale(ratiosToSemitones(scaleValues));
|
this.values.parsedScale = safeScale(ratiosToSemitones(scaleValues));
|
||||||
this.updateKeyAndPitch();
|
this.defaultPitchKeyScale();
|
||||||
|
this.update();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
edo(value: number, intervals: string|number[] = new Array(value).fill(1)) {
|
||||||
|
this.values.parsedScale = edoToSemitones(value, intervals);
|
||||||
|
this.defaultPitchKeyScale();
|
||||||
this.update();
|
this.update();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { AudibleEvent } from "./AbstractEvents";
|
import { AudibleEvent } from "./AbstractEvents";
|
||||||
import { type Editor } from "../main";
|
import { type Editor } from "../main";
|
||||||
import { MidiConnection } from "../IO/MidiConnection";
|
import { MidiConnection } from "../IO/MidiConnection";
|
||||||
import { noteFromPc } from "zifferjs";
|
import { resolvePitchClass } from "zifferjs";
|
||||||
import {
|
import {
|
||||||
filterObject,
|
filterObject,
|
||||||
arrayOfObjectsToObjectWithArrays,
|
arrayOfObjectsToObjectWithArrays,
|
||||||
@ -84,27 +84,28 @@ export class MidiEvent extends AudibleEvent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
update = (): void => {
|
update = (): void => {
|
||||||
// Get key, pitch, parsedScale and octave from this.values object
|
|
||||||
const filteredValues = filterObject(this.values, [
|
const filteredValues = filterObject(this.values, [
|
||||||
"key",
|
"key",
|
||||||
"pitch",
|
"pitch",
|
||||||
|
"originalPitch",
|
||||||
"parsedScale",
|
"parsedScale",
|
||||||
"octave",
|
"addedOctave"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const events = objectWithArraysToArrayOfObjects(filteredValues, [
|
const events = objectWithArraysToArrayOfObjects(filteredValues, [
|
||||||
"parsedScale",
|
"parsedScale",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
events.forEach((event) => {
|
events.forEach((soundEvent) => {
|
||||||
const [note, bend] = noteFromPc(
|
const resolvedPitchClass = resolvePitchClass(
|
||||||
(event.key as number) || "C4",
|
(soundEvent.key || "C4"),
|
||||||
(event.pitch as number) || 0,
|
(soundEvent.originalPitch || soundEvent.pitch || 0),
|
||||||
(event.parsedScale as number[]) || event.scale || "MAJOR",
|
(soundEvent.parsedScale || soundEvent.scale || "MAJOR"),
|
||||||
(event.octave as number) || 0,
|
(soundEvent.addedOctave || 0)
|
||||||
);
|
);
|
||||||
event.note = note;
|
soundEvent.note = resolvedPitchClass.note;
|
||||||
if (bend) event.bend = bend;
|
soundEvent.pitch = resolvedPitchClass.pitch;
|
||||||
|
soundEvent.octave = resolvedPitchClass.octave;
|
||||||
});
|
});
|
||||||
|
|
||||||
const newArrays = arrayOfObjectsToObjectWithArrays(events) as MidiParams;
|
const newArrays = arrayOfObjectsToObjectWithArrays(events) as MidiParams;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
arrayOfObjectsToObjectWithArrays,
|
arrayOfObjectsToObjectWithArrays,
|
||||||
objectWithArraysToArrayOfObjects,
|
objectWithArraysToArrayOfObjects,
|
||||||
} from "../Utils/Generic";
|
} from "../Utils/Generic";
|
||||||
import { midiToFreq, noteFromPc } from "zifferjs";
|
import { midiToFreq, resolvePitchClass } from "zifferjs";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
superdough,
|
superdough,
|
||||||
@ -22,10 +22,13 @@ export type SoundParams = {
|
|||||||
note?: number | number[];
|
note?: number | number[];
|
||||||
freq?: number | number[];
|
freq?: number | number[];
|
||||||
pitch?: number | number[];
|
pitch?: number | number[];
|
||||||
|
originalPitch?: number | number[];
|
||||||
key?: string;
|
key?: string;
|
||||||
scale?: string;
|
scale?: string;
|
||||||
parsedScale?: number[];
|
parsedScale?: number[];
|
||||||
octave?: number | number[];
|
octave?: number | number[];
|
||||||
|
addedOctave?: number | number[];
|
||||||
|
pitchOctave?: number | number[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export class SoundEvent extends AudibleEvent {
|
export class SoundEvent extends AudibleEvent {
|
||||||
@ -387,27 +390,36 @@ export class SoundEvent extends AudibleEvent {
|
|||||||
const filteredValues = filterObject(this.values, [
|
const filteredValues = filterObject(this.values, [
|
||||||
"key",
|
"key",
|
||||||
"pitch",
|
"pitch",
|
||||||
|
"originalPitch",
|
||||||
"parsedScale",
|
"parsedScale",
|
||||||
|
"addedOctave",
|
||||||
"octave",
|
"octave",
|
||||||
|
"paramOctave"
|
||||||
]);
|
]);
|
||||||
const events = objectWithArraysToArrayOfObjects(filteredValues, [
|
const events = objectWithArraysToArrayOfObjects(filteredValues, [
|
||||||
"parsedScale",
|
"parsedScale",
|
||||||
]);
|
]);
|
||||||
events.forEach((event) => {
|
events.forEach((soundEvent) => {
|
||||||
const [note, _] = noteFromPc(
|
const resolvedPitchClass = resolvePitchClass(
|
||||||
(event.key as number) || "C4",
|
(soundEvent.key || "C4"),
|
||||||
(event.pitch as number) || 0,
|
(soundEvent.originalPitch || soundEvent.pitch || 0),
|
||||||
(event.parsedScale as number[]) || event.scale || "MAJOR",
|
(soundEvent.parsedScale || soundEvent.scale || "MAJOR"),
|
||||||
(event.octave as number) || 0,
|
(soundEvent.paramOctave || 0)+(soundEvent.addedOctave || 0)
|
||||||
);
|
);
|
||||||
event.note = note;
|
soundEvent.note = resolvedPitchClass.note;
|
||||||
event.freq = midiToFreq(note);
|
soundEvent.freq = midiToFreq(resolvedPitchClass.note);
|
||||||
|
soundEvent.pitch = resolvedPitchClass.pitch;
|
||||||
|
soundEvent.octave = resolvedPitchClass.octave;
|
||||||
});
|
});
|
||||||
|
|
||||||
const newArrays = arrayOfObjectsToObjectWithArrays(events) as SoundParams;
|
const newArrays = arrayOfObjectsToObjectWithArrays(events) as SoundParams;
|
||||||
|
|
||||||
this.values.note = newArrays.note;
|
this.values.note = newArrays.note;
|
||||||
this.values.freq = newArrays.freq;
|
this.values.freq = newArrays.freq;
|
||||||
|
this.values.pitch = newArrays.pitch;
|
||||||
|
this.values.octave = newArrays.octave;
|
||||||
|
this.values.pitchOctave = newArrays.pitchOctave;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
out = (orbit?: number | number[]): void => {
|
out = (orbit?: number | number[]): void => {
|
||||||
|
|||||||
@ -186,9 +186,12 @@ export class Player extends AbstractEvent {
|
|||||||
"freq",
|
"freq",
|
||||||
"note",
|
"note",
|
||||||
"pitch",
|
"pitch",
|
||||||
|
"originalPitch",
|
||||||
"key",
|
"key",
|
||||||
"scale",
|
"scale",
|
||||||
"octave",
|
"octave",
|
||||||
|
"pitchOctave",
|
||||||
|
"addedOctave",
|
||||||
"parsedScale",
|
"parsedScale",
|
||||||
) as SoundParams;
|
) as SoundParams;
|
||||||
|
|
||||||
@ -205,9 +208,12 @@ export class Player extends AbstractEvent {
|
|||||||
"freq",
|
"freq",
|
||||||
"note",
|
"note",
|
||||||
"pitch",
|
"pitch",
|
||||||
|
"originalPitch",
|
||||||
"key",
|
"key",
|
||||||
"scale",
|
"scale",
|
||||||
"octave",
|
"octave",
|
||||||
|
"pitchOctave",
|
||||||
|
"addedOctave",
|
||||||
"parsedScale",
|
"parsedScale",
|
||||||
);
|
);
|
||||||
}) as SoundParams[];
|
}) as SoundParams[];
|
||||||
@ -236,10 +242,13 @@ export class Player extends AbstractEvent {
|
|||||||
const obj = event.getExisting(
|
const obj = event.getExisting(
|
||||||
"note",
|
"note",
|
||||||
"pitch",
|
"pitch",
|
||||||
|
"originalPitch",
|
||||||
"bend",
|
"bend",
|
||||||
"key",
|
"key",
|
||||||
"scale",
|
"scale",
|
||||||
"octave",
|
"octave",
|
||||||
|
"pitchOctave",
|
||||||
|
"addedOctave",
|
||||||
"parsedScale",
|
"parsedScale",
|
||||||
) as MidiParams;
|
) as MidiParams;
|
||||||
if (event instanceof Pitch) {
|
if (event instanceof Pitch) {
|
||||||
@ -281,6 +290,11 @@ export class Player extends AbstractEvent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edo(value: number, scale: string|number[] = new Array(value).fill(1)) {
|
||||||
|
if (this.atTheBeginning()) this.ziffers.edo(value, scale);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
key(name: string) {
|
key(name: string) {
|
||||||
if (this.atTheBeginning()) this.ziffers.key(name);
|
if (this.atTheBeginning()) this.ziffers.key(name);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@ -170,6 +170,26 @@ ${makeExample(
|
|||||||
true,
|
true,
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
- <ic>edo(number, scale?: string|number[])</ic>: Create scale from equal divisions of the octave. Creates chromatic scale by default.
|
||||||
|
|
||||||
|
${makeExample(
|
||||||
|
"Play pitches from scale created from equal divisions of the octave",
|
||||||
|
`
|
||||||
|
z0("e bd bd <bd bd [bd bd] [bd bd bd bd]>").sound().out()
|
||||||
|
flipbar(1) :: rhythm(.25,14,16) :: sound("ST10:30").stretch(3).gain(0.5)
|
||||||
|
.pitch([0,10,r(20,40),r(100,200),r(-200,200),r(200,300),200,r(3,666)].beat([1.0,0.5,0.25].bar(6)))
|
||||||
|
.octave(r(-6,6))
|
||||||
|
.edo(666,"rocritonic")
|
||||||
|
.out()
|
||||||
|
rhythm(2.0,26,32) :: sound("ST20").n([22,5,24,34,31,5,11,19].pick()).stretch(rI(1,6))
|
||||||
|
.pitch(rI(127,300))
|
||||||
|
.edo(666)
|
||||||
|
.out()
|
||||||
|
`,
|
||||||
|
true,
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
- <ic>scale(scale: string, base note: number)</ic>: Map each element of the list to the closest note of the slected scale. [0, 2, 3, 5 ].scale("major", 50) returns [50, 52, <ic>54</ic>, 55]. You can use western scale names like (Major, Minor, Minor pentatonic ...) or [zeitler](https://ianring.com/musictheory/scales/traditions/zeitler) scale names. Alternatively you can also use the integers as used by Ian Ring in his [study of scales](https://ianring.com/musictheory/scales/).
|
- <ic>scale(scale: string, base note: number)</ic>: Map each element of the list to the closest note of the slected scale. [0, 2, 3, 5 ].scale("major", 50) returns [50, 52, <ic>54</ic>, 55]. You can use western scale names like (Major, Minor, Minor pentatonic ...) or [zeitler](https://ianring.com/musictheory/scales/traditions/zeitler) scale names. Alternatively you can also use the integers as used by Ian Ring in his [study of scales](https://ianring.com/musictheory/scales/).
|
||||||
|
|
||||||
${makeExample(
|
${makeExample(
|
||||||
|
|||||||
@ -4028,10 +4028,10 @@ yaml@^2.1.1:
|
|||||||
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b"
|
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b"
|
||||||
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==
|
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==
|
||||||
|
|
||||||
zifferjs@^0.0.53:
|
zifferjs@^0.0.54:
|
||||||
version "0.0.53"
|
version "0.0.54"
|
||||||
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.53.tgz#5e6e8a80ef90cd59ed607ab7cf02592efc03b08d"
|
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.54.tgz#2dd4b43820f85d797c13dd35d933476ecacdb146"
|
||||||
integrity sha512-XGREU1ClhaatEZaek6gTBcwaNfFkUZLENWhXILPjLCODXzFoC6D/qaYCaIegcJdGgqB7At3DqID4yNwFLRPeqQ==
|
integrity sha512-vo1I12VvW4yFdVJTVnrfOxeOpWq7tIMZ67BfXxcK0t9GveLi+3GrF1zjowq8WCDssVgw+lQHEjdGVhO5FbK3RA==
|
||||||
|
|
||||||
zyklus@^0.1.4:
|
zyklus@^0.1.4:
|
||||||
version "0.1.4"
|
version "0.1.4"
|
||||||
|
|||||||
Reference in New Issue
Block a user