refactor: split editor.rs into editor/ widget modules

Move the egui editor from a single editor.rs into an editor/ module: mod.rs
(aggregator: create(), EditorState, layout, placeholder slider columns),
meter.rs (|L|GR|R| meters + ceiling lamp, owns MeterState), and plot.rs
(rolling in/out/GR plot, owns PlotState + PlotHistory). Each visualiser owns
its GUI state; the aggregator composes them. No behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Mikkeli Matlock
2026-06-24 05:01:50 +09:00
parent 3ae860188e
commit eb2499bad3
4 changed files with 427 additions and 394 deletions
+107
View File
@@ -0,0 +1,107 @@
//! egui editor: assembly + control layout.
//!
//! The aggregator. Builds the editor window and lays out the heading, the meter panel
//! ([`meter`]), the rolling plot ([`plot`]), and the (placeholder) per-channel slider columns.
//! Each visualiser owns its GUI state and drawing in its submodule; this module wires them
//! together and holds the shared [`EditorState`]. When the UI is redesigned the slider columns
//! get replaced and the visualisers stay as self-contained widgets.
use nih_plug::prelude::*;
use nih_plug_egui::{
create_egui_editor,
egui::{self, Vec2},
resizable_window::ResizableWindow,
widgets,
};
use std::sync::Arc;
use crate::meters::Meters;
use crate::params::{Codename206Params, CompressorParams};
use crate::Codename206;
mod meter;
mod plot;
/// Bottom of the dB scale shared by the meters and the plot (top is 0 dBFS).
const METER_FLOOR_DB: f32 = -60.0;
/// GUI-side editor state (not persisted): the per-widget state for the meter panel and the plot.
#[derive(Default)]
struct EditorState {
meter: meter::MeterState,
plot: plot::PlotState,
}
/// Build the plugin editor over shared handles to the params and meter state.
pub(crate) fn create(params: Arc<Codename206Params>, meters: Arc<Meters>) -> Option<Box<dyn Editor>> {
let egui_state = params.editor_state.clone();
create_egui_editor(
params.editor_state.clone(),
EditorState::default(),
|_, _| {},
move |egui_ctx, setter, state| {
// Keep frames coming so the meters animate and the lamp can time out while open.
egui_ctx.request_repaint();
// One column of controls for a single compressor channel (placeholder layout).
let band_col = |ui: &mut egui::Ui, title: &str, p: &CompressorParams| {
ui.strong(title);
ui.label("Pre-gain");
ui.add(widgets::ParamSlider::for_param(&p.pre_gain_db, setter));
ui.add(widgets::ParamSlider::for_param(&p.detection, setter));
ui.label("Threshold");
ui.add(widgets::ParamSlider::for_param(&p.threshold_db, setter));
ui.label("Ratio");
ui.add(widgets::ParamSlider::for_param(&p.ratio, setter));
ui.label("Knee");
ui.add(widgets::ParamSlider::for_param(&p.knee_db, setter));
ui.label("Attack");
ui.add(widgets::ParamSlider::for_param(&p.attack_ms, setter));
ui.label("Release");
ui.add(widgets::ParamSlider::for_param(&p.release_ms, setter));
ui.label("Makeup");
ui.add(widgets::ParamSlider::for_param(&p.makeup_db, setter));
ui.add(widgets::ParamSlider::for_param(&p.bypass, setter));
};
// Resizable window; vertical scroll so every control stays reachable even when the
// window is small. (Placeholder layout — the redesign will replace the slider columns.)
ResizableWindow::new("editor")
.min_size(Vec2::new(480.0, 320.0))
.show(egui_ctx, egui_state.as_ref(), |ui| {
egui::ScrollArea::vertical().show(ui, |ui| {
ui.heading(Codename206::NAME);
meter::draw(ui, &meters, &mut state.meter);
ui.separator();
plot::draw(ui, &meters, &mut state.plot);
ui.separator();
// Global controls stacked vertically so they never overflow sideways.
egui::Grid::new("globals").num_columns(2).show(ui, |ui| {
ui.label("Xover Lo/Mid");
ui.add(widgets::ParamSlider::for_param(&params.crossover_low_hz, setter));
ui.end_row();
ui.label("Xover Mid/Hi");
ui.add(widgets::ParamSlider::for_param(&params.crossover_high_hz, setter));
ui.end_row();
ui.label("Look-ahead");
ui.add(widgets::ParamSlider::for_param(&params.look_ahead_ms, setter));
ui.end_row();
ui.label("Ceiling");
ui.add(widgets::ParamSlider::for_param(&params.output_ceiling_db, setter));
ui.end_row();
ui.label("Lim Release");
ui.add(widgets::ParamSlider::for_param(&params.limiter_release_ms, setter));
ui.end_row();
});
ui.separator();
ui.columns(4, |cols| {
band_col(&mut cols[0], "LOW", &params.low);
band_col(&mut cols[1], "MID", &params.mid);
band_col(&mut cols[2], "HIGH", &params.high);
band_col(&mut cols[3], "ALL", &params.all);
});
});
});
},
)
}