handle invalid spawns + remove logs

This commit is contained in:
Felix Roos 2025-06-05 10:30:53 +02:00
parent 2cbd35f6d2
commit f0e6c5483c
No known key found for this signature in database

View file

@ -507,6 +507,12 @@ export class Dough {
// console.log('init dough', this.sampleRate, this.t); // console.log('init dough', this.sampleRate, this.t);
} }
scheduleSpawn(value) { scheduleSpawn(value) {
if (value._begin === undefined) {
throw new Error('[dough]: scheduleSpawn expected _begin to be set');
}
if (value._duration === undefined) {
throw new Error('[dough]: scheduleSpawn expected _duration to be set');
}
const time = value._begin; // set from supradough.mjs const time = value._begin; // set from supradough.mjs
this.schedule({ time, type: 'spawn', arg: value }); this.schedule({ time, type: 'spawn', arg: value });
} }
@ -514,14 +520,14 @@ export class Dough {
value.id = this.vid++; value.id = this.vid++;
const voice = new DoughVoice(value); const voice = new DoughVoice(value);
this.voices.push(voice); this.voices.push(voice);
console.log('spawn', voice.id, 'voices:', this.voices.length); // console.log('spawn', voice.id, 'voices:', this.voices.length);
// schedule removal // schedule removal
const endTime = Math.ceil(voice._end * this.sampleRate); const endTime = Math.ceil(voice._end * this.sampleRate);
this.schedule({ time: endTime /* + 48000 */, type: 'despawn', arg: voice.id }); this.schedule({ time: endTime /* + 48000 */, type: 'despawn', arg: voice.id });
} }
despawn(vid) { despawn(vid) {
this.voices = this.voices.filter((v) => v.id !== vid); this.voices = this.voices.filter((v) => v.id !== vid);
console.log('despawn', vid, 'voices:', this.voices.length); // console.log('despawn', vid, 'voices:', this.voices.length);
} }
// schedules a function call with a single argument // schedules a function call with a single argument
// msg = {time:number,type:string, arg: any} // msg = {time:number,type:string, arg: any}