Skip to content
Merged
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
1 change: 0 additions & 1 deletion scripts/build-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ clone_slopsmith() {
mattromano/feedBack-plugin-song-preview:song_preview
mattromano/feedBack-plugin-splitscreen@custom:splitscreen
mattromano/feedBack-plugin-staffview:staffview
mattromano/feedBack-plugin-stem-mixer:stem_mixer
mattromano/feedBack-plugin-stem-splitter:stem_splitter
mattromano/feedBack-plugin-stems@custom:stems
mattromano/feedBack-plugin-stepmode:stepmode
Expand Down
26 changes: 25 additions & 1 deletion src/renderer/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,16 @@ window.__feedBackDesktopAudioHooks = window.__feedBackDesktopAudioHooks || {};
try { snapshotBlob = await api.savePreset(); } catch (_) { /* best-effort */ }
}

// Mute the guitar chain for the swap (issue #16): the engine builds the new chain stage by
// stage with audio running, so a high-gain amp could play for ~1 s before its cabinet IR
// landed — a burst of harsh, cab-less fizz. applyPresetGainLevels() below restores the
// level on success; every failure path restores the slider's level (the current one).
const restoreChainGain = () => {
const db = parseFloat(outputGainSlider ? outputGainSlider.value : '0');
try { api.setGain('chain', dbToLinearGain(Number.isFinite(db) ? db : 0)); } catch (_) { /* best-effort */ }
};
try { await api.setGain('chain', 0); } catch (_) { /* best-effort */ }

