Skip to content

Commit

Permalink
#161 Display instance track name if pinned
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Jun 19, 2022
1 parent 76d2fcc commit 31f0da2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
54 changes: 36 additions & 18 deletions main/src/application/target_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2409,17 +2409,7 @@ impl<'a> TargetModelFormatMultiLine<'a> {
None => return TARGET_UNDEFINED_LABEL.into(),
Some(t) => t,
};
use VirtualTrack::*;
match virtual_track {
ById(_) | ByIdOrName(_, _) => {
if let Ok(t) = self.target_with_context().first_effective_track() {
get_track_label(&t)
} else {
get_non_present_virtual_track_label(virtual_track)
}
}
_ => virtual_track.to_string(),
}
get_virtual_track_label(virtual_track, self.compartment, self.context)
}

fn route_label(&self) -> Cow<str> {
Expand Down Expand Up @@ -2733,17 +2723,27 @@ impl<'a> TargetModelWithContext<'a> {
}

pub fn first_effective_track(&self) -> Result<Track, &'static str> {
self.target
let virtual_track = self
.target
.virtual_track()
.ok_or("virtual track not complete")?
.resolve(self.context, self.compartment)
.map_err(|_| "particular track couldn't be resolved")?
.into_iter()
.next()
.ok_or("resolved to empty track list")
.ok_or("virtual track not complete")?;
first_effective_track(&virtual_track, self.compartment, self.context)
}
}

pub fn first_effective_track(
virtual_track: &VirtualTrack,
compartment: Compartment,
context: ExtendedProcessorContext,
) -> Result<Track, &'static str> {
virtual_track
.resolve(context, compartment)
.map_err(|_| "particular track couldn't be resolved")?
.into_iter()
.next()
.ok_or("resolved to empty track list")
}

pub fn get_bookmark_label_by_id(bookmark_type: BookmarkType, id: BookmarkId, name: &str) -> String {
format!(
"{} {}. {}",
Expand Down Expand Up @@ -3643,6 +3643,24 @@ impl<'a> ResolvedConcreteFxInstruction<'a> {

const TARGET_UNDEFINED_LABEL: &str = "<Undefined>";

pub fn get_virtual_track_label(
virtual_track: &VirtualTrack,
compartment: Compartment,
context: ExtendedProcessorContext,
) -> String {
use VirtualTrack::*;
match virtual_track {
ById(_) | ByIdOrName(_, _) => {
if let Ok(t) = first_effective_track(virtual_track, compartment, context) {
get_track_label(&t)
} else {
get_non_present_virtual_track_label(virtual_track)
}
}
_ => virtual_track.to_string(),
}
}

fn get_track_label(track: &Track) -> String {
match track.location() {
TrackLocation::MasterTrack => "<Master track>".into(),
Expand Down
8 changes: 7 additions & 1 deletion main/src/domain/targets/track_tool_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ impl RealearnTarget for TrackToolTarget {
}
TrackToolAction::PinAsInstanceTrack => {
let track = self.track.as_ref().ok_or("track could not be resolved")?;
InstanceTrackChangeRequestedEvent::Pin(*track.guid())
if track.is_master_track() {
InstanceTrackChangeRequestedEvent::SetFromMapping(
context.mapping_data.qualified_mapping_id(),
)
} else {
InstanceTrackChangeRequestedEvent::Pin(*track.guid())
}
}
};
let instruction = UpdateInstanceTrack { event };
Expand Down
15 changes: 12 additions & 3 deletions main/src/infrastructure/ui/main_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use reaper_high::{AvailablePanValue, ChangeEvent, Guid, OrCurrentProject, Reaper
use slog::debug;
use std::cell::{Cell, RefCell};

use crate::application::{Affected, CompartmentProp, Session, SessionProp, SessionUi, WeakSession};
use crate::application::{
get_virtual_track_label, Affected, CompartmentProp, Session, SessionProp, SessionUi,
WeakSession,
};
use crate::base::when;
use crate::domain::{
Compartment, MappingId, MappingMatchedEvent, PanExt, ProjectionFeedbackValue,
Expand Down Expand Up @@ -151,9 +154,15 @@ impl MainPanel {
let scroll_status = state.scroll_status.get_ref();
let tags = session.tags.get_ref();
let instance_state = session.instance_state().borrow();
let instance_track = instance_state.instance_track();
let instance_track_label = get_virtual_track_label(
instance_track,
Compartment::Main,
session.extended_context(),
);
let mut text = format!(
"Track: {} | Showing mappings {} to {} of {}",
instance_state.instance_track(),
"Track: {:.20} | Showing mappings {} to {} of {}",
instance_track_label,
scroll_status.from_pos,
scroll_status.to_pos,
scroll_status.item_count
Expand Down

0 comments on commit 31f0da2

Please sign in to comment.