feat(M7.1): activate server and diagnostic commands
Validate profiles before side effects, honor session-only adapter overrides, launch the Pulse-backed local server, query revisioned status, and enumerate MIDI identities. 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: serve/status reported one ready live PipeWire-Pulse stream through the private socket.
This commit is contained in:
parent
3b318256bf
commit
3c164221b0
|
|
@ -429,6 +429,11 @@ dependencies = [
|
|||
"fader-config",
|
||||
"fader-core",
|
||||
"midi",
|
||||
"rustix 1.1.5",
|
||||
"serde",
|
||||
"tempfile",
|
||||
"thiserror 2.0.21",
|
||||
"toml",
|
||||
"tui",
|
||||
"volume_lib",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ pub enum Command {
|
|||
/// Session-only audio backend override.
|
||||
#[arg(long, value_enum)]
|
||||
audio: Option<AudioArgument>,
|
||||
/// Override the XDG runtime socket path.
|
||||
#[arg(long)]
|
||||
socket: Option<PathBuf>,
|
||||
},
|
||||
/// Open the terminal mixer connected to the running server.
|
||||
Tui {
|
||||
|
|
|
|||
|
|
@ -1,21 +1,145 @@
|
|||
use std::fs;
|
||||
use std::{fs, os::unix::fs::PermissionsExt, path::Path};
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use clap::Parser;
|
||||
use fader_config::Profile;
|
||||
use fader_master::cli::{Cli, Command};
|
||||
use fader_config::{Profile, XdgEnvironment, XdgPaths};
|
||||
use fader_core::Gain;
|
||||
use fader_master::{
|
||||
audio_selection_policy,
|
||||
cli::{Cli, Command},
|
||||
ipc::{ClientRequest, PROTOCOL_VERSION, RequestCommand, ResponseResult},
|
||||
local::{LocalServer, client_request, default_socket_path},
|
||||
};
|
||||
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::Validate { config } => {
|
||||
let input = fs::read_to_string(&config)
|
||||
.with_context(|| format!("could not read profile {}", config.display()))?;
|
||||
let profile = Profile::parse(&input)
|
||||
.with_context(|| format!("profile {} is invalid", config.display()))?;
|
||||
let profile = load_profile(&config)?;
|
||||
println!("profile {:?} is valid", profile.id().as_str());
|
||||
Ok(())
|
||||
}
|
||||
command => bail!("{command:?} is not available until the local server increment is active"),
|
||||
Command::Serve {
|
||||
config,
|
||||
audio,
|
||||
socket,
|
||||
} => serve(
|
||||
&config,
|
||||
audio.map(|value| value.choice()),
|
||||
socket.as_deref(),
|
||||
),
|
||||
Command::Status { socket } => status(socket.as_deref()),
|
||||
Command::Devices => devices(),
|
||||
command => bail!("{command:?} is not available until its later milestone"),
|
||||
}
|
||||
}
|
||||
|
||||
fn load_profile(path: &Path) -> Result<Profile> {
|
||||
let input = fs::read_to_string(path)
|
||||
.with_context(|| format!("could not read profile {}", path.display()))?;
|
||||
Profile::parse(&input).with_context(|| format!("profile {} is invalid", path.display()))
|
||||
}
|
||||
|
||||
fn serve(
|
||||
config: &Path,
|
||||
override_choice: Option<volume_lib::AdapterChoice>,
|
||||
socket_override: Option<&Path>,
|
||||
) -> Result<()> {
|
||||
let profile = load_profile(config)?;
|
||||
let policy = audio_selection_policy(&profile, override_choice)?;
|
||||
let selected = select_adapter(
|
||||
&policy,
|
||||
TargetRequirements::APPLICATION_MIXER,
|
||||
&mut CompiledAdapterProbe::default(),
|
||||
)?;
|
||||
if selected.backend != AudioBackend::Pulse {
|
||||
bail!("selected backend {} is not implemented", selected.backend);
|
||||
}
|
||||
|
||||
let socket = match socket_override {
|
||||
Some(path) => {
|
||||
prepare_private_parent(path)?;
|
||||
path.to_owned()
|
||||
}
|
||||
None => {
|
||||
let environment = XdgEnvironment::from_process()?;
|
||||
let paths = XdgPaths::resolve(&environment)?;
|
||||
paths.create_layout()?;
|
||||
default_socket_path()?
|
||||
}
|
||||
};
|
||||
println!(
|
||||
"serving profile={} backend={} socket={}",
|
||||
profile.id(),
|
||||
selected.backend,
|
||||
socket.display()
|
||||
);
|
||||
LocalServer::pulse(socket, Gain::new(profile.max_gain())?)?.run()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prepare_private_parent(socket: &Path) -> Result<()> {
|
||||
let parent = socket
|
||||
.parent()
|
||||
.context("socket override must have a parent directory")?;
|
||||
fs::create_dir_all(parent)
|
||||
.with_context(|| format!("could not create socket directory {}", parent.display()))?;
|
||||
fs::set_permissions(parent, fs::Permissions::from_mode(0o700))
|
||||
.with_context(|| format!("could not secure socket directory {}", parent.display()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn status(socket_override: Option<&Path>) -> Result<()> {
|
||||
let socket = socket_override.map_or_else(default_socket_path, |path| Ok(path.to_owned()))?;
|
||||
let response = client_request(
|
||||
&socket,
|
||||
&ClientRequest {
|
||||
version: PROTOCOL_VERSION,
|
||||
request_id: 1,
|
||||
command: RequestCommand::Snapshot,
|
||||
},
|
||||
)?;
|
||||
match response.result {
|
||||
ResponseResult::Snapshot { snapshot } => {
|
||||
println!(
|
||||
"backend={} status={} revision={} streams={}",
|
||||
snapshot.backend,
|
||||
snapshot.status,
|
||||
snapshot.revision,
|
||||
snapshot.streams.len()
|
||||
);
|
||||
for stream in snapshot.streams {
|
||||
println!(
|
||||
"id={}:{}:{} label={:?} process={:?} gain={:.3} muted={} pending={} writable={} error={:?}",
|
||||
stream.stream.epoch,
|
||||
stream.stream.backend_id,
|
||||
stream.stream.incarnation,
|
||||
stream.label,
|
||||
stream.process,
|
||||
stream.gain,
|
||||
stream.muted,
|
||||
stream.pending,
|
||||
stream.writable,
|
||||
stream.error
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
ResponseResult::Error { message, .. } => bail!(message),
|
||||
}
|
||||
}
|
||||
|
||||
fn devices() -> Result<()> {
|
||||
let catalog = MidiInputCatalog::new("fader_master devices")?;
|
||||
let ports = catalog.ports()?;
|
||||
let identities = LinuxIdentityCatalog::new()?;
|
||||
for (index, port) in ports.iter().enumerate() {
|
||||
println!("index={index} identity={:?}", identities.inspect(port)?);
|
||||
}
|
||||
if ports.is_empty() {
|
||||
println!("no MIDI input ports found");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ fn serve_requires_a_config_and_parses_session_override() {
|
|||
Command::Serve {
|
||||
config: PathBuf::from("profile.toml"),
|
||||
audio: Some(AudioArgument::Pulse),
|
||||
socket: None,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue