replace ::cast_dynamic() with relevant ActionManager::get_*_action() calls
[ardour.git] / gtk2_ardour / verbose_cursor.cc
index 1f43f754e6b84d34eb6c86dcf695db44da463432..d316a15984e94be8c991887e3634952b07f329dc 100644 (file)
 #include "pbd/stacktrace.h"
 #include "ardour/profile.h"
 
-#include "ardour_ui.h"
+#include "canvas/debug.h"
+#include "canvas/scroll_group.h"
+#include "canvas/tracking_text.h"
+
 #include "audio_clock.h"
 #include "editor.h"
 #include "editor_drag.h"
 #include "main_clock.h"
-#include "utils.h"
 #include "verbose_cursor.h"
+#include "ardour_ui.h"
+#include "ui_config.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
 
 VerboseCursor::VerboseCursor (Editor* editor)
        : _editor (editor)
-       , _visible (false)
-       , _xoffset (0)
-       , _yoffset (0)
 {
-       _canvas_item = new ArdourCanvas::Text (_editor->_track_canvas->root());
-       _canvas_item->set_ignore_events (true);
-       _canvas_item->set_font_description (get_font_for_style (N_("VerboseCanvasCursor")));
-       // CAIROCANVAS
-       // _canvas_item->property_anchor() = Gtk::ANCHOR_NW;
+       _canvas_item = new ArdourCanvas::TrackingText (_editor->get_noscroll_group());
+       CANVAS_DEBUG_NAME (_canvas_item, "verbose canvas cursor");
+       _canvas_item->set_font_description (Pango::FontDescription (UIConfiguration::instance().get_LargerBoldFont()));
+       color_handler ();
+
+       UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &VerboseCursor::color_handler));
 }
 
-ArdourCanvas::Item *
-VerboseCursor::canvas_item () const
+void
+VerboseCursor::color_handler ()
 {
-       return _canvas_item;
+       _canvas_item->set_color (UIConfiguration::instance().color_mod ("verbose canvas cursor", "verbose canvas cursor"));
 }
 
-void
-VerboseCursor::set (string const & text, double x, double y)
+ArdourCanvas::Item *
+VerboseCursor::canvas_item () const
 {
-       set_text (text);
-       set_position (x, y);
+       return _canvas_item;
 }
 
+/** Set the contents of the cursor.
+ */
 void
-VerboseCursor::set_text (string const & text)
+VerboseCursor::set (string const & text)
 {
        _canvas_item->set (text);
 }
 
-/** @param xoffset x offset to be applied on top of any set_position() call
- *  before the next show ().
- *  @param yoffset y offset as above.
- */
 void
-VerboseCursor::show (double xoffset, double yoffset)
+VerboseCursor::show ()
 {
-       _xoffset = xoffset;
-       _yoffset = yoffset;
-
-       if (_visible) {
-               return;
-       }
-
-       _canvas_item->raise_to_top ();
-       _canvas_item->show ();
-       _visible = true;
+       _canvas_item->show_and_track (true, true);
+       _canvas_item->parent()->raise_to_top ();
 }
 
 void
 VerboseCursor::hide ()
 {
        _canvas_item->hide ();
-       _visible = false;
-}
-
-double
-VerboseCursor::clamp_x (double x)
-{
-       _editor->clamp_verbose_cursor_x (x);
-       return x;
+       _canvas_item->parent()->lower_to_bottom ();
+       /* reset back to a sensible default for the next time we display the VC */
+       _canvas_item->set_offset (ArdourCanvas::Duple (10, 10));
 }
 
-double
-VerboseCursor::clamp_y (double y)
+void
+VerboseCursor::set_offset (ArdourCanvas::Duple const & d)
 {
-       _editor->clamp_verbose_cursor_y (y);
-       return y;
+       _canvas_item->set_offset (d);
 }
 
 void
