fixing a few bugs
This commit is contained in:
@ -19,6 +19,13 @@ export type SoundParams = {
|
|||||||
s?: string;
|
s?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ValuesType = {
|
||||||
|
s: string | string[];
|
||||||
|
n?: string | string[];
|
||||||
|
dur: number;
|
||||||
|
analyze: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export class SoundEvent extends AudibleEvent {
|
export class SoundEvent extends AudibleEvent {
|
||||||
nudge: number;
|
nudge: number;
|
||||||
|
|
||||||
@ -59,6 +66,7 @@ export class SoundEvent extends AudibleEvent {
|
|||||||
fmad: (a: number, d: number) => {
|
fmad: (a: number, d: number) => {
|
||||||
this.updateValue("fmattack", a);
|
this.updateValue("fmattack", a);
|
||||||
this.updateValue("fmdecay", d);
|
this.updateValue("fmdecay", d);
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
ftype: ["ftype"],
|
ftype: ["ftype"],
|
||||||
fanchor: ["fanchor"],
|
fanchor: ["fanchor"],
|
||||||
@ -209,9 +217,11 @@ export class SoundEvent extends AudibleEvent {
|
|||||||
gain: ["gain"],
|
gain: ["gain"],
|
||||||
dbgain: (value: number) => {
|
dbgain: (value: number) => {
|
||||||
this.updateValue("gain", Math.min(Math.pow(10, value / 20), 10));
|
this.updateValue("gain", Math.min(Math.pow(10, value / 20), 10));
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
db: (value: number) => {
|
db: (value: number) => {
|
||||||
this.updateValue("gain", Math.min(Math.pow(10, value / 20), 10));
|
this.updateValue("gain", Math.min(Math.pow(10, value / 20), 10));
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
velocity: ["velocity", "vel"],
|
velocity: ["velocity", "vel"],
|
||||||
pan: ["pan"],
|
pan: ["pan"],
|
||||||
@ -233,22 +243,28 @@ export class SoundEvent extends AudibleEvent {
|
|||||||
roomdim: ["roomdim", "rdim"],
|
roomdim: ["roomdim", "rdim"],
|
||||||
size: (value: number) => {
|
size: (value: number) => {
|
||||||
this.updateValue("roomsize", value);
|
this.updateValue("roomsize", value);
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
sz: (value: number) => {
|
sz: (value: number) => {
|
||||||
this.updateValue("roomsize", value);
|
this.updateValue("roomsize", value);
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
comp: ["compressor", "cmp"],
|
comp: ["compressor", "cmp"],
|
||||||
ratio: (value: number) => {
|
ratio: (value: number) => {
|
||||||
this.updateValue("compressorRatio", value);
|
this.updateValue("compressorRatio", value);
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
knee: (value: number) => {
|
knee: (value: number) => {
|
||||||
this.updateValue("compressorKnee", value);
|
this.updateValue("compressorKnee", value);
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
compAttack: (value: number) => {
|
compAttack: (value: number) => {
|
||||||
this.updateValue("compressorAttack", value);
|
this.updateValue("compressorAttack", value);
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
compRelease: (value: number) => {
|
compRelease: (value: number) => {
|
||||||
this.updateValue("compressorRelease", value);
|
this.updateValue("compressorRelease", value);
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
stretch: (beat: number) => {
|
stretch: (beat: number) => {
|
||||||
this.updateValue("unit", "c");
|
this.updateValue("unit", "c");
|
||||||
@ -258,7 +274,8 @@ export class SoundEvent extends AudibleEvent {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(sound: string | object, public app: Editor) {
|
|
||||||
|
constructor(sound: string | string[] | object, public app: Editor) {
|
||||||
super(app);
|
super(app);
|
||||||
this.nudge = app.dough_nudge / 100;
|
this.nudge = app.dough_nudge / 100;
|
||||||
|
|
||||||
@ -273,23 +290,42 @@ export class SoundEvent extends AudibleEvent {
|
|||||||
this[methodName] = keys;
|
this[methodName] = keys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.values = this.processSound(sound);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof sound === "string") {
|
private processSound = (sound: string | string[] | object): ValuesType => {
|
||||||
if (sound.includes(":")) {
|
if (Array.isArray(sound)) {
|
||||||
this.values = {
|
const s: string[] = [];
|
||||||
s: sound.split(":")[0],
|
const n: string[] = [];
|
||||||
n: sound.split(":")[1],
|
sound.forEach(str => {
|
||||||
dur: app.clock.convertPulseToSecond(app.clock.ppqn),
|
const parts = str.split(":");
|
||||||
analyze: true,
|
s.push(parts[0]);
|
||||||
|
if (parts[1]) {
|
||||||
|
n.push(parts[1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
s,
|
||||||
|
n: n.length > 0 ? n : undefined,
|
||||||
|
dur: this.app.clock.convertPulseToSecond(this.app.clock.ppqn),
|
||||||
|
analyze: true
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
if ((sound as string).includes(":")) {
|
||||||
|
const [s, n] = (sound as string).split(":");
|
||||||
|
return {
|
||||||
|
s,
|
||||||
|
n,
|
||||||
|
dur: this.app.clock.convertPulseToSecond(this.app.clock.ppqn),
|
||||||
|
analyze: true
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
this.values = { s: sound, dur: 0.5, analyze: true };
|
return { s: sound, dur: 0.5, analyze: true };
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
this.values = sound;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private updateValue<T>(key: string, value: T | T[] | null): this {
|
private updateValue<T>(key: string, value: T | T[] | null): this {
|
||||||
if (value == null) return this;
|
if (value == null) return this;
|
||||||
this.values[key] = value;
|
this.values[key] = value;
|
||||||
|
|||||||
Reference in New Issue
Block a user