Sources and events
Sources start when they are added and stop when they are removed. Svelte's control flow is the transport.
Start and stop
oscillator, bufferSource and constantSource call start() once they are connected. Removing an element stops sources and disconnects every
node.
{#if playing}
<!-- osc.start() when added; osc.stop() and disconnect() when removed -->
<oscillator frequency={440}></oscillator>
{/if}Scheduling
start={time} passes a time to start(). stop={time} calls stop(time), and calls it again when the time changes. Times are in the
context's currentTime.
<!-- osc.start(now + 1); osc.stop(now + 2) -->
<oscillator start={now + 1} stop={now + 2} onended={() => (playing = false)}></oscillator>Events
on… attributes are added with addEventListener, for example onended on a source, or onprocessorerror on an audioWorklet.
Voices
A keyed {#each} of components is a polyphonic instrument: each note is its own
voice, and it is removed when it ends. See the Keyboard example.
{#each notes as note (note.id)}
<Note frequency={note.frequency} onended={() => remove(note.id)} />
{/each}