2 Copyright (C) 2000-2011 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <gtkmm/enums.h>
22 #include "pbd/stacktrace.h"
23 #include "ardour/profile.h"
25 #include "ardour_ui.h"
26 #include "audio_clock.h"
28 #include "editor_drag.h"
29 #include "main_clock.h"
31 #include "verbose_cursor.h"
36 using namespace ARDOUR;
38 VerboseCursor::VerboseCursor (Editor* editor)
44 _canvas_item = new ArdourCanvas::NoEventText (*_editor->track_canvas->root());
45 _canvas_item->property_font_desc() = get_font_for_style (N_("VerboseCanvasCursor"));
46 _canvas_item->property_anchor() = Gtk::ANCHOR_NW;
50 VerboseCursor::canvas_item () const
56 VerboseCursor::set (string const & text, double x, double y)
63 VerboseCursor::set_text (string const & text)
65 _canvas_item->property_text() = text.c_str();
68 /** @param xoffset x offset to be applied on top of any set_position() call
69 * before the next show ().
70 * @param yoffset y offset as above.
73 VerboseCursor::show (double xoffset, double yoffset)
82 _canvas_item->raise_to_top ();
83 _canvas_item->show ();
88 VerboseCursor::hide ()
90 _canvas_item->hide ();
95 VerboseCursor::clamp_x (double x)
100 x = min (_editor->_canvas_width - 200.0, x);
106 VerboseCursor::clamp_y (double y)
108 if (y < _editor->canvas_timebars_vsize) {
109 y = _editor->canvas_timebars_vsize;
111 y = min (_editor->_canvas_height - 50, y);
117 VerboseCursor::set_time (framepos_t frame, double x, double y)
120 Timecode::Time timecode;
121 Timecode::BBT_Time bbt;
123 framepos_t frame_rate;
126 if (_editor->_session == 0) {
132 if (Profile->get_sae() || Profile->get_small_screen()) {
133 m = ARDOUR_UI::instance()->primary_clock->mode();
135 m = ARDOUR_UI::instance()->secondary_clock->mode();
139 case AudioClock::BBT:
140 _editor->_session->bbt_time (frame, bbt);
141 snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks);
144 case AudioClock::Timecode:
145 _editor->_session->timecode_time (frame, timecode);
146 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
149 case AudioClock::MinSec:
150 /* XXX this is copied from show_verbose_duration_cursor() */
151 frame_rate = _editor->_session->frame_rate();
152 hours = frame / (frame_rate * 3600);
153 frame = frame % (frame_rate * 3600);
154 mins = frame / (frame_rate * 60);
155 frame = frame % (frame_rate * 60);
156 secs = (float) frame / (float) frame_rate;
157 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%07.4f", hours, mins, secs);
161 snprintf (buf, sizeof(buf), "%" PRIi64, frame);
169 VerboseCursor::set_duration (framepos_t start, framepos_t end, double x, double y)
172 Timecode::Time timecode;
173 Timecode::BBT_Time sbbt;
174 Timecode::BBT_Time ebbt;
176 framepos_t distance, frame_rate;
178 Meter meter_at_start (_editor->_session->tempo_map().meter_at(start));
180 if (_editor->_session == 0) {
186 if (Profile->get_sae() || Profile->get_small_screen()) {
187 m = ARDOUR_UI::instance()->primary_clock->mode ();
189 m = ARDOUR_UI::instance()->secondary_clock->mode ();
193 case AudioClock::BBT:
195 _editor->_session->bbt_time (start, sbbt);
196 _editor->_session->bbt_time (end, ebbt);
199 /* XXX this computation won't work well if the
200 user makes a selection that spans any meter changes.
203 /* use signed integers for the working values so that
207 int ticks = ebbt.ticks;
208 int beats = ebbt.beats;
209 int bars = ebbt.bars;
213 ticks += int (Timecode::BBT_Time::ticks_per_beat);
219 beats += int (meter_at_start.divisions_per_bar());
225 snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bars, beats, ticks);
229 case AudioClock::Timecode:
230 _editor->_session->timecode_duration (end - start, timecode);
231 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
234 case AudioClock::MinSec:
235 /* XXX this stuff should be elsewhere.. */
236 distance = end - start;
237 frame_rate = _editor->_session->frame_rate();
238 hours = distance / (frame_rate * 3600);
239 distance = distance % (frame_rate * 3600);
240 mins = distance / (frame_rate * 60);
241 distance = distance % (frame_rate * 60);
242 secs = (float) distance / (float) frame_rate;
243 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%07.4f", hours, mins, secs);
247 snprintf (buf, sizeof(buf), "%" PRIi64, end - start);
255 VerboseCursor::set_color (uint32_t color)
257 _canvas_item->property_fill_color_rgba() = color;
260 /** Set the position of the verbose cursor. Any x/y offsets
261 * passed to the last call to show() will be applied to the
262 * coordinates passed in here.
265 VerboseCursor::set_position (double x, double y)
267 _canvas_item->property_x() = clamp_x (x + _xoffset);
268 _canvas_item->property_y() = clamp_y (y + _yoffset);
272 VerboseCursor::visible () const