initial rework of tempo text display (numbers are curve items)
authornick_m <mainsbridge@gmail.com>
Mon, 27 Feb 2017 06:53:31 +0000 (17:53 +1100)
committerRobin Gareus <robin@gareus.org>
Mon, 27 Feb 2017 19:16:10 +0000 (20:16 +0100)
- move tempo numbers to a layer above the curve.

- the offset of the text box in Marker is horrible here.
  what to do?

gtk2_ardour/editor_tempodisplay.cc
gtk2_ardour/tempo_curve.cc
gtk2_ardour/tempo_curve.h

index 767d84d91854090e36ba3c2a632794714258bf41..752373db6efee5910d97fae63631a7a87b3edeb5 100644 (file)
@@ -105,19 +105,6 @@ Editor::draw_metric_marks (const Metrics& metrics)
                        }
                } else if ((ts = dynamic_cast<TempoSection*>(*i)) != 0) {
 
-                       if (ts->type() == TempoSection::Constant) {
-                               if (ts->note_type() != 4.0) {
-                                       snprintf (buf, sizeof (buf), "%.3f/%.0f", ts->note_types_per_minute(), ts->note_type());
-                               } else {
-                                       snprintf (buf, sizeof (buf), "%.3f", ts->note_types_per_minute());
-                               }
-                       } else {
-                               if (ts->note_type() != 4.0) {
-                                       snprintf (buf, sizeof (buf), "%.3f/%.0f>%.3f", ts->note_types_per_minute(), ts->note_type(), ts->end_note_types_per_minute());
-                               } else {
-                                       snprintf (buf, sizeof (buf), "%.3f>%.3f", ts->note_types_per_minute(), ts->end_note_types_per_minute());
-                               }
-                       }
                        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());
@@ -127,11 +114,12 @@ Editor::draw_metric_marks (const Metrics& metrics)
                        tempo_curves.push_back (new TempoCurve (*this, *tempo_group, tc_color,
                                                                *(const_cast<TempoSection*>(ts)), ts->frame(), false));
 