-VerboseCursor::set_time (framepos_t frame, double x, double y)
+VerboseCursor::set_time (samplepos_t sample)
 {
        char buf[128];
        Timecode::Time timecode;
        Timecode::BBT_Time bbt;
-       int hours, mins;
-       framepos_t frame_rate;
-       float secs;
 
        if (_editor->_session == 0) {
                return;
        }
 
-       AudioClock::Mode m;
+       /* Take clock mode from the primary clock */
 
-       if (Profile->get_sae() || Profile->get_small_screen()) {
-               m = ARDOUR_UI::instance()->primary_clock->mode();
-       } else {
-               m = ARDOUR_UI::instance()->secondary_clock->mode();
-       }
+       AudioClock::Mode m = ARDOUR_UI::instance()->primary_clock->mode();
 
        switch (m) {
        case AudioClock::BBT:
-               _editor->_session->bbt_time (frame, bbt);
+               _editor->_session->bbt_time (sample, bbt);
                snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks);
                break;
 
        case AudioClock::Timecode:
-               _editor->_session->timecode_time (frame, timecode);
-               snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
+               _editor->_session->timecode_time (sample, timecode);
+               snprintf (buf, sizeof (buf), "%s", Timecode::timecode_format_time (timecode).c_str());
                break;
 
        case AudioClock::MinSec:
-               /* XXX this is copied from show_verbose_duration_cursor() */
-               frame_rate = _editor->_session->frame_rate();
-               hours = frame / (frame_rate * 3600);
-               frame = frame % (frame_rate * 3600);
-               mins = frame / (frame_rate * 60);
-               frame = frame % (frame_rate * 60);
-               secs = (float) frame / (float) frame_rate;
-               snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%07.4f", hours, mins, secs);
+               AudioClock::print_minsec (sample, buf, sizeof (buf), _editor->_session->sample_rate());
+               break;
+
+       case AudioClock::Seconds:
+               snprintf (buf, sizeof(buf), "%.1f", sample / (float)_editor->_session->sample_rate());
                break;
 
        default:
-               snprintf (buf, sizeof(buf), "%" PRIi64, frame);
+               snprintf (buf, sizeof(buf), "%" PRIi64, sample);
                break;
        }
 
-       set (buf, x, y);
+       _canvas_item->set (buf);
 }
 
 void
-VerboseCursor::set_duration (framepos_t start, framepos_t end, double x, double y)
+VerboseCursor::set_duration (samplepos_t start, samplepos_t end)
 {
        char buf[128];
        Timecode::Time timecode;
        Timecode::BBT_Time sbbt;
        Timecode::BBT_Time ebbt;
-       int hours, mins;
-       framepos_t distance, frame_rate;
-       float secs;
-       Meter meter_at_start (_editor->_session->tempo_map().meter_at(start));
+       Meter meter_at_start (_editor->_session->tempo_map().meter_at_sample (start));
 
        if (_editor->_session == 0) {
                return;
        }
 
-       AudioClock::Mode m;
-
-       if (Profile->get_sae() || Profile->get_small_screen()) {
-               m = ARDOUR_UI::instance()->primary_clock->mode ();
-       } else {
-               m = ARDOUR_UI::instance()->secondary_clock->mode ();
-       }
+       AudioClock::Mode m = ARDOUR_UI::instance()->primary_clock->mode ();
 
        switch (m) {
        case AudioClock::BBT:
@@ -222,19 +188,15 @@ VerboseCursor::set_duration (framepos_t start, framepos_t end, double x, double
 
        case AudioClock::Timecode:
                _editor->_session->timecode_duration (end - start, timecode);
-               snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
+               snprintf (buf, sizeof (buf), "%s", Timecode::timecode_format_time (timecode).c_str());
                break;
 
        case AudioClock::MinSec:
-               /* XXX this stuff should be elsewhere.. */
-               distance = end - start;
-               frame_rate = _editor->_session->frame_rate();
-               hours = distance / (frame_rate * 3600);
-               distance = distance % (frame_rate * 3600);
-               mins = distance / (frame_rate * 60);
-               distance = distance % (frame_rate * 60);
-               secs = (float) distance / (float) frame_rate;
-               snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%07.4f", hours, mins, secs);
+               AudioClock::print_minsec (end - start, buf, sizeof (buf), _editor->_session->sample_rate());
+               break;
+
+       case AudioClock::Seconds:
+               snprintf (buf, sizeof(buf), "%.1f", (end - start) / (float)_editor->_session->sample_rate());
                break;
 
        default:
@@ -242,28 +204,11 @@ VerboseCursor::set_duration (framepos_t start, framepos_t end, double x, double
                break;
        }
 
-       set (buf, x, y);
-}
-
-void
-VerboseCursor::set_color (uint32_t color)
-{
-       _canvas_item->set_color (color);
-}
-
-/** Set the position of the verbose cursor.  Any x/y offsets
- *  passed to the last call to show() will be applied to the
- *  coordinates passed in here.
- */
-void
-VerboseCursor::set_position (double x, double y)
-{
-       _canvas_item->set_x_position (clamp_x (x + _xoffset));
-       _canvas_item->set_y_position (clamp_y (y + _yoffset));
+       _canvas_item->set (buf);
 }
 
 bool
 VerboseCursor::visible () const
 {
-       return _visible;
+       return _canvas_item->visible();
 }