feat: connect M13 media actions, MIDI learn and feedback to the server
Verify: cargo test -p fader_master --lib --quiet: 38 passed, 1 opt-in ignored (temporary Unix sockets require elevated sandbox permissions). cargo test -p fader_master media_triggers --quiet passed. cargo fmt --all passed. Live hardware not exercised.
This commit is contained in:
parent
5d0126abff
commit
c7e33d45d2
|
|
@ -162,6 +162,34 @@ impl ConfigurationEditor {
|
|||
self.document
|
||||
.set_application(&id, &label, &[selector(&field, pattern, regex)?])?
|
||||
}
|
||||
ConfigurationEdit::SetMediaEntry { entry } => self.document.set_media_entry(&entry)?,
|
||||
ConfigurationEdit::RemoveMediaEntry { id } => self.document.remove_media_entry(&id)?,
|
||||
ConfigurationEdit::SetMediaBinding {
|
||||
entry,
|
||||
control,
|
||||
binding,
|
||||
} => {
|
||||
let profile = self.document.preview()?;
|
||||
let mut entry = profile
|
||||
.media()
|
||||
.iter()
|
||||
.find(|e| e.id == entry)
|
||||
.cloned()
|
||||
.ok_or_else(|| ConfigError::Validation {
|
||||
path: "media".into(),
|
||||
message: "unknown entry".into(),
|
||||
})?;
|
||||
let target = entry
|
||||
.controls
|
||||
.iter_mut()
|
||||
.find(|c| c.id == control)
|
||||
.ok_or_else(|| ConfigError::Validation {
|
||||
path: "media".into(),
|
||||
message: "unknown control".into(),
|
||||
})?;
|
||||
target.binding = binding;
|
||||
self.document.set_media_entry(&entry)?;
|
||||
}
|
||||
ConfigurationEdit::SetFeedbackEnabled { fader, enabled } => self
|
||||
.document
|
||||
.set_feedback_enabled(fader.as_deref(), enabled)?,
|
||||
|
|
|
|||
|
|
@ -42,6 +42,15 @@ pub struct ClientRequest {
|
|||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum RequestCommand {
|
||||
MediaAction {
|
||||
entry: String,
|
||||
control: String,
|
||||
},
|
||||
StartMediaLearn {
|
||||
surface: String,
|
||||
entry: String,
|
||||
control: String,
|
||||
},
|
||||
Snapshot,
|
||||
EditConfiguration {
|
||||
expected_revision: u64,
|
||||
|
|
@ -77,6 +86,17 @@ pub enum RequestCommand {
|
|||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(tag = "operation", rename_all = "snake_case")]
|
||||
pub enum ConfigurationEdit {
|
||||
SetMediaEntry {
|
||||
entry: media::Entry,
|
||||
},
|
||||
RemoveMediaEntry {
|
||||
id: String,
|
||||
},
|
||||
SetMediaBinding {
|
||||
entry: String,
|
||||
control: String,
|
||||
binding: Option<media::Binding>,
|
||||
},
|
||||
SetFeedbackEnabled {
|
||||
fader: Option<String>,
|
||||
enabled: bool,
|
||||
|
|
@ -264,6 +284,10 @@ pub struct MixerSnapshot {
|
|||
|
||||
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
|
||||
pub struct ConfigurationSnapshot {
|
||||
#[serde(default)]
|
||||
pub media_entries: Vec<media::Entry>,
|
||||
#[serde(default)]
|
||||
pub media_state: media::Snapshot,
|
||||
#[serde(default)]
|
||||
pub feedback_disabled: bool,
|
||||
#[serde(default)]
|
||||
|
|
|
|||
|
|
@ -110,6 +110,8 @@ pub(crate) fn configuration_snapshot(
|
|||
applied_revision: u64,
|
||||
) -> ConfigurationSnapshot {
|
||||
ConfigurationSnapshot {
|
||||
media_entries: profile.media().to_vec(),
|
||||
media_state: media::Snapshot::default(),
|
||||
feedback_disabled: !profile.feedback_enabled(),
|
||||
disabled_feedback_faders: profile
|
||||
.faders()
|
||||
|
|
@ -611,10 +613,15 @@ impl LiveMixerState {
|
|||
self.discovered_midi_ports = ports;
|
||||
}
|
||||
|
||||
pub(crate) fn set_configuration(&mut self, configuration: ConfigurationSnapshot) {
|
||||
pub(crate) fn set_configuration(&mut self, mut configuration: ConfigurationSnapshot) {
|
||||
configuration.media_state = self.configuration.media_state.clone();
|
||||
self.configuration = configuration;
|
||||
}
|
||||
|
||||
pub(crate) fn set_media(&mut self, snapshot: media::Snapshot) {
|
||||
self.configuration.media_state = snapshot;
|
||||
}
|
||||
|
||||
/// Replaces profile-derived routing while retaining confirmed backend state.
|
||||
pub(crate) fn reconfigure(
|
||||
&mut self,
|
||||
|
|
@ -874,7 +881,10 @@ impl LiveMixerState {
|
|||
"configuration edits must be handled by the server owner".to_owned(),
|
||||
));
|
||||
}
|
||||
RequestCommand::StartMidiLearn { .. } | RequestCommand::CancelMidiLearn => {
|
||||
RequestCommand::StartMidiLearn { .. }
|
||||
| RequestCommand::CancelMidiLearn
|
||||
| RequestCommand::StartMediaLearn { .. }
|
||||
| RequestCommand::MediaAction { .. } => {
|
||||
return Err(LiveMixerError::Profile(
|
||||
"MIDI learn commands must be handled by the server owner".to_owned(),
|
||||
));
|
||||
|
|
|
|||
|
|
@ -174,6 +174,8 @@ pub fn client_request(
|
|||
/// Persistent local server joining the Pulse owner thread on drop.
|
||||
#[derive(Debug)]
|
||||
pub struct LocalServer {
|
||||
media: crate::media_runtime::MediaRuntime,
|
||||
active_media: Vec<media::Entry>,
|
||||
listener: OwnedListener,
|
||||
worker: PulseWorker,
|
||||
mixer: LiveMixerState,
|
||||
|
|
@ -208,6 +210,9 @@ impl LocalServer {
|
|||
})?
|
||||
.to_owned();
|
||||
let mut server = Self {
|
||||
media: crate::media_runtime::MediaRuntime::start()
|
||||
.map_err(|e| LocalError::MidiRuntime(format!("MPRIS worker: {e}")))?,
|
||||
active_media: profile.media().to_vec(),
|
||||
listener: OwnedListener::bind(socket)?,
|
||||
// One waiting native command keeps round-trip backpressure at the
|
||||
// state-owner boundary, where unsent volume motion can coalesce.
|
||||
|
|
@ -254,7 +259,37 @@ impl LocalServer {
|
|||
}
|
||||
|
||||
pub fn tick(&mut self) -> Result<(), LocalError> {
|
||||
self.mixer.set_media(self.media.snapshot());
|
||||
let midi_tick = self.midi.tick();
|
||||
for (entry, control) in &midi_tick.media_actions {
|
||||
if let Err(error) = self.execute_media(entry, control) {
|
||||
let profile = self
|
||||
.configuration
|
||||
.profile()
|
||||
.map_err(|e| crate::live::LiveMixerError::Profile(e.to_string()))?;
|
||||
self.publish_configuration(&profile, Some(error));
|
||||
}
|
||||
}
|
||||
if let Some((learn, binding)) = midi_tick.learned_media {
|
||||
let edit = crate::ipc::ConfigurationEdit::SetMediaBinding {
|
||||
entry: learn.entry,
|
||||
control: learn.control,
|
||||
binding: Some(binding),
|
||||
};
|
||||
match self
|
||||
.configuration
|
||||
.apply(self.configuration.revision(), edit)
|
||||
{
|
||||
Ok(profile) => self.publish_configuration(&profile, None),
|
||||
Err(error) => {
|
||||
let profile = self
|
||||
.configuration
|
||||
.profile()
|
||||
.map_err(|e| crate::live::LiveMixerError::Profile(e.to_string()))?;
|
||||
self.publish_configuration(&profile, Some(error.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
self.flush_dispatch();
|
||||
let mut worker_events = Vec::new();
|
||||
match self.worker.receive_timeout(self.poll_interval) {
|
||||
|
|
@ -331,6 +366,49 @@ impl LocalServer {
|
|||
let request_id = request.request_id;
|
||||
let result = (|| -> Result<_, crate::live::LiveMixerError> {
|
||||
match request.command {
|
||||
crate::ipc::RequestCommand::StartMediaLearn {
|
||||
surface,
|
||||
entry,
|
||||
control,
|
||||
} if request.version == PROTOCOL_VERSION => {
|
||||
let profile = self
|
||||
.configuration
|
||||
.profile()
|
||||
.map_err(|e| crate::live::LiveMixerError::Profile(e.to_string()))?;
|
||||
if !profile.surfaces().iter().any(|s| s.id() == surface)
|
||||
|| !profile
|
||||
.media()
|
||||
.iter()
|
||||
.any(|e| e.id == entry && e.controls.iter().any(|c| c.id == control))
|
||||
{
|
||||
return Err(crate::live::LiveMixerError::Profile(
|
||||
"unknown media entry, control or MIDI surface".into(),
|
||||
));
|
||||
}
|
||||
self.midi
|
||||
.start_media_learn(crate::midi_runtime::MediaLearn {
|
||||
surface,
|
||||
entry,
|
||||
control,
|
||||
});
|
||||
self.publish_configuration(&profile, None);
|
||||
self.mixer.request(ClientRequest {
|
||||
version: request.version,
|
||||
request_id,
|
||||
command: crate::ipc::RequestCommand::Snapshot,
|
||||
})
|
||||
}
|
||||
crate::ipc::RequestCommand::MediaAction { entry, control }
|
||||
if request.version == PROTOCOL_VERSION =>
|
||||
{
|
||||
self.execute_media(&entry, &control)
|
||||
.map_err(crate::live::LiveMixerError::Profile)?;
|
||||
self.mixer.request(ClientRequest {
|
||||
version: request.version,
|
||||
request_id,
|
||||
command: crate::ipc::RequestCommand::Snapshot,
|
||||
})
|
||||
}
|
||||
crate::ipc::RequestCommand::EditConfiguration {
|
||||
expected_revision,
|
||||
edit,
|
||||
|
|
@ -441,11 +519,15 @@ impl LocalServer {
|
|||
let midi = crate::midi_runtime::MidiRuntime::new(&profile)
|
||||
.map_err(crate::live::LiveMixerError::Profile)?;
|
||||
let max_gain = Gain::new(profile.max_gain())?;
|
||||
self.media
|
||||
.fence()
|
||||
.map_err(crate::live::LiveMixerError::Profile)?;
|
||||
self.configuration
|
||||
.save(current_revision)
|
||||
.map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?;
|
||||
self.mixer.reconfigure(&profile, max_gain)?;
|
||||
self.midi = midi;
|
||||
self.active_media = profile.media().to_vec();
|
||||
self.applied_configuration_revision = self.configuration.revision();
|
||||
self.publish_configuration(&profile, None);
|
||||
self.mixer.request(ClientRequest {
|
||||
|
|
@ -457,6 +539,9 @@ impl LocalServer {
|
|||
crate::ipc::RequestCommand::ResetConfiguration { expected_revision }
|
||||
if request.version == PROTOCOL_VERSION =>
|
||||
{
|
||||
self.media
|
||||
.fence()
|
||||
.map_err(crate::live::LiveMixerError::Profile)?;
|
||||
let profile = self
|
||||
.configuration
|
||||
.reset(expected_revision)
|
||||
|
|
@ -466,6 +551,7 @@ impl LocalServer {
|
|||
self.mixer
|
||||
.reconfigure(&profile, Gain::new(profile.max_gain())?)?;
|
||||
self.midi = midi;
|
||||
self.active_media = profile.media().to_vec();
|
||||
self.applied_configuration_revision = self.configuration.revision();
|
||||
self.publish_configuration(&profile, None);
|
||||
self.mixer.request(ClientRequest {
|
||||
|
|
@ -558,6 +644,9 @@ impl LocalServer {
|
|||
};
|
||||
let midi = crate::midi_runtime::MidiRuntime::new(&profile)
|
||||
.map_err(crate::live::LiveMixerError::Profile)?;
|
||||
self.media
|
||||
.fence()
|
||||
.map_err(crate::live::LiveMixerError::Profile)?;
|
||||
self.mixer
|
||||
.reconfigure(&profile, Gain::new(profile.max_gain())?)?;
|
||||
let restore_commands = self.mixer.activate_restore(
|
||||
|
|
@ -566,6 +655,7 @@ impl LocalServer {
|
|||
&& profile.new_stream() == fader_config::NewStreamPolicy::Restore,
|
||||
)?;
|
||||
self.midi = midi;
|
||||
self.active_media = profile.media().to_vec();
|
||||
self.configuration = ConfigurationEditor::new(document, path);
|
||||
self.applied_configuration_revision = 0;
|
||||
let persistence_error = (|| {
|
||||
|
|
@ -625,6 +715,21 @@ impl LocalServer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn execute_media(&self, entry: &str, control: &str) -> Result<(), String> {
|
||||
let entry = self
|
||||
.active_media
|
||||
.iter()
|
||||
.find(|e| e.id == entry)
|
||||
.ok_or("media entry is not active; save configuration first")?;
|
||||
let control = entry
|
||||
.controls
|
||||
.iter()
|
||||
.find(|c| c.id == control)
|
||||
.ok_or("unknown active media control")?;
|
||||
self.media
|
||||
.command(entry.selector.clone(), control.action.clone())
|
||||
}
|
||||
|
||||
fn publish_configuration(&mut self, profile: &fader_config::Profile, error: Option<String>) {
|
||||
let mut configuration = configuration_snapshot(
|
||||
profile,
|
||||
|
|
@ -636,6 +741,7 @@ impl LocalServer {
|
|||
configuration.available_profiles =
|
||||
available_profile_ids(&self.profile_directory, profile.id().as_str());
|
||||
configuration.error = error;
|
||||
configuration.learning = self.midi.learning_label();
|
||||
self.mixer.set_configuration(configuration);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@ const EVENT_CAPACITY: usize = 256;
|
|||
|
||||
/// Owns native MIDI input connections and periodically reconciles hotplug state.
|
||||
pub struct MidiRuntime {
|
||||
media_entries: Vec<(media::Entry, media::PlayerMatcher)>,
|
||||
media_feedback_enabled: bool,
|
||||
media_sent: BTreeMap<(String, String, String), [u8; 3]>,
|
||||
media_down: BTreeSet<(String, bool, u16, u16)>,
|
||||
media_learn: Option<MediaLearn>,
|
||||
lifecycle: SurfaceLifecycle,
|
||||
labels: BTreeMap<SurfaceId, String>,
|
||||
connections: BTreeMap<SurfaceId, MidiInputConnection>,
|
||||
|
|
@ -177,10 +182,19 @@ pub struct LearnedBinding {
|
|||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct MidiTick {
|
||||
pub media_actions: Vec<(String, String)>,
|
||||
pub learned_media: Option<(MediaLearn, media::Binding)>,
|
||||
pub intents: Vec<MidiIntent>,
|
||||
pub learned: Option<LearnedBinding>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MediaLearn {
|
||||
pub surface: String,
|
||||
pub entry: String,
|
||||
pub control: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for MidiRuntime {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
formatter
|
||||
|
|
@ -251,6 +265,21 @@ impl MidiRuntime {
|
|||
let feedback = FeedbackEngine::new(profile)?;
|
||||
let (sender, receiver) = sync_channel(EVENT_CAPACITY);
|
||||
Ok(Self {
|
||||
media_entries: profile
|
||||
.media()
|
||||
.iter()
|
||||
.map(|entry| {
|
||||
entry
|
||||
.selector
|
||||
.compile()
|
||||
.map(|matcher| (entry.clone(), matcher))
|
||||
.map_err(|e| e.to_string())
|
||||
})
|
||||
.collect::<Result<_, _>>()?,
|
||||
media_feedback_enabled: profile.feedback_enabled(),
|
||||
media_sent: BTreeMap::new(),
|
||||
media_down: BTreeSet::new(),
|
||||
media_learn: None,
|
||||
lifecycle,
|
||||
labels,
|
||||
connections: BTreeMap::new(),
|
||||
|
|
@ -302,19 +331,55 @@ impl MidiRuntime {
|
|||
}
|
||||
|
||||
pub fn start_learn(&mut self, learn: MidiLearn) {
|
||||
self.media_learn = None;
|
||||
self.learn = Some(learn);
|
||||
}
|
||||
|
||||
pub fn cancel_learn(&mut self) {
|
||||
self.media_learn = None;
|
||||
self.learn = None;
|
||||
}
|
||||
|
||||
pub fn start_media_learn(&mut self, learn: MediaLearn) {
|
||||
self.learn = None;
|
||||
self.media_learn = Some(learn);
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn learning(&self) -> Option<&MidiLearn> {
|
||||
self.learn.as_ref()
|
||||
}
|
||||
|
||||
pub fn learning_label(&self) -> Option<String> {
|
||||
self.media_learn
|
||||
.as_ref()
|
||||
.map(|l| format!("{} -> {} / {}", l.surface, l.entry, l.control))
|
||||
.or_else(|| {
|
||||
self.learn
|
||||
.as_ref()
|
||||
.map(|l| format!("{} -> {} ({:?})", l.surface, l.fader, l.action))
|
||||
})
|
||||
}
|
||||
|
||||
fn handle_message(&mut self, surface: SurfaceId, message: MidiMessage, result: &mut MidiTick) {
|
||||
let (input, pressed) = media_input(message);
|
||||
if self
|
||||
.media_learn
|
||||
.as_ref()
|
||||
.is_some_and(|learn| learn.surface == surface.as_str())
|
||||
{
|
||||
if pressed && let Some(learn) = self.media_learn.take() {
|
||||
result.learned_media = Some((
|
||||
learn,
|
||||
media::Binding {
|
||||
surface: surface.to_string(),
|
||||
message: input,
|
||||
feedback: None,
|
||||
},
|
||||
));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if self
|
||||
.learn
|
||||
.as_ref()
|
||||
|
|
@ -362,6 +427,32 @@ impl MidiRuntime {
|
|||
}
|
||||
return;
|
||||
}
|
||||
for (entry, _) in &self.media_entries {
|
||||
for control in &entry.controls {
|
||||
if control
|
||||
.binding
|
||||
.as_ref()
|
||||
.is_some_and(|b| b.surface == surface.as_str() && b.message == input)
|
||||
{
|
||||
let key = (
|
||||
surface.to_string(),
|
||||
input.kind == media::MessageKind::Note,
|
||||
input.channel,
|
||||
input.number,
|
||||
);
|
||||
if pressed {
|
||||
if self.media_down.insert(key) {
|
||||
result
|
||||
.media_actions
|
||||
.push((entry.id.clone(), control.id.clone()));
|
||||
}
|
||||
} else {
|
||||
self.media_down.remove(&key);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(intent) = self.router.route(&surface, message) {
|
||||
result.intents.push(intent);
|
||||
}
|
||||
|
|
@ -441,6 +532,7 @@ impl MidiRuntime {
|
|||
match action {
|
||||
SurfaceAction::Disconnect { surface, .. } => {
|
||||
self.connections.remove(&surface);
|
||||
self.media_down.retain(|(id, ..)| id != surface.as_str());
|
||||
}
|
||||
SurfaceAction::Connect {
|
||||
surface,
|
||||
|
|
@ -552,6 +644,7 @@ impl MidiRuntime {
|
|||
}
|
||||
|
||||
fn disconnect_output(&mut self, surface: &SurfaceId) {
|
||||
self.media_sent.retain(|(id, ..), _| id != surface.as_str());
|
||||
if self.output_connections.remove(surface).is_some() {
|
||||
self.feedback.invalidate_surface(surface);
|
||||
}
|
||||
|
|
@ -559,6 +652,7 @@ impl MidiRuntime {
|
|||
}
|
||||
|
||||
pub fn sync_feedback(&mut self, snapshot: &MixerSnapshot) {
|
||||
self.sync_media_feedback(&snapshot.configuration.media_state);
|
||||
let confirmed = self
|
||||
.feedback
|
||||
.bindings
|
||||
|
|
@ -590,6 +684,85 @@ impl MidiRuntime {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn sync_media_feedback(&mut self, snapshot: &media::Snapshot) {
|
||||
if !self.media_feedback_enabled {
|
||||
return;
|
||||
}
|
||||
let mut writes = Vec::new();
|
||||
for (entry, matcher) in &self.media_entries {
|
||||
if !entry.feedback_enabled {
|
||||
continue;
|
||||
}
|
||||
let player = matcher.resolve(&snapshot.players).ok();
|
||||
for control in &entry.controls {
|
||||
let Some(binding) = &control.binding else {
|
||||
continue;
|
||||
};
|
||||
let on = control.action.feedback(player);
|
||||
let Some(bytes) = binding.feedback_bytes(on) else {
|
||||
continue;
|
||||
};
|
||||
let key = (
|
||||
binding.surface.clone(),
|
||||
entry.id.clone(),
|
||||
control.id.clone(),
|
||||
);
|
||||
if self.media_sent.get(&key) != Some(&bytes) {
|
||||
writes.push((key, bytes, on));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Turn old state lights off before turning a new state light on.
|
||||
writes.sort_by_key(|(_, _, on)| *on);
|
||||
for (key, bytes, _) in writes {
|
||||
let Ok(surface) = SurfaceId::new(&key.0) else {
|
||||
continue;
|
||||
};
|
||||
let Some(connection) = self.output_connections.get_mut(&surface) else {
|
||||
continue;
|
||||
};
|
||||
match connection.send(&bytes) {
|
||||
Ok(()) => {
|
||||
self.media_sent.insert(key, bytes);
|
||||
}
|
||||
Err(error) => {
|
||||
self.output_errors
|
||||
.insert(surface.clone(), error.to_string());
|
||||
self.disconnect_output(&surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn media_input(message: MidiMessage) -> (media::Message, bool) {
|
||||
let (kind, channel, number, pressed) = match message {
|
||||
MidiMessage::Note {
|
||||
channel,
|
||||
number,
|
||||
edge,
|
||||
..
|
||||
} => (
|
||||
media::MessageKind::Note,
|
||||
channel,
|
||||
number,
|
||||
edge == ButtonEdge::Press,
|
||||
),
|
||||
MidiMessage::ControlChange {
|
||||
channel,
|
||||
number,
|
||||
value,
|
||||
} => (media::MessageKind::Cc, channel, number, value.get() > 0),
|
||||
};
|
||||
(
|
||||
media::Message {
|
||||
kind,
|
||||
channel: u16::from(channel.get()),
|
||||
number: u16::from(number.get()),
|
||||
},
|
||||
pressed,
|
||||
)
|
||||
}
|
||||
|
||||
fn unclaimed_ports(visible: Vec<PortIdentity>, lifecycle: &SurfaceLifecycle) -> Vec<PortIdentity> {
|
||||
|
|
@ -634,6 +807,69 @@ mod tests {
|
|||
use fader_core::{MidiChannel, MidiData};
|
||||
use midi::{ButtonEdge, MidiMessage};
|
||||
|
||||
#[test]
|
||||
fn media_triggers_are_press_edges_and_learn_is_scoped() {
|
||||
let profile =
|
||||
Profile::parse(include_str!("../../examples/profiles/arch-pipewire.toml")).unwrap();
|
||||
let mut runtime = MidiRuntime::new(&profile).unwrap();
|
||||
let surface = SurfaceId::new("buttons").unwrap();
|
||||
let selector = media::PlayerSelector {
|
||||
field: media::PlayerField::BusName,
|
||||
pattern: "org.mpris.MediaPlayer2.test".into(),
|
||||
regex: false,
|
||||
};
|
||||
let binding = media::Binding {
|
||||
surface: surface.to_string(),
|
||||
message: media::Message {
|
||||
kind: media::MessageKind::Cc,
|
||||
channel: 1,
|
||||
number: 12,
|
||||
},
|
||||
feedback: None,
|
||||
};
|
||||
runtime.media_entries.push((
|
||||
media::Entry {
|
||||
id: "player".into(),
|
||||
label: "Player".into(),
|
||||
selector: selector.clone(),
|
||||
feedback_enabled: true,
|
||||
controls: vec![media::Control {
|
||||
id: "play".into(),
|
||||
action: media::Action::Play,
|
||||
binding: Some(binding.clone()),
|
||||
}],
|
||||
},
|
||||
selector.compile().unwrap(),
|
||||
));
|
||||
let message = |value| MidiMessage::ControlChange {
|
||||
channel: MidiChannel::new(1).unwrap(),
|
||||
number: MidiData::new(12).unwrap(),
|
||||
value: MidiData::new(value).unwrap(),
|
||||
};
|
||||
let mut result = MidiTick::default();
|
||||
for value in [127, 127, 50, 0, 127] {
|
||||
runtime.handle_message(surface.clone(), message(value), &mut result);
|
||||
}
|
||||
assert_eq!(
|
||||
result.media_actions,
|
||||
vec![("player".into(), "play".into()); 2]
|
||||
);
|
||||
assert!(result.intents.is_empty());
|
||||
runtime.start_media_learn(MediaLearn {
|
||||
surface: surface.to_string(),
|
||||
entry: "player".into(),
|
||||
control: "play".into(),
|
||||
});
|
||||
let mut learned = MidiTick::default();
|
||||
runtime.handle_message(SurfaceId::new("other").unwrap(), message(127), &mut learned);
|
||||
runtime.handle_message(surface.clone(), message(0), &mut learned);
|
||||
assert!(learned.learned_media.is_none());
|
||||
runtime.handle_message(surface, message(127), &mut learned);
|
||||
assert_eq!(learned.learned_media.unwrap().1, binding);
|
||||
assert!(learned.media_actions.is_empty());
|
||||
assert!(runtime.learning_label().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_exposes_only_ports_not_claimed_by_configured_surfaces() {
|
||||
let surface = SurfaceId::new("configured").unwrap();
|
||||
|
|
|
|||
Loading…
Reference in New Issue