From 60e522f4ee7d39965ebc5c41c5ab15c2fe51768a Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Mon, 22 Nov 2021 16:52:39 -0600 Subject: [PATCH] MIDI Program Changes: Fix some thinkos in patch-change flag locations Program Changes are stored as an offset from the 'source' start, and must be translated to/from region time. Better locating of patches wrt the grid: You can't assume time_to_pixel is steady across the timeline * calculate position of the patch-change flag * calculate region start position, and set flag's x offset from there also: consolidate patch-location code into display_patch_changes() --- gtk2_ardour/midi_region_view.cc | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 90e8bf40d2..9f58acb5b7 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -1250,12 +1250,15 @@ MidiRegionView::display_patch_changes_on_channel (uint8_t channel, bool active_c if ((p = find_canvas_patch_change (*i)) != 0) { const timepos_t region_time = _region->source_beats_to_region_time ((*i)->time()); - if (region_time < timepos_t() || region_time >= _region->length()) { p->hide(); } else { - const double x = trackview.editor().time_to_pixel (region_time); - p->canvas_item()->set_position (ArdourCanvas::Duple (x, 1.0)); + const timepos_t flag_time = _region->source_beats_to_absolute_time ((*i)->time()); + const double flag_x = trackview.editor().time_to_pixel (flag_time); + + const double region_x = trackview.editor().time_to_pixel (_region->position()); + + p->canvas_item()->set_position (ArdourCanvas::Duple (flag_x-region_x, 1.0)); p->update_name (); p->show(); @@ -1861,9 +1864,7 @@ MidiRegionView::step_sustain (Temporal::Beats beats) void MidiRegionView::add_canvas_patch_change (MidiModel::PatchChangePtr patch) { - timepos_t patch_time = _region->source_beats_to_absolute_time (patch->time()); - const double x = trackview.editor().time_to_pixel (patch_time); - + const double x = 0; double const height = midi_stream_view()->contents_height(); // CAIROCANVAS: active_channel info removed from PatcChange constructor @@ -1879,18 +1880,9 @@ MidiRegionView::add_canvas_patch_change (MidiModel::PatchChangePtr patch) _patch_change_fill) ); - if (patch_change->item().width() < _pixel_width) { - // Show unless patch change is beyond the region bounds - if (patch_time < _region->position() || patch_time >= _region->nt_last()) { - patch_change->hide(); - } else { - patch_change->show(); - } - } else { - patch_change->hide (); - } - _patch_changes.insert (make_pair (patch, patch_change)); + + display_patch_changes(); } void