Following the compiler directions

This commit is contained in:
2024-04-19 23:44:04 +02:00
parent 8c0555b02f
commit 9dfac1141f
2 changed files with 44 additions and 56 deletions

View File

@ -319,9 +319,9 @@ export abstract class AudibleEvent extends AbstractEvent {
} }
this.values["paramOctave"] = 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) &&
this.values.parsedScale this.values['parsedScale']
) { ) {
return this.update(); return this.update();
} }
@ -340,8 +340,8 @@ export abstract class AudibleEvent extends AbstractEvent {
} }
this.values["key"] = value; this.values["key"] = value;
if ( if (
(this.values.pitch || this.values.pitch === 0) && (this.values['pitch'] || this.values['pitch'] === 0) &&
this.values.parsedScale this.values['parsedScale']
) { ) {
return this.update(); return this.update();
} }
@ -350,9 +350,9 @@ export abstract class AudibleEvent extends AbstractEvent {
}; };
defaultPitchKeyScale() { defaultPitchKeyScale() {
if (!this.values.key) this.values.key = 60; if (!this.values["key"]) this.values["key"] = 60;
if (!(this.values.pitch || this.values.pitch === 0)) this.values.pitch = 0; if (!(this.values["pitch"] || this.values["pitch"] === 0)) this.values["pitch"] = 0;
if (!this.values.parsedScale) this.values.parsedScale = safeScale("major"); if (!this.values["parsedScale"]) this.values["parsedScale"] = safeScale("major");
} }
scale = ( scale = (
@ -368,9 +368,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];
} }
if (typeof value === "string" || typeof value === "number") { if (typeof value === "string" || typeof value === "number") {
this.values.parsedScale = safeScale(value) as number[]; this.values["parsedScale"] = safeScale(value) as number[];
} 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));
} }
this.defaultPitchKeyScale(); this.defaultPitchKeyScale();
return this.update(); return this.update();
@ -378,7 +378,7 @@ export abstract class AudibleEvent extends AbstractEvent {
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.defaultPitchKeyScale(); this.defaultPitchKeyScale();
return this.update(); return this.update();
} }
@ -386,20 +386,20 @@ 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.defaultPitchKeyScale(); this.defaultPitchKeyScale();
return this.update(); return this.update();
} }
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.defaultPitchKeyScale(); this.defaultPitchKeyScale();
return this.update(); return this.update();
} }
edo(value: number, intervals: string|number[] = new Array(value).fill(1)) { edo(value: number, intervals: string|number[] = new Array(value).fill(1)) {
this.values.parsedScale = edoToSemitones(value, intervals); this.values["parsedScale"] = edoToSemitones(value, intervals);
this.defaultPitchKeyScale(); this.defaultPitchKeyScale();
return this.update(); return this.update();
} }
@ -436,8 +436,8 @@ export abstract class AudibleEvent extends AbstractEvent {
public invert = (howMany: number = 0) => { public invert = (howMany: number = 0) => {
if(howMany === 0) return this; if(howMany === 0) return this;
if (this.values.note) { if (this.values["note"]) {
let notes = [...this.values.note]; let notes = [...this.values["note"]];
notes = howMany < 0 ? [...notes].reverse() : notes; notes = howMany < 0 ? [...notes].reverse() : notes;
for (let i = 0; i < Math.abs(howMany); i++) { for (let i = 0; i < Math.abs(howMany); i++) {
notes[i % notes.length] += howMany <= 0 ? -12 : 12; notes[i % notes.length] += howMany <= 0 ? -12 : 12;
@ -468,7 +468,7 @@ export abstract class AudibleEvent extends AbstractEvent {
} }
public draw = (lambda: Function) => { public draw = (lambda: Function) => {
lambda(this.values, (this.app.interface.drawings as HTMLCanvasElement).getContext("2d")); lambda(this.values, (this.app.interface.feedback as HTMLCanvasElement).getContext("2d"));
return this; return this;
} }
@ -499,7 +499,7 @@ export abstract class AudibleEvent extends AbstractEvent {
this.values["note"].push(midiNote); this.values["note"].push(midiNote);
} }
} }
if (this.values.bend.length === 0) delete this.values.bend; if (this.values["bend"].length === 0) delete this.values["bend"];
} else { } else {
const midiNote = freqToMidi(value); const midiNote = freqToMidi(value);
if (midiNote % 1 !== 0) { if (midiNote % 1 !== 0) {

View File

@ -292,8 +292,8 @@ export class SoundEvent extends AudibleEvent {
self.values["fmi"] = value; self.values["fmi"] = value;
} else { } else {
let values = value.split(":"); let values = value.split(":");
self.values["fmi"] = parseFloat(values[0]); self.values["fmi"] = parseFloat(values[0]!);
if (values.length > 1) self.values["fmh"] = parseFloat(values[1]); if (values.length > 1) self.values["fmh"] = parseFloat(values[1]!);
} }
return self; return self;
}, },
@ -365,7 +365,7 @@ export class SoundEvent extends AudibleEvent {
constructor( constructor(
sound: string | string[] | SoundParams, sound: string | string[] | SoundParams,
public app: Editor, app: Editor,
) { ) {
super(app); super(app);
this.nudge = app.dough_nudge / 100; this.nudge = app.dough_nudge / 100;
@ -374,25 +374,13 @@ export class SoundEvent extends AudibleEvent {
if (typeof keys === "object" && Symbol.iterator in Object(keys)) { if (typeof keys === "object" && Symbol.iterator in Object(keys)) {
for (const key of keys as string[]) { for (const key of keys as string[]) {
// Using arrow function to maintain 'this' context // Using arrow function to maintain 'this' context
this[key] = (value: number) => this.updateValue(keys[0], value); this[key] = (value: number) => this.updateValue(keys[0]!, value);
} }
} else { } else {
// @ts-ignore // @ts-ignore
this[methodName] = (...args) => keys(this, ...args); this[methodName] = (...args) => keys(this, ...args);
} }
} }
// for (const [methodName, keys] of Object.entries(SoundEvent.methodMap)) {
// if (typeof keys === "object" && Symbol.iterator in Object(keys)) {
// for (const key of keys as string[]) {
// // @ts-ignore
// this[key] = (value: number) => this.updateValue(this, keys[0], value);
// }
// } else {
// // @ts-ignore
// this[methodName] = keys;
// }
// }
this.values = this.processSound(sound); this.values = this.processSound(sound);
} }
@ -400,7 +388,7 @@ export class SoundEvent extends AudibleEvent {
// AbstactEvent overrides // AbstactEvent overrides
// ================================================================================ // ================================================================================
modify = (func: Function): this => { override modify = (func: Function): this => {
const funcResult = func(this); const funcResult = func(this);
if (funcResult instanceof Object) return funcResult; if (funcResult instanceof Object) return funcResult;
else { else {
@ -409,7 +397,7 @@ export class SoundEvent extends AudibleEvent {
} }
}; };
update = (): this => { override update = (): this => {
const filteredValues = filterObject(this.values, [ const filteredValues = filterObject(this.values, [
"key", "key",
"pitch", "pitch",
@ -424,24 +412,24 @@ export class SoundEvent extends AudibleEvent {
]); ]);
events.forEach((soundEvent) => { events.forEach((soundEvent) => {
const resolvedPitchClass = resolvePitchClass( const resolvedPitchClass = resolvePitchClass(
(soundEvent.key || "C4"), (soundEvent['key'] || "C4"),
(soundEvent.originalPitch || soundEvent.pitch || 0), (soundEvent['originalPitch'] || soundEvent['pitch'] || 0),
(soundEvent.parsedScale || soundEvent.scale || "MAJOR"), (soundEvent['parsedScale'] || soundEvent['scale'] || "MAJOR"),
(soundEvent.paramOctave || 0) + (soundEvent.addedOctave || 0) (soundEvent['paramOctave'] || 0) + (soundEvent['addedOctave'] || 0)
); );
soundEvent.note = resolvedPitchClass.note; soundEvent['note'] = resolvedPitchClass.note;
soundEvent.freq = midiToFreq(resolvedPitchClass.note); soundEvent['freq'] = midiToFreq(resolvedPitchClass.note);
soundEvent.pitch = resolvedPitchClass.pitch; soundEvent['pitch'] = resolvedPitchClass.pitch;
soundEvent.octave = resolvedPitchClass.octave; soundEvent['octave'] = resolvedPitchClass.octave;
}); });
const newArrays = arrayOfObjectsToObjectWithArrays(events) as SoundParams; const newArrays = arrayOfObjectsToObjectWithArrays(events) as SoundParams;
this.values.note = maybeAtomic(newArrays.note); this.values['note'] = maybeAtomic(newArrays.note);
this.values.freq = maybeAtomic(newArrays.freq); this.values['freq'] = maybeAtomic(newArrays.freq);
this.values.pitch = maybeAtomic(newArrays.pitch); this.values['pitch'] = maybeAtomic(newArrays.pitch);
this.values.octave = maybeAtomic(newArrays.octave); this.values['octave'] = maybeAtomic(newArrays.octave);
this.values.pitchOctave = maybeAtomic(newArrays.pitchOctave); this.values['pitchOctave'] = maybeAtomic(newArrays.pitchOctave);
return this; return this;
}; };
@ -458,13 +446,13 @@ export class SoundEvent extends AudibleEvent {
// const filteredEvent = filterObject(event, ["analyze","note","dur","freq","s"]); // const filteredEvent = filterObject(event, ["analyze","note","dur","freq","s"]);
const filteredEvent = event; const filteredEvent = event;
// No need for note if there is freq // No need for note if there is freq
if (filteredEvent.freq) { if (filteredEvent['freq']) {
delete filteredEvent.note; delete filteredEvent['note'];
} }
superdough( superdough(
filteredEvent, filteredEvent,
this.nudge - this.app.clock.deviation, this.nudge - this.app.clock.deviation,
filteredEvent.dur filteredEvent['dur']
); );
} }
}; };
@ -477,13 +465,13 @@ export class SoundEvent extends AudibleEvent {
for (const event of events) { for (const event of events) {
const filteredEvent = event; const filteredEvent = event;
let oscAddress = "address" in event ? event.address : "/topos"; let oscAddress = "address" in event ? event['address'] : "/topos";
oscAddress = oscAddress?.startsWith("/") ? oscAddress : "/" + oscAddress; oscAddress = oscAddress?.startsWith("/") ? oscAddress : "/" + oscAddress;
let oscPort = "port" in event ? event.port : 57120; let oscPort = "port" in event ? event['port'] : 57120;
if (filteredEvent.freq) { if (filteredEvent['freq']) {
delete filteredEvent.note; delete filteredEvent['note'];
} }
sendToServer({ sendToServer({
address: oscAddress, address: oscAddress,