diff --git a/src/classes/AbstractEvents.ts b/src/classes/AbstractEvents.ts index 7788cf2..438672d 100644 --- a/src/classes/AbstractEvents.ts +++ b/src/classes/AbstractEvents.ts @@ -319,9 +319,9 @@ export abstract class AudibleEvent extends AbstractEvent { } this.values["paramOctave"] = value; if ( - this.values.key && - (this.values.pitch || this.values.pitch === 0) && - this.values.parsedScale + this.values['key'] && + (this.values['pitch'] || this.values['pitch'] === 0) && + this.values['parsedScale'] ) { return this.update(); } @@ -340,8 +340,8 @@ export abstract class AudibleEvent extends AbstractEvent { } this.values["key"] = value; if ( - (this.values.pitch || this.values.pitch === 0) && - this.values.parsedScale + (this.values['pitch'] || this.values['pitch'] === 0) && + this.values['parsedScale'] ) { return this.update(); } @@ -350,9 +350,9 @@ export abstract class AudibleEvent extends AbstractEvent { }; 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"); + 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 = ( @@ -368,9 +368,9 @@ export abstract class AudibleEvent extends AbstractEvent { value = Array.isArray(value) ? value.concat(kwargs) : [value, ...kwargs]; } 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)) { - this.values.parsedScale = value.map((v) => safeScale(v)); + this.values["parsedScale"] = value.map((v) => safeScale(v)); } this.defaultPitchKeyScale(); return this.update(); @@ -378,7 +378,7 @@ export abstract class AudibleEvent extends AbstractEvent { semitones(values: number|number[], ...rest: number[]) { const scaleValues = typeof values === "number" ? [values, ...rest] : values; - this.values.parsedScale = safeScale(scaleValues); + this.values["parsedScale"] = safeScale(scaleValues); this.defaultPitchKeyScale(); return this.update(); } @@ -386,20 +386,20 @@ export abstract class AudibleEvent extends AbstractEvent { cents(values: number|number[], ...rest: number[]) { const scaleValues = typeof values === "number" ? [values, ...rest] : values; - this.values.parsedScale = safeScale(centsToSemitones(scaleValues)); + this.values["parsedScale"] = safeScale(centsToSemitones(scaleValues)); this.defaultPitchKeyScale(); return this.update(); } ratios(values: number|number[], ...rest: number[]) { const scaleValues = typeof values === "number" ? [values, ...rest] : values; - this.values.parsedScale = safeScale(ratiosToSemitones(scaleValues)); + this.values["parsedScale"] = safeScale(ratiosToSemitones(scaleValues)); this.defaultPitchKeyScale(); return this.update(); } 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(); return this.update(); } @@ -436,8 +436,8 @@ export abstract class AudibleEvent extends AbstractEvent { public invert = (howMany: number = 0) => { if(howMany === 0) return this; - if (this.values.note) { - let notes = [...this.values.note]; + if (this.values["note"]) { + let notes = [...this.values["note"]]; notes = howMany < 0 ? [...notes].reverse() : notes; for (let i = 0; i < Math.abs(howMany); i++) { notes[i % notes.length] += howMany <= 0 ? -12 : 12; @@ -468,7 +468,7 @@ export abstract class AudibleEvent extends AbstractEvent { } 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; } @@ -499,7 +499,7 @@ export abstract class AudibleEvent extends AbstractEvent { 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 { const midiNote = freqToMidi(value); if (midiNote % 1 !== 0) { diff --git a/src/classes/SoundEvent.ts b/src/classes/SoundEvent.ts index da482b0..321220f 100644 --- a/src/classes/SoundEvent.ts +++ b/src/classes/SoundEvent.ts @@ -292,8 +292,8 @@ export class SoundEvent extends AudibleEvent { self.values["fmi"] = value; } else { let values = value.split(":"); - self.values["fmi"] = parseFloat(values[0]); - if (values.length > 1) self.values["fmh"] = parseFloat(values[1]); + self.values["fmi"] = parseFloat(values[0]!); + if (values.length > 1) self.values["fmh"] = parseFloat(values[1]!); } return self; }, @@ -365,7 +365,7 @@ export class SoundEvent extends AudibleEvent { constructor( sound: string | string[] | SoundParams, - public app: Editor, + app: Editor, ) { super(app); this.nudge = app.dough_nudge / 100; @@ -374,25 +374,13 @@ export class SoundEvent extends AudibleEvent { if (typeof keys === "object" && Symbol.iterator in Object(keys)) { for (const key of keys as string[]) { // 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 { // @ts-ignore 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); } @@ -400,7 +388,7 @@ export class SoundEvent extends AudibleEvent { // AbstactEvent overrides // ================================================================================ - modify = (func: Function): this => { + override modify = (func: Function): this => { const funcResult = func(this); if (funcResult instanceof Object) return funcResult; else { @@ -409,7 +397,7 @@ export class SoundEvent extends AudibleEvent { } }; - update = (): this => { + override update = (): this => { const filteredValues = filterObject(this.values, [ "key", "pitch", @@ -424,24 +412,24 @@ export class SoundEvent extends AudibleEvent { ]); events.forEach((soundEvent) => { const resolvedPitchClass = resolvePitchClass( - (soundEvent.key || "C4"), - (soundEvent.originalPitch || soundEvent.pitch || 0), - (soundEvent.parsedScale || soundEvent.scale || "MAJOR"), - (soundEvent.paramOctave || 0) + (soundEvent.addedOctave || 0) + (soundEvent['key'] || "C4"), + (soundEvent['originalPitch'] || soundEvent['pitch'] || 0), + (soundEvent['parsedScale'] || soundEvent['scale'] || "MAJOR"), + (soundEvent['paramOctave'] || 0) + (soundEvent['addedOctave'] || 0) ); - soundEvent.note = resolvedPitchClass.note; - soundEvent.freq = midiToFreq(resolvedPitchClass.note); - soundEvent.pitch = resolvedPitchClass.pitch; - soundEvent.octave = resolvedPitchClass.octave; + soundEvent['note'] = resolvedPitchClass.note; + soundEvent['freq'] = midiToFreq(resolvedPitchClass.note); + soundEvent['pitch'] = resolvedPitchClass.pitch; + soundEvent['octave'] = resolvedPitchClass.octave; }); const newArrays = arrayOfObjectsToObjectWithArrays(events) as SoundParams; - this.values.note = maybeAtomic(newArrays.note); - this.values.freq = maybeAtomic(newArrays.freq); - this.values.pitch = maybeAtomic(newArrays.pitch); - this.values.octave = maybeAtomic(newArrays.octave); - this.values.pitchOctave = maybeAtomic(newArrays.pitchOctave); + this.values['note'] = maybeAtomic(newArrays.note); + this.values['freq'] = maybeAtomic(newArrays.freq); + this.values['pitch'] = maybeAtomic(newArrays.pitch); + this.values['octave'] = maybeAtomic(newArrays.octave); + this.values['pitchOctave'] = maybeAtomic(newArrays.pitchOctave); return this; }; @@ -458,13 +446,13 @@ export class SoundEvent extends AudibleEvent { // const filteredEvent = filterObject(event, ["analyze","note","dur","freq","s"]); const filteredEvent = event; // No need for note if there is freq - if (filteredEvent.freq) { - delete filteredEvent.note; + if (filteredEvent['freq']) { + delete filteredEvent['note']; } superdough( filteredEvent, this.nudge - this.app.clock.deviation, - filteredEvent.dur + filteredEvent['dur'] ); } }; @@ -477,13 +465,13 @@ export class SoundEvent extends AudibleEvent { for (const event of events) { const filteredEvent = event; - let oscAddress = "address" in event ? event.address : "/topos"; + let oscAddress = "address" in event ? event['address'] : "/topos"; oscAddress = oscAddress?.startsWith("/") ? oscAddress : "/" + oscAddress; - let oscPort = "port" in event ? event.port : 57120; + let oscPort = "port" in event ? event['port'] : 57120; - if (filteredEvent.freq) { - delete filteredEvent.note; + if (filteredEvent['freq']) { + delete filteredEvent['note']; } sendToServer({ address: oscAddress,