+                       const std::string tname (X_(""));
                        if (ts->position_lock_style() == MusicTime) {
-                               metric_marks.push_back (new TempoMarker (*this, *tempo_group, UIConfiguration::instance().color ("tempo marker music"), buf,
+                               metric_marks.push_back (new TempoMarker (*this, *tempo_group, UIConfiguration::instance().color ("tempo marker music"), tname,
                                                                 *(const_cast<TempoSection*>(ts))));
                        } else {
-                               metric_marks.push_back (new TempoMarker (*this, *tempo_group, UIConfiguration::instance().color ("tempo marker"), buf,
+                               metric_marks.push_back (new TempoMarker (*this, *tempo_group, UIConfiguration::instance().color ("tempo marker"), tname,
                                                                 *(const_cast<TempoSection*>(ts))));
                        }
                        if (prev_ts && abs (prev_ts->end_note_types_per_minute() - ts->note_types_per_minute()) < 1.0) {
@@ -233,7 +221,6 @@ Editor::tempometric_position_changed (const PropertyChange& /*ignored*/)
                        if ((ts = &tempo_marker->tempo()) != 0) {
 
                                tempo_marker->set_position (ts->frame ());
-                               char buf[64];
 
                                if (prev_ts && abs (prev_ts->end_note_types_per_minute() - ts->note_types_per_minute()) < 1.0) {
                                        tempo_marker->set_points_color (UIConfiguration::instance().color ("tempo marker music"));
@@ -241,22 +228,6 @@ Editor::tempometric_position_changed (const PropertyChange& /*ignored*/)
                                        tempo_marker->set_points_color (UIConfiguration::instance().color ("tempo marker"));
                                }
 
-                               if (ts->type() == TempoSection::Constant) {
-                                       if (ts->note_type() != 4.0) {
-                                               snprintf (buf, sizeof (buf), "%.3f/%.0f", ts->note_types_per_minute(), ts->note_type());
-                                       } else {
-                                               snprintf (buf, sizeof (buf), "%.3f", ts->note_types_per_minute());
-                                       }
-                               } else {
-                                       if (ts->note_type() != 4.0) {
-                                               snprintf (buf, sizeof (buf), "%.3f/%.0f>%.3f", ts->note_types_per_minute(), ts->note_type(), ts->end_note_types_per_minute());
-                                       } else {
-                                               snprintf (buf, sizeof (buf), "%.3f>%.3f", ts->note_types_per_minute(), ts->end_note_types_per_minute());
-                                       }
-                               }
-
-                               tempo_marker->set_name (buf);
-
                                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());
index c43e91c9ac9e0eda8d06fde7ecbbc1e5306d7f2b..720418e030aafc9d7baf0820297233f5bc080c99 100644 (file)
@@ -37,7 +37,8 @@ TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Container& parent, guint
        , _min_tempo (temp.note_types_per_minute())
        , _max_tempo (temp.note_types_per_minute())
        , _tempo (temp)
-
+       , _start_text (0)
+       , _end_text (0)
 {
        frame_position = frame;
        unit_position = editor.sample_to_pixel (frame);
@@ -55,6 +56,18 @@ TempoCurve::TempoCurve (PublicEditor& ed, ArdourCanvas::Container& parent, guint
        points = new ArdourCanvas::Points ();
        _curve->set (*points);
 
+       _start_text = new ArdourCanvas::Text (group);
+       _end_text = new ArdourCanvas::Text (group);
+       _start_text->set_font_description (ARDOUR_UI_UTILS::get_font_for_style (N_("MarkerText")));
+       _end_text->set_font_description (ARDOUR_UI_UTILS::get_font_for_style (N_("MarkerText")));
+       _start_text->set_color (RGBA_TO_UINT (255,255,255,255));
+       _end_text->set_color (RGBA_TO_UINT (255,255,255,255));
+       char buf[10];
+       snprintf (buf, sizeof (buf), "%.3f/%.0f", _tempo.note_types_per_minute(), _tempo.note_type());
+       _start_text->set (buf);
+       snprintf (buf, sizeof (buf), "%.3f", _tempo.end_note_types_per_minute());
+       _end_text->set (buf);
+
        set_color_rgba (rgba);
 
        editor.ZoomChanged.connect (sigc::mem_fun (*this, &TempoCurve::reposition));
@@ -147,6 +160,23 @@ TempoCurve::set_position (framepos_t frame, framepos_t end_frame)
        }
 
        _curve->set (*points);
+
+       char buf[10];
+       snprintf (buf, sizeof (buf), "%.3f/%.0f", _tempo.note_types_per_minute(), _tempo.note_type());
+       _start_text->set (buf);
+       snprintf (buf, sizeof (buf), "%.3f", _tempo.end_note_types_per_minute());
+       _end_text->set (buf);
+
+       _start_text->set_position (ArdourCanvas::Duple (10, .5 ));
+       _end_text->set_position (ArdourCanvas::Duple (editor.sample_to_pixel (end_frame - frame) - _end_text->text_width() - 10, .5 ));
+
+       if (_end_text->text_width() + _start_text->text_width() + 20 > editor.sample_to_pixel (end_frame - frame)) {
+               _start_text->hide();
+               _end_text->hide();
+       } else {
+               _start_text->show();
+               _end_text->show();
+       }
 }
 
 void
index 9cee2265f0bc4b7355251db2d7992ccf1b49cf1d..ec1c6fd90ff88262ea2e6039db033ef58644bf42 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "canvas/types.h"
 #include "canvas/framed_curve.h"
+#include "canvas/text.h"
 
 namespace ARDOUR {
        class TempoSection;
@@ -68,6 +69,8 @@ private:
        TempoCurve (TempoCurve const &);
        TempoCurve & operator= (TempoCurve const &);
        ARDOUR::TempoSection& _tempo;
+        ArdourCanvas::Text *_start_text;
+        ArdourCanvas::Text *_end_text;
 
 };
 #endif /* __gtk_ardour_tempo_curve_h__ */