feat: reflect confirmed mute state over MIDI
Rust CI fader_master passed its selected CI mode.
MadGobblins/fader_master/pipeline/head This commit looks good
Details
Rust CI fader_master passed its selected CI mode.
MadGobblins/fader_master/pipeline/head This commit looks good
Details
Open and reconcile configured MIDI outputs independently, send opt-in note or CC feedback from confirmed mute observations, deduplicate successful values, and resynchronize after reconnect. Enable green mute feedback in the APC MINI example and document the profile fields and mixed/offline policy. Tests: cargo fmt --all -- --check Tests: cargo check --workspace --all-targets --all-features --locked Tests: cargo test --workspace --all-targets --all-features --locked Tests: cargo test --workspace --doc --all-features --locked Tests: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings Tests: cargo build --workspace --release --all-features --locked Tests: cargo check --workspace --locked Tests: cargo check --workspace --no-default-features --locked Tests: cargo check -p midi --no-default-features --features midir --locked Tests: cargo check -p volume_lib --no-default-features --features pulse --locked
This commit is contained in:
parent
9464944634
commit
a47e1452bd
|
|
@ -21,7 +21,8 @@ same profile can switch to a compact stacked layout for narrow terminals:
|
|||
exact and regular-expression capture rules.
|
||||
- Control individual applications, non-nesting application groups, and the
|
||||
default output without changing live audio during discovery.
|
||||
- Learn volume and mute controls from MIDI, use pickup to prevent jumps, and
|
||||
- Learn volume and mute controls from MIDI, reflect confirmed mute state on
|
||||
control-surface LEDs, use pickup to prevent jumps, and
|
||||
keep independently identified controllers from colliding.
|
||||
- Arrange faders and named separators directly in the mixer. Choose Slim,
|
||||
Standard, or Thick faders, and hide detail faders behind a group when useful.
|
||||
|
|
|
|||
|
|
@ -209,6 +209,13 @@ Keep bindings for absent surfaces. Re-enumerate ports on hotplug notifications o
|
|||
|
||||
Output capabilities are explicit: mute LED, value display, motorized fader, or none. Non-motorized devices may still receive supported LED/display feedback; never assume every surface has LEDs. Mixed mute uses a declared mixed indicator, otherwise LED on only for all-muted and the TUI shows mixed. Send full supported state on attach and incremental changes thereafter. Device feedback failures are separate from audio operation failures.
|
||||
|
||||
The first implemented output slice is binding-level mute feedback. A binding
|
||||
with `feedback` sends its declared note or CC `on` value only for a uniformly
|
||||
confirmed muted target, sends `off` for uniformly unmuted or mixed state, and
|
||||
sends nothing for an unavailable target. Successful messages are deduplicated;
|
||||
an independently reconnected output invalidates that cache and receives a full
|
||||
current refresh. Pending intent is never treated as confirmation.
|
||||
|
||||
Non-motorized absolute controls default to pickup: after startup, external changes, another surface's move, or profile switch, wait until the physical value crosses or enters a configured tolerance around the observed target before sending volume commands. First input establishes position; an out-of-range external volume uses the nearest physical endpoint. Relative encoders do not need pickup. Reset pickup on disconnect/rebind. For motors, add touch-aware inhibition before enabling motor output; unsupported touch means no claimed touch protection.
|
||||
|
||||
Avoid feedback loops with direction/origin tracking, quantization-aware equality, rate limiting, and device-specific echo suppression. MIDI has no universal request IDs: generic time-window byte suppression can swallow real input, so only enable it for documented echoing device profiles and test it. Server observations never themselves generate audio commands.
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ enum Edge {
|
|||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Feedback {
|
||||
pub struct Feedback {
|
||||
kind: MessageKind,
|
||||
channel: u16,
|
||||
number: u16,
|
||||
|
|
@ -653,6 +653,33 @@ impl Binding {
|
|||
pub const fn number(&self) -> u16 {
|
||||
self.message.number
|
||||
}
|
||||
|
||||
/// Optional outbound message used to reflect confirmed state on the surface.
|
||||
pub const fn feedback(&self) -> Option<&Feedback> {
|
||||
self.feedback.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Feedback {
|
||||
pub const fn message_kind(&self) -> MessageKind {
|
||||
self.kind
|
||||
}
|
||||
|
||||
pub const fn channel(&self) -> u16 {
|
||||
self.channel
|
||||
}
|
||||
|
||||
pub const fn number(&self) -> u16 {
|
||||
self.number
|
||||
}
|
||||
|
||||
pub const fn on(&self) -> u16 {
|
||||
self.on
|
||||
}
|
||||
|
||||
pub const fn off(&self) -> u16 {
|
||||
self.off
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_version(version: u16) -> Result<(), ConfigError> {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ default adopts live audio without changing it.
|
|||
Start from one of the tracked, validated examples:
|
||||
|
||||
- [`arch-pipewire.toml`](../examples/profiles/arch-pipewire.toml) demonstrates
|
||||
multiple applications, a group, APC MINI identity, and volume/mute bindings.
|
||||
multiple applications, a group, APC MINI identity, volume/mute bindings, and
|
||||
green mute-button feedback.
|
||||
- [`desktop.toml`](../examples/profiles/desktop.toml) is a smaller profile with
|
||||
MIDI output feedback.
|
||||
|
||||
|
|
@ -169,12 +170,22 @@ fader = "music-fader"
|
|||
action = "toggle_mute"
|
||||
edge = "press"
|
||||
message = { kind = "note", channel = 1, number = 64 }
|
||||
feedback = { kind = "note", channel = 1, number = 64, on = 127, off = 0 }
|
||||
```
|
||||
|
||||
The TUI can choose a controller, learn the next supported movement or button
|
||||
press, and remove an assignment independently for volume and mute. Unassigned
|
||||
actions inherit `[ui].default_controller` for learning.
|
||||
|
||||
`feedback` is optional and requires the binding's surface to define
|
||||
`output_port`. After that output attaches, the server sends `on` when the
|
||||
fader's target is uniformly and observably muted and `off` when it is unmuted
|
||||
or a group has mixed mute state. Offline targets emit no guess. Only confirmed
|
||||
audio observations drive feedback, so a pending or failed mute write never
|
||||
lights an LED as if it succeeded. Reconnect sends the current state again;
|
||||
unchanged states are deduplicated. Both note and CC feedback use 1-based
|
||||
channels and values from 0–127.
|
||||
|
||||
## Validation, migration, and Save
|
||||
|
||||
Validate a file without opening MIDI/audio devices or changing live audio:
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ volume_mode = "absolute"
|
|||
id = "apc-mini"
|
||||
label = "APC MINI"
|
||||
input_port = "APC MINI:APC MINI MIDI 1"
|
||||
output_port = "APC MINI:APC MINI MIDI 1"
|
||||
usb_vendor_id = "09e8"
|
||||
usb_product_id = "0028"
|
||||
usb_serial = "Ver00.10"
|
||||
|
|
@ -100,6 +101,7 @@ fader = "music-fader"
|
|||
action = "toggle_mute"
|
||||
edge = "press"
|
||||
message = { kind = "note", channel = 1, number = 64 }
|
||||
feedback = { kind = "note", channel = 1, number = 64, on = 1, off = 0 }
|
||||
|
||||
[[bindings]]
|
||||
surface = "apc-mini"
|
||||
|
|
@ -107,6 +109,7 @@ fader = "browser-fader"
|
|||
action = "toggle_mute"
|
||||
edge = "press"
|
||||
message = { kind = "note", channel = 1, number = 65 }
|
||||
feedback = { kind = "note", channel = 1, number = 65, on = 1, off = 0 }
|
||||
|
||||
[[bindings]]
|
||||
surface = "apc-mini"
|
||||
|
|
@ -114,6 +117,7 @@ fader = "media-fader"
|
|||
action = "toggle_mute"
|
||||
edge = "press"
|
||||
message = { kind = "note", channel = 1, number = 66 }
|
||||
feedback = { kind = "note", channel = 1, number = 66, on = 1, off = 0 }
|
||||
|
||||
[[bindings]]
|
||||
surface = "apc-mini"
|
||||
|
|
@ -121,3 +125,4 @@ fader = "master-fader"
|
|||
action = "toggle_mute"
|
||||
edge = "press"
|
||||
message = { kind = "note", channel = 1, number = 98 }
|
||||
feedback = { kind = "note", channel = 1, number = 98, on = 1, off = 0 }
|
||||
|
|
|
|||
|
|
@ -292,7 +292,6 @@ impl LocalServer {
|
|||
}
|
||||
}
|
||||
}
|
||||
self.mixer.set_devices(self.midi.snapshot());
|
||||
self.flush_dispatch();
|
||||
match self.worker.receive_timeout(self.poll_interval) {
|
||||
Ok(event) => {
|
||||
|
|
@ -315,6 +314,8 @@ impl LocalServer {
|
|||
}
|
||||
}
|
||||
self.flush_dispatch();
|
||||
self.midi.sync_feedback(&self.mixer.snapshot());
|
||||
self.mixer.set_devices(self.midi.snapshot());
|
||||
while let Some(mut client) = self.listener.accept()? {
|
||||
let _ = client.set_read_timeout(Some(SERVER_CLIENT_TIMEOUT));
|
||||
let _ = client.set_write_timeout(Some(SERVER_CLIENT_TIMEOUT));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use std::{
|
||||
collections::BTreeMap,
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
sync::mpsc::{Receiver, SyncSender, TryRecvError, sync_channel},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
|
@ -11,11 +11,11 @@ use fader_core::{
|
|||
};
|
||||
use midi::{
|
||||
ButtonEdge, DeviceMatch, LinuxIdentityCatalog, MidiInputCatalog, MidiInputConnection,
|
||||
MidiInputEvent, MidiIntent, MidiMessage, MidiRouter, SurfaceAction, SurfaceAssignment,
|
||||
SurfaceLifecycle, SurfaceStatus,
|
||||
MidiInputEvent, MidiIntent, MidiMessage, MidiOutputCatalog, MidiOutputConnection, MidiRouter,
|
||||
SurfaceAction, SurfaceAssignment, SurfaceLifecycle, SurfaceStatus,
|
||||
};
|
||||
|
||||
use crate::ipc::MidiDevice;
|
||||
use crate::ipc::{MidiDevice, MixerObjectKey, MixerObjectKind, MixerSnapshot};
|
||||
|
||||
const SCAN_INTERVAL: Duration = Duration::from_secs(1);
|
||||
const EVENT_CAPACITY: usize = 256;
|
||||
|
|
@ -25,14 +25,135 @@ pub struct MidiRuntime {
|
|||
lifecycle: SurfaceLifecycle,
|
||||
labels: BTreeMap<SurfaceId, String>,
|
||||
connections: BTreeMap<SurfaceId, MidiInputConnection>,
|
||||
output_names: BTreeMap<SurfaceId, String>,
|
||||
output_connections: BTreeMap<SurfaceId, MidiOutputConnection>,
|
||||
output_backend_ids: BTreeMap<SurfaceId, String>,
|
||||
output_errors: BTreeMap<SurfaceId, String>,
|
||||
sender: SyncSender<MidiInputEvent>,
|
||||
receiver: Receiver<MidiInputEvent>,
|
||||
last_scan: Option<Instant>,
|
||||
scan_error: Option<String>,
|
||||
router: MidiRouter,
|
||||
feedback: FeedbackEngine,
|
||||
learn: Option<MidiLearn>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
struct FeedbackBinding {
|
||||
surface: SurfaceId,
|
||||
fader: FaderId,
|
||||
target: MixerObjectKey,
|
||||
on: [u8; 3],
|
||||
off: [u8; 3],
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
struct FeedbackMessage {
|
||||
binding: usize,
|
||||
surface: SurfaceId,
|
||||
bytes: [u8; 3],
|
||||
muted: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FeedbackEngine {
|
||||
bindings: Vec<FeedbackBinding>,
|
||||
sent: BTreeMap<usize, bool>,
|
||||
}
|
||||
|
||||
impl FeedbackEngine {
|
||||
fn new(profile: &Profile) -> Result<Self, String> {
|
||||
let bindings = profile
|
||||
.bindings()
|
||||
.iter()
|
||||
.filter_map(|binding| {
|
||||
(binding.action() == fader_config::Action::ToggleMute)
|
||||
.then(|| binding.feedback().map(|feedback| (binding, feedback)))?
|
||||
})
|
||||
.map(|(binding, feedback)| {
|
||||
let channel =
|
||||
u8::try_from(feedback.channel() - 1).map_err(|error| error.to_string())?;
|
||||
let status = match feedback.message_kind() {
|
||||
fader_config::MessageKind::Cc => 0xb0 | channel,
|
||||
fader_config::MessageKind::Note => 0x90 | channel,
|
||||
};
|
||||
let number = u8::try_from(feedback.number()).map_err(|error| error.to_string())?;
|
||||
let fader = profile
|
||||
.faders()
|
||||
.iter()
|
||||
.find(|fader| fader.id() == binding.fader())
|
||||
.ok_or_else(|| {
|
||||
format!("feedback references unknown fader {:?}", binding.fader())
|
||||
})?;
|
||||
Ok(FeedbackBinding {
|
||||
surface: SurfaceId::new(binding.surface())
|
||||
.map_err(|error| error.to_string())?,
|
||||
fader: FaderId::new(binding.fader()).map_err(|error| error.to_string())?,
|
||||
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(),
|
||||
},
|
||||
on: [
|
||||
status,
|
||||
number,
|
||||
u8::try_from(feedback.on()).map_err(|error| error.to_string())?,
|
||||
],
|
||||
off: [
|
||||
status,
|
||||
number,
|
||||
u8::try_from(feedback.off()).map_err(|error| error.to_string())?,
|
||||
],
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>, String>>()?;
|
||||
Ok(Self {
|
||||
bindings,
|
||||
sent: BTreeMap::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn plan(
|
||||
&self,
|
||||
confirmed: &BTreeMap<FaderId, bool>,
|
||||
attached: &BTreeSet<SurfaceId>,
|
||||
) -> Vec<FeedbackMessage> {
|
||||
self.bindings
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, binding)| {
|
||||
let muted = *confirmed.get(&binding.fader)?;
|
||||
if !attached.contains(&binding.surface)
|
||||
|| self.sent.get(&index).is_some_and(|sent| *sent == muted)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Some(FeedbackMessage {
|
||||
binding: index,
|
||||
surface: binding.surface.clone(),
|
||||
bytes: if muted { binding.on } else { binding.off },
|
||||
muted,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn record_sent(&mut self, message: &FeedbackMessage) {
|
||||
self.sent.insert(message.binding, message.muted);
|
||||
}
|
||||
|
||||
fn invalidate_surface(&mut self, surface: &SurfaceId) {
|
||||
for (index, binding) in self.bindings.iter().enumerate() {
|
||||
if &binding.surface == surface {
|
||||
self.sent.remove(&index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct MidiLearn {
|
||||
pub surface: SurfaceId,
|
||||
|
|
@ -62,6 +183,7 @@ impl std::fmt::Debug for MidiRuntime {
|
|||
.debug_struct("MidiRuntime")
|
||||
.field("surfaces", &self.labels.len())
|
||||
.field("connections", &self.connections.len())
|
||||
.field("output_connections", &self.output_connections.len())
|
||||
.field("scan_error", &self.scan_error)
|
||||
.finish()
|
||||
}
|
||||
|
|
@ -70,12 +192,16 @@ impl std::fmt::Debug for MidiRuntime {
|
|||
impl MidiRuntime {
|
||||
pub fn new(profile: &Profile) -> Result<Self, String> {
|
||||
let mut labels = BTreeMap::new();
|
||||
let mut output_names = BTreeMap::new();
|
||||
let assignments = profile
|
||||
.surfaces()
|
||||
.iter()
|
||||
.map(|surface| {
|
||||
let id = SurfaceId::new(surface.id()).map_err(|error| error.to_string())?;
|
||||
labels.insert(id.clone(), surface.label().to_owned());
|
||||
if let Some(output) = surface.output_port() {
|
||||
output_names.insert(id.clone(), output.to_owned());
|
||||
}
|
||||
Ok(SurfaceAssignment {
|
||||
surface: id,
|
||||
expected: DeviceMatch {
|
||||
|
|
@ -118,16 +244,22 @@ impl MidiRuntime {
|
|||
})
|
||||
.collect::<Result<Vec<_>, String>>()?;
|
||||
let router = MidiRouter::new(Bindings::new(bindings).map_err(|error| error.to_string())?);
|
||||
let feedback = FeedbackEngine::new(profile)?;
|
||||
let (sender, receiver) = sync_channel(EVENT_CAPACITY);
|
||||
Ok(Self {
|
||||
lifecycle,
|
||||
labels,
|
||||
connections: BTreeMap::new(),
|
||||
output_names,
|
||||
output_connections: BTreeMap::new(),
|
||||
output_backend_ids: BTreeMap::new(),
|
||||
output_errors: BTreeMap::new(),
|
||||
sender,
|
||||
receiver,
|
||||
last_scan: None,
|
||||
scan_error: None,
|
||||
router,
|
||||
feedback,
|
||||
learn: None,
|
||||
})
|
||||
}
|
||||
|
|
@ -258,15 +390,22 @@ impl MidiRuntime {
|
|||
.unwrap_or_else(|| id.as_str().to_owned()),
|
||||
status: name.to_owned(),
|
||||
backend_id,
|
||||
error: status_error.or_else(|| self.scan_error.clone()),
|
||||
error: status_error
|
||||
.or_else(|| self.output_errors.get(id).cloned())
|
||||
.or_else(|| self.scan_error.clone()),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn scan(&mut self) {
|
||||
let result = self.discover_and_reconcile();
|
||||
self.scan_error = result.err();
|
||||
let input_error = self.discover_and_reconcile().err();
|
||||
if let Err(error) = self.discover_and_reconcile_outputs() {
|
||||
for surface in self.output_names.keys() {
|
||||
self.output_errors.insert(surface.clone(), error.clone());
|
||||
}
|
||||
}
|
||||
self.scan_error = input_error;
|
||||
}
|
||||
|
||||
fn discover_and_reconcile(&mut self) -> Result<(), String> {
|
||||
|
|
@ -322,10 +461,138 @@ impl MidiRuntime {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn discover_and_reconcile_outputs(&mut self) -> Result<(), String> {
|
||||
if self.output_names.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let catalog = MidiOutputCatalog::new("fader_master output discovery")
|
||||
.map_err(|error| error.to_string())?;
|
||||
let ports = catalog.ports().map_err(|error| error.to_string())?;
|
||||
let configured: Vec<_> = self
|
||||
.output_names
|
||||
.iter()
|
||||
.map(|(surface, name)| (surface.clone(), name.clone()))
|
||||
.collect();
|
||||
for (surface, expected_name) in configured {
|
||||
let matches: Vec<_> = ports
|
||||
.iter()
|
||||
.filter(|port| stable_port_name(port.name()) == stable_port_name(&expected_name))
|
||||
.collect();
|
||||
match matches.as_slice() {
|
||||
[port] => {
|
||||
if self.output_backend_ids.get(&surface).map(String::as_str) != Some(port.id())
|
||||
{
|
||||
self.disconnect_output(&surface);
|
||||
self.connect_output(surface, port.id());
|
||||
}
|
||||
}
|
||||
[] => {
|
||||
self.disconnect_output(&surface);
|
||||
self.output_errors
|
||||
.insert(surface, format!("MIDI output {expected_name:?} is missing"));
|
||||
}
|
||||
_ => {
|
||||
self.disconnect_output(&surface);
|
||||
self.output_errors.insert(
|
||||
surface,
|
||||
format!("MIDI output {expected_name:?} is ambiguous"),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn connect_output(&mut self, surface: SurfaceId, backend_id: &str) {
|
||||
let result = (|| {
|
||||
let catalog = MidiOutputCatalog::new("fader_master output")?;
|
||||
let ports = catalog.ports()?;
|
||||
let port = ports
|
||||
.iter()
|
||||
.find(|port| port.id() == backend_id)
|
||||
.ok_or_else(|| {
|
||||
midi::MidiTransportError::OutputConnect("port disappeared".to_owned())
|
||||
})?;
|
||||
catalog.connect(port, &format!("fader_master {} output", surface.as_str()))
|
||||
})();
|
||||
match result {
|
||||
Ok(connection) => {
|
||||
self.output_connections.insert(surface.clone(), connection);
|
||||
self.output_backend_ids
|
||||
.insert(surface.clone(), backend_id.to_owned());
|
||||
self.output_errors.remove(&surface);
|
||||
self.feedback.invalidate_surface(&surface);
|
||||
}
|
||||
Err(error) => {
|
||||
self.output_errors.insert(surface, error.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn disconnect_output(&mut self, surface: &SurfaceId) {
|
||||
if self.output_connections.remove(surface).is_some() {
|
||||
self.feedback.invalidate_surface(surface);
|
||||
}
|
||||
self.output_backend_ids.remove(surface);
|
||||
}
|
||||
|
||||
pub fn sync_feedback(&mut self, snapshot: &MixerSnapshot) {
|
||||
let confirmed = self
|
||||
.feedback
|
||||
.bindings
|
||||
.iter()
|
||||
.filter_map(|binding| {
|
||||
let object = snapshot
|
||||
.objects
|
||||
.iter()
|
||||
.find(|object| object.object == binding.target)?;
|
||||
object
|
||||
.muted
|
||||
.or(object.mute_mixed.then_some(false))
|
||||
.map(|muted| (binding.fader.clone(), muted))
|
||||
})
|
||||
.collect();
|
||||
let attached = self.output_connections.keys().cloned().collect();
|
||||
for message in self.feedback.plan(&confirmed, &attached) {
|
||||
let Some(connection) = self.output_connections.get_mut(&message.surface) else {
|
||||
continue;
|
||||
};
|
||||
let result = connection.send(&message.bytes);
|
||||
match result {
|
||||
Ok(()) => self.feedback.record_sent(&message),
|
||||
Err(error) => {
|
||||
self.output_errors
|
||||
.insert(message.surface.clone(), error.to_string());
|
||||
self.disconnect_output(&message.surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn stable_port_name(name: &str) -> &str {
|
||||
let Some((prefix, suffix)) = name.rsplit_once(' ') else {
|
||||
return name;
|
||||
};
|
||||
let Some((client, port)) = suffix.split_once(':') else {
|
||||
return name;
|
||||
};
|
||||
if !client.is_empty()
|
||||
&& !port.is_empty()
|
||||
&& client.bytes().all(|byte| byte.is_ascii_digit())
|
||||
&& port.bytes().all(|byte| byte.is_ascii_digit())
|
||||
{
|
||||
prefix
|
||||
} else {
|
||||
name
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use super::*;
|
||||
use fader_core::{MidiChannel, MidiData};
|
||||
use midi::{ButtonEdge, MidiMessage};
|
||||
|
|
@ -460,4 +727,33 @@ mod tests {
|
|||
[MidiIntent::AbsoluteVolume { fader, .. }] if fader.as_str() == "music-fader"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confirmed_mute_feedback_is_surface_scoped_deduplicated_and_resynced() {
|
||||
let profile = Profile::parse(include_str!("../../examples/profiles/desktop.toml")).unwrap();
|
||||
let mut feedback = FeedbackEngine::new(&profile).unwrap();
|
||||
let surface = SurfaceId::new("desk-left").unwrap();
|
||||
let fader = FaderId::new("media-fader").unwrap();
|
||||
let attached = BTreeSet::from([surface.clone()]);
|
||||
|
||||
assert!(feedback.plan(&BTreeMap::new(), &attached).is_empty());
|
||||
|
||||
let muted = BTreeMap::from([(fader.clone(), true)]);
|
||||
let messages = feedback.plan(&muted, &attached);
|
||||
assert_eq!(messages.len(), 1);
|
||||
assert_eq!(messages[0].surface, surface);
|
||||
assert_eq!(messages[0].bytes, [0x90, 32, 127]);
|
||||
feedback.record_sent(&messages[0]);
|
||||
assert!(feedback.plan(&muted, &attached).is_empty());
|
||||
|
||||
let unmuted = BTreeMap::from([(fader, false)]);
|
||||
let messages = feedback.plan(&unmuted, &attached);
|
||||
assert_eq!(messages.len(), 1);
|
||||
assert_eq!(messages[0].bytes, [0x90, 32, 0]);
|
||||
feedback.record_sent(&messages[0]);
|
||||
|
||||
feedback.invalidate_surface(&surface);
|
||||
assert_eq!(feedback.plan(&unmuted, &attached).len(), 1);
|
||||
assert!(feedback.plan(&unmuted, &BTreeSet::new()).is_empty());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,5 +23,6 @@ pub use linux_identity::{LinuxIdentityCatalog, LinuxIdentityError};
|
|||
pub use router::{MidiIntent, MidiRouter};
|
||||
#[cfg(feature = "midir")]
|
||||
pub use transport::{
|
||||
InputPort, MidiInputCatalog, MidiInputConnection, MidiInputEvent, MidiTransportError,
|
||||
InputPort, MidiInputCatalog, MidiInputConnection, MidiInputEvent, MidiOutputCatalog,
|
||||
MidiOutputConnection, MidiTransportError, OutputPort,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ use std::sync::{
|
|||
};
|
||||
|
||||
use fader_core::SurfaceId;
|
||||
use midir::{Ignore, MidiInput, MidiInputConnection as NativeConnection, MidiInputPort};
|
||||
use midir::{
|
||||
Ignore, MidiInput, MidiInputConnection as NativeInputConnection, MidiInputPort, MidiOutput,
|
||||
MidiOutputConnection as NativeOutputConnection, MidiOutputPort,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{DecodeError, MidiMessage, decode_message};
|
||||
|
|
@ -63,6 +66,14 @@ pub enum MidiTransportError {
|
|||
PortInfo(String),
|
||||
#[error("could not connect MIDI input: {0}")]
|
||||
Connect(String),
|
||||
#[error("could not initialize MIDI output: {0}")]
|
||||
OutputInitialize(String),
|
||||
#[error("could not read MIDI output port information: {0}")]
|
||||
OutputPortInfo(String),
|
||||
#[error("could not connect MIDI output: {0}")]
|
||||
OutputConnect(String),
|
||||
#[error("could not send MIDI output: {0}")]
|
||||
OutputSend(String),
|
||||
}
|
||||
|
||||
/// One-use midir catalog; connecting consumes it because midir transfers input ownership.
|
||||
|
|
@ -154,10 +165,81 @@ fn enqueue_bytes(
|
|||
|
||||
/// Keeps a midir input open and exposes callback overflow as an explicit fault.
|
||||
pub struct MidiInputConnection {
|
||||
_connection: NativeConnection<()>,
|
||||
_connection: NativeInputConnection<()>,
|
||||
overflowed: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
/// One MIDI output port reported by midir.
|
||||
pub struct OutputPort {
|
||||
id: String,
|
||||
name: String,
|
||||
native: MidiOutputPort,
|
||||
}
|
||||
|
||||
impl OutputPort {
|
||||
#[must_use]
|
||||
pub fn id(&self) -> &str {
|
||||
&self.id
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
}
|
||||
|
||||
/// One-use midir output catalog.
|
||||
pub struct MidiOutputCatalog {
|
||||
output: MidiOutput,
|
||||
}
|
||||
|
||||
impl MidiOutputCatalog {
|
||||
pub fn new(client_name: &str) -> Result<Self, MidiTransportError> {
|
||||
MidiOutput::new(client_name)
|
||||
.map(|output| Self { output })
|
||||
.map_err(|error| MidiTransportError::OutputInitialize(error.to_string()))
|
||||
}
|
||||
|
||||
pub fn ports(&self) -> Result<Vec<OutputPort>, MidiTransportError> {
|
||||
self.output
|
||||
.ports()
|
||||
.into_iter()
|
||||
.map(|native| {
|
||||
let id = native.id();
|
||||
let name = self
|
||||
.output
|
||||
.port_name(&native)
|
||||
.map_err(|error| MidiTransportError::OutputPortInfo(error.to_string()))?;
|
||||
Ok(OutputPort { id, name, native })
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn connect(
|
||||
self,
|
||||
port: &OutputPort,
|
||||
connection_name: &str,
|
||||
) -> Result<MidiOutputConnection, MidiTransportError> {
|
||||
self.output
|
||||
.connect(&port.native, connection_name)
|
||||
.map(|connection| MidiOutputConnection { connection })
|
||||
.map_err(|error| MidiTransportError::OutputConnect(error.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps a native MIDI output open for synchronous, short-message writes.
|
||||
pub struct MidiOutputConnection {
|
||||
connection: NativeOutputConnection,
|
||||
}
|
||||
|
||||
impl MidiOutputConnection {
|
||||
pub fn send(&mut self, message: &[u8]) -> Result<(), MidiTransportError> {
|
||||
self.connection
|
||||
.send(message)
|
||||
.map_err(|error| MidiTransportError::OutputSend(error.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl MidiInputConnection {
|
||||
#[must_use]
|
||||
pub fn overflowed(&self) -> bool {
|
||||
|
|
|
|||
7
task.md
7
task.md
|
|
@ -218,6 +218,13 @@ and no-default-feature checks/tests pass.
|
|||
|
||||
Dependencies: M4, M5.
|
||||
|
||||
- [x] **M6.0 Confirmed mute lights:** opt-in note/CC feedback follows confirmed
|
||||
uniform mute state, treats mixed as off, does not guess for offline targets,
|
||||
deduplicates successful writes, and resynchronizes after independent output
|
||||
reconnect. Output failures remain surface-local and do not disable MIDI
|
||||
input or audio operation. Hardware-free planner tests cover on/off,
|
||||
deduplication, unavailable state, surface scoping, and reconnect refresh;
|
||||
physical LED verification remains part of M6.1.
|
||||
- [ ] **M6.1 Output profiles:** mute LED/value/motor capabilities, output pairing, mixed-state policy. Tests: confirmed/internal and external changes reach all bound surfaces; outputless surfaces receive no unsupported message; pending/failed writes never produce false success feedback.
|
||||
- [ ] **M6.2 Feedback lifecycle:** attach snapshot, rate limits, deduplication, separate audio/output errors, documented device-specific echo suppression. Tests: feedback echoed as input cannot oscillate volume/mute; rapid updates converge; suppression does not swallow a genuine tested input sequence.
|
||||
- [ ] **M6.3 Extended controllers:** 14-bit CC/pitch bend, explicit relative encoder modes, motor output and touch handling for declared profiles. Tests: endpoints/byte-pair ordering, relative increments, no motor push while touched, and non-motorized profile never receives motor commands. Hardware-verify every shipped specialized profile.
|
||||
|
|
|
|||
Loading…
Reference in New Issue