From 855dce7c0f975310120762dbab459e590c731fee Mon Sep 17 00:00:00 2001 From: Benjamin Klum Date: Wed, 21 Aug 2024 05:18:19 +0200 Subject: [PATCH] Fix tests --- main/src/domain/control_surface.rs | 18 ++++++++++-------- main/src/domain/reaper_target.rs | 8 ++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/main/src/domain/control_surface.rs b/main/src/domain/control_surface.rs index 83c5e83b2..0d2b2a1fd 100644 --- a/main/src/domain/control_surface.rs +++ b/main/src/domain/control_surface.rs @@ -123,12 +123,11 @@ pub enum AdditionalFeedbackEvent { /// depend on this (see https://github.com/helgoboss/helgobox/issues/663). BeatChanged(BeatChangedEvent), MappedFxParametersChanged, - /// This event is raised whenever switching between FX windows (something that REAPER's own FxFocused change - /// event detects as well), but also when an FX window loses focus and a non-FX window gains focus, - /// and vice versa (not notified FxFocused change event). + /// This event is raised when an FX window loses focus and a non-FX window gains focus, + /// and vice versa (not covered by FxFocused change event). /// /// Attention: This will only be fired for REAPER 7+! - FocusSwitched, + FocusSwitchedBetweenMainAndFx, /// Forwarded unit state event /// /// Not all unit events are forwarded, only those that might matter for other @@ -295,7 +294,7 @@ impl RealearnControlSurfaceMiddleware { self.process_instance_orchestration_events(); // Inform ReaLearn about various changes that are not relevant for target learning self.detect_reaper_config_changes(); - self.emit_focus_switch_as_feedback_event(); + self.emit_focus_switch_between_main_and_fx_as_feedback_event(); self.emit_instance_events(); self.emit_beats_as_feedback_events(); self.detect_device_changes(timestamp); @@ -607,7 +606,7 @@ impl RealearnControlSurfaceMiddleware { } } - fn emit_focus_switch_as_feedback_event(&mut self) { + fn emit_focus_switch_between_main_and_fx_as_feedback_event(&mut self) { let reaper = Reaper::get().medium_reaper(); if reaper.low().pointers().GetFocusedFX2.is_none() { // Detection of unfocusing FX (without focusing a new one) not supported in REAPER versions < 7. @@ -630,11 +629,14 @@ impl RealearnControlSurfaceMiddleware { true } (Some(last), Some(new)) => { - last.is_still_focused != new.is_still_focused || last.fx != new.fx + // Only fire if we changed from "no FX focused" to "FX focused" or vice versa (not when focusing + // between FX ... this is detected better by REAPER's built-in control surface FxFocused event, + // mainly because latter doesn't fire when an FX is removed - which would be too much) + last.is_still_focused != new.is_still_focused } }; if fire { - let event = AdditionalFeedbackEvent::FocusSwitched; + let event = AdditionalFeedbackEvent::FocusSwitchedBetweenMainAndFx; for p in &mut *self.main_processors.borrow_mut() { p.process_additional_feedback_event(&event); } diff --git a/main/src/domain/reaper_target.rs b/main/src/domain/reaper_target.rs index f4fdd3acf..ad9537bf9 100644 --- a/main/src/domain/reaper_target.rs +++ b/main/src/domain/reaper_target.rs @@ -286,6 +286,7 @@ impl ReaperTarget { evt { | FxClosed(_) | FxOpened(_) + | FxFocused(_) // For FX-to-preset links that also have preset name as criteria | FxPresetChanged(_) | ProjectSwitched(_) @@ -302,11 +303,6 @@ impl ReaperTarget { | HardwareOutputSendCountChanged(_) | TrackSelectedChanged(_) | TrackVisibilityChanged(_) => true, - FxFocused(_) => { - // This is only relevant if GetFocusedFX2 doesn't exist (REAPER < v7). For REAPER 7+, - // our own FocusSwitched event is the best. See below. - Reaper::get().medium_reaper().low().pointers().GetFocusedFX2.is_none() - }, _ => false, } } @@ -316,7 +312,7 @@ impl ReaperTarget { matches!( evt, // Auto-load should load other preset (REAPER 7+ only!) - FocusSwitched + FocusSwitchedBetweenMainAndFx // Dynamic FX parameter expression should be re-resolved | MappedFxParametersChanged )