Skip to content

Commit

Permalink
#1366 Fix laggy "Track: Set automation touch state" when combined wit…
Browse files Browse the repository at this point in the history
…h volume/pan/width target
  • Loading branch information
helgoboss committed Dec 28, 2024
1 parent 431448f commit 996619b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 64 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

44 changes: 16 additions & 28 deletions main/src/domain/realearn_target_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::domain::{
};
use base::hash_util::{NonCryptoHashMap, NonCryptoHashSet};
use base::{NamedChannelSender, SenderToNormalThread};
use reaper_high::{Fx, Track};
use reaper_high::{Fx, Track, TrackSetSmartOpts};
use reaper_medium::{GangBehavior, MediaTrack, NotificationBehavior, ValueChange};

/// Feedback for most targets comes from REAPER itself but there are some targets for which ReaLearn
Expand Down Expand Up @@ -111,7 +111,7 @@ impl RealearnTargetState {
};
self.touched_things
.insert(TouchedThing::new(raw_track, parameter_type));
self.post_process_touch(track, parameter_type);
self.post_process_touch(track, parameter_type, true);
self.additional_feedback_event_sender.send_complaining(
AdditionalFeedbackEvent::ParameterAutomationTouchStateChanged(
ParameterAutomationTouchStateChangedEvent {
Expand All @@ -133,7 +133,7 @@ impl RealearnTargetState {
};
self.touched_things
.remove(&TouchedThing::new(raw_track, parameter_type));
self.post_process_touch(track, parameter_type);
self.post_process_touch(track, parameter_type, false);
self.additional_feedback_event_sender.send_complaining(
AdditionalFeedbackEvent::ParameterAutomationTouchStateChanged(
ParameterAutomationTouchStateChangedEvent {
Expand All @@ -145,37 +145,25 @@ impl RealearnTargetState {
);
}

fn post_process_touch(&mut self, track: &Track, parameter_type: TouchedTrackParameterType) {
fn post_process_touch(
&mut self,
track: &Track,
parameter_type: TouchedTrackParameterType,
touched: bool,
) {
let opts = TrackSetSmartOpts {
done: !touched,
..Default::default()
};
match parameter_type {
TouchedTrackParameterType::Volume => {
let resulting_value = track.csurf_on_volume_change_ex(
ValueChange::Absolute(track.volume()),
GangBehavior::DenyGang,
);
if let Ok(v) = resulting_value {
let _ = track.csurf_set_surface_volume(v, NotificationBehavior::NotifyAll);
}
let _ = track.set_volume_smart(track.volume(), opts);
}
TouchedTrackParameterType::Pan => {
let resulting_value = track.csurf_on_pan_change_ex(
ValueChange::Absolute(track.pan().reaper_value()),
GangBehavior::DenyGang,
);
if let Ok(v) = resulting_value {
let _ = track.csurf_set_surface_pan(v, NotificationBehavior::NotifyAll);
}
let _ = track.set_pan_smart(track.pan().reaper_value(), opts);
}
TouchedTrackParameterType::Width => {
let result = track.csurf_on_width_change_ex(
ValueChange::Absolute(track.width().reaper_value()),
GangBehavior::DenyGang,
);
if result.is_ok() {
let _ = track.csurf_set_surface_pan(
track.pan().reaper_value(),
NotificationBehavior::NotifyAll,
);
}
let _ = track.set_width_smart(track.width().reaper_value(), opts);
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions main/src/domain/targets/track_pan_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use helgoboss_learn::{
AbsoluteValue, ControlType, ControlValue, NumericValue, PropValue, Target, UnitValue,
BASE_EPSILON,
};
use reaper_high::{AvailablePanValue, ChangeEvent, Pan, PanExt, Project, Track};
use reaper_high::{AvailablePanValue, ChangeEvent, Pan, PanExt, Project, Track, TrackSetSmartOpts};
use std::borrow::Cow;

#[derive(Debug)]
Expand Down Expand Up @@ -104,8 +104,15 @@ impl RealearnTarget for TrackPanTarget {
self.gang_behavior,
&TRACK_PAN_TARGET,
|gang_behavior, grouping_behavior| {
self.track
.set_pan_smart(pan, gang_behavior, grouping_behavior)
self.track.set_pan_smart(
pan.reaper_value(),
TrackSetSmartOpts {
gang_behavior,
grouping_behavior,
// Important because we don't want undo points for each little fader movement!
done: false,
},
)
},
)?;
Ok(HitResponse::processed_with_effect())
Expand Down
10 changes: 7 additions & 3 deletions main/src/domain/targets/track_volume_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::domain::{
TrackGangBehavior, UnresolvedReaperTargetDef, DEFAULT_TARGET,
};
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, NumericValue, Target, UnitValue};
use reaper_high::{ChangeEvent, Project, SliderVolume, Track};
use reaper_high::{ChangeEvent, Project, SliderVolume, Track, TrackSetSmartOpts};
use std::borrow::Cow;

#[derive(Debug)]
Expand Down Expand Up @@ -89,8 +89,12 @@ impl RealearnTarget for TrackVolumeTarget {
|gang_behavior, grouping_behavior| {
self.track.set_volume_smart(
volume.unwrap_or(SliderVolume::MIN).reaper_value(),
gang_behavior,
grouping_behavior,
TrackSetSmartOpts {
gang_behavior,
grouping_behavior,
// Important because we don't want undo points for each little fader movement!
done: false,
},
)
},
)?;
Expand Down
15 changes: 12 additions & 3 deletions main/src/domain/targets/track_width_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::domain::{
use helgoboss_learn::{
AbsoluteValue, ControlType, ControlValue, NumericValue, PropValue, Target, UnitValue,
};
use reaper_high::{AvailablePanValue, ChangeEvent, PanExt, Project, Track, Width};
use reaper_high::{
AvailablePanValue, ChangeEvent, PanExt, Project, Track, TrackSetSmartOpts, Width,
};
use std::borrow::Cow;

#[derive(Debug)]
Expand Down Expand Up @@ -103,8 +105,15 @@ impl RealearnTarget for TrackWidthTarget {
self.gang_behavior,
&TRACK_WIDTH_TARGET,
|gang_behavior, grouping_behavior| {
self.track
.set_width_smart(width, gang_behavior, grouping_behavior)
self.track.set_width_smart(
width.reaper_value(),
TrackSetSmartOpts {
gang_behavior,
grouping_behavior,
// Important because we don't want undo points for each little fader movement!
done: false,
},
)
},
)?;
Ok(HitResponse::processed_with_effect())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::base::notification;
use reaper_low::firewall;
use std::sync;

use crate::domain::{ParameterManager, PluginParamIndex};
Expand Down
25 changes: 7 additions & 18 deletions main/src/infrastructure/proto/playtime_request_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Context;
use reaper_high::{GroupingBehavior, Guid, Pan, Track};
use reaper_high::{GroupingBehavior, Guid, Pan, Track, TrackSetSmartOpts};
use reaper_medium::{Bpm, Db, GangBehavior, PlaybackSpeedFactor, ReaperPanValue, SoloMode};
use tonic::{Response, Status};

Expand Down Expand Up @@ -589,8 +589,7 @@ impl PlaytimeProtoRequestHandler {
let project = matrix.project();
project.master_track()?.set_volume_smart(
db.to_linear_volume_value(),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
TrackSetSmartOpts::default(),
)?;
}
MatrixVolumeKind::Click => {
Expand All @@ -609,35 +608,25 @@ 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_smart(
Pan::from_reaper_value(pan),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
)?;
project
.master_track()?
.set_pan_smart(pan, TrackSetSmartOpts::default())?;
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_smart(
db.to_linear_volume_value(),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
)?;
track.set_volume_smart(db.to_linear_volume_value(), TrackSetSmartOpts::default())?;
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_smart(
Pan::from_reaper_value(pan),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
)?;
track.set_pan_smart(pan, TrackSetSmartOpts::default())?;
Ok(())
})
}
Expand Down

0 comments on commit 996619b

Please sign in to comment.