feat(M9.1): add server-backed configuration tab
Test: cargo test -p tui --all-targets --all-features Test: cargo test -p fader_master --all-targets --all-features Test: cargo clippy -p tui -p fader_master --all-targets --all-features -- -D warnings
This commit is contained in:
parent
9493183365
commit
3452fee880
|
|
@ -3,7 +3,7 @@ use std::io::{self, Read, Write};
|
|||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
use thiserror::Error;
|
||||
|
||||
pub const PROTOCOL_VERSION: u16 = 4;
|
||||
pub const PROTOCOL_VERSION: u16 = 5;
|
||||
pub const MAX_FRAME_BYTES: usize = 64 * 1024;
|
||||
|
||||
/// Kind of mixer object addressed by a client.
|
||||
|
|
@ -75,6 +75,44 @@ pub struct MixerSnapshot {
|
|||
pub status: String,
|
||||
pub objects: Vec<MixerObject>,
|
||||
pub devices: Vec<MidiDevice>,
|
||||
pub configuration: ConfigurationSnapshot,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct ConfigurationSnapshot {
|
||||
pub profile_id: String,
|
||||
pub applications: Vec<ConfiguredApplication>,
|
||||
pub groups: Vec<ConfiguredGroup>,
|
||||
pub faders: Vec<ConfiguredFader>,
|
||||
pub bindings: Vec<ConfiguredBinding>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct ConfiguredApplication {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct ConfiguredGroup {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
pub members: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct ConfiguredFader {
|
||||
pub id: String,
|
||||
pub target: MixerObjectKey,
|
||||
pub pickup: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct ConfiguredBinding {
|
||||
pub surface: String,
|
||||
pub fader: String,
|
||||
pub action: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ use thiserror::Error;
|
|||
use volume_lib::WorkerEvent;
|
||||
|
||||
use crate::ipc::{
|
||||
ClientRequest, MidiDevice, MixerObject, MixerObjectKey, MixerObjectKind, MixerSnapshot,
|
||||
PROTOCOL_VERSION, PickupStatus, RequestCommand, ResponseResult, ServerResponse,
|
||||
ClientRequest, ConfigurationSnapshot, ConfiguredApplication as IpcApplication,
|
||||
ConfiguredBinding as IpcBinding, ConfiguredFader as IpcFader, ConfiguredGroup as IpcGroup,
|
||||
MidiDevice, MixerObject, MixerObjectKey, MixerObjectKind, MixerSnapshot, PROTOCOL_VERSION,
|
||||
PickupStatus, RequestCommand, ResponseResult, ServerResponse,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -64,6 +66,7 @@ pub struct LiveMixerState {
|
|||
write_ceiling: Gain,
|
||||
backend: String,
|
||||
status: String,
|
||||
configuration: ConfigurationSnapshot,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
@ -94,6 +97,67 @@ pub enum LiveMixerError {
|
|||
Profile(String),
|
||||
}
|
||||
|
||||
fn configuration_snapshot(profile: &Profile) -> ConfigurationSnapshot {
|
||||
ConfigurationSnapshot {
|
||||
profile_id: profile.id().to_string(),
|
||||
applications: profile
|
||||
.applications()
|
||||
.iter()
|
||||
.map(|application| IpcApplication {
|
||||
id: application.id().to_owned(),
|
||||
label: application.label().to_owned(),
|
||||
})
|
||||
.collect(),
|
||||
groups: profile
|
||||
.groups()
|
||||
.iter()
|
||||
.map(|group| IpcGroup {
|
||||
id: group.id().to_owned(),
|
||||
label: group.label().to_owned(),
|
||||
members: group.members().to_vec(),
|
||||
})
|
||||
.collect(),
|
||||
faders: profile
|
||||
.faders()
|
||||
.iter()
|
||||
.map(|fader| IpcFader {
|
||||
id: fader.id().to_owned(),
|
||||
target: MixerObjectKey {
|
||||
kind: match fader.target_kind() {
|
||||
fader_config::TargetKind::Application => MixerObjectKind::Application,
|
||||
fader_config::TargetKind::Group => MixerObjectKind::Group,
|
||||
fader_config::TargetKind::Output => MixerObjectKind::Output,
|
||||
},
|
||||
id: fader.target_id().to_owned(),
|
||||
},
|
||||
pickup: fader.pickup(),
|
||||
})
|
||||
.collect(),
|
||||
bindings: profile
|
||||
.bindings()
|
||||
.iter()
|
||||
.map(|binding| IpcBinding {
|
||||
surface: binding.surface().to_owned(),
|
||||
fader: binding.fader().to_owned(),
|
||||
action: match binding.action() {
|
||||
Action::Volume => "volume",
|
||||
Action::ToggleMute => "toggle_mute",
|
||||
}
|
||||
.to_owned(),
|
||||
message: format!(
|
||||
"{} ch{} #{}",
|
||||
match binding.message_kind() {
|
||||
fader_config::MessageKind::Cc => "cc",
|
||||
fader_config::MessageKind::Note => "note",
|
||||
},
|
||||
binding.channel(),
|
||||
binding.number()
|
||||
),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
impl LiveMixerState {
|
||||
pub fn new(
|
||||
write_ceiling: Gain,
|
||||
|
|
@ -187,6 +251,7 @@ impl LiveMixerState {
|
|||
write_ceiling,
|
||||
backend: backend.into(),
|
||||
status: "connecting".to_owned(),
|
||||
configuration: configuration_snapshot(profile),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -312,6 +377,7 @@ impl LiveMixerState {
|
|||
status: self.status.clone(),
|
||||
objects,
|
||||
devices: self.devices.clone(),
|
||||
configuration: self.configuration.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,6 +89,56 @@ impl IpcMixerClient {
|
|||
error: device.error,
|
||||
})
|
||||
.collect(),
|
||||
configuration: tui::ConfigurationSnapshot {
|
||||
profile_id: snapshot.configuration.profile_id,
|
||||
applications: snapshot
|
||||
.configuration
|
||||
.applications
|
||||
.into_iter()
|
||||
.map(|application| tui::ConfiguredApplication {
|
||||
id: application.id,
|
||||
label: application.label,
|
||||
})
|
||||
.collect(),
|
||||
groups: snapshot
|
||||
.configuration
|
||||
.groups
|
||||
.into_iter()
|
||||
.map(|group| tui::ConfiguredGroup {
|
||||
id: group.id,
|
||||
label: group.label,
|
||||
members: group.members,
|
||||
})
|
||||
.collect(),
|
||||
faders: snapshot
|
||||
.configuration
|
||||
.faders
|
||||
.into_iter()
|
||||
.map(|fader| tui::ConfiguredFader {
|
||||
id: fader.id,
|
||||
target: MixerObjectId {
|
||||
kind: match fader.target.kind {
|
||||
IpcObjectKind::Application => MixerObjectKind::Application,
|
||||
IpcObjectKind::Group => MixerObjectKind::Group,
|
||||
IpcObjectKind::Output => MixerObjectKind::Output,
|
||||
},
|
||||
id: fader.target.id,
|
||||
},
|
||||
pickup: fader.pickup,
|
||||
})
|
||||
.collect(),
|
||||
bindings: snapshot
|
||||
.configuration
|
||||
.bindings
|
||||
.into_iter()
|
||||
.map(|binding| tui::ConfiguredBinding {
|
||||
surface: binding.surface,
|
||||
fader: binding.fader,
|
||||
action: binding.action,
|
||||
message: binding.message,
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
}),
|
||||
ResponseResult::Error { message, .. } => {
|
||||
let kind = if message.contains("stale revision") {
|
||||
|
|
|
|||
5
task.md
5
task.md
|
|
@ -335,8 +335,9 @@ Dependencies: M8, M2, M1.
|
|||
- [ ] **M9.1 Editor drafts:** separate tab to create/edit/delete applications, groups and faders; target/member selection, matcher preview, validation errors and referenced-delete handling. Tests: invalid regex/dangling member rejected; Cancel has no side effects; creating a group/fader produces the expected semantic TOML.
|
||||
Transactional, comment-preserving draft primitives now create applications,
|
||||
absolute groups and faders, and roll back invalid regexes or referenced
|
||||
deletes. The separate TUI tab, selection controls, matcher preview, and full
|
||||
edit/delete surface remain.
|
||||
deletes. A separate Config tab now shows the server-owned applications, group
|
||||
membership, logical fader targets, pickup policy, and MIDI assignments. The
|
||||
selection controls, matcher preview, and full edit/delete surface remain.
|
||||
- [ ] **M9.2 Surface bindings / MIDI learn:** select surface, listen for one supported control, preview conflicts and save binding. Tests: learning suppresses the normal action, other surfaces are not captured accidentally, cancellation restores routing, duplicate binding is rejected.
|
||||
- [ ] **M9.3 Apply/save/conflict:** server-owned revisioned edits, separate live apply and persistence. Tests: stale edits conflict, external file edits are not overwritten, comments survive save, write failure is shown as unsaved and leaves previous disk config usable.
|
||||
|
||||
|
|
|
|||
185
tui/src/lib.rs
185
tui/src/lib.rs
|
|
@ -19,8 +19,8 @@ use ratatui::{
|
|||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
style::{Style, Stylize},
|
||||
symbols::border,
|
||||
text::Line,
|
||||
widgets::{Block, Gauge, Paragraph, Widget},
|
||||
text::{Line, Text},
|
||||
widgets::{Block, Gauge, Paragraph, Widget, Wrap},
|
||||
};
|
||||
|
||||
const VOLUME_STEP: f64 = 0.05;
|
||||
|
|
@ -74,6 +74,43 @@ pub struct MidiDevice {
|
|||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||
pub struct ConfigurationSnapshot {
|
||||
pub profile_id: String,
|
||||
pub applications: Vec<ConfiguredApplication>,
|
||||
pub groups: Vec<ConfiguredGroup>,
|
||||
pub faders: Vec<ConfiguredFader>,
|
||||
pub bindings: Vec<ConfiguredBinding>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct ConfiguredApplication {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct ConfiguredGroup {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
pub members: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct ConfiguredFader {
|
||||
pub id: String,
|
||||
pub target: MixerObjectId,
|
||||
pub pickup: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct ConfiguredBinding {
|
||||
pub surface: String,
|
||||
pub fader: String,
|
||||
pub action: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct MixerSnapshot {
|
||||
pub revision: u64,
|
||||
|
|
@ -83,6 +120,7 @@ pub struct MixerSnapshot {
|
|||
pub error: Option<String>,
|
||||
pub items: Vec<MixerItem>,
|
||||
pub devices: Vec<MidiDevice>,
|
||||
pub configuration: ConfigurationSnapshot,
|
||||
}
|
||||
|
||||
/// Client boundary kept independent of sockets for deterministic TUI tests.
|
||||
|
|
@ -137,6 +175,7 @@ impl BufferedMixerClient {
|
|||
error: None,
|
||||
items: Vec::new(),
|
||||
devices: Vec::new(),
|
||||
configuration: ConfigurationSnapshot::default(),
|
||||
};
|
||||
let shared = Arc::new((
|
||||
Mutex::new(BufferedState {
|
||||
|
|
@ -439,6 +478,14 @@ pub struct LiveTui<C> {
|
|||
theme: ThemeName,
|
||||
exit: bool,
|
||||
client_error: Option<String>,
|
||||
tab: Tab,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
enum Tab {
|
||||
#[default]
|
||||
Mixer,
|
||||
Configuration,
|
||||
}
|
||||
|
||||
impl<C: MixerClient> LiveTui<C> {
|
||||
|
|
@ -455,6 +502,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
theme,
|
||||
exit: false,
|
||||
client_error: None,
|
||||
tab: Tab::Mixer,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -521,6 +569,14 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
KeyCode::End => self.set_selected_volume(1.0),
|
||||
KeyCode::Char('m') => self.toggle_selected_mute(),
|
||||
KeyCode::Char('t') => self.theme = self.theme.next(),
|
||||
KeyCode::Tab => {
|
||||
self.tab = match self.tab {
|
||||
Tab::Mixer => Tab::Configuration,
|
||||
Tab::Configuration => Tab::Mixer,
|
||||
};
|
||||
}
|
||||
KeyCode::Char('1') => self.tab = Tab::Mixer,
|
||||
KeyCode::Char('2') => self.tab = Tab::Configuration,
|
||||
KeyCode::Esc | KeyCode::Char('q') => self.exit = true,
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -592,7 +648,7 @@ impl<C> Widget for &LiveTui<C> {
|
|||
.bold(),
|
||||
" MASTER ".fg(theme.foreground).bold(),
|
||||
format!(
|
||||
" {} · {} · rev {} · {} ",
|
||||
" [1 Mixer] [2 Config] · {} · {} · rev {} · {} ",
|
||||
self.snapshot.backend,
|
||||
self.snapshot.status,
|
||||
self.snapshot.revision,
|
||||
|
|
@ -619,7 +675,14 @@ impl<C> Widget for &LiveTui<C> {
|
|||
.unwrap_or_else(|| "confirmed server state".to_owned())
|
||||
});
|
||||
let mixer = Block::bordered()
|
||||
.title(" Live mixer objects ".fg(theme.accent).bold())
|
||||
.title(
|
||||
match self.tab {
|
||||
Tab::Mixer => " Live mixer objects ",
|
||||
Tab::Configuration => " Configuration ",
|
||||
}
|
||||
.fg(theme.accent)
|
||||
.bold(),
|
||||
)
|
||||
.title_bottom(if status_error {
|
||||
status.fg(theme.error)
|
||||
} else {
|
||||
|
|
@ -629,7 +692,10 @@ impl<C> Widget for &LiveTui<C> {
|
|||
.border_set(border::THICK);
|
||||
let inner = mixer.inner(body);
|
||||
mixer.render(body, buf);
|
||||
self.render_streams(inner, buf);
|
||||
match self.tab {
|
||||
Tab::Mixer => self.render_streams(inner, buf),
|
||||
Tab::Configuration => self.render_configuration(inner, buf),
|
||||
}
|
||||
|
||||
Paragraph::new(Line::from(vec![
|
||||
" ↑/↓ or j/k ".fg(theme.foreground),
|
||||
|
|
@ -642,6 +708,8 @@ impl<C> Widget for &LiveTui<C> {
|
|||
"0/100%".fg(theme.secondary),
|
||||
" T ".fg(theme.foreground),
|
||||
"theme".fg(theme.secondary),
|
||||
" Tab/1/2 ".fg(theme.foreground),
|
||||
"view".fg(theme.secondary),
|
||||
" Q/Esc ".fg(theme.foreground),
|
||||
"quit".fg(theme.secondary),
|
||||
]))
|
||||
|
|
@ -682,6 +750,62 @@ fn device_summary(devices: &[MidiDevice]) -> Option<String> {
|
|||
}
|
||||
|
||||
impl<C> LiveTui<C> {
|
||||
fn render_configuration(&self, area: Rect, buf: &mut Buffer) {
|
||||
let theme = self.theme.palette();
|
||||
let config = &self.snapshot.configuration;
|
||||
let mut lines = vec![Line::from(format!("Profile: {}", config.profile_id)).bold()];
|
||||
lines.push(Line::from(""));
|
||||
lines.push(Line::from("Applications").fg(theme.accent).bold());
|
||||
lines.extend(config.applications.iter().map(|application| {
|
||||
Line::from(format!(" {} — {}", application.id, application.label))
|
||||
}));
|
||||
lines.push(Line::from("Groups").fg(theme.accent).bold());
|
||||
lines.extend(config.groups.iter().map(|group| {
|
||||
Line::from(format!(
|
||||
" {} — {} [{}]",
|
||||
group.id,
|
||||
group.label,
|
||||
group.members.join(", ")
|
||||
))
|
||||
}));
|
||||
lines.push(
|
||||
Line::from("Faders and MIDI assignments")
|
||||
.fg(theme.accent)
|
||||
.bold(),
|
||||
);
|
||||
for fader in &config.faders {
|
||||
let target_kind = match fader.target.kind {
|
||||
MixerObjectKind::Application => "application",
|
||||
MixerObjectKind::Group => "group",
|
||||
MixerObjectKind::Output => "output",
|
||||
};
|
||||
lines.push(Line::from(format!(
|
||||
" {} -> {}:{}{}",
|
||||
fader.id,
|
||||
target_kind,
|
||||
fader.target.id,
|
||||
if fader.pickup { " (pickup)" } else { "" }
|
||||
)));
|
||||
lines.extend(
|
||||
config
|
||||
.bindings
|
||||
.iter()
|
||||
.filter(|binding| binding.fader == fader.id)
|
||||
.map(|binding| {
|
||||
Line::from(format!(
|
||||
" {} · {} · {} · {}",
|
||||
binding.surface, binding.action, binding.message, binding.fader
|
||||
))
|
||||
.fg(theme.secondary)
|
||||
}),
|
||||
);
|
||||
}
|
||||
Paragraph::new(Text::from(lines))
|
||||
.style(Style::default().fg(theme.foreground))
|
||||
.wrap(Wrap { trim: false })
|
||||
.render(area, buf);
|
||||
}
|
||||
|
||||
fn render_streams(&self, area: Rect, buf: &mut Buffer) {
|
||||
let theme = self.theme.palette();
|
||||
if self.snapshot.items.is_empty() {
|
||||
|
|
@ -809,6 +933,7 @@ impl DemoClient {
|
|||
error: None,
|
||||
}],
|
||||
devices: Vec::new(),
|
||||
configuration: ConfigurationSnapshot::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -970,6 +1095,56 @@ mod tests {
|
|||
assert!(rendered.contains("Q/Esc"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn configuration_tab_shows_groups_faders_and_midi_assignments() {
|
||||
let mut client = DemoClient::default();
|
||||
let mut snapshot = client.view();
|
||||
snapshot.configuration = ConfigurationSnapshot {
|
||||
profile_id: "desktop".into(),
|
||||
applications: vec![ConfiguredApplication {
|
||||
id: "browser".into(),
|
||||
label: "Browser".into(),
|
||||
}],
|
||||
groups: vec![ConfiguredGroup {
|
||||
id: "media".into(),
|
||||
label: "Media".into(),
|
||||
members: vec!["browser".into()],
|
||||
}],
|
||||
faders: vec![ConfiguredFader {
|
||||
id: "media-fader".into(),
|
||||
target: MixerObjectId {
|
||||
kind: MixerObjectKind::Group,
|
||||
id: "media".into(),
|
||||
},
|
||||
pickup: true,
|
||||
}],
|
||||
bindings: vec![ConfiguredBinding {
|
||||
surface: "desk-left".into(),
|
||||
fader: "media-fader".into(),
|
||||
action: "volume".into(),
|
||||
message: "cc ch1 #49".into(),
|
||||
}],
|
||||
};
|
||||
client.revision = snapshot.revision;
|
||||
let mut app = LiveTui::new(client).unwrap();
|
||||
app.snapshot = snapshot;
|
||||
app.handle_key_event(press(KeyCode::Tab));
|
||||
|
||||
let area = Rect::new(0, 0, 100, 24);
|
||||
let mut buffer = Buffer::empty(area);
|
||||
(&app).render(area, &mut buffer);
|
||||
let rendered = buffer
|
||||
.content
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
|
||||
assert!(rendered.contains("Profile: desktop"));
|
||||
assert!(rendered.contains("media — Media [browser]"));
|
||||
assert!(rendered.contains("media-fader -> group:media (pickup)"));
|
||||
assert!(rendered.contains("desk-left · volume · cc ch1 #49"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn device_status_summaries_include_recovery_actions_and_errors() {
|
||||
let ambiguous = MidiDevice {
|
||||
|
|
|
|||
Loading…
Reference in New Issue