Skip to content

Commit

Permalink
#1366 Fix laggy "Track: Set automation touch state"
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Dec 18, 2024
1 parent 4e8bdde commit c152350
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 48 deletions.
8 changes: 0 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ vst = { git = "https://github.com/helgoboss/vst-rs.git", branch = "feature/param
#vst = { path = "../vst-rs" }

# This is for temporary development with local reaper-rs.
#[patch.'https://github.com/helgoboss/reaper-rs.git']
#reaper-common-types = { path = "../reaper-rs/main/common-types" }
#reaper-fluent = { path = "../reaper-rs/main/fluent" }
#reaper-high = { path = "../reaper-rs/main/high" }
#reaper-medium = { path = "../reaper-rs/main/medium" }
#reaper-macros = { path = "../reaper-rs/main/macros" }
#reaper-low = { path = "../reaper-rs/main/low" }
#reaper-rx = { path = "../reaper-rs/main/rx" }
#rppxml-parser = { path = "../reaper-rs/main/rppxml-parser" }
[patch.'https://github.com/helgoboss/reaper-rs.git']
reaper-common-types = { path = "../reaper-rs/main/common-types" }
reaper-fluent = { path = "../reaper-rs/main/fluent" }
reaper-high = { path = "../reaper-rs/main/high" }
reaper-medium = { path = "../reaper-rs/main/medium" }
reaper-macros = { path = "../reaper-rs/main/macros" }
reaper-low = { path = "../reaper-rs/main/low" }
reaper-rx = { path = "../reaper-rs/main/rx" }
rppxml-parser = { path = "../reaper-rs/main/rppxml-parser" }

## This is for temporary development with local egui-baseview.
#[patch.'https://github.com/helgoboss/egui-baseview.git']
Expand Down
1 change: 1 addition & 0 deletions main/src/domain/control_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ impl<EH: DomainEventHandler> RealearnControlSurfaceMiddleware<EH> {
}
}

