feat(pedals): Neural Amp pedal (S3) + PedalState resource path; Lyrebird 1.7.1
Bump Lyrebird to 1.7.1 (ProteusModelImporter) and add a neural amp-capture pedal. - NeuralAmpPedal: loads a GuitarML Proteus/NeuralPi model (via ProteusModelImporter) and runs it with LSTMAmp on the gain-trimmed input; passes through clean when no model is loaded. Model files are user-supplied, not bundled (GuitarML = GPL-3.0). - PedalState gains an optional `resourcePath` (backward-compatible, decodeIfPresent) and Pedal a matching `resourcePath` property, wired through captureState/applyState — so the loaded model file persists across rig save/load. The neural pedal reads it at build() (applied on rebuild). This foundation also unblocks a future custom-cabinet-IR path. - Registered in PedalRegistry / PedalType / PedalCategory (.gain) / palette / enclosure color; Help acknowledges the GuitarML model format. Tests: no-model passthrough; loaded model transforms output & differs from passthrough; gain affects modeled output; resourcePath round-trips through PedalState; gain knob exposed; registry resolves "Neural Amp". Full suite 501. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,11 @@ open class Pedal: SynthesizerBase {
|
||||
/// Output gain as a linear multiplier. `1.0` = unity gain.
|
||||
@UIParam public var level: Double = 1.0
|
||||
|
||||
/// Optional path to an external resource this pedal references (e.g. a neural-amp model file).
|
||||
/// Not a `@UIParam` — it's a `String`, applied at `build()`, and persisted separately in
|
||||
/// ``PedalState/resourcePath``. Default `nil`. Pedals that don't use an external file ignore it.
|
||||
public var resourcePath: String?
|
||||
|
||||
// MARK: - Sample rate
|
||||
|
||||
/// Engine sample rate, injected by `PedalBoard.add(_:)` before the pedal is added
|
||||
|
||||
@@ -45,6 +45,7 @@ public extension PedalType {
|
||||
|
||||
// Drive & dynamics
|
||||
static let amp = PedalType("Amp")
|
||||
static let neuralAmp = PedalType("Neural Amp")
|
||||
static let overdrive = PedalType("Overdrive")
|
||||
static let distortion = PedalType("Distortion")
|
||||
static let fuzz = PedalType("Fuzz")
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
// NeuralAmpPedal.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
|
||||
/// Neural amp/pedal capture player: runs a GuitarML Proteus / NeuralPi LSTM model on the input.
|
||||
///
|
||||
/// Load a model with ``loadModel(path:)`` (or set ``Pedal/resourcePath``); the file path is
|
||||
/// persisted in the rig, so a saved rig reloads the same capture. With no model loaded the pedal
|
||||
/// passes the signal through clean.
|
||||
///
|
||||
/// Signal chain (inside `effect(_:)`):
|
||||
/// ```
|
||||
/// dry → × gain → LSTMAmp(model) → mono out (model loaded)
|
||||
/// dry → mono out (no model)
|
||||
/// ```
|
||||
///
|
||||
/// The model is read and built at `build()` (off the RT thread); changing it takes effect on the
|
||||
/// next rebuild. Fully wet when a model is loaded; `Level` is the master.
|
||||
///
|
||||
/// > Model files are **user-supplied and not bundled** — GuitarML models are GPL-3.0. Download a
|
||||
/// > capture (e.g. from the GuitarML Tone Library or Tone3000) and point the pedal at it.
|
||||
///
|
||||
/// ## Parameters
|
||||
///
|
||||
/// Inherits `bypass` and `level` (master) from `Pedal`, plus:
|
||||
/// - `gain`: Input drive into the model (linear). Range `[0.25, 4]`.
|
||||
public final class NeuralAmpPedal: Pedal {
|
||||
|
||||
/// One-line description shown in the picker and info panel.
|
||||
public override var summary: String {
|
||||
"Plays a neural amp/pedal capture (GuitarML Proteus / NeuralPi model)."
|
||||
}
|
||||
|
||||
/// Fully wet when a model is loaded; hide the Mix control.
|
||||
public override var showsMixControl: Bool { false }
|
||||
|
||||
// MARK: - Parameters
|
||||
|
||||
/// Input drive into the model (linear multiplier). Range [0.25, 4].
|
||||
@UIParam public var gain: Double = 1.0
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private static let defaultMix: Double = 1.0
|
||||
private let gainRange: ClosedRange<Double> = 0.25 ... 4.0
|
||||
|
||||
/// Caches the parsed model per path so a stereo-region build (which calls `effect(_:)` once
|
||||
/// per channel) reads and decodes the file only once. Keyed on the path so a model change
|
||||
/// re-parses. Touched only at `build()` on the main thread.
|
||||
private var loadedModel: (path: String, model: NeuralAmpModel)?
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a neural amp pedal.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
|
||||
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
|
||||
public init(
|
||||
inputBus: Int = 0,
|
||||
outputBus: Int = 0
|
||||
) {
|
||||
super.init(
|
||||
name: "Neural Amp",
|
||||
inputBus: inputBus,
|
||||
outputBus: outputBus,
|
||||
initialMix: NeuralAmpPedal.defaultMix
|
||||
)
|
||||
}
|
||||
|
||||
/// Points the pedal at a Proteus/NeuralPi model file. Takes effect on the next rebuild.
|
||||
///
|
||||
/// - Parameter path: Filesystem path to the model `.json`.
|
||||
public func loadModel(path: String) {
|
||||
resourcePath = path
|
||||
}
|
||||
|
||||
// MARK: - UI
|
||||
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Gain", node: $gain, range: gainRange),
|
||||
]
|
||||
}
|
||||
|
||||
// MARK: - Effect
|
||||
|
||||
/// Runs the loaded model on the (gain-trimmed) input; passes through clean if no model is set
|
||||
/// or the file can't be read/parsed.
|
||||
///
|
||||
/// - Parameter dry: Dry mono input signal.
|
||||
/// - Returns: The model output, or the dry signal when no model is loaded.
|
||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
guard let path: String = resourcePath, let model: NeuralAmpModel = resolveModel(path: path) else {
|
||||
return dry
|
||||
}
|
||||
let driven: any ValidGeneratorInput = dry * $gain
|
||||
return LSTMAmp(input: driven, model: model)
|
||||
}
|
||||
|
||||
/// Loads (and caches) the model at `path`, or returns `nil` if the file is missing/unparsable.
|
||||
private func resolveModel(path: String) -> NeuralAmpModel? {
|
||||
if let cached: (path: String, model: NeuralAmpModel) = loadedModel, cached.path == path {
|
||||
return cached.model
|
||||
}
|
||||
guard let data: Data = try? Data(contentsOf: URL(fileURLWithPath: path)),
|
||||
let model: NeuralAmpModel = try? ProteusModelImporter.model(fromProteusJSON: data)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
loadedModel = (path, model)
|
||||
return model
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,8 @@ extension Pedal {
|
||||
sliderValues: sliderValues,
|
||||
selectorValues: selectorValues,
|
||||
bypass: bypass,
|
||||
tempoSync: tempoSync.isEmpty ? nil : tempoSync
|
||||
tempoSync: tempoSync.isEmpty ? nil : tempoSync,
|
||||
resourcePath: resourcePath
|
||||
)
|
||||
}
|
||||
|
||||
@@ -66,5 +67,6 @@ extension Pedal {
|
||||
// tempo by `ShoeGaze` after the rebuild, so no clock is required here.
|
||||
tempoSync = state.tempoSync ?? [:]
|
||||
tempoSyncRevision.bump()
|
||||
resourcePath = state.resourcePath
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public enum PedalRegistry {
|
||||
/// to a board via `board.add(_:)`.
|
||||
public static let builtIn: [String: @MainActor () -> Pedal] = [
|
||||
"Amp": { AmpPedal() },
|
||||
"Neural Amp": { NeuralAmpPedal() },
|
||||
"Overdrive": { OverdrivePedal() },
|
||||
"Distortion": { DistortionPedal() },
|
||||
"Delay": { DelayPedal() },
|
||||
|
||||
@@ -50,6 +50,10 @@ public struct PedalState: Codable, Equatable {
|
||||
/// decode to "all parameters free".
|
||||
public let tempoSync: [String: TempoSync]?
|
||||
|
||||
/// Optional path to an external resource the pedal references (e.g. a neural-amp model file).
|
||||
/// `nil` for pedals that use no external file, and for presets saved before this existed.
|
||||
public let resourcePath: String?
|
||||
|
||||
/// Creates a pedal state snapshot.
|
||||
///
|
||||
/// - Parameters:
|
||||
@@ -60,6 +64,8 @@ public struct PedalState: Codable, Equatable {
|
||||
/// - selectorValues: Current selector values in `Pedal.effectSelectors` order. Defaults to empty.
|
||||
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
|
||||
/// - tempoSync: Tempo-sync state per syncable parameter, or `nil` for none. Defaults to `nil`.
|
||||
/// - resourcePath: Path to an external resource the pedal references (e.g. a neural-amp
|
||||
/// model file), or `nil`. Defaults to `nil`.
|
||||
public init(
|
||||
id: UUID = UUID(),
|
||||
type: String,
|
||||
@@ -68,7 +74,8 @@ public struct PedalState: Codable, Equatable {
|
||||
sliderValues: [Double] = [],
|
||||
selectorValues: [Double] = [],
|
||||
bypass: Double,
|
||||
tempoSync: [String: TempoSync]? = nil
|
||||
tempoSync: [String: TempoSync]? = nil,
|
||||
resourcePath: String? = nil
|
||||
) {
|
||||
self.id = id
|
||||
self.type = type
|
||||
@@ -78,6 +85,7 @@ public struct PedalState: Codable, Equatable {
|
||||
self.selectorValues = selectorValues
|
||||
self.bypass = bypass
|
||||
self.tempoSync = tempoSync
|
||||
self.resourcePath = resourcePath
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
@@ -89,6 +97,7 @@ public struct PedalState: Codable, Equatable {
|
||||
case selectorValues
|
||||
case bypass
|
||||
case tempoSync
|
||||
case resourcePath
|
||||
}
|
||||
|
||||
/// Decodes a snapshot, tolerating presets saved before `switchValues` / `sliderValues` /
|
||||
@@ -103,5 +112,6 @@ public struct PedalState: Codable, Equatable {
|
||||
self.selectorValues = try container.decodeIfPresent([Double].self, forKey: .selectorValues) ?? []
|
||||
self.bypass = try container.decode(Double.self, forKey: .bypass)
|
||||
self.tempoSync = try container.decodeIfPresent([String: TempoSync].self, forKey: .tempoSync)
|
||||
self.resourcePath = try container.decodeIfPresent(String.self, forKey: .resourcePath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +181,9 @@ public struct HelpView: View {
|
||||
"The Amp pedal's tone stack follows the Yeh & Smith analysis of the Fender/Marshall/Vox "
|
||||
+ "tone-stack circuit (\"Discretization of the '59 Fender Bassman Tone Stack\", DAFx-06); "
|
||||
+ "its models are original code, not captures of specific hardware.",
|
||||
"The Neural Amp pedal loads GuitarML Proteus / NeuralPi capture models (the open LSTM "
|
||||
+ "format from github.com/GuitarML). You supply the model file; none are bundled, and "
|
||||
+ "those models are licensed by their respective authors.",
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public enum PedalCategory: String, CaseIterable, Identifiable, Sendable {
|
||||
}
|
||||
|
||||
private static let mapping: [String: PedalCategory] = [
|
||||
"Amp": .gain, "Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain,
|
||||
"Amp": .gain, "Neural Amp": .gain, "Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain,
|
||||
"Compressor": .dynamics, "Sustainer": .dynamics, "Limiter": .dynamics, "Noise Gate": .dynamics,
|
||||
"Graphic EQ": .filter, "Auto-Wah": .filter, "Wah": .filter, "Mutant": .filter,
|
||||
"Cabinet": .filter,
|
||||
|
||||
@@ -54,7 +54,7 @@ public struct PedalPaletteView: View {
|
||||
/// Preferred display order for the built-in pedals. Any registered pedal not listed here is
|
||||
/// appended afterwards (sorted) so the palette never silently drops a newly added pedal.
|
||||
private static let preferredOrder: [String] = [
|
||||
"Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
|
||||
"Amp", "Neural Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
|
||||
"Volume",
|
||||
"Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary",
|
||||
"Auto-Wah", "Wah", "Mutant", "Cabinet", "Ring Modulator", "Diffuser", "Bitcrusher", "Granulator",
|
||||
|
||||
@@ -17,6 +17,7 @@ import LyrebirdShoeGaze
|
||||
private func enclosureColor(for displayName: String) -> Color {
|
||||
switch displayName {
|
||||
case "Amp": return Color(red: 0.18, green: 0.17, blue: 0.20) // amp-head charcoal
|
||||
case "Neural Amp": return Color(red: 0.22, green: 0.16, blue: 0.30) // deep neural violet
|
||||
case "Overdrive": return Color(red: 0.85, green: 0.42, blue: 0.08) // warm orange
|
||||
case "Distortion": return Color(red: 0.80, green: 0.26, blue: 0.12) // hot rust
|
||||
case "Delay": return Color(red: 0.10, green: 0.55, blue: 0.55) // teal
|
||||
|
||||
Reference in New Issue
Block a user