feat(M8.1): connect the mixer TUI to IPC

Translate revisioned server snapshots into the event-driven TUI and send selected stream volume and mute actions through correlated IPC requests.

Tests: cargo test -p fader_master --all-targets --all-features --locked

Tests: cargo clippy -p fader_master --all-targets --all-features --locked -- -D warnings

Manual: live PTY rendered the ready Pulse snapshot and restored the terminal on quit.
This commit is contained in:
Dandaedre 2026-10-15 00:17:36 +02:00
parent ed46d3ae37
commit 472625301e
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
3 changed files with 107 additions and 1 deletions

View File

@ -6,6 +6,7 @@ pub mod cli;
pub mod ipc;
pub mod live;
pub mod local;
pub mod tui_client;
use std::{collections::BTreeMap, error::Error, fmt};

View File

@ -9,13 +9,17 @@ use fader_master::{
cli::{Cli, Command},
ipc::{ClientRequest, PROTOCOL_VERSION, RequestCommand, ResponseResult},
local::{LocalServer, client_request, default_socket_path},
tui_client::IpcMixerClient,
};
use midi::{LinuxIdentityCatalog, MidiInputCatalog};
use volume_lib::{AudioBackend, CompiledAdapterProbe, TargetRequirements, select_adapter};
fn main() -> Result<()> {
match Cli::parse().command {
Command::Tui { socket: None } => tui::run().context("terminal UI failed"),
Command::Tui { socket } => {
let socket = socket.map_or_else(default_socket_path, Ok)?;
tui::run_live(IpcMixerClient::new(socket)).context("terminal UI failed")
}
Command::Validate { config } => {
let profile = load_profile(&config)?;
println!("profile {:?} is valid", profile.id().as_str());

View File

@ -0,0 +1,101 @@
use std::{io, path::PathBuf};
use tui::{MixerClient, MixerItem, MixerSnapshot, StreamId};
use crate::{
ipc::{ClientRequest, PROTOCOL_VERSION, RequestCommand, ResponseResult, StreamKey},
local::client_request,
};
/// Short-lived request client used by the refresh-driven terminal UI.
pub struct IpcMixerClient {
socket: PathBuf,
next_request: u64,
}
impl IpcMixerClient {
#[must_use]
pub fn new(socket: impl Into<PathBuf>) -> Self {
Self {
socket: socket.into(),
next_request: 1,
}
}
fn send(&mut self, command: RequestCommand) -> io::Result<MixerSnapshot> {
let request_id = self.next_request;
self.next_request = self
.next_request
.checked_add(1)
.ok_or_else(|| io::Error::other("TUI request counter exhausted"))?;
let response = client_request(
&self.socket,
&ClientRequest {
version: PROTOCOL_VERSION,
request_id,
command,
},
)
.map_err(io::Error::other)?;
match response.result {
ResponseResult::Snapshot { snapshot } => Ok(MixerSnapshot {
revision: snapshot.revision,
backend: snapshot.backend,
status: snapshot.status,
items: snapshot
.streams
.into_iter()
.map(|stream| MixerItem {
id: StreamId {
epoch: stream.stream.epoch,
backend_id: stream.stream.backend_id,
incarnation: stream.stream.incarnation,
},
label: stream.label,
process: stream.process,
gain: stream.gain,
muted: stream.muted,
pending: stream.pending,
writable: stream.writable,
error: stream.error,
})
.collect(),
}),
ResponseResult::Error { message, .. } => Err(io::Error::other(message)),
}
}
}
impl MixerClient for IpcMixerClient {
fn snapshot(&mut self) -> io::Result<MixerSnapshot> {
self.send(RequestCommand::Snapshot)
}
fn set_volume(
&mut self,
id: StreamId,
gain: f64,
expected_revision: u64,
) -> io::Result<MixerSnapshot> {
self.send(RequestCommand::SetVolume {
stream: key(id),
gain,
expected_revision,
})
}
fn toggle_mute(&mut self, id: StreamId, expected_revision: u64) -> io::Result<MixerSnapshot> {
self.send(RequestCommand::ToggleMute {
stream: key(id),
expected_revision,
})
}
}
const fn key(id: StreamId) -> StreamKey {
StreamKey {
epoch: id.epoch,
backend_id: id.backend_id,
incarnation: id.incarnation,
}
}