#[allow(deprecated)]
fn detect_focus_switch_between_main_and_fx_as_feedback_event_deprecated(&mut self) -> bool {
let reaper = Reaper::get().medium_reaper();
let new = reaper.get_focused_fx_2();
Expand Down
32 changes: 21 additions & 11 deletions main/src/domain/realearn_target_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::domain::{
};
use base::hash_util::{NonCryptoHashMap, NonCryptoHashSet};
use base::{NamedChannelSender, SenderToNormalThread};
use reaper_high::{Fx, GroupingBehavior, Track};
use reaper_medium::{GangBehavior, MediaTrack};
use reaper_high::{Fx, GroupingBehavior, Reaper, Track};
use reaper_medium::{GangBehavior, MediaTrack, NotificationBehavior, ValueChange};

/// Feedback for most targets comes from REAPER itself but there are some targets for which ReaLearn
/// holds the state. It's in this struct.
Expand Down Expand Up @@ -127,6 +127,7 @@ impl RealearnTargetState {
) {
self.touched_things
.remove(&TouchedThing::new(track.raw(), parameter_type));
self.post_process_touch(track, parameter_type);
self.additional_feedback_event_sender.send_complaining(
AdditionalFeedbackEvent::ParameterAutomationTouchStateChanged(
ParameterAutomationTouchStateChangedEvent {
Expand All @@ -141,25 +142,34 @@ impl RealearnTargetState {
fn post_process_touch(&mut self, track: &Track, parameter_type: TouchedTrackParameterType) {
match parameter_type {
TouchedTrackParameterType::Volume => {
track.set_volume(
track.volume(),
let resulting_value = track.csurf_on_volume_change_ex(
ValueChange::Absolute(track.volume()),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
);
if let Ok(v) = resulting_value {
let _ = track.csurf_set_surface_volume(v, NotificationBehavior::NotifyAll);
}
}
TouchedTrackParameterType::Pan => {
track.set_pan(
track.pan(),
let resulting_value = track.csurf_on_pan_change_ex(
ValueChange::Absolute(track.pan().reaper_value()),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
);
if let Ok(v) = resulting_value {
let _ = track.csurf_set_surface_pan(v, NotificationBehavior::NotifyAll);
}
}
TouchedTrackParameterType::Width => {
track.set_width(
track.width(),
let result = track.csurf_on_width_change_ex(
ValueChange::Absolute(track.width().reaper_value()),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
);
if result.is_ok() {
let _ = track.csurf_set_surface_pan(
track.pan().reaper_value(),
NotificationBehavior::NotifyAll,
);
}
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions main/src/domain/reaper_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use enum_dispatch::enum_dispatch;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use reaper_high::{
Action, AvailablePanValue, BookmarkType, ChangeEvent, Fx, FxChain, FxParameter,
GroupingBehavior, Pan, PanExt, PlayRate, Project, Reaper, Tempo, Track, TrackRoute, Width,
GroupingBehavior, Pan, PanExt, PlayRate, Project, Reaper, ReaperError, Tempo, Track,
TrackRoute, Width,
};
use reaper_medium::{
AutomationMode, Bpm, GangBehavior, GlobalAutomationModeOverride, NormalizedPlayRate, ParamId,
Expand Down Expand Up @@ -1506,12 +1507,12 @@ pub fn with_gang_behavior(
project: Project,
behavior: TrackGangBehavior,
target_type_def: &TargetTypeDef,
f: impl FnOnce(GangBehavior, GroupingBehavior),
f: impl FnOnce(GangBehavior, GroupingBehavior) -> Result<(), ReaperError>,
) -> Result<(), &'static str> {
let (gang_behavior, grouping_behavior) = behavior.gang_and_grouping_behavior();
if new_set_track_ui_functions_are_available() {
// REAPER >= 6.69+dev1027 makes things much easier.
f(gang_behavior, grouping_behavior);
f(gang_behavior, grouping_behavior)?;
return Ok(());
}
use TrackGangBehavior::*;
Expand All @@ -1521,22 +1522,26 @@ pub fn with_gang_behavior(
// CSurf_OnMuteChangeEx, CSurf_OnSoloChangeEx, CSurf_OnRecArmChangeEx respect
// track grouping even when passing DenyGang. So we need to switch it off
// temporarily.
project.with_track_grouping(false, || f(gang_behavior, grouping_behavior))
project.with_track_grouping(false, || f(gang_behavior, grouping_behavior))?;
} else {
f(gang_behavior, grouping_behavior)
f(gang_behavior, grouping_behavior)?;
}
}
SelectionOnly => project.with_track_grouping(false, || f(gang_behavior, grouping_behavior)),
SelectionOnly => {
project.with_track_grouping(false, || f(gang_behavior, grouping_behavior))?;
}
GroupingOnly => {
if target_type_def.supports_track_grouping_only_gang_behavior {
// CSurf_OnMuteChangeEx, CSurf_OnSoloChangeEx, CSurf_OnRecArmChangeEx respect
// track grouping even when passing DenyGang. Perfect.
f(gang_behavior, grouping_behavior)
f(gang_behavior, grouping_behavior)?;
} else {
return Err("grouping-only is not supported for this target");
}
}
SelectionAndGrouping => f(GangBehavior::AllowGang, GroupingBehavior::UseGrouping),
SelectionAndGrouping => {
f(GangBehavior::AllowGang, GroupingBehavior::UseGrouping)?;
}
};
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions main/src/domain/targets/track_arm_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl RealearnTarget for TrackArmTarget {
|t| t.arm(false, gang_behavior, grouping_behavior),
|t| t.disarm(false, gang_behavior, grouping_behavior),
);
Ok(())
},
)?;
Ok(HitResponse::processed_with_effect())
Expand Down
1 change: 1 addition & 0 deletions main/src/domain/targets/track_monitoring_mode_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl RealearnTarget for TrackMonitoringModeTarget {
)
},
);
Ok(())
},
)?;
Ok(HitResponse::processed_with_effect())
Expand Down
1 change: 1 addition & 0 deletions main/src/domain/targets/track_mute_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl RealearnTarget for TrackMuteTarget {
|t| t.mute(gang_behavior, grouping_behavior),
|t| t.unmute(gang_behavior, grouping_behavior),
);
Ok(())
},
)?;
Ok(HitResponse::processed_with_effect())
Expand Down
3 changes: 2 additions & 1 deletion main/src/domain/targets/track_pan_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ impl RealearnTarget for TrackPanTarget {
self.gang_behavior,
&TRACK_PAN_TARGET,
|gang_behavior, grouping_behavior| {
self.track.set_pan(pan, gang_behavior, grouping_behavior);
self.track
.set_pan_smart(pan, gang_behavior, grouping_behavior)
},
)?;
Ok(HitResponse::processed_with_effect())
Expand Down
1 change: 1 addition & 0 deletions main/src/domain/targets/track_solo_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl RealearnTarget for TrackSoloTarget {
|t| t.unsolo(gang_behavior, grouping_behavior),
);
});
Ok(())
},
)?;
Ok(HitResponse::processed_with_effect())
Expand Down
4 changes: 2 additions & 2 deletions main/src/domain/targets/track_volume_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ impl RealearnTarget for TrackVolumeTarget {
self.gang_behavior,
&TRACK_VOLUME_TARGET,
|gang_behavior, grouping_behavior| {
self.track.set_volume(
self.track.set_volume_smart(
volume.unwrap_or(SliderVolume::MIN).reaper_value(),
gang_behavior,
grouping_behavior,
);
)
},
)?;
Ok(HitResponse::processed_with_effect())
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_width_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl RealearnTarget for TrackWidthTarget {
&TRACK_WIDTH_TARGET,
|gang_behavior, grouping_behavior| {
self.track
.set_width(width, gang_behavior, grouping_behavior);
.set_width_smart(width, gang_behavior, grouping_behavior)
},
)?;
Ok(HitResponse::processed_with_effect())
Expand Down
16 changes: 8 additions & 8 deletions main/src/infrastructure/proto/playtime_request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,11 @@ impl PlaytimeProtoRequestHandler {
match kind {
MatrixVolumeKind::Master => {
let project = matrix.project();
project.master_track()?.set_volume(
project.master_track()?.set_volume_smart(
db.to_linear_volume_value(),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
);
)?;
}
MatrixVolumeKind::Click => {
matrix.set_click_volume(db);
Expand All @@ -609,35 +609,35 @@ impl PlaytimeProtoRequestHandler {
.map_err(|e| Status::invalid_argument(e.to_string()))?;
self.handle_matrix_command(req.matrix_id, |matrix| {
let project = matrix.project();
project.master_track()?.set_pan(
project.master_track()?.set_pan_smart(
Pan::from_reaper_value(pan),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
);
)?;
Ok(())
})
}

pub fn set_track_volume(&self, req: SetTrackVolumeRequest) -> Result<Response<Empty>, Status> {
let db = Db::try_from(req.db).map_err(|e| Status::invalid_argument(e.to_string()))?;
self.handle_track_command(&req.track_address, |_matrix, track| {
track.set_volume(
track.set_volume_smart(
db.to_linear_volume_value(),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
);
)?;
Ok(())
})
}

pub fn set_track_pan(&self, req: SetTrackPanRequest) -> Result<Response<Empty>, Status> {
let pan = ReaperPanValue::new_panic(req.pan.clamp(-1.0, 1.0));
self.handle_track_command(&req.track_address, |_matrix, track| {
track.set_pan(
track.set_pan_smart(
Pan::from_reaper_value(pan),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
);
)?;
Ok(())
})
}
Expand Down

0 comments on commit c152350

Please sign in to comment.