try {
await api.clearChain();
// Clean any Rig Builder stages a pre-fix build baked into this saved
Expand All @@ -2390,6 +2400,7 @@ window.__feedBackDesktopAudioHooks = window.__feedBackDesktopAudioHooks || {};
if (result === false || (result && result.success === false)) {
console.error(tag + ': loadPreset failed:', result?.error || 'unknown error');
await _restorePresetBlob(snapshotBlob, tag);
restoreChainGain();
if (!snapshotBlob) {
// No rollback available; chain is now empty — sync localStorage and UI to match.
try { localStorage.setItem('slopsmith-signal-chain', '[]'); } catch (_) {}
Expand All @@ -2409,6 +2420,7 @@ window.__feedBackDesktopAudioHooks = window.__feedBackDesktopAudioHooks || {};
} catch (e) {
console.error(tag + ':', e);
await _restorePresetBlob(snapshotBlob, tag);
restoreChainGain();
if (!snapshotBlob) {
// No rollback available; chain is now empty — sync localStorage and UI to match.
try { localStorage.setItem('slopsmith-signal-chain', '[]'); } catch (_) {}
Expand Down Expand Up @@ -4219,6 +4231,11 @@ window.__feedBackDesktopAudioHooks = window.__feedBackDesktopAudioHooks || {};
constructor() {
this.activeTone = null;
this.activePreset = null;
// The song's base tone (issue #15): CDLC authors often name it "Lead" or
// "<song>_solo", which the keyword classifier files under solo, so the whole
// song played on the solo preset. The base tone is the song's default sound —
// it never takes the solo target unless the user overrode it for this tone.
this.baseTone = '';
this.taSwitcher = true;
this._switchLock = null; // in-flight Promise; null when idle
this._pendingTone = null; // latest request that arrived while locked (coalesced)
Expand All @@ -4244,7 +4261,13 @@ window.__feedBackDesktopAudioHooks = window.__feedBackDesktopAudioHooks || {};
}
async _doSwitch(input) {
const cfg = readTaStore();
const { effectiveName: presetName, autoName, category } = getTaSessionEffectivePreset(input, cfg);
let { effectiveName: presetName, autoName, category } = getTaSessionEffectivePreset(input, cfg);
const ov = (typeof window !== 'undefined') ? window._aeTaSessionOverrides : null;
const userOverride = !!(ov && Object.prototype.hasOwnProperty.call(ov, input) && ov[input]);
if (this.baseTone && input === this.baseTone && category === 'solo' && !userOverride) {
const idle = (cfg.targets || {}).idle;
if (idle) { presetName = idle; autoName = idle; category = 'idle (base tone)'; }
}
if (!presetName || presetName === this.activePreset) return;
const ok = await loadPresetByName(presetName);
if (ok) {
Expand Down Expand Up @@ -4282,6 +4305,7 @@ window.__feedBackDesktopAudioHooks = window.__feedBackDesktopAudioHooks || {};
return true;
}
const switcher = new ToneAutomationSwitcher();
switcher.baseTone = String(toneBase || '').trim();
window._toneSwitcher = switcher;
const initialInput = String(toneBase || songKey || '').trim();
if (initialInput) await switcher.switchToTone(initialInput);
Expand Down
39 changes: 39 additions & 0 deletions tests/preset-swap-mute.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Issue #16: while a preset loads, the engine builds the chain stage by stage with audio
// running, so a high-gain amp played for ~1 s without its cabinet IR (harsh fizz). The swap
// now mutes the guitar chain first; success restores the preset level, failure the slider's.

'use strict';

const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');

const SRC = fs.readFileSync(path.join(__dirname, '..', 'src', 'renderer', 'screen.js'), 'utf8').replace(/\r\n/g, '\n');

function fnBody(name) {
const start = SRC.indexOf(`async function ${name}(`);
assert.ok(start !== -1, `${name} not found`);
let i = SRC.indexOf('{', SRC.indexOf(')', start)) + 1, depth = 1;
while (i < SRC.length && depth > 0) { if (SRC[i] === '{') depth++; else if (SRC[i] === '}') depth--; i++; }
return SRC.slice(start, i);
}

test('the guitar chain is muted before the old chain is cleared', () => {
const body = fnBody('replaceChainWithPresetBlob');
const mute = body.indexOf("api.setGain('chain', 0)");
const clear = body.indexOf('api.clearChain()');
assert.ok(mute > 0 && clear > mute, 'mute happens before clearChain');
});

test('success restores the preset level after the whole chain is loaded', () => {
const body = fnBody('replaceChainWithPresetBlob');
assert.ok(body.indexOf('applyPresetGainLevels(preset)') > body.indexOf('api.loadPreset('));
});

test('both failure paths restore the current level (never left silent)', () => {
const body = fnBody('replaceChainWithPresetBlob');
const restores = body.match(/_restorePresetBlob\(snapshotBlob, tag\);\s*restoreChainGain\(\);/g) || [];
assert.equal(restores.length, 2);
assert.match(body, /const restoreChainGain = \(\) => \{[\s\S]*?outputGainSlider[\s\S]*?api\.setGain\('chain'/);
});
79 changes: 79 additions & 0 deletions tests/tone-automation-base-tone.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Issue #15: Tone Automation filed a song's BASE tone under "solo" when its name contained
// "lead"/"solo" (CDLC: "Lead", "mychdead_solo"), so the whole song played on the solo preset.
// The base tone now takes the idle (default) target; real solo tone changes keep solo.

'use strict';

const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');

const SRC = fs.readFileSync(path.join(__dirname, '..', 'src', 'renderer', 'screen.js'), 'utf8');

function extractClass(src, name) {
const start = src.indexOf(`class ${name} {`);
assert.ok(start !== -1, `class ${name} not found`);
let i = src.indexOf('{', start) + 1, depth = 1;
while (i < src.length && depth > 0) { if (src[i] === '{') depth++; else if (src[i] === '}') depth--; i++; }
return src.slice(start, i);
}

function harness({ overrides = {} } = {}) {
const loads = [];
const cfg = { enabled: true, targets: { idle: 'Main Lead', solo: 'Metal Lead', dist: 'Main Lead' } };
const ctx = {
window: { _aeTaSessionOverrides: overrides },
console: { log() {} },
readTaStore: () => cfg,
// Stub classifier: "lead"/"solo" in the name -> solo, else idle (mirrors the real keyword split).
getTaSessionEffectivePreset: (t) => {
const category = /lead|solo/i.test(t) ? 'solo' : 'idle';
const autoName = cfg.targets[category];
const effectiveName = Object.prototype.hasOwnProperty.call(overrides, t) ? overrides[t] : autoName;
return { autoName, effectiveName, category };
},
loadPresetByName: async (n) => { loads.push(n); return true; },
};
vm.runInNewContext(`${extractClass(SRC, 'ToneAutomationSwitcher')}; this.S = ToneAutomationSwitcher;`, ctx);
return { S: ctx.S, loads };
}

test('a base tone named "Lead" plays the default tone, not the solo preset', async () => {
const { S, loads } = harness();
const sw = new S();
sw.baseTone = 'Lead';
await sw.switchToTone('Lead');
assert.deepEqual(loads, ['Main Lead']);
});

test('a "<song>_solo" base tone is treated the same way', async () => {
const { S, loads } = harness();
const sw = new S();
sw.baseTone = 'mychdead_solo';
await sw.switchToTone('mychdead_solo');
assert.deepEqual(loads, ['Main Lead']);
});

test('a real solo tone change still gets the solo preset, and returning to base goes back', async () => {
const { S, loads } = harness();
const sw = new S();
sw.baseTone = 'Lead';
await sw.switchToTone('Lead');
await sw.switchToTone('Guitar Solo');
await sw.switchToTone('Lead');
assert.deepEqual(loads, ['Main Lead', 'Metal Lead', 'Main Lead']);
});

test("the user's own per-tone override still wins", async () => {
const { S, loads } = harness({ overrides: { Lead: 'Metal Lead' } });
const sw = new S();
sw.baseTone = 'Lead';
await sw.switchToTone('Lead');
assert.deepEqual(loads, ['Metal Lead']);
});

test('the install sets the base tone on the switcher', () => {
assert.match(SRC, /const switcher = new ToneAutomationSwitcher\(\);\s*switcher\.baseTone = String\(toneBase \|\| ''\)\.trim\(\);/);
});
Loading