feat(M8.1): expose physical pickup state in the TUI

Instantiate pickup controls from validated bindings before discovery, aggregate their unavailable/waiting/tracking/mixed state into mixer snapshots, and render it in live rows. Reorder first observations so startup can arm configured controls.

Tests: full workspace fmt/check/test/doc/clippy/release gates; default/no-default backend matrix; focused pickup transition and TUI rendering regressions.
This commit is contained in:
Dandaedre 2026-10-15 03:58:12 +02:00
parent c812af52ee
commit 69a49cdbfd
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
7 changed files with 133 additions and 17 deletions

View File

@ -330,6 +330,11 @@ transport failures, surface the connection error inside the terminal, and keep
retrying so starting or restarting the server reconnects without restarting the
TUI.
Mixer-object snapshots also aggregate pickup state across configured physical
volume bindings. They expose `unavailable`, `waiting`, `tracking`, or `mixed`;
controls are instantiated from the profile before discovery so the first live
observation can arm them without waiting for an initial MIDI packet.
Terminal colors come from semantic theme palettes rather than renderer-local
literals. The built-ins are Default, Dracula, Nord, Gruvbox Dark, Catppuccin
Mocha, and Solarized Dark. `tui --theme NAME` selects the initial palette and

View File

@ -3,7 +3,7 @@ use std::io::{self, Read, Write};
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use thiserror::Error;
pub const PROTOCOL_VERSION: u16 = 3;
pub const PROTOCOL_VERSION: u16 = 4;
pub const MAX_FRAME_BYTES: usize = 64 * 1024;
/// Kind of mixer object addressed by a client.
@ -15,6 +15,16 @@ pub enum MixerObjectKind {
Output,
}
/// Aggregate pickup state for physical controls mapped to one mixer object.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum PickupStatus {
Unavailable,
Waiting,
Tracking,
Mixed,
}
/// Stable configured mixer-object identity.
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
pub struct MixerObjectKey {
@ -86,6 +96,7 @@ pub struct MixerObject {
pub muted: Option<bool>,
pub mute_mixed: bool,
pub pending: bool,
pub pickup: Option<PickupStatus>,
pub writable: bool,
pub error: Option<String>,
}

View File

@ -1,6 +1,6 @@
use std::collections::{BTreeMap, BTreeSet};
use fader_config::Profile;
use fader_config::{Action, Profile};
use fader_core::{
AdapterCommand, AdapterEvent, ApplicationMatcher, ChannelGains, CommandOrigin, FaderId, Gain,
Mute, Pickup, PickupState, ServerCommand, ServerReducer, StreamHandle, StreamMetadata,
@ -12,7 +12,7 @@ use volume_lib::WorkerEvent;
use crate::ipc::{
ClientRequest, MidiDevice, MixerObject, MixerObjectKey, MixerObjectKind, MixerSnapshot,
PROTOCOL_VERSION, RequestCommand, ResponseResult, ServerResponse,
PROTOCOL_VERSION, PickupStatus, RequestCommand, ResponseResult, ServerResponse,
};
#[derive(Clone, Debug)]
@ -147,6 +147,33 @@ impl LiveMixerState {
let has_default_output = faders
.values()
.any(|fader| fader.target.kind == MixerObjectKind::Output);
let mut pickups = BTreeMap::new();
for binding in profile
.bindings()
.iter()
.filter(|binding| binding.action() == Action::Volume)
{
let fader = FaderId::new(binding.fader())
.map_err(|error| LiveMixerError::Profile(error.to_string()))?;
let configured = faders.get(&fader).ok_or_else(|| {
LiveMixerError::Profile(format!(
"volume binding references missing fader {:?}",
binding.fader()
))
})?;
if !configured.pickup {
continue;
}
let surface = SurfaceId::new(binding.surface())
.map_err(|error| LiveMixerError::Profile(error.to_string()))?;
let pickup = Pickup::new(configured.tolerance)
.map_err(|error| LiveMixerError::Pickup(error.to_string()))?;
if pickups.insert((surface, fader), pickup).is_some() {
return Err(LiveMixerError::Profile(
"duplicate physical volume binding reached live mixer".to_owned(),
));
}
}
Ok(Self {
reducer: ServerReducer::new(write_ceiling),
metadata: BTreeMap::new(),
@ -155,7 +182,7 @@ impl LiveMixerState {
has_default_output,
output: None,
faders,
pickups: BTreeMap::new(),
pickups,
devices: Vec::new(),
write_ceiling,
backend: backend.into(),
@ -197,13 +224,16 @@ impl LiveMixerState {
});
}
WorkerEvent::Adapter(event) => {
let affected_faders = match &event {
let external_observation = match &event {
AdapterEvent::Observed {
stream,
operation: None,
..
}
| AdapterEvent::StreamRemoved { stream } => self.faders_for_stream(*stream),
} => Some(*stream),
_ => None,
};
let mut affected_faders = match &event {
AdapterEvent::StreamRemoved { stream } => self.faders_for_stream(*stream),
_ => Vec::new(),
};
if let AdapterEvent::StreamRemoved { stream } = &event {
@ -217,6 +247,9 @@ impl LiveMixerState {
}
}
let commands = self.reducer.event(event)?.adapter;
if let Some(stream) = external_observation {
affected_faders = self.faders_for_stream(stream);
}
self.rearm_faders(&affected_faders);
return Ok(commands);
}
@ -541,6 +574,7 @@ impl LiveMixerState {
let volume = volume_view(&channels);
let mute = mute_view(views.iter().map(|view| view.muted));
let stream_count = views.len();
let pickup = self.pickup_status(&object);
MixerObject {
object,
label,
@ -559,12 +593,32 @@ impl LiveMixerState {
},
mute_mixed: mute == ValueState::Mixed,
pending: views.iter().any(|view| view.pending),
pickup,
writable: !views.is_empty()
&& handles.iter().all(|handle| self.handle_writable(*handle)),
error: views.iter().find_map(|view| view.error.clone()),
}
}
fn pickup_status(&self, object: &MixerObjectKey) -> Option<PickupStatus> {
let mut states = self.pickups.iter().filter_map(|((_, fader), pickup)| {
self.faders
.get(fader)
.filter(|configured| configured.target == *object)
.map(|_| pickup.state())
});
let first = states.next()?;
if states.all(|state| state == first) {
Some(match first {
PickupState::Unavailable => PickupStatus::Unavailable,
PickupState::Waiting => PickupStatus::Waiting,
PickupState::Tracking => PickupStatus::Tracking,
})
} else {
Some(PickupStatus::Mixed)
}
}
fn handle_writable(&self, handle: StreamHandle) -> bool {
self.metadata
.get(&handle)

View File

@ -1,6 +1,9 @@
use std::{io, path::PathBuf};
use tui::{MixerClient, MixerItem, MixerObjectId, MixerObjectKind, MixerSnapshot};
use tui::{
MixerClient, MixerItem, MixerObjectId, MixerObjectKind, MixerSnapshot,
PickupStatus as TuiPickupStatus,
};
use crate::{
ipc::{
@ -65,6 +68,12 @@ impl IpcMixerClient {
muted: object.muted,
mute_mixed: object.mute_mixed,
pending: object.pending,
pickup: object.pickup.map(|pickup| match pickup {
crate::ipc::PickupStatus::Unavailable => TuiPickupStatus::Unavailable,
crate::ipc::PickupStatus::Waiting => TuiPickupStatus::Waiting,
crate::ipc::PickupStatus::Tracking => TuiPickupStatus::Tracking,
crate::ipc::PickupStatus::Mixed => TuiPickupStatus::Mixed,
}),
writable: object.writable,
error: object.error,
})

View File

@ -5,7 +5,7 @@ use fader_core::{
};
use fader_master::{
ipc::{
ClientRequest, MidiDevice, MixerObjectKey, MixerObjectKind, PROTOCOL_VERSION,
ClientRequest, MidiDevice, MixerObjectKey, MixerObjectKind, PROTOCOL_VERSION, PickupStatus,
RequestCommand, ResponseResult,
},
live::LiveMixerState,
@ -252,7 +252,15 @@ fn midi_volume_waits_for_pickup_crossing_before_dispatch() {
gain: gain(value),
};
assert_eq!(
state.snapshot().objects[2].pickup,
Some(PickupStatus::Waiting)
);
assert!(state.midi_intent(intent(0.1), 1).unwrap().is_empty());
assert_eq!(
state.snapshot().objects[2].pickup,
Some(PickupStatus::Waiting)
);
assert!(state.midi_intent(intent(0.3), 2).unwrap().is_empty());
let commands = state.midi_intent(intent(0.5), 3).unwrap();
assert_eq!(commands.len(), 1);
@ -260,6 +268,10 @@ fn midi_volume_waits_for_pickup_crossing_before_dispatch() {
commands[0],
fader_core::AdapterCommand::SetVolume { .. }
));
assert_eq!(
state.snapshot().objects[2].pickup,
Some(PickupStatus::Tracking)
);
}
#[test]
@ -278,6 +290,10 @@ fn external_volume_change_rearms_midi_pickup() {
.worker_event(observed_for(stream(), [0.8, 0.8], Mute::Unmuted, None))
.unwrap();
assert_eq!(
state.snapshot().objects[2].pickup,
Some(PickupStatus::Waiting)
);
assert!(state.midi_intent(intent(0.5), 2).unwrap().is_empty());
assert_eq!(state.midi_intent(intent(0.8), 3).unwrap().len(), 1);
}

11
task.md
View File

@ -263,16 +263,17 @@ Dependencies: M3, M2; may proceed after the fake-adapter slice.
Dependencies: M7, M4 for real use.
- [ ] **M8.1 Mixer:** replace blocking prototype with event-driven client views and volume/mute actions. Test-backend assertions: groups/applications, mixed/offline/pending/error indicators, pickup state, resize and keyboard navigation reflect snapshots accurately.
- [x] **M8.1 Mixer:** replace blocking prototype with event-driven client views and volume/mute actions. Test-backend assertions: groups/applications, mixed/offline/pending/error indicators, pickup state, resize and keyboard navigation reflect snapshots accurately.
The live slice now lists stable configured applications and groups, preserves
offline and mixed gain/mute states, deduplicates overlapping group streams,
and fans sync-group writes out with absolute policy. It refreshes without
blocking rendering or server operation, updates accepted input locally, and
shows pending, read-only, and error indicators.
Keep this item open until pickup state is integrated and the profile-aware
hands-on checks, including terminal resize, pass. The profile-aware hands-on
slice passed on 2026-10-15; pickup remains. A later UI refinement should add
a denser row mode and/or horizontal fader layout for smaller terminals.
Pickup state now follows configured surface/fader bindings through IPC and is
rendered as unavailable, waiting, tracking, or mixed. Profile-aware hands-on
checks including terminal resize passed on 2026-10-15. A later UI refinement
should add a denser row mode and/or horizontal fader layout for smaller
terminals.
- [ ] **M8.2 Devices/status:** show adapter selection/probe errors, device mappings, ambiguity and persistence problems. Tests: disconnected/unsupported states have useful actions; manual backend selection validates rather than silently applying incompatible mappings.
- [ ] **M8.3 Terminal lifecycle:** restoration on normal/error exit, nonblocking refresh, logging away from display. Tests: injected IO/client failure releases terminal guard; polling/refresh does not block server operation.
Blocking IPC now runs on a joined worker and a delayed request cannot block

View File

@ -36,6 +36,14 @@ pub enum MixerObjectKind {
Output,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum PickupStatus {
Unavailable,
Waiting,
Tracking,
Mixed,
}
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct MixerObjectId {
pub kind: MixerObjectKind,
@ -52,6 +60,7 @@ pub struct MixerItem {
pub muted: Option<bool>,
pub mute_mixed: bool,
pub pending: bool,
pub pickup: Option<PickupStatus>,
pub writable: bool,
pub error: Option<String>,
}
@ -648,7 +657,7 @@ impl<C> LiveTui<C> {
}
let selected = index == self.selected;
let title = format!(
"{} {} [{} · {}]{}",
"{} {} [{} · {}]{}{}",
if selected { "▶" } else { " " },
item.label,
match item.id.kind {
@ -657,7 +666,14 @@ impl<C> LiveTui<C> {
MixerObjectKind::Output => "output",
},
item.detail,
if item.pending { " … pending" } else { "" }
if item.pending { " … pending" } else { "" },
match item.pickup {
Some(PickupStatus::Unavailable) => " pickup: unavailable",
Some(PickupStatus::Waiting) => " pickup: waiting",
Some(PickupStatus::Tracking) => " pickup: tracking",
Some(PickupStatus::Mixed) => " pickup: mixed",
None => "",
}
);
let block = Block::bordered().title(title).border_style(if selected {
Style::default().fg(theme.accent)
@ -729,6 +745,7 @@ impl DemoClient {
muted: Some(self.muted),
mute_mixed: false,
pending: false,
pickup: None,
writable: true,
error: None,
}],
@ -829,7 +846,8 @@ mod tests {
#[test]
fn live_mixer_renders_status_and_stream_at_typical_size() {
let app = LiveTui::new(DemoClient::default()).unwrap();
let mut app = LiveTui::new(DemoClient::default()).unwrap();
app.snapshot.items[0].pickup = Some(PickupStatus::Waiting);
let area = Rect::new(0, 0, 100, 20);
let mut buffer = Buffer::empty(area);
(&app).render(area, &mut buffer);
@ -842,6 +860,7 @@ mod tests {
assert!(rendered.contains("FADER"));
assert!(rendered.contains("Desktop audio"));
assert!(rendered.contains("65%"));
assert!(rendered.contains("pickup: waiting"));
assert!(rendered.contains("Q/Esc"));
}
@ -861,6 +880,7 @@ mod tests {
muted: None,
mute_mixed: false,
pending: false,
pickup: None,
writable: false,
error: None,
});