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.
This commit is contained in:
Paul Davis 2023-09-24 18:38:20 -06:00
parent 61d8ceaa85
commit 1f13b311fd
3 changed files with 14 additions and 7 deletions

View File

@ -1740,17 +1740,21 @@ MidiRegionView::start_playing_midi_chord (vector<std::shared_ptr<NoteType> > not
player->play ();
}
bool
MidiRegionView::note_in_region_time_range (const std::shared_ptr<NoteType> note) const
{
const std::shared_ptr<ARDOUR::MidiRegion> 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<NoteType> note, bool& visible) const
{
const std::shared_ptr<ARDOUR::MidiRegion> 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;
}

View File

@ -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<NoteType> 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<NoteType> note) const;
/** Get the region position in pixels relative to session. */
double get_position_pixels();

View File

@ -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<MidiRegionView*> (&parent_rv);
if (mrv->note_in_region_time_range (nb->note())) {
set_size_and_position (*event);
} else {
l->hide();
}
}
}