trying some weird trick
This commit is contained in:
@ -12,6 +12,8 @@ import {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
} from "superdough";
|
} from "superdough";
|
||||||
|
|
||||||
|
type EventObj = { [key: string]: number | number[] };
|
||||||
|
|
||||||
export type SoundParams = {
|
export type SoundParams = {
|
||||||
dur: number;
|
dur: number;
|
||||||
s?: string;
|
s?: string;
|
||||||
@ -86,14 +88,14 @@ export class SoundEvent extends AudibleEvent {
|
|||||||
cutoff: (value: number, resonance?: number) => {
|
cutoff: (value: number, resonance?: number) => {
|
||||||
this.updateValue("cutoff", value);
|
this.updateValue("cutoff", value);
|
||||||
if (resonance) {
|
if (resonance) {
|
||||||
this.resonance(resonance);
|
this.updateValue("resonance", resonance);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
lpf: (value: number, resonance?: number) => {
|
lpf: (value: number, resonance?: number) => {
|
||||||
this.updateValue("cutoff", value);
|
this.updateValue("cutoff", value);
|
||||||
if (resonance) {
|
if (resonance) {
|
||||||
this.resonance(resonance);
|
this.updateValue("resonance", resonance);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
@ -318,15 +320,42 @@ export class SoundEvent extends AudibleEvent {
|
|||||||
this.values.freq = midiToFreq(note);
|
this.values.freq = midiToFreq(note);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
generateEvents = (input: EventObj): EventObj[] => {
|
||||||
|
const keys = Object.keys(input);
|
||||||
|
const maxLength = Math.max(
|
||||||
|
...keys.map((k) =>
|
||||||
|
Array.isArray(input[k]) ? (input[k] as number[]).length : 1
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const output: EventObj[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < maxLength; i++) {
|
||||||
|
const event: EventObj = {};
|
||||||
|
for (const k of keys) {
|
||||||
|
if (Array.isArray(input[k])) {
|
||||||
|
// @ts-ignore
|
||||||
|
event[k] = input[k][i % (input[k] as number[]).length];
|
||||||
|
} else {
|
||||||
|
event[k] = input[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output.push(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
};
|
||||||
|
|
||||||
out = (): void => {
|
out = (): void => {
|
||||||
if (this.values.chord) {
|
const input = this.values.chord || this.values;
|
||||||
this.values.chord.forEach((obj: { [key: string]: number }) => {
|
const events = this.generateEvents(input);
|
||||||
const copy = { ...this.values };
|
console.log(events);
|
||||||
copy.freq = obj.freq;
|
for (const event of events) {
|
||||||
superdough(copy, this.nudge, this.values.dur);
|
superdough(
|
||||||
});
|
{ ...event, ...{ freq: event.freq, dur: this.values.dur } },
|
||||||
} else {
|
this.nudge,
|
||||||
superdough(this.values, this.nudge, this.values.dur);
|
this.values.dur
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user