' +
+ pill('data-lr-follow', 'Follow song' + (state.follow && fst ? ` ${fst > 0 ? '+' : ''}${fst}` : ''), state.follow,
+ 'Also shift by the song’s tuning when every string is down (or up) by the same amount, so a guitar in E plays Eb/D songs without retuning.') +
+ (cur || state.cents ? pill('data-lr-zero', 'No shift', false, 'Back to no shift') : '') +
+ '
';
+ const setAndRefresh = (patch) => { set(patch); ctx.refresh(); };
+ slot.querySelector('[data-lr-sound-as]').addEventListener('change', (e) => setAndRefresh({ semitones: Number(e.target.value) }));
+ slot.querySelector('[data-lr-down]').addEventListener('click', () => setAndRefresh({ semitones: state.semitones - 1 }));
+ slot.querySelector('[data-lr-up]').addEventListener('click', () => setAndRefresh({ semitones: state.semitones + 1 }));
+ slot.querySelector('[data-lr-follow]').addEventListener('click', () => setAndRefresh({ follow: !state.follow }));
+ const zero = slot.querySelector('[data-lr-zero]');
+ if (zero) zero.addEventListener('click', () => setAndRefresh({ semitones: 0, cents: 0 }));
+ }
+ (function registerMenuSection() {
+ const section = { id: 'live-retune-shift', render: renderMenuSection, order: 10 };
+ if (window.v3Badges && typeof window.v3Badges.registerMenuSection === 'function') {
+ window.v3Badges.registerMenuSection(section.id, section.render, section);
+ } else {
+ window._v3BadgesPendingSections = window._v3BadgesPendingSections || [];
+ window._v3BadgesPendingSections.push(section);
+ }
+ })();
+
+ window.__liveRetune = { state, set, apply, songTuningSt, followSt, shiftSt, shiftedTuningName, renderMenuSection };
window.addEventListener('songcents:change', () => { apply(); render(); });
const bus = window.feedBack || window.slopsmith;
diff --git a/src/renderer/screen.js b/src/renderer/screen.js
index 2f1e85d..c9bc8c9 100644
--- a/src/renderer/screen.js
+++ b/src/renderer/screen.js
@@ -2280,6 +2280,144 @@ window.__feedBackDesktopAudioHooks = window.__feedBackDesktopAudioHooks || {};
else localStorage.setItem('slopsmith-default-preset-name', name);
}
+ // ── Top tones (instrument menu) ──────────────────────────────────────────
+ // Starred presets first, then the most-loaded ones, as one-click buttons in
+ // the core's instrument menu. Stars: array of preset names. Counts: name → n,
+ // bumped by recordPresetUse on every load of a named preset except the
+ // startup default (which would just count app launches).
+ const PRESET_STARS_KEY = 'slopsmith-preset-stars';
+ const PRESET_USES_KEY = 'slopsmith-preset-use-counts';
+ const TOP_TONES_LIMIT = 5;
+ function readPresetStars() {
+ try {
+ const v = JSON.parse(localStorage.getItem(PRESET_STARS_KEY) || '[]');
+ return Array.isArray(v) ? v.filter((n) => typeof n === 'string' && n) : [];
+ } catch (e) { return []; }
+ }
+ function writePresetStars(names) {
+ try { localStorage.setItem(PRESET_STARS_KEY, JSON.stringify(names)); } catch (e) {
+ console.warn('[audio-engine] could not save starred presets:', e);
+ }
+ }
+ function readPresetUses() {
+ try {
+ const v = JSON.parse(localStorage.getItem(PRESET_USES_KEY) || '{}');
+ return (v && typeof v === 'object' && !Array.isArray(v)) ? v : {};
+ } catch (e) { return {}; }
+ }
+ function writePresetUses(uses) {
+ try { localStorage.setItem(PRESET_USES_KEY, JSON.stringify(uses)); } catch (e) {
+ console.warn('[audio-engine] could not save preset use counts:', e);
+ }
+ }
+ function togglePresetStar(name) {
+ const stars = readPresetStars();
+ const i = stars.indexOf(name);
+ if (i >= 0) stars.splice(i, 1); else stars.push(name);
+ writePresetStars(stars);
+ return i < 0;
+ }
+ function recordPresetUse(name) {
+ if (!name) return;
+ const uses = readPresetUses();
+ uses[name] = (Number(uses[name]) || 0) + 1;
+ writePresetUses(uses);
+ }
+ // Drop a deleted preset from stars and counts.
+ function forgetPresetStats(name) {
+ const stars = readPresetStars();
+ if (stars.includes(name)) writePresetStars(stars.filter((n) => n !== name));
+ const uses = readPresetUses();
+ if (name in uses) { delete uses[name]; writePresetUses(uses); }
+ }
+ /** Starred (in star order), then most used (ties by name), only presets that
+ * still exist, at most `limit`. */
+ function topTonePresetNames(presets, stars, uses, limit) {
+ const exists = (n) => Object.prototype.hasOwnProperty.call(presets || {}, n);
+ const out = [];
+ for (const n of stars || []) if (exists(n) && !out.includes(n)) out.push(n);
+ const used = Object.keys(uses || {})
+ .filter((n) => exists(n) && !out.includes(n) && Number(uses[n]) > 0)
+ .sort((a, b) => (Number(uses[b]) - Number(uses[a])) || a.localeCompare(b));
+ return out.concat(used).slice(0, limit);
+ }
+ /** How much each preset is used: counted loads, plus the choices already on
+ * record before counting existed (each song's whole-song tone lock, and each
+ * Tone Automation slot that targets it), so Top tones isn't empty on day one. */
+ function presetUseScores(uses, songLocks, taTargets) {
+ const out = {};
+ const add = (n, k) => { if (typeof n === 'string' && n) out[n] = (out[n] || 0) + k; };
+ for (const [n, c] of Object.entries(uses || {})) add(n, Number(c) || 0);
+ for (const n of Object.values(songLocks || {})) add(n, 1);
+ // The 'bass' slot is the tone for bass arrangements, not a guitar tone.
+ for (const [slot, n] of Object.entries(taTargets || {})) if (slot !== 'bass') add(n, 1);
+ return out;
+ }
+ // The one manual "load this preset now" path (Settings → Load and the
+ // instrument menu's top tones). Snapshots the chain so a failed load rolls back.
+ // Runs under the tone chain lock so it can't interleave with a song's chain
+ // rebuild, and refuses while a song is loading (that rebuild would replace it).
+ async function loadPresetManually(name, source) {
+ const p = getPresets()[name];
+ if (!p) return false;
+ if (isSongTransitioning()) {
+ console.warn('[audio-engine] Not loading preset during a song load:', name);
+ return false;
+ }
+ const ok = await withToneChainLock(() => replaceChainWithPresetBlob(p, `${source}:${name}`));
+ if (ok) {
+ recordPresetUse(name);
+ console.log('[audio-engine] Preset loaded:', name);
+ }
+ return ok;
+ }
+ let _instMenuLoading = null;
+ function renderInstMenuTopTones(slot, ctx) {
+ const presets = getPresets();
+ if (!Object.keys(presets).length) { slot.innerHTML = ''; return; }
+ const scores = presetUseScores(readPresetUses(), readSongToneLocks(), (readTaStore() || {}).targets);
+ const names = topTonePresetNames(presets, readPresetStars(), scores, TOP_TONES_LIMIT);
+ const stars = readPresetStars();
+ const head = '
Top tones
';
+ if (!names.length) {
+ slot.innerHTML = '
' + head +
+ '
Star tones in Audio Engine settings to pin them here.