From c3f40aedeb4268b57fea147e906c31b56a4e397c Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 25 Jun 2022 22:26:34 -0600 Subject: [PATCH] tempodisplay: fix thinko in display of tempo/meter/bartime markers Code used to just push back new markers to the end of the relevant list, and this would then the new marker to be deleted soon thereafter. Instead pass an interator indicating where to place the marker in the list. Note that we rely on the use of std::list here to keep the iterator to the existing marker valid. --- gtk2_ardour/editor.h | 6 +++--- gtk2_ardour/editor_tempodisplay.cc | 30 +++++++++++++++++------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index ba68e419f1..c670014c2e 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1858,9 +1858,9 @@ private: void reassociate_metric_markers (Temporal::TempoMap::SharedPtr const &); void reassociate_metric_marker (Temporal::TempoMap::SharedPtr const & tmap, Temporal::TempoMap::Metrics & metric, MetricMarker& marker); - void make_bbt_marker (Temporal::MusicTimePoint const *); - void make_meter_marker (Temporal::MeterPoint const *); - void make_tempo_marker (Temporal::TempoPoint const * ts, double& min_tempo, double& max_tempo, Temporal::TempoPoint const *& prev_ts, uint32_t tc_color, samplecnt_t sr); + void make_bbt_marker (Temporal::MusicTimePoint const *, Marks::iterator before); + void make_meter_marker (Temporal::MeterPoint const *, Marks::iterator before); + void make_tempo_marker (Temporal::TempoPoint const * ts, double& min_tempo, double& max_tempo, Temporal::TempoPoint const *& prev_ts, uint32_t tc_color, samplecnt_t sr3, Marks::iterator before); void update_tempo_curves (double min_tempo, double max_tempo, samplecnt_t sr); void tempo_map_changed (); diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index 03b856539f..8af7aee33d 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -162,22 +162,22 @@ Editor::reassociate_metric_marker (TempoMap::SharedPtr const & tmap, TempoMap::M } void -Editor::make_bbt_marker (MusicTimePoint const * mtp) +Editor::make_bbt_marker (MusicTimePoint const * mtp, Marks::iterator before) { - bbt_marks.push_back (new BBTMarker (*this, *bbt_ruler, UIConfiguration::instance().color ("meter marker"), *mtp)); + bbt_marks.insert (before, new BBTMarker (*this, *bbt_ruler, UIConfiguration::instance().color ("meter marker"), *mtp)); } void -Editor::make_meter_marker (Temporal::MeterPoint const * ms) +Editor::make_meter_marker (Temporal::MeterPoint const * ms, Marks::iterator before) { char buf[64]; snprintf (buf, sizeof(buf), "%d/%d", ms->divisions_per_bar(), ms->note_value ()); - meter_marks.push_back (new MeterMarker (*this, *meter_group, UIConfiguration::instance().color ("meter marker"), buf, *ms)); + meter_marks.insert (before, new MeterMarker (*this, *meter_group, UIConfiguration::instance().color ("meter marker"), buf, *ms)); } void -Editor::make_tempo_marker (Temporal::TempoPoint const * ts, double& min_tempo, double& max_tempo, TempoPoint const *& prev_ts, uint32_t tc_color, samplecnt_t sr) +Editor::make_tempo_marker (Temporal::TempoPoint const * ts, double& min_tempo, double& max_tempo, TempoPoint const *& prev_ts, uint32_t tc_color, samplecnt_t sr, Marks::iterator before) { max_tempo = max (max_tempo, ts->note_types_per_minute()); max_tempo = max (max_tempo, ts->end_note_types_per_minute()); @@ -187,7 +187,7 @@ Editor::make_tempo_marker (Temporal::TempoPoint const * ts, double& min_tempo, d const std::string tname (X_("")); char const * color_name = X_("tempo marker"); - tempo_marks.push_back (new TempoMarker (*this, *tempo_group, UIConfiguration::instance().color (color_name), tname, *ts, ts->sample (sr), tc_color)); + tempo_marks.insert (before, new TempoMarker (*this, *tempo_group, UIConfiguration::instance().color (color_name), tname, *ts, ts->sample (sr), tc_color)); /* XXX the point of this code was "a jump in tempo by more than 1 ntpm results in a red tempo mark pointer." (3a7bc1fd3f32f0) @@ -236,10 +236,13 @@ Editor::draw_tempo_marks () continue; } + /* catch BBT position elements that are both tempo & meter points */ + Temporal::Point const & mark_point ((*mm)->point()); if (mark_point.sclock() < metric_point.sclock()) { + /* advance through markers, deleting the unused ones */ delete *mm; @@ -248,7 +251,7 @@ Editor::draw_tempo_marks () } else if (metric_point.sclock() < mark_point.sclock()) { - make_tempo_marker (&metric_point, min_tempo, max_tempo, prev_ts, tc_color, sr); + make_tempo_marker (&metric_point, min_tempo, max_tempo, prev_ts, tc_color, sr, mm); ++t; } else { @@ -274,12 +277,12 @@ Editor::draw_tempo_marks () } } - if ((mm == tempo_marks.end()) && (t != tempi.end())) { + if ((mm == tempo_marks.end())) { while (t != tempi.end()) { if (!dynamic_cast (&(*t))) { - make_tempo_marker (&*t, min_tempo, max_tempo, prev_ts, tc_color, sr); + make_tempo_marker (&*t, min_tempo, max_tempo, prev_ts, tc_color, sr, tempo_marks.end()); } ++t; @@ -321,7 +324,7 @@ Editor::draw_meter_marks () } else if (metric_point.sclock() < mark_point.sclock()) { - make_meter_marker (&metric_point); + make_meter_marker (&metric_point, mm); ++m; } else { @@ -346,7 +349,7 @@ Editor::draw_meter_marks () while (m != meters.end()) { if (!dynamic_cast (&(*m))) { - make_meter_marker (&*m); + make_meter_marker (&*m, meter_marks.end()); } ++m; @@ -380,7 +383,7 @@ Editor::draw_bbt_marks () } else if (metric_point.sclock() < mark_point.sclock()) { - make_bbt_marker (&metric_point); + make_bbt_marker (&metric_point, mm); ++m; } else { @@ -402,7 +405,7 @@ Editor::draw_bbt_marks () if ((mm == bbt_marks.end()) && (m != bartimes.end())) { while (m != bartimes.end()) { - make_bbt_marker (&*m); + make_bbt_marker (&*m, bbt_marks.end()); ++m; } } @@ -449,6 +452,7 @@ void Editor::tempo_map_changed () { TempoMap::SharedPtr current_map = TempoMap::fetch (); + /* If the tempo map was changed by something other than the Editor, we * will need to reassociate all visual elements used for tempo display * with the new map.