Moved processSound() to AbstractEvent for Ziffers
This commit is contained in:
@ -369,46 +369,6 @@ export class SoundEvent extends AudibleEvent {
|
||||
this.values = this.processSound(sound);
|
||||
}
|
||||
|
||||
private processSound = (
|
||||
sound: string | string[] | SoundParams | SoundParams[],
|
||||
): SoundParams => {
|
||||
if (Array.isArray(sound) && typeof sound[0] === "string") {
|
||||
const s: string[] = [];
|
||||
const n: number[] = [];
|
||||
sound.forEach((str) => {
|
||||
const parts = (str as string).split(":");
|
||||
s.push(parts[0]);
|
||||
if (parts[1]) {
|
||||
n.push(parseInt(parts[1]));
|
||||
}
|
||||
});
|
||||
return {
|
||||
s,
|
||||
n: n.length > 0 ? n : undefined,
|
||||
dur: this.app.clock.convertPulseToSecond(this.app.clock.ppqn),
|
||||
};
|
||||
} else if (typeof sound === "object") {
|
||||
const validatedObj: SoundParams = {
|
||||
dur: this.app.clock.convertPulseToSecond(this.app.clock.ppqn),
|
||||
...(sound as Partial<SoundParams>),
|
||||
};
|
||||
return validatedObj;
|
||||
} else {
|
||||
if (sound.includes(":")) {
|
||||
const vals = sound.split(":");
|
||||
const s = vals[0];
|
||||
const n = parseInt(vals[1]);
|
||||
return {
|
||||
s,
|
||||
n,
|
||||
dur: this.app.clock.convertPulseToSecond(this.app.clock.ppqn),
|
||||
};
|
||||
} else {
|
||||
return { s: sound, dur: 0.5 };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// ================================================================================
|
||||
// AbstactEvent overrides
|
||||
// ================================================================================
|
||||
|
||||
Reference in New Issue
Block a user