fix: Workshop load doesn't stop audio — matches loadPreset pattern
Calling stopAudio() before deserialize+rebuildGraph broke the audio graph because rebuildGraph needs isRunning=true to work properly. Now follows the same pattern as loadPreset(): deserialize then rebuildGraph (which destroys and recreates all nodes internally). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
import { workshop as workshopApi } from '../services/api.js';
|
import { workshop as workshopApi } from '../services/api.js';
|
||||||
import { useAuth } from '../services/AuthContext.jsx';
|
import { useAuth } from '../services/AuthContext.jsx';
|
||||||
import { state, deserialize, emit } from '../engine/state.js';
|
import { state, deserialize } from '../engine/state.js';
|
||||||
import { stopAudio, rebuildGraph } from '../engine/audioEngine.js';
|
import { rebuildGraph } from '../engine/audioEngine.js';
|
||||||
import { getPresets } from '../engine/presets.js';
|
import { getPresets } from '../engine/presets.js';
|
||||||
|
|
||||||
const TAGS = ['ambient', 'bass', 'drums', 'pad', 'lead', 'fx', 'chiptune', 'experimental'];
|
const TAGS = ['ambient', 'bass', 'drums', 'pad', 'lead', 'fx', 'chiptune', 'experimental'];
|
||||||
@@ -171,14 +171,11 @@ export default function Workshop({ onSwitchToSandbox, onSwitchToGame, onSwitchTo
|
|||||||
const handleLoad = (patch) => {
|
const handleLoad = (patch) => {
|
||||||
if (!patch.data) return;
|
if (!patch.data) return;
|
||||||
|
|
||||||
// Stop audio, clean state, then load
|
// Deep clone and load — same pattern as loadPreset()
|
||||||
if (state.isRunning) stopAudio();
|
// Don't stop audio first: rebuildGraph destroys and recreates all nodes
|
||||||
|
|
||||||
// Deep clone to avoid reference issues
|
|
||||||
const cleanData = JSON.parse(JSON.stringify(patch.data));
|
const cleanData = JSON.parse(JSON.stringify(patch.data));
|
||||||
deserialize(cleanData);
|
deserialize(cleanData);
|
||||||
rebuildGraph();
|
if (state.isRunning) rebuildGraph();
|
||||||
emit();
|
|
||||||
|
|
||||||
onSwitchToSandbox?.();
|
onSwitchToSandbox?.();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user