/** * Pi Multi-FX Pedal — App Shell * * Main application with: * - Status bar (mode selector, connection status, CPU, sample rate) * - Screen area (tab content: Rig, FX Chain, Models, IRs, Presets, Settings) * - Footswitch bar (8 footswitches with dynamic scribble strips per mode) * - Tab bar (bottom navigation) */ import { useState, useEffect, useCallback } from 'react'; import { usePedalState, fetchPresets, apiPost, apiPut, apiGet, apiUpload } from './pedal/hooks/usePedalState'; import { FootswitchModeProvider } from './pedal/FootswitchModeContext'; import { FootswitchBar } from './pedal/footswitch/FootswitchBar'; import { ModeSelector } from './pedal/footswitch/ModeSelector'; import type { PedalState, PedalBlock, BankData } from './pedal/types'; import './pedal/pedal.css'; const T = { bg: '#0A0A0C', panel: '#141418', surface: '#1C1C22', border: '#2A2A32', amber: '#E8A030', blue: '#3A7BA8', blueDim: '#1E4060', amberDim: '#7A5218', green: '#3AB87A', red: '#C84040', text: '#F0EDE6', textSec: '#8888A0', textDim: '#444458', }; // ── VU Meter ───────────────────────────────────────────────── function VUMeter({ level = 0, height = 60 }: { level?: number; height?: number }) { const segs = 12; const active = Math.round((level / 100) * segs); const segColor = (i: number) => { if (i >= 10) return T.red; if (i >= 8) return '#E8C030'; return T.green; }; return (
{Array.from({ length: segs }).map((_, i) => (
))}
); } // ── FX Type Labels ─────────────────────────────────────────── const FX_TYPE_LABELS: Record = { noise_gate: 'Noise Gate', compressor: 'Compressor', boost: 'Boost', overdrive: 'Overdrive', distortion: 'Distortion', fuzz: 'Fuzz', eq: 'EQ', chorus: 'Chorus', flanger: 'Flanger', phaser: 'Phaser', tremolo: 'Tremolo', vibrato: 'Vibrato', delay: 'Delay', reverb: 'Reverb', volume: 'Volume', nam_amp: 'NAM Amp', ir_cab: 'IR Cab', octaver: 'Octaver', pitch_shifter: 'Pitch Shifter', harmonizer: 'Harmonizer', whammy: 'Whammy', detune: 'Detune', ring_modulator: 'Ring Mod', auto_wah: 'Auto Wah', envelope_filter: 'Env Filter', rotary_speaker: 'Rotary', uni_vibe: 'Uni-Vibe', auto_pan: 'Auto Pan', stereo_widener: 'Stereo Widener', bitcrusher: 'Bitcrusher', wavefolder: 'Wavefolder', rectifier: 'Rectifier', expander: 'Expander', de_esser: 'De-esser', transient_shaper: 'Transient Shaper', parametric_eq: 'Parametric EQ', high_pass_filter: 'High Pass', low_pass_filter: 'Low Pass', band_pass_filter: 'Band Pass', notch_filter: 'Notch Filter', formant_filter: 'Formant Filter', ping_pong_delay: 'Ping Pong Delay', multi_tap_delay: 'Multi Tap', reverse_delay: 'Reverse Delay', tape_echo: 'Tape Echo', shimmer_reverb: 'Shimmer Reverb', early_reflections: 'Early Reflections', sidechain_compressor: 'Sidechain Comp', looper: 'Looper', }; // ══════════════════════════════════════════════════════════════ // RIG SCREEN // ══════════════════════════════════════════════════════════════ function RigScreen({ state, connected }: { state: PedalState | null; connected: boolean; refresh?: () => void }) { const [volume, setVolume] = useState( state?.master_volume != null ? Math.round(state.master_volume * 100) : 80 ); const [localBypass, setLocalBypass] = useState(null); const [localTuner, setLocalTuner] = useState(null); const bypass = localBypass ?? state?.bypass ?? false; const tuner = localTuner ?? state?.tuner_enabled ?? false; useEffect(() => { if (state?.master_volume != null) setVolume(Math.round(state.master_volume * 100)); }, [state?.master_volume]); useEffect(() => { if (state?.bypass !== undefined) setLocalBypass(null); if (state?.tuner_enabled !== undefined) setLocalTuner(null); }, [state?.bypass, state?.tuner_enabled]); const handleVolume = async (val: number) => { setVolume(val); try { await apiPut('/api/volume', { volume: val / 100 }); } catch {} }; const handleBypass = async () => { const next = !bypass; setLocalBypass(next); try { await apiPost('/api/bypass', { bypass: next }); } catch { setLocalBypass(null); } }; const handleTuner = async () => { const next = !tuner; setLocalTuner(next); try { await apiPost('/api/tuner', { enabled: next }); } catch { setLocalTuner(null); } }; const inputLevel = state?.input_level ?? 0; const outputLevel = state?.output_level ?? 0; return (
Active Rig
{state?.current_preset ? ( {state.current_preset.name} ) : ( No preset loaded )} {connected ? ( Connected ) : ( Offline )}
{/* Status row */}
Bypass
Tuner
Routing
{state?.routing_mode || 'mono'}
{/* Tuner */} {tuner && (
🎵
TUNER ACTIVE
—————●—————
Tap switch again to exit tuner mode
)} {/* Volume */}
Master Volume
handleVolume(+e.target.value)} style={{ width: '100%', accentColor: T.amber }} />
{volume}%
{state?.nam_loaded ? 'NAM: Active' : 'NAM: —'}
{state?.ir_loaded ? 'IR: Active' : 'IR: —'}
{/* Signal chain */}
Signal Chain
{['IN', state?.bypass ? 'BYP' : (state?.nam_loaded ? 'NAM' : 'AMP'), state?.ir_loaded ? 'IR' : 'CAB', 'OUT'].map((s, i, arr) => (
{s}
{i < arr.length - 1 &&
}
))}
); } // ══════════════════════════════════════════════════════════════ // FX CHAIN SCREEN // ══════════════════════════════════════════════════════════════ function FXBlock({ title, type, active = true, bypassed = false }: { title: string; type: string; active?: boolean; bypassed?: boolean; }) { const [open, setOpen] = useState(true); return (
setOpen(o => !o)}>
{title} {type} {open ? '▾' : '▸'}
); } function FXScreen({ state, connected }: { state: PedalState | null; connected: boolean }) { const [fxList, setFxList] = useState<{ id: number; title: string; type: string; bypassed: boolean }[]>([]); const [loading, setLoading] = useState(true); useEffect(() => { if (!connected || !state?.current_preset) { setFxList([]); setLoading(false); return; } fetchPresets().then(data => { const banks = data.banks || []; const cp = state.current_preset; const preset = cp ? banks[cp.bank]?.presets?.[cp.program] : null; if (preset?.chain) { setFxList(preset.chain.map((b, i) => ({ id: i + 1, title: FX_TYPE_LABELS[b.fx_type] || b.fx_type, type: b.fx_type, bypassed: b.bypassed ?? false, }))); } setLoading(false); }).catch(() => { setFxList([]); setLoading(false); }); }, [connected, state]); if (loading) return
; return (
FX Chain {fxList.length > 0 ? `(${fxList.length})` : ''}
{fxList.length === 0 ? (
No FX blocks in the chain.
) : ( fxList.map(f => ) )}
); } // ══════════════════════════════════════════════════════════════ // MODELS SCREEN // ══════════════════════════════════════════════════════════════ function ModelsScreen({ connected, refresh }: { state?: PedalState | null; connected: boolean; refresh: () => void }) { const [models, setModels] = useState<{ name: string; path?: string; architecture?: string; size_mb?: string; loaded?: boolean }[]>([]); const [current, setCurrent] = useState(null); const [loading, setLoading] = useState(true); const [fileRef, setFileRef] = useState(null); const loadModels = useCallback(async () => { if (!connected) { setLoading(false); return; } try { const data = await apiGet<{ models?: any[]; current?: string }>('/api/models'); setModels(data.models || []); setCurrent(data.current ?? null); } catch {} setLoading(false); }, [connected]); useEffect(() => { loadModels(); }, [loadModels]); const handleLoad = async (path?: string) => { if (!path) return; try { await apiPost('/api/models/load', { path }); await loadModels(); refresh(); } catch { alert('Failed to load model'); } }; const handleUnload = async () => { try { await apiPost('/api/models/unload'); setCurrent(null); await loadModels(); refresh(); } catch { alert('Failed to unload'); } }; const handleUpload = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; try { await apiUpload('/api/models/upload', file); await loadModels(); } catch { alert('Upload failed'); } }; if (loading) return
; return (
NAM Models ({models.length})
setFileRef(el)} type="file" accept=".nam" style={{ display: 'none' }} onChange={handleUpload} />
{current && (
Loaded Model
{current}
)} {models.length === 0 ? (
No NAM models found.
) : ( models.map(m => (
!m.loaded && handleLoad(m.path)}>
{m.name}
{m.architecture} · {m.size_mb} MB
{m.loaded ? Loaded : }
)) )}
); } // ══════════════════════════════════════════════════════════════ // IRS SCREEN // ══════════════════════════════════════════════════════════════ function IRsScreen({ connected, refresh }: { state?: PedalState | null; connected: boolean; refresh: () => void }) { const [irs, setIrs] = useState<{ name: string; path?: string; sample_rate?: number; length_ms?: number; loaded?: boolean }[]>([]); const [current, setCurrent] = useState(null); const [loading, setLoading] = useState(true); const [fileRef, setFileRef] = useState(null); const loadIrs = useCallback(async () => { if (!connected) { setLoading(false); return; } try { const data = await apiGet<{ irs?: any[]; current?: string }>('/api/irs'); setIrs(data.irs || []); setCurrent(data.current ?? null); } catch {} setLoading(false); }, [connected]); useEffect(() => { loadIrs(); }, [loadIrs]); const handleLoad = async (path?: string) => { if (!path) return; try { await apiPost('/api/irs/load', { path }); await loadIrs(); refresh(); } catch { alert('Failed to load IR'); } }; const handleUnload = async () => { try { await apiPost('/api/irs/unload'); setCurrent(null); await loadIrs(); refresh(); } catch { alert('Failed to unload'); } }; const handleUpload = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; try { await apiUpload('/api/irs/upload', file); await loadIrs(); } catch { alert('Upload failed'); } }; if (loading) return
; return (
IR Files ({irs.length})
setFileRef(el)} type="file" accept=".wav" style={{ display: 'none' }} onChange={handleUpload} />
{current && (
Loaded IR
{current}
)} {irs.length === 0 ? (
No IR files found.
) : ( irs.map(ir => (
!ir.loaded && handleLoad(ir.path)}>
{ir.name}
{ir.sample_rate} Hz · {ir.length_ms} ms
{ir.loaded ? Loaded : }
)) )}
); } // ══════════════════════════════════════════════════════════════ // PRESETS SCREEN // ══════════════════════════════════════════════════════════════ function PresetsScreen({ state, connected, refresh }: { state: PedalState | null; connected: boolean; refresh: () => void }) { const [banks, setBanks] = useState([]); const [selectedBank, setSelectedBank] = useState(0); const [loading, setLoading] = useState(true); const loadPresets = useCallback(async () => { if (!connected) { setBanks([{ name: 'Default', number: 0, presets: [{ name: 'Edge of Breakup', bank: 0, program: 0 }, { name: 'Modern High Gain', bank: 0, program: 1 }, null, null] }]); setLoading(false); return; } try { const data = await fetchPresets(); setBanks(data.banks || []); } catch {} setLoading(false); }, [connected]); useEffect(() => { loadPresets(); }, [loadPresets]); const handleActivate = async (bank: number, program: number) => { try { await apiPost(`/api/presets/${bank}/${program}/activate`); await loadPresets(); refresh(); } catch { alert('Failed to load preset'); } }; if (loading) return
; const currentPreset = state?.current_preset; const bankData = banks[selectedBank]; const presets = bankData?.presets || []; return (
Presets
{banks.length > 1 && (
{banks.map((b, i) => ( ))}
)} {currentPreset && (
Current
{currentPreset.name} Bank {currentPreset.bank} · Prog {currentPreset.program}
)} {presets.length === 0 ? (
No presets in this bank.
) : ( presets.map((p, i) => { if (!p) return null; const isActive = currentPreset?.bank === p.bank && currentPreset?.program === p.program; return (
handleActivate(p.bank, p.program)}>
{p.program + 1}
{p.name}
Bank {p.bank} · Program {p.program}
{isActive && }
); }) )}
); } // ══════════════════════════════════════════════════════════════ // SETTINGS SCREEN // ══════════════════════════════════════════════════════════════ function SettingsScreen({ state: pedalState }: { state: PedalState | null; refresh?: () => void }) { return (
Settings
System
{pedalState?.cpu_percent != null && (
CPU {pedalState.cpu_percent}%
)} {pedalState?.sample_rate && (
Sample Rate {pedalState.sample_rate / 1000}kHz
)}
Connection Live
); } // ══════════════════════════════════════════════════════════════ // APP SHELL // ══════════════════════════════════════════════════════════════ const TABS = [ { id: 'rig', label: 'Rig', icon: '🎛' }, { id: 'fx', label: 'FX', icon: '⛓' }, { id: 'models', label: 'Models', icon: '📁' }, { id: 'irs', label: 'IRs', icon: '🎚' }, { id: 'presets', label: 'Presets', icon: '⭐' }, { id: 'settings', label: 'Settings', icon: '⚙' }, ] as const; type TabId = (typeof TABS)[number]['id']; // ── Pedal Shell Content (inner component that has context access) ── function PedalContent() { const [tab, setTab] = useState('rig'); const { state, connected, refresh } = usePedalState(); // Build block list from current preset state const [blocks, setBlocks] = useState([]); const [bankNames, setBankNames] = useState(['Default']); useEffect(() => { if (connected && state?.current_preset) { fetchPresets().then(data => { const names = (data.banks || []).map((b: BankData) => b.name); if (names.length > 0) setBankNames(names); const cp = state.current_preset; if (!cp) return; const bank = data.banks?.[cp.bank]; const preset = bank?.presets?.[cp.program]; if (preset?.chain) { setBlocks(preset.chain.map((b, i) => ({ id: i + 1, fx_type: b.fx_type, title: FX_TYPE_LABELS[b.fx_type] || b.fx_type, bypassed: b.bypassed ?? false, }))); } }).catch(() => {}); } }, [connected, state?.current_preset]); const handleToggleBlock = useCallback(async (blockId: number, newBypass: boolean) => { setBlocks(prev => prev.map(b => b.id === blockId ? { ...b, bypassed: newBypass } : b)); if (connected) { try { await apiPost('/api/blocks/toggle', { block_id: blockId, bypass: newBypass }); } catch {} } }, [connected]); // Snapshots (placeholder — will be wired to real API) const [snapshots] = useState<{ name: string; active: boolean }[]>( Array.from({ length: 8 }, (_, i) => ({ name: `Snap ${i + 1}`, active: false })) ); return (
{/* ── Status Bar ── */}
PI MULTI-FX {state?.tuner_enabled && TUNER}
{state?.cpu_percent != null && ( CPU {state.cpu_percent}% )} {state?.sample_rate && ( {state.sample_rate / 1000}kHz )} {state?.bypass && BYP} {state?.nam_loaded && NAM} {state?.ir_loaded && IR}
{/* ── Screen Area ── */}
{tab === 'rig' && } {tab === 'fx' && } {tab === 'models' && } {tab === 'irs' && } {tab === 'presets' && } {tab === 'settings' && }
{/* ── Footswitch Bar ── */} {/* ── Tab Bar ── */}
{TABS.map(t => (
setTab(t.id)}> {t.icon} {t.label}
))}
); } // ── Root App ───────────────────────────────────────────────── export default function App() { useEffect(() => { document.title = 'Pi Multi-FX Pedal'; }, []); return ( <> {/* Global styles for inline-styled components */} ); }