fix: supply APC Mini mute feedback for fresh profiles

M6.1: Resolve missing feedback from the original APC Mini USB identity and supported note LED map, allowing the first learned mute binding to send confirmed feedback. Preserve explicit mappings and exclude unknown/outputless devices, unsupported controls, and MK2. Resolve defaults without rewriting user profiles.

Tests: fresh-profile planner regression failed with zero messages before the fix and passes after it. Added device/control exclusion and override coverage. cargo fmt --all -- --check, cargo check --workspace --all-targets --all-features, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo test --workspace --doc --all-features, cargo build --workspace --release --all-features pass. cargo test --workspace --all-targets --all-features --no-fail-fast --quiet exercises all targets: four existing Arch-profile fixture failures (schema ID and three MIDI device/routing assertions); remaining tests pass. Physical LED verification not performed.
This commit is contained in:
Dandaedre 2026-10-18 13:47:27 +02:00
parent e64195e783
commit 7a0e8840ed
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
6 changed files with 194 additions and 6 deletions

View File

@ -231,7 +231,15 @@ 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.
or conflicting conventions remain explicitly unconfigured for unknown devices.
The runtime resolves omitted feedback for the original APC Mini identified by
USB `09e8:0028` and a configured output port: channel-1 mute note bindings on
LED notes 0–71 and 82–89 use on=1/off=0. This covers the first learned binding
in a fresh profile and existing profiles without feedback entries. Explicit
feedback always wins; no defaults apply to CCs, other channels, Shift, unknown
devices, or the MK2. Defaults are resolved without rewriting the user's TOML.
The note map and LED values follow the original device's
[captured protocol](https://github.com/TomasHubelbauer/akai-apc-mini).
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.

View File

@ -472,6 +472,41 @@ impl Profile {
&self.raw.bindings
}
/// Resolves explicit feedback first, then supported device defaults.
///
/// The original APC Mini (USB 09e8:0028) has note LEDs on channel 1.
/// Unknown devices, CCs, and controls without LEDs have no implicit output.
/// This does not rewrite the document or override an explicit mapping.
pub fn effective_feedback(&self, binding: &Binding) -> Option<Feedback> {
if let Some(feedback) = binding.feedback() {
return Some(feedback.clone());
}
let surface = self
.surfaces()
.iter()
.find(|surface| surface.id() == binding.surface())?;
let original_apc_mini = surface
.usb_vendor_id()
.is_some_and(|id| id.eq_ignore_ascii_case("09e8"))
&& surface.usb_product_id() == Some("0028");
if !original_apc_mini
|| surface.output_port().is_none()
|| binding.action() != Action::ToggleMute
|| binding.message_kind() != MessageKind::Note
|| binding.channel() != 1
|| !matches!(binding.number(), 0..=71 | 82..=89)
{
return None;
}
Some(Feedback {
kind: MessageKind::Note,
channel: 1,
number: binding.number(),
on: 1,
off: 0,
})
}
/// Maximum configured gain for outbound writes and restored intents.
pub fn max_gain(&self) -> f64 {
self.raw.audio.max_gain

View File

@ -170,6 +170,89 @@ fn separator_presentation_round_trips_without_changing_order() {
);
}
#[test]
fn fresh_apc_feedback_defaults_are_device_and_control_scoped() {
let mut draft = ProfileDocument::empty("fresh").unwrap();
draft
.add_surface(
"controller",
"APC MINI",
"APC MINI:APC MINI MIDI 1",
Some("APC MINI:APC MINI MIDI 1"),
Some("09e8"),
Some("0028"),
None,
None,
None,
)
.unwrap();
for (kind, channel, number, supported) in [
(MessageKind::Note, 1, 0, true),
(MessageKind::Note, 1, 64, true),
(MessageKind::Note, 1, 71, true),
(MessageKind::Note, 1, 72, false),
(MessageKind::Note, 1, 82, true),
(MessageKind::Note, 1, 89, true),
(MessageKind::Note, 1, 98, false),
(MessageKind::Note, 2, 64, false),
(MessageKind::Cc, 1, 64, false),
] {
draft
.set_binding(
"controller",
"master-fader",
Action::ToggleMute,
kind,
channel,
number,
)
.unwrap();
let profile = draft.preview().unwrap();
let feedback = profile.effective_feedback(&profile.bindings()[0]);
assert_eq!(feedback.is_some(), supported);
if let Some(feedback) = feedback {
assert_eq!(
(
feedback.channel(),
feedback.number(),
feedback.on(),
feedback.off()
),
(1, number, 1, 0)
);
}
}
draft
.set_binding(
"controller",
"master-fader",
Action::ToggleMute,
MessageKind::Note,
1,
64,
)
.unwrap();
let source = draft.source();
for unsupported in [
source.replace("0028", "0029"),
source.replace("09e8", "1234"),
source.replace("output_port = \"APC MINI:APC MINI MIDI 1\"", ""),
source
.replace("action = \"toggle_mute\"", "action = \"volume\"")
.replace("kind = \"note\"", "kind = \"cc\"")
.replace("edge = \"press\"", ""),
] {
let profile = fader_config::Profile::parse(&unsupported).unwrap();
assert!(profile.effective_feedback(&profile.bindings()[0]).is_none());
}
let explicit = format!(
"{source}\nfeedback = {{ kind = \"note\", channel = 1, number = 65, on = 3, off = 0 }}\n"
);
let profile = fader_config::Profile::parse(&explicit).unwrap();
let feedback = profile.effective_feedback(&profile.bindings()[0]).unwrap();
assert_eq!((feedback.number(), feedback.on()), (65, 3));
}
#[test]
fn draft_adds_a_discovered_midi_surface_with_durable_identity() {
let mut draft = ProfileDocument::empty("default").unwrap();

View File

@ -278,9 +278,16 @@ green value. Relearning a mute binding moves its feedback assignment to the new
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.
or absent conventions leave feedback unset for unknown controllers.
The original APC Mini (`usb_vendor_id = "09e8"`, `usb_product_id = "0028"`)
has built-in mute LED defaults when `output_port` is configured. Channel-1 note
bindings for LEDs 0–71 and 82–89 use on=1/off=0, so learning the first mute button
in a new configuration works without copying another binding. Existing missing
mappings also use these defaults after Save or server restart. Explicit
`feedback` overrides them. Shift, CC faders, other channels, and the APC Mini
MK2 do not use these defaults. Other controllers still require their own
feedback values and output-port details in the profile.
## Validation, migration, and Save

View File

@ -68,8 +68,11 @@ impl FeedbackEngine {
.bindings()
.iter()
.filter_map(|binding| {
(binding.action() == fader_config::Action::ToggleMute)
.then(|| binding.feedback().map(|feedback| (binding, feedback)))?
(binding.action() == fader_config::Action::ToggleMute).then(|| {
profile
.effective_feedback(binding)
.map(|feedback| (binding, feedback))
})?
})
.map(|(binding, feedback)| {
let channel =
@ -797,6 +800,53 @@ mod tests {
));
}
#[test]
fn fresh_apc_profile_sends_feedback_without_an_existing_feedback_binding() {
let mut document = fader_config::ProfileDocument::empty("fresh").unwrap();
document
.add_surface(
"controller",
"APC MINI",
"APC MINI:APC MINI MIDI 1",
Some("APC MINI:APC MINI MIDI 1"),
Some("09e8"),
Some("0028"),
None,
None,
None,
)
.unwrap();
document
.set_binding(
"controller",
"master-fader",
fader_config::Action::ToggleMute,
fader_config::MessageKind::Note,
1,
89,
)
.unwrap();
// Exercise the saved/reloaded first binding, with no convention to copy.
let profile = Profile::parse(&document.source()).unwrap();
assert!(profile.bindings()[0].feedback().is_none());
let mut feedback = FeedbackEngine::new(&profile).unwrap();
let surface = SurfaceId::new("controller").unwrap();
let fader = FaderId::new("master-fader").unwrap();
let attached = BTreeSet::from([surface.clone()]);
assert!(feedback.plan(&BTreeMap::new(), &attached).is_empty());
for (muted, value) in [(false, 0), (true, 1), (false, 0)] {
let confirmed = BTreeMap::from([(fader.clone(), muted)]);
let messages = feedback.plan(&confirmed, &attached);
assert_eq!(messages.len(), 1);
assert_eq!(messages[0].bytes, [0x90, 89, value]);
feedback.record_sent(&messages[0]);
assert!(feedback.plan(&confirmed, &attached).is_empty());
feedback.invalidate_surface(&surface);
assert_eq!(feedback.plan(&confirmed, &attached).len(), 1);
assert!(feedback.plan(&confirmed, &BTreeSet::new()).is_empty());
}
}
#[test]
fn confirmed_mute_feedback_is_surface_scoped_deduplicated_and_resynced() {
let profile = Profile::parse(include_str!("../../examples/profiles/desktop.toml")).unwrap();

View File

@ -235,6 +235,11 @@ Dependencies: M4, M5.
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.
Original APC Mini USB identity now supplies missing mute LED defaults for
supported notes, including the first learned binding in an empty profile.
Tests cover save/reload, on/off, reconnect/deduplication, explicit overrides,
and exclusion of outputless/unknown devices and unsupported controls.
Other device profiles and physical hardware verification remain outstanding.
- [ ] **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.