Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ import {
return songKey ? { songKey, ...extra } : { ...extra };
}

// ── Teardown ──
/**
* Cleans up the stem mixer, stops playback, and restores core audio control.
*/
function teardown() {
// Defensive reset: a new song load starting mid-takeover (or after a
// crash before the flag was cleared) must not leave togglePlay()
Expand Down Expand Up @@ -772,7 +774,15 @@ import {
}
}

// ── Main entry: called after song_info arrives ──
/**
* Initializes stem playback for the loaded song.
*
* Loads audio stems, selects a playback strategy (streaming for WAV audio,
* full decode for OGG), and builds the audio graph for stem mixing. If any
* step fails, playback degrades to native HTML5 audio. For songs with no stems
* or on unavailable hardware, emits a provider-ready event without building
* the stem graph.
*/
async function onSongReady() {
console.log('[stems debug] onSongReady called, gen was:', S.loadGeneration);
teardown();
Expand Down Expand Up @@ -959,6 +969,11 @@ import {
else window._stemsRerouteInProgress = false;
}

/**
* Generates a deterministic signature for the current song and its stem configuration.
* @param {Object} info - Optional song metadata containing stems and filename.
* @return {string} A signature string that uniquely identifies the song state.
*/
function songInfoSignature(info) {
const stems = Array.isArray(info && info.stems) ? info.stems : [];
const filename = (info && info.filename) || (window.slopsmith && window.slopsmith.currentSong && window.slopsmith.currentSong.filename) || S.currentFilename || '';
Expand Down
10 changes: 9 additions & 1 deletion src/streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,15 @@ export async function repositionStream(targetSec) {
// runs asynchronously), false on failure. On failure it does NOT teardown()
// (that would bump S.loadGeneration and hide the failure from onSongReady's
// supersession check) — the caller tears down + falls back. A `false` return
// with `gen === S.loadGeneration` is a real failure; a stale gen is supersession.
/**
* Set up bounded-memory streaming playback for the provided WAV stems.
* @param {Array} stems - Stem descriptors containing stream URLs and metadata.
* @param {Response} probeResp - Response containing the first stem.
* @param {string|null} fullUrl - Optional URL for a full-mix WAV stream.
* @param {number} gen - Load generation used to discard superseded setup operations.
* @param {AbortSignal} [signal=S.abortController.signal] - Signal used to cancel stream requests.
* @return {Promise<boolean>} `true` when streaming playback is initialized, `false` when setup fails or is superseded.
*/
export async function setupStreaming(stems, probeResp, fullUrl, gen, signal = S.abortController.signal) {
// 1. Open readers + parse headers for every stem (and the full mix).
let restResps = [];
Expand Down
4 changes: 4 additions & 0 deletions src/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ export function flushPendingPlayResolvers() {
}
}

/**
* Starts playback from the current position and dispatches a `play` event when playback begins.
* @returns {void}
*/
export function transportPlay() {
resumeCtx();
if (!S.buffersReady) { S.pendingPlay = true; return; }
Expand Down