2 * Copyright (C) 2011-2012 Carl Hetherington <carl@carlh.net>
3 * Copyright (C) 2011-2014 David Robillard <d@drobilla.net>
4 * Copyright (C) 2011-2017 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
6 * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <gtkmm/enums.h>
25 #include "pbd/stacktrace.h"
26 #include "ardour/profile.h"
28 #include "canvas/debug.h"
29 #include "canvas/scroll_group.h"
30 #include "canvas/tracking_text.h"
32 #include "audio_clock.h"
34 #include "editor_drag.h"
35 #include "main_clock.h"
36 #include "verbose_cursor.h"
37 #include "ardour_ui.h"
38 #include "ui_config.h"
43 using namespace ARDOUR;
45 VerboseCursor::VerboseCursor (Editor* editor)
48 _canvas_item = new ArdourCanvas::TrackingText (_editor->get_noscroll_group());
49 CANVAS_DEBUG_NAME (_canvas_item, "verbose canvas cursor");
50 _canvas_item->set_font_description (Pango::FontDescription (UIConfiguration::instance().get_LargerBoldFont()));
53 UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &VerboseCursor::color_handler));
57 VerboseCursor::color_handler ()
59 _canvas_item->set_color (UIConfiguration::instance().color_mod ("verbose canvas cursor", "verbose canvas cursor"));
63 VerboseCursor::canvas_item () const
68 /** Set the contents of the cursor.
71 VerboseCursor::set (string const & text)
73 _canvas_item->set (text);
77 VerboseCursor::show ()
79 _canvas_item->show_and_track (true, true);
80 _canvas_item->parent()->raise_to_top ();
84 VerboseCursor::hide ()
86 _canvas_item->hide ();
87 _canvas_item->parent()->lower_to_bottom ();
88 /* reset back to a sensible default for the next time we display the VC */
89 _canvas_item->set_offset (ArdourCanvas::Duple (10, 10));
93 VerboseCursor::set_offset (ArdourCanvas::Duple const & d)
95 _canvas_item->set_offset (d);
99 VerboseCursor::set_time (samplepos_t sample)
102 Timecode::Time timecode;
103 Timecode::BBT_Time bbt;
105 if (_editor->_session == 0) {
109 /* Take clock mode from the primary clock */
111 AudioClock::Mode m = ARDOUR_UI::instance()->primary_clock->mode();
114 case AudioClock::BBT:
115 _editor->_session->bbt_time (sample, bbt);
116 snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks);
119 case AudioClock::Timecode:
120 _editor->_session->timecode_time (sample, timecode);
121 snprintf (buf, sizeof (buf), "%s", Timecode::timecode_format_time (timecode).c_str());
124 case AudioClock::MinSec:
125 AudioClock::print_minsec (sample, buf, sizeof (buf), _editor->_session->sample_rate());
128 case AudioClock::Seconds:
129 snprintf (buf, sizeof(buf), "%.1f", sample / (float)_editor->_session->sample_rate());
133 snprintf (buf, sizeof(buf), "%" PRIi64, sample);
137 _canvas_item->set (buf);
141 VerboseCursor::set_duration (samplepos_t start, samplepos_t end)
144 Timecode::Time timecode;
145 Timecode::BBT_Time sbbt;
146 Timecode::BBT_Time ebbt;
147 Meter meter_at_start (_editor->_session->tempo_map().meter_at_sample (start));
149 if (_editor->_session == 0) {
153 AudioClock::Mode m = ARDOUR_UI::instance()->primary_clock->mode ();
156 case AudioClock::BBT:
158 _editor->_session->bbt_time (start, sbbt);
159 _editor->_session->bbt_time (end, ebbt);
162 /* XXX this computation won't work well if the
163 user makes a selection that spans any meter changes.
166 /* use signed integers for the working values so that
170 int ticks = ebbt.ticks;
171 int beats = ebbt.beats;
172 int bars = ebbt.bars;
176 ticks += int (Timecode::BBT_Time::ticks_per_beat);
182 beats += int (meter_at_start.divisions_per_bar());
188 snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bars, beats, ticks);
192 case AudioClock::Timecode:
193 _editor->_session->timecode_duration (end - start, timecode);
194 snprintf (buf, sizeof (buf), "%s", Timecode::timecode_format_time (timecode).c_str());
197 case AudioClock::MinSec:
198 AudioClock::print_minsec (end - start, buf, sizeof (buf), _editor->_session->sample_rate());
201 case AudioClock::Seconds:
202 snprintf (buf, sizeof(buf), "%.1f", (end - start) / (float)_editor->_session->sample_rate());
206 snprintf (buf, sizeof(buf), "%" PRIi64, end - start);
210 _canvas_item->set (buf);
214 VerboseCursor::visible () const
216 return _canvas_item->visible();