Let a looped sample play out past its loop when the note ends #331
With "Mode" and "Loop" as two fields, One-shot plus Loop ran until Stop was pressed: letting go of the key did nothing. The two fields are now one, "Play", with four entries that each say what happens while the note is held and when it is let go. - Gate and One-shot play the sound once, as before. Loop repeats it and fades out with the note. - "Loop, then release" is new: the sampler's sustain loop. Let go, it finishes the round it is in and plays what comes after "Loop end" to the end of the sound. - A buffer source stops looping and plays on by itself. The pitch worklet gets a "leave" message. The phase vocoder then lets the round finish that its newest frame has read into, so nothing read already changes under the frames still sounding. - Samples saved with "Mode" and "Loop" are turned into "Play" on load. Gate and One-shot stay, either with Loop becomes Loop, since playing until stopped is gone. - The keys of the Instrument tab stay half lit while a note let go is still heard. Esc on the keys stops everything, like Stop. - Striking a ringing key again plays a new note beside it rather than stopping the old one, so a drum can be hit quickly. This differs from what was proposed in the issue discussion. Tests: - instrument + pitch-player + sound-library + node-catalog: 477 tests, green (12 new). - e2e 34 (melektaus-atx): ALL PASSED, 45 checks (+1). Let go after a loop of 0.05 s, the note played out for 0.31 s on the audio clock, the key half lit meanwhile. - Counter-check: a release that does not leave the loop fails the 2 new player tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8a4e4a6762
commit
144dee0a97
14 files changed
+285
-29
No files matched your search
@@ -50,6 +50,8 @@ interface Source {
|
||||
fade: GainNode | null;
|
||||
/** Ends with the note (#331): a release fades it out, where everything else plays on. */
|
||||
gate: boolean;
|
||||
/** Plays on past its loop to the end of the sound; null where a release leaves it as it is. */
|
||||
leave: (() => void) | null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,14 +224,16 @@ export class SoundLibrary implements AudioSink {
|
||||
}
|
||||
|
||||
/**
|
||||
* The end of a note (#331): the ways that end with it fade out, the others play on, and the voice
|
||||
* goes once they have all ended – or rings on first where it has echoes.
|
||||
* The end of a note (#331): the ways that end with it fade out, a looping one that does not leaves
|
||||
* its loop, the others play on, and the voice goes once they have all ended – or rings on first
|
||||
* where it has echoes.
|
||||
*/
|
||||
release(id: number): void {
|
||||
const waiting = this.pending.find((other) => other.id === id);
|
||||
if (waiting) waiting.released = true;
|
||||
const voice = this.voices.find((other) => other.id === id);
|
||||
if (!voice) return;
|
||||
for (const source of voice.sources) if (!source.gate) source.leave?.();
|
||||
const context = this.audio();
|
||||
const gated = voice.sources.filter((source) => source.gate);
|
||||
for (const source of gated) if (source.fade) fadeOut(source.fade.gain, context.currentTime);
|
||||
@@ -305,6 +309,11 @@ export class SoundLibrary implements AudioSink {
|
||||
return voice ? this.tailOf(voice.fx) : 0;
|
||||
}
|
||||
|
||||
/** Whether a voice is still heard – or waiting on its bytes to be. */
|
||||
playing(id: number): boolean {
|
||||
return this.voices.some((voice) => voice.id === id) || this.pending.some((other) => other.id === id);
|
||||
}
|
||||
|
||||
/** `letRing` stops the sound itself and lets its echoes fade as they would (#324). */
|
||||
stop(file: string, letRing = false): void {
|
||||
this.silence(file === '' ? this.voices : this.voices.filter((voice) => voice.file === file), letRing);
|
||||
@@ -673,6 +682,7 @@ export class SoundLibrary implements AudioSink {
|
||||
},
|
||||
fade: null,
|
||||
gate,
|
||||
leave: own && loop ? () => node.port.postMessage('leave') : null,
|
||||
});
|
||||
wiring.knobs.push({ param: node.parameters.get('pitch')!, target: pitch, even: 'value' });
|
||||
return node;
|
||||
@@ -692,6 +702,13 @@ export class SoundLibrary implements AudioSink {
|
||||
},
|
||||
fade: null,
|
||||
gate,
|
||||
// Web Audio plays a buffer that stops looping on to its end, past `loopEnd`.
|
||||
leave:
|
||||
own && loop
|
||||
? () => {
|
||||
source.loop = false;
|
||||
}
|
||||
: null,
|
||||
});
|
||||
if (shifted) wiring.knobs.push({ param: null, target: pitch, even: 'value' });
|
||||
return source;
|
||||
|
||||
Reference in new issue
Block a user