Skip to content

Commit

Permalink
#1366 Add selection and group ganging options to track automation tou…
Browse files Browse the repository at this point in the history
…ch state target
  • Loading branch information
helgoboss committed Dec 28, 2024
1 parent 996619b commit 7018de3
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 13 deletions.
4 changes: 4 additions & 0 deletions api/src/persistence/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ pub struct TrackAutomationTouchStateTarget {
pub track: Option<TrackDescriptor>,
#[serde(skip_serializing_if = "Option::is_none")]
pub exclusivity: Option<TrackExclusivity>,
#[serde(skip_serializing_if = "Option::is_none")]
pub use_track_grouping: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub use_selection_ganging: Option<bool>,
pub touched_parameter: TouchedTrackParameter,
}

Expand Down
1 change: 1 addition & 0 deletions main/src/application/target_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,7 @@ impl TargetModel {
track_descriptor: self.track_descriptor()?,
parameter_type: self.touched_track_parameter_type,
exclusivity: self.track_exclusivity,
gang_behavior: self.fixed_gang_behavior(),
})
}
GoToBookmark => {
Expand Down
15 changes: 10 additions & 5 deletions main/src/domain/realearn_target_context.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::domain::{
AdditionalFeedbackEvent, FxSnapshotLoadedEvent, ParameterAutomationTouchStateChangedEvent,
TouchedTrackParameterType,
TouchedTrackParameterType, TrackGangBehavior,
};
use base::hash_util::{NonCryptoHashMap, NonCryptoHashSet};
use base::{NamedChannelSender, SenderToNormalThread};
use reaper_high::{Fx, Track, TrackSetSmartOpts};
use reaper_medium::{GangBehavior, MediaTrack, NotificationBehavior, ValueChange};
use reaper_medium::MediaTrack;

/// 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 @@ -105,13 +105,14 @@ impl RealearnTargetState {
&mut self,
track: &Track,
parameter_type: TouchedTrackParameterType,
gang_behavior: TrackGangBehavior,
) {
let Ok(raw_track) = track.raw() else {
return;
};
self.touched_things
.insert(TouchedThing::new(raw_track, parameter_type));
self.post_process_touch(track, parameter_type, true);
self.post_process_touch(track, parameter_type, gang_behavior, true);
self.additional_feedback_event_sender.send_complaining(
AdditionalFeedbackEvent::ParameterAutomationTouchStateChanged(
ParameterAutomationTouchStateChangedEvent {
Expand All @@ -127,13 +128,14 @@ impl RealearnTargetState {
&mut self,
track: &Track,
parameter_type: TouchedTrackParameterType,
gang_behavior: TrackGangBehavior,
) {
let Ok(raw_track) = track.raw() else {
return;
};
self.touched_things
.remove(&TouchedThing::new(raw_track, parameter_type));
self.post_process_touch(track, parameter_type, false);
self.post_process_touch(track, parameter_type, gang_behavior, false);
self.additional_feedback_event_sender.send_complaining(
AdditionalFeedbackEvent::ParameterAutomationTouchStateChanged(
ParameterAutomationTouchStateChangedEvent {
Expand All @@ -149,11 +151,14 @@ impl RealearnTargetState {
&mut self,
track: &Track,
parameter_type: TouchedTrackParameterType,
gang_behavior: TrackGangBehavior,
touched: bool,
) {
let (gang_behavior, grouping_behavior) = gang_behavior.gang_and_grouping_behavior();
let opts = TrackSetSmartOpts {
grouping_behavior,
gang_behavior,
done: !touched,
..Default::default()
};
match parameter_type {
TouchedTrackParameterType::Volume => {
Expand Down
23 changes: 16 additions & 7 deletions main/src/domain/targets/track_touch_state_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::domain::{
AdditionalFeedbackEvent, Backbone, CompartmentKind, CompoundChangeEvent, ControlContext,
ExtendedProcessorContext, HitResponse, MappingControlContext, RealearnTarget, ReaperTarget,
ReaperTargetType, TargetCharacter, TargetSection, TargetTypeDef, TrackDescriptor,
TrackExclusivity, UnresolvedReaperTargetDef, DEFAULT_TARGET,
TrackExclusivity, TrackGangBehavior, UnresolvedReaperTargetDef, DEFAULT_TARGET,
};
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, Target, UnitValue};
use reaper_high::{Project, Track};
Expand All @@ -16,6 +16,7 @@ pub struct UnresolvedTrackTouchStateTarget {
pub track_descriptor: TrackDescriptor,
pub parameter_type: TouchedTrackParameterType,
pub exclusivity: TrackExclusivity,
pub gang_behavior: TrackGangBehavior,
}

impl UnresolvedReaperTargetDef for UnresolvedTrackTouchStateTarget {
Expand All @@ -32,6 +33,7 @@ impl UnresolvedReaperTargetDef for UnresolvedTrackTouchStateTarget {
track,
parameter_type: self.parameter_type,
exclusivity: self.exclusivity,
gang_behavior: self.gang_behavior,
})
})
.collect(),
Expand All @@ -48,6 +50,7 @@ pub struct TrackTouchStateTarget {
pub track: Track,
pub parameter_type: TouchedTrackParameterType,
pub exclusivity: TrackExclusivity,
pub gang_behavior: TrackGangBehavior,
}

impl RealearnTarget for TrackTouchStateTarget {
Expand All @@ -70,14 +73,18 @@ impl RealearnTarget for TrackTouchStateTarget {
self.exclusivity,
value.to_unit_value()?,
|t| {
target_context
.borrow_mut()
.touch_automation_parameter(t, self.parameter_type)
target_context.borrow_mut().touch_automation_parameter(
t,
self.parameter_type,
self.gang_behavior,
)
},
|t| {
target_context
.borrow_mut()
.untouch_automation_parameter(t, self.parameter_type)
target_context.borrow_mut().untouch_automation_parameter(
t,
self.parameter_type,
self.gang_behavior,
)
},
);
Ok(HitResponse::processed_with_effect())
Expand Down Expand Up @@ -149,6 +156,8 @@ pub const TRACK_TOUCH_STATE_TARGET: TargetTypeDef = TargetTypeDef {
short_name: "Track touch state",
supports_track: true,
supports_track_exclusivity: true,
supports_gang_selected: true,
supports_gang_grouping: true,
..DEFAULT_TARGET
};

Expand Down
8 changes: 8 additions & 0 deletions main/src/infrastructure/api/convert/from_data/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ fn convert_real_target(
style,
),
exclusivity: convert_track_exclusivity(data.track_exclusivity),
use_track_grouping: style.optional_value_with_default(
data.use_track_grouping,
defaults::TARGET_USE_TRACK_GROUPING,
),
use_selection_ganging: style.optional_value_with_default(
data.use_selection_ganging,
defaults::TARGET_USE_SELECTION_GANGING,
),
touched_parameter: {
use persistence::TouchedTrackParameter as T;
use TouchedTrackParameterType::*;
Expand Down
8 changes: 8 additions & 0 deletions main/src/infrastructure/api/convert/to_data/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ pub fn convert_target(t: Target) -> ConversionResult<TargetModelData> {
enable_only_if_track_is_selected: track_desc.track_must_be_selected,
clip_column: track_desc.clip_column.unwrap_or_default(),
track_exclusivity: convert_track_exclusivity(d.exclusivity),
use_track_grouping: Some(
d.use_track_grouping
.unwrap_or(defaults::TARGET_USE_TRACK_GROUPING),
),
use_selection_ganging: Some(
d.use_selection_ganging
.unwrap_or(defaults::TARGET_USE_SELECTION_GANGING),
),
touched_parameter_type: {
use domain::TouchedTrackParameterType as T;
use TouchedTrackParameter::*;
Expand Down
2 changes: 1 addition & 1 deletion 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, TrackSetSmartOpts};
use reaper_high::{GroupingBehavior, Guid, Track, TrackSetSmartOpts};
use reaper_medium::{Bpm, Db, GangBehavior, PlaybackSpeedFactor, ReaperPanValue, SoloMode};
use tonic::{Response, Status};

Expand Down

0 comments on commit 7018de3

Please sign in to comment.