From 1f13b311fdfdcb21f46562a52ca389b64ba7c9a4 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 24 Sep 2023 18:38:20 -0600 Subject: [PATCH] midi display: ensure that lollipops are visible right after import VelocityGhostRegion used the visibility of the "parent" note canvas item of a lollipop canvas item to determine the lolli's visibility. But during the construction of the MidiRegionView, the note's container is not yet visible, so this fails. In addition this logic would hide lollis for notes that are outside the current visible note range of the track (because the parent note item was not visible). This change adds a method to MidiRegionView to decide if a note is within the region's time range, and if so, we show the lollipop item. This means that lollis for notes outside the note-range will still be visible, which seems more correct. In addition, the nascent condition of the parent note's container no longer affects lolli visibility. --- gtk2_ardour/midi_region_view.cc | 12 ++++++++---- gtk2_ardour/midi_region_view.h | 2 ++ gtk2_ardour/velocity_ghost_region.cc | 7 ++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 8a10b95ec7..7e1106c6d6 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -1740,17 +1740,21 @@ MidiRegionView::start_playing_midi_chord (vector > not player->play (); } +bool +MidiRegionView::note_in_region_time_range (const std::shared_ptr note) const +{ + const std::shared_ptr midi_reg = midi_region(); + return (timepos_t (note->time()) >= _region->start()) && (timepos_t (note->time()) < _region->start() + _region->length()); +} bool MidiRegionView::note_in_region_range (const std::shared_ptr note, bool& visible) const { const std::shared_ptr midi_reg = midi_region(); - /* must compare double explicitly as Beats::operator< rounds to ppqn */ - const bool outside = (timepos_t (note->time()) < _region->start()) || (timepos_t (note->time()) >= _region->start() + _region->length()); + const bool outside = !note_in_region_time_range (note); - visible = (note->note() >= _current_range_min) && - (note->note() <= _current_range_max); + visible = (note->note() >= _current_range_min) && (note->note() <= _current_range_max); return !outside; } diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 5e3ffaeacf..b61443f767 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -234,6 +234,8 @@ public: * @return true iff the note is within the (time) extent of the region. */ bool note_in_region_range(const std::shared_ptr note, bool& visible) const; + /* Test if a note is withing this region's time range. Return true if so */ + bool note_in_region_time_range(const std::shared_ptr note) const; /** Get the region position in pixels relative to session. */ double get_position_pixels(); diff --git a/gtk2_ardour/velocity_ghost_region.cc b/gtk2_ardour/velocity_ghost_region.cc index c3b6972554..d4bac1048d 100644 --- a/gtk2_ardour/velocity_ghost_region.cc +++ b/gtk2_ardour/velocity_ghost_region.cc @@ -138,10 +138,11 @@ VelocityGhostRegion::add_note (NoteBase* nb) MidiStreamView* mv = midi_view(); if (mv) { - if (!nb->item()->visible()) { - l->hide(); - } else { + MidiRegionView* mrv = dynamic_cast (&parent_rv); + if (mrv->note_in_region_time_range (nb->note())) { set_size_and_position (*event); + } else { + l->hide(); } } }