Skip to content

Commit

Permalink
#252 Add menu action to make targets of all listed mappings use unit …
Browse files Browse the repository at this point in the history
…track and FX
  • Loading branch information
helgoboss committed Aug 14, 2024
1 parent 60627a6 commit e508c6b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 15 deletions.
20 changes: 20 additions & 0 deletions main/src/application/mapping_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,26 @@ impl MappingModel {
}
}

pub fn make_target_use_unit_track_and_fx(
&mut self,
context: ExtendedProcessorContext,
) -> Option<Affected<MappingProp>> {
let compartment = self.compartment();
let target = &mut self.target_model;
match target.category() {
TargetCategory::Reaper => {
if target.supports_track() {
let _ = target.set_virtual_track(VirtualTrack::Unit, Some(context.context()));
}
if target.supports_fx() {
let _ = target.set_virtual_fx(VirtualFx::Unit, context, compartment);
}
}
TargetCategory::Virtual => {}
}
Some(Affected::Multiple)
}

pub fn make_target_sticky(
&mut self,
context: ExtendedProcessorContext,
Expand Down
68 changes: 53 additions & 15 deletions main/src/infrastructure/ui/header_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,21 +395,30 @@ impl HeaderPanel {
disabled_item("Paste mappings (replace all in group)")
}
},
item(
"Auto-name listed mappings",
MainMenuAction::AutoNameListedMappings,
),
item(
"Name listed mappings after source",
MainMenuAction::NameListedMappingsAfterSource,
),
item(
"Make sources of all main mappings virtual",
MainMenuAction::MakeSourcesOfMainMappingsVirtual,
),
item(
"Make targets of listed mappings sticky",
MainMenuAction::MakeTargetsOfListedMappingsSticky,
menu(
"Modify multiple mappings",
vec![
item(
"Auto-name listed mappings",
MainMenuAction::AutoNameListedMappings,
),
item(
"Name listed mappings after source",
MainMenuAction::NameListedMappingsAfterSource,
),
item(
"Make sources of all main mappings virtual",
MainMenuAction::MakeSourcesOfMainMappingsVirtual,
),
item(
"Make targets of listed mappings sticky",
MainMenuAction::MakeTargetsOfListedMappingsSticky,
),
item(
"Make targets of listed mappings use the unit track and unit FX",
MainMenuAction::MakeTargetsOfListedMappingsUseUnitTrackAndFx,
),
],
),
menu(
"Move listed mappings to group",
Expand Down Expand Up @@ -727,6 +736,9 @@ impl HeaderPanel {
MainMenuAction::MakeTargetsOfListedMappingsSticky => {
self.make_targets_of_listed_mappings_sticky()
}
MainMenuAction::MakeTargetsOfListedMappingsUseUnitTrackAndFx => {
self.make_targets_of_listed_mappings_use_unit_track_and_fx();
}
MainMenuAction::MoveListedMappingsToGroup(group_id) => {
let _ = self.move_listed_mappings_to_group(group_id);
}
Expand Down Expand Up @@ -1025,6 +1037,31 @@ impl HeaderPanel {
}
}

fn make_targets_of_listed_mappings_use_unit_track_and_fx(&self) {
let compartment = self.active_compartment();
let listed_mappings = self.get_listened_mappings(compartment);
if listed_mappings.is_empty() {
return;
}
if !self.view.require_window().confirm(
"ReaLearn",
format!(
"This will change the targets of {} mappings refer to the unit track / unit FX, wherever applicable. Do you really want to continue?",
listed_mappings.len()
),
) {
return;
}
let session = self.session();
let mut session = session.borrow_mut();
let context = session.extended_context();
for m in &listed_mappings {
let mut m = m.borrow_mut();
m.make_target_use_unit_track_and_fx(context);
}
session.notify_compartment_has_changed(compartment, self.session.clone());
}

fn move_listed_mappings_to_group(&self, group_id: Option<GroupId>) -> Result<(), &'static str> {
let group_id = group_id
.or_else(|| self.add_group_internal().ok())
Expand Down Expand Up @@ -2985,6 +3022,7 @@ enum MainMenuAction {
AutoNameListedMappings,
NameListedMappingsAfterSource,
MakeTargetsOfListedMappingsSticky,
MakeTargetsOfListedMappingsUseUnitTrackAndFx,
MakeSourcesOfMainMappingsVirtual,
MoveListedMappingsToGroup(Option<GroupId>),
PasteReplaceAllInGroup(Envelope<Vec<MappingModelData>>),
Expand Down

0 comments on commit e508c6b

Please sign in to comment.