fix: infer feedback for learned mute bindings
Copy an unambiguous same-surface, same-message-kind feedback convention onto new mute bindings while preserving device-specific values and refusing conflicting guesses.\n\nTests: cargo fmt --all -- --check\nTests: cargo test -p fader-config --test editor --all-features\nTests: cargo check --workspace --all-targets --all-features\nTests: cargo clippy --workspace --all-targets --all-features -- -D warnings
This commit is contained in:
parent
86a12fbfe4
commit
a967cc30ea
|
|
@ -228,6 +228,10 @@ 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.
|
||||
When learning a new mute binding, the editor may copy `on`/`off` values only
|
||||
from an unambiguous convention already used by feedback of the same message kind
|
||||
on that surface; the new feedback address follows the learned control. Missing
|
||||
or conflicting conventions remain explicitly unconfigured.
|
||||
|
||||
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.
|
||||
|
||||
|
|
|
|||
|
|
@ -678,6 +678,9 @@ pickup_tolerance = 0.02
|
|||
number: u16,
|
||||
) -> Result<(), ConfigError> {
|
||||
self.transaction(|document| {
|
||||
let inferred_feedback = (action == Action::ToggleMute)
|
||||
.then(|| inferred_feedback_values(document, surface, kind))
|
||||
.flatten();
|
||||
let bindings = document
|
||||
.get_mut("bindings")
|
||||
.and_then(Item::as_array_of_tables_mut)
|
||||
|
|
@ -693,16 +696,13 @@ pickup_tolerance = 0.02
|
|||
table["edge"] = value("press");
|
||||
}
|
||||
let mut message = InlineTable::new();
|
||||
message.insert(
|
||||
"kind",
|
||||
Value::from(match kind {
|
||||
MessageKind::Cc => "cc",
|
||||
MessageKind::Note => "note",
|
||||
}),
|
||||
);
|
||||
message.insert("kind", Value::from(message_kind_name(kind)));
|
||||
message.insert("channel", Value::from(i64::from(channel)));
|
||||
message.insert("number", Value::from(i64::from(number)));
|
||||
table["message"] = value(message);
|
||||
if let Some((on, off)) = inferred_feedback {
|
||||
table["feedback"] = value(feedback_table(kind, channel, number, on, off));
|
||||
}
|
||||
bindings.push(table);
|
||||
Ok(())
|
||||
})
|
||||
|
|
@ -719,6 +719,9 @@ pickup_tolerance = 0.02
|
|||
number: u16,
|
||||
) -> Result<(), ConfigError> {
|
||||
self.transaction(|document| {
|
||||
let inferred_feedback = (action == Action::ToggleMute)
|
||||
.then(|| inferred_feedback_values(document, surface, kind))
|
||||
.flatten();
|
||||
let bindings = document
|
||||
.get_mut("bindings")
|
||||
.and_then(Item::as_array_of_tables_mut)
|
||||
|
|
@ -732,12 +735,20 @@ pickup_tolerance = 0.02
|
|||
let table = bindings.get_mut(first).ok_or_else(|| {
|
||||
ConfigError::validation("bindings", "binding disappeared during edit")
|
||||
})?;
|
||||
let has_feedback = table.get("feedback").is_some();
|
||||
update_binding_table(table, surface, fader, action, kind, channel, number);
|
||||
if !has_feedback && let Some((on, off)) = inferred_feedback {
|
||||
table["feedback"] = value(feedback_table(kind, channel, number, on, off));
|
||||
}
|
||||
for index in matching.into_iter().skip(1).rev() {
|
||||
bindings.remove(index);
|
||||
}
|
||||
} else {
|
||||
bindings.push(binding_table(surface, fader, action, kind, channel, number));
|
||||
let mut table = binding_table(surface, fader, action, kind, channel, number);
|
||||
if let Some((on, off)) = inferred_feedback {
|
||||
table["feedback"] = value(feedback_table(kind, channel, number, on, off));
|
||||
}
|
||||
bindings.push(table);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
|
|
@ -1032,6 +1043,59 @@ fn binding_table(
|
|||
table
|
||||
}
|
||||
|
||||
fn inferred_feedback_values(
|
||||
document: &DocumentMut,
|
||||
surface: &str,
|
||||
kind: MessageKind,
|
||||
) -> Option<(i64, i64)> {
|
||||
let mut inferred = None;
|
||||
for table in document
|
||||
.get("bindings")?
|
||||
.as_array_of_tables()?
|
||||
.iter()
|
||||
.filter(|table| {
|
||||
table.get("surface").and_then(Item::as_str) == Some(surface)
|
||||
&& table.get("action").and_then(Item::as_str) == Some("toggle_mute")
|
||||
})
|
||||
{
|
||||
let Some(feedback) = table.get("feedback").and_then(Item::as_inline_table) else {
|
||||
continue;
|
||||
};
|
||||
if feedback.get("kind").and_then(Value::as_str) != Some(message_kind_name(kind)) {
|
||||
continue;
|
||||
}
|
||||
let Some(candidate) = feedback
|
||||
.get("on")
|
||||
.and_then(Value::as_integer)
|
||||
.zip(feedback.get("off").and_then(Value::as_integer))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if inferred.is_some_and(|existing| existing != candidate) {
|
||||
return None;
|
||||
}
|
||||
inferred = Some(candidate);
|
||||
}
|
||||
inferred
|
||||
}
|
||||
|
||||
fn feedback_table(kind: MessageKind, channel: u16, number: u16, on: i64, off: i64) -> InlineTable {
|
||||
let mut feedback = InlineTable::new();
|
||||
feedback.insert("kind", Value::from(message_kind_name(kind)));
|
||||
feedback.insert("channel", Value::from(i64::from(channel)));
|
||||
feedback.insert("number", Value::from(i64::from(number)));
|
||||
feedback.insert("on", Value::from(on));
|
||||
feedback.insert("off", Value::from(off));
|
||||
feedback
|
||||
}
|
||||
|
||||
const fn message_kind_name(kind: MessageKind) -> &'static str {
|
||||
match kind {
|
||||
MessageKind::Cc => "cc",
|
||||
MessageKind::Note => "note",
|
||||
}
|
||||
}
|
||||
|
||||
fn update_binding_table(
|
||||
table: &mut Table,
|
||||
surface: &str,
|
||||
|
|
@ -1065,13 +1129,7 @@ fn update_binding_table(
|
|||
table.remove("edge");
|
||||
}
|
||||
let mut message = InlineTable::new();
|
||||
message.insert(
|
||||
"kind",
|
||||
Value::from(match kind {
|
||||
MessageKind::Cc => "cc",
|
||||
MessageKind::Note => "note",
|
||||
}),
|
||||
);
|
||||
message.insert("kind", Value::from(message_kind_name(kind)));
|
||||
message.insert("channel", Value::from(i64::from(channel)));
|
||||
message.insert("number", Value::from(i64::from(number)));
|
||||
table["message"] = value(message);
|
||||
|
|
@ -1080,13 +1138,7 @@ fn update_binding_table(
|
|||
.get_mut("feedback")
|
||||
.and_then(Item::as_inline_table_mut)
|
||||
{
|
||||
feedback.insert(
|
||||
"kind",
|
||||
Value::from(match kind {
|
||||
MessageKind::Cc => "cc",
|
||||
MessageKind::Note => "note",
|
||||
}),
|
||||
);
|
||||
feedback.insert("kind", Value::from(message_kind_name(kind)));
|
||||
feedback.insert("channel", Value::from(i64::from(channel)));
|
||||
feedback.insert("number", Value::from(i64::from(number)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -563,3 +563,72 @@ fn changing_a_mute_binding_moves_its_feedback_to_the_new_control() {
|
|||
.unwrap();
|
||||
assert_eq!(feedback.number(), 33);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_new_mute_binding_inherits_unambiguous_surface_feedback_values() {
|
||||
let mut draft = ProfileDocument::parse(PROFILE).unwrap();
|
||||
draft
|
||||
.add_fader("second-media-fader", TargetKind::Group, "media", true, 0.02)
|
||||
.unwrap();
|
||||
draft
|
||||
.set_binding(
|
||||
"desk-left",
|
||||
"second-media-fader",
|
||||
Action::ToggleMute,
|
||||
MessageKind::Note,
|
||||
1,
|
||||
42,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let profile = draft.preview().unwrap();
|
||||
let feedback = profile
|
||||
.bindings()
|
||||
.iter()
|
||||
.find(|binding| binding.fader() == "second-media-fader")
|
||||
.and_then(|binding| binding.feedback())
|
||||
.expect("the established surface feedback convention is inherited");
|
||||
assert_eq!(feedback.number(), 42);
|
||||
assert_eq!((feedback.on(), feedback.off()), (127, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_new_mute_binding_does_not_guess_between_conflicting_feedback_values() {
|
||||
let source = format!(
|
||||
"{PROFILE}\n\
|
||||
[[faders]]\n\
|
||||
id = \"alternate-media-fader\"\n\
|
||||
target = {{ kind = \"group\", id = \"media\" }}\n\
|
||||
pickup = true\n\
|
||||
pickup_tolerance = 0.02\n\n\
|
||||
[[bindings]]\n\
|
||||
surface = \"desk-left\"\n\
|
||||
fader = \"alternate-media-fader\"\n\
|
||||
action = \"toggle_mute\"\n\
|
||||
edge = \"press\"\n\
|
||||
message = {{ kind = \"note\", channel = 1, number = 33 }}\n\
|
||||
feedback = {{ kind = \"note\", channel = 1, number = 33, on = 1, off = 0 }}\n"
|
||||
);
|
||||
let mut draft = ProfileDocument::parse(&source).unwrap();
|
||||
draft
|
||||
.add_fader("third-media-fader", TargetKind::Group, "media", true, 0.02)
|
||||
.unwrap();
|
||||
draft
|
||||
.set_binding(
|
||||
"desk-left",
|
||||
"third-media-fader",
|
||||
Action::ToggleMute,
|
||||
MessageKind::Note,
|
||||
1,
|
||||
42,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let profile = draft.preview().unwrap();
|
||||
let binding = profile
|
||||
.bindings()
|
||||
.iter()
|
||||
.find(|binding| binding.fader() == "third-media-fader")
|
||||
.unwrap();
|
||||
assert!(binding.feedback().is_none());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,8 +264,12 @@ channels and values from 0–127.
|
|||
LED values are device-specific: a note velocity can mean a color or animation,
|
||||
so 127 is not a universal “on” value. The APC MINI example uses its configured
|
||||
green value. Relearning a mute binding moves its feedback assignment to the new
|
||||
control. Set feedback values and output-port details in the profile when your
|
||||
surface requires a different protocol.
|
||||
control. A new mute binding inherits `on`/`off` values only when existing
|
||||
feedback entries on the same surface and message kind establish one unambiguous
|
||||
convention; its feedback address follows the newly learned control. Conflicting
|
||||
or absent conventions leave feedback unset rather than guessing. Set feedback
|
||||
values and output-port details in the profile when your surface requires a
|
||||
different protocol.
|
||||
|
||||
## Validation, migration, and Save
|
||||
|
||||
|
|
|
|||
4
task.md
4
task.md
|
|
@ -444,7 +444,9 @@ Dependencies: M8, M2, M1.
|
|||
in one terminal row; Bordered slim uses a three-row bordered card; both are
|
||||
narrower strips for horizontal faders. Config stores a validated default
|
||||
controller; unassigned volume and mute learn actions inherit it while explicit
|
||||
bindings keep their selected surface.
|
||||
bindings keep their selected surface. A new mute assignment inherits feedback
|
||||
values only from one unambiguous same-surface, same-message-kind convention
|
||||
and otherwise leaves device-specific feedback unset.
|
||||
- [x] **M9.6 Single-screen configuration workflow:** remove the normalized
|
||||
Config table browser once all its operations are reachable from the mixer,
|
||||
keep Save and draft/durable status visible, and expose hidden-item
|
||||
|
|
|
|||
Loading…
Reference in New Issue