From 0d89bc578912e51f3851e92d12663af40e73622c Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 31 Aug 2023 18:25:18 -0600 Subject: [PATCH] fix height of tempo ruler curve elements These were being drawn in a way that failed to really convey relative tempos very well. This is now better, though perhaps there are other improvements possible --- gtk2_ardour/editor.h | 3 +- gtk2_ardour/editor_tempodisplay.cc | 65 ++++++++++++++---------------- gtk2_ardour/public_editor.h | 2 + gtk2_ardour/tempo_curve.cc | 4 +- gtk2_ardour/tempo_curve.h | 3 +- 5 files changed, 38 insertions(+), 39 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 926f0f8fc1..676c918d80 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1385,6 +1385,7 @@ private: void reset_region_gain (); ARDOUR::Quantize get_quantize_op (bool force_dialog, bool& did_show_dialog); void apply_midi_note_edit_op (ARDOUR::MidiOperator& op, const RegionSelection& rs); + void set_tempo_curve_range (double& max, double& min) const; void quantize_region (); void quantize_regions (const RegionSelection& rs); void legatize_region (bool shrink_only); @@ -1924,7 +1925,7 @@ private: 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 make_tempo_marker (Temporal::TempoPoint const * ts, 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 1b290f6725..6b25d696fd 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -159,13 +159,8 @@ Editor::make_meter_marker (Temporal::MeterPoint const * ms, Marks::iterator befo } 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, Marks::iterator before) +Editor::make_tempo_marker (Temporal::TempoPoint const * ts, 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()); - min_tempo = min (min_tempo, ts->note_types_per_minute()); - min_tempo = min (min_tempo, ts->end_note_types_per_minute()); - const std::string tname (X_("")); char const * color_name = X_("tempo marker"); @@ -205,8 +200,6 @@ Editor::reset_tempo_marks () Tempos const & tempi (TempoMap::use()->tempos()); TempoPoint const * prev_ts = 0; - double max_tempo = 0.0; - double min_tempo = DBL_MAX; for (auto & t : tempo_marks) { delete t; @@ -215,11 +208,15 @@ Editor::reset_tempo_marks () tempo_marks.clear (); for (auto const & t : tempi) { - make_tempo_marker (&t, min_tempo, max_tempo, prev_ts, tc_color, sr, tempo_marks.end()); + make_tempo_marker (&t, prev_ts, tc_color, sr, tempo_marks.end()); prev_ts = &t; } - update_tempo_curves (min_tempo, max_tempo, sr); + double max_tempo; + double min_tempo; + + set_tempo_curve_range (max_tempo, min_tempo); + update_tempo_curves (min_tempo, max_tempo, sr); } void @@ -266,14 +263,6 @@ Editor::reset_bbt_marks () void Editor::update_tempo_curves (double min_tempo, double max_tempo, samplecnt_t sr) { - const double min_tempo_range = 5.0; - const double tempo_delta = fabs (max_tempo - min_tempo); - - if (tempo_delta < min_tempo_range) { - max_tempo += min_tempo_range - tempo_delta; - min_tempo += tempo_delta - min_tempo_range; - } - for (Marks::iterator m = tempo_marks.begin(); m != tempo_marks.end(); ++m) { TempoMarker* tm = static_cast(*m); @@ -282,8 +271,7 @@ Editor::update_tempo_curves (double min_tempo, double max_tempo, samplecnt_t sr) TempoCurve& curve (tm->curve()); - curve.set_max_tempo (max_tempo); - curve.set_min_tempo (min_tempo); + curve.update_range (min_tempo, max_tempo); if (tmp != tempo_marks.end()) { TempoMarker* nxt = static_cast(*tmp); @@ -882,6 +870,26 @@ Editor::_commit_tempo_map_edit (TempoMap::WritableSharedPtr& new_map, bool with_ } } +void +Editor::set_tempo_curve_range (double& max_tempo, double& min_tempo) const +{ + TempoMap::SharedPtr map (TempoMap::use()); + + max_tempo = map->max_notes_per_minute(); + min_tempo = map->min_notes_per_minute(); + + max_tempo = std::max (max_tempo, 200.); + min_tempo = std::min (min_tempo, 40.); + + const double min_tempo_range = 5.0; + const double tempo_delta = fabs (max_tempo - min_tempo); + + if (tempo_delta < min_tempo_range) { + max_tempo += min_tempo_range - tempo_delta; + min_tempo += tempo_delta - min_tempo_range; + } +} + void Editor::mid_tempo_change (MidTempoChanges what_changed) { @@ -890,20 +898,9 @@ Editor::mid_tempo_change (MidTempoChanges what_changed) // map->dump (std::cerr); if ((what_changed & MidTempoChanges(BBTChanged|TempoChanged|MappingChanged))) { - double min_tempo = DBL_MAX; - double max_tempo = 0.0; - - for (auto & t : tempo_marks) { - t->update (); - - TempoMarker* tm (dynamic_cast (t)); - - max_tempo = max (max_tempo, tm->tempo().note_types_per_minute()); - max_tempo = max (max_tempo, tm->tempo().end_note_types_per_minute()); - min_tempo = min (min_tempo, tm->tempo().note_types_per_minute()); - min_tempo = min (min_tempo, tm->tempo().end_note_types_per_minute()); - - } + double max_tempo; + double min_tempo; + set_tempo_curve_range (max_tempo, min_tempo); update_tempo_curves (min_tempo, max_tempo, _session->sample_rate()); } diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index d8cb9e2821..958f815e1b 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -582,6 +582,8 @@ public: virtual ARDOUR::Quantize get_quantize_op (bool force_dialog, bool& did_show_dialog) = 0; virtual void apply_midi_note_edit_op (ARDOUR::MidiOperator& op, const RegionSelection& rs) = 0; + virtual void set_tempo_curve_range (double& max, double& min) const = 0; + /// Singleton instance, set up by Editor::Editor() static PublicEditor* _instance; diff --git a/gtk2_ardour/tempo_curve.cc b/gtk2_ardour/tempo_curve.cc index 12ab15bdd1..0ab6ac12ef 100644 --- a/gtk2_ardour/tempo_curve.cc +++ b/gtk2_ardour/tempo_curve.cc @@ -60,12 +60,12 @@ TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Item& parent, guint32 rg , _duration (UINT32_MAX) , _marker_width (marker_width) , _color (rgba) - , _min_tempo (temp.note_types_per_minute()) - , _max_tempo (temp.note_types_per_minute()) , _tempo (&temp) , _start_text (0) , _end_text (0) { + ed.set_tempo_curve_range (_max_tempo, _min_tempo); + /* XXX x arg for Duple should probably be marker width, passed in from owner */ group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (marker_width + 1, 1)); #ifdef CANVAS_DEBUG diff --git a/gtk2_ardour/tempo_curve.h b/gtk2_ardour/tempo_curve.h index 89be6ab285..fd196e0b23 100644 --- a/gtk2_ardour/tempo_curve.h +++ b/gtk2_ardour/tempo_curve.h @@ -58,8 +58,7 @@ public: Temporal::TempoPoint const & tempo () const { return *_tempo; } void reset_point (Temporal::TempoPoint const &); - void set_max_tempo (const double& max) { _max_tempo = max; } - void set_min_tempo (const double& min) { _min_tempo = min; } + void update_range (double min, double max) { _max_tempo = max; _min_tempo = min; } static void format_tempo (double ntpm, int nt, char*, size_t);