Skip to content

refactor: deduplicate preset handler and add stage_registry! macro#200

Merged
OpenSauce merged 1 commit intomainfrom
refactor/preset-cleanup-stage-macro
Feb 28, 2026
Merged

refactor: deduplicate preset handler and add stage_registry! macro#200
OpenSauce merged 1 commit intomainfrom
refactor/preset-cleanup-stage-macro

Conversation

@OpenSauce
Copy link
Copy Markdown
Owner

Extract preset_names() and build_preset_load_tasks() helpers in the preset handler to eliminate repeated code. Replace 4 hand-written stage dispatch impls (32 match arms) with a stage_registry! macro, making new stage addition a single-line change.

Copilot AI review requested due to automatic review settings February 28, 2026 21:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the GUI stage plumbing to reduce repetitive dispatch code and streamlines preset loading logic by extracting small helpers, improving maintainability when adding or modifying stages/presets.

Changes:

  • Introduces a stage_registry! macro to generate stage module declarations, re-exports, and StageMessage/StageConfig dispatch implementations.
  • Updates LevelConfig::to_stage to accept a (currently unused) sample_rate for uniform stage construction.
  • Deduplicates preset listing and preset-load task construction via preset_names() and build_preset_load_tasks() helpers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/gui/stages/mod.rs Replaces hand-written stage dispatch with stage_registry! macro-generated items.
src/gui/stages/level.rs Aligns LevelConfig::to_stage signature with other stages by adding a _sample_rate parameter.
src/gui/handlers/preset.rs Extracts helpers to avoid repeated preset-name mapping and repeated task batching when loading presets.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/gui/stages/mod.rs Outdated
Comment on lines 63 to 76
stage_registry! {
Filter => filter, FilterConfig, FilterMessage;
Preamp => preamp, PreampConfig, PreampMessage;
Compressor => compressor, CompressorConfig, CompressorMessage;
ToneStack => tonestack, ToneStackConfig, ToneStackMessage;
PowerAmp => poweramp, PowerAmpConfig, PowerAmpMessage;
Level => level, LevelConfig, LevelMessage;
NoiseGate => noise_gate, NoiseGateConfig, NoiseGateMessage;
MultibandSaturator => multiband_saturator, MultibandSaturatorConfig, MultibandSaturatorMessage;
}

// --- StageType ---
// Kept manual: needs #[default] on one variant and tr!() i18n keys in Display.

Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description claims adding a new stage becomes a single-line change, but StageType (and its Display impl / i18n keys) still has to be updated manually alongside the stage_registry! invocation. Consider adjusting the PR description to reflect the remaining manual steps, or extend the macro inputs to also generate StageType/Display so the claim is accurate.

Copilot uses AI. Check for mistakes.
Comment thread src/gui/handlers/preset.rs Outdated
Comment on lines +157 to +165
fn build_preset_load_tasks(preset: &Preset) -> Task<Message> {
let set_stage_task = Task::done(Message::SetStages(preset.stages.clone()));
let set_ir_task = match &preset.ir_name {
Some(ir_name) => Task::done(Message::IrSelected(ir_name.clone())),
None => Task::none(),
};
let set_ir_gain_task = Task::done(Message::IrGainChanged(preset.ir_gain));
let set_pitch_shift_task = Task::done(Message::PitchShiftChanged(preset.pitch_shift_semitones));

Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build_preset_load_tasks takes &Preset and clones ir_name (and stages). In the current callers, preset is already an owned value (Option<Preset>), so this helper could take Preset by value and move stages/ir_name into the messages to avoid extra allocations/copies on every preset load.

Copilot uses AI. Check for mistakes.
Extract preset_names() and build_preset_load_tasks() helpers in the
preset handler to eliminate repeated code. Replace all hand-written
stage dispatch impls with a stage_registry! macro that generates
StageType, StageMessage, StageConfig, and all their impls from a
single registration list. Adding a new stage is now a single line
in the macro invocation plus the stage module file.
@OpenSauce OpenSauce force-pushed the refactor/preset-cleanup-stage-macro branch from 76751a4 to 7364f3c Compare February 28, 2026 21:55
@OpenSauce OpenSauce enabled auto-merge (squash) February 28, 2026 21:56
@OpenSauce OpenSauce merged commit 3485bed into main Feb 28, 2026
7 checks passed
@OpenSauce OpenSauce deleted the refactor/preset-cleanup-stage-macro branch February 28, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants