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::Text (_editor->_track_canvas->root());
45 _canvas_item->set_ignore_events (true);
46 _canvas_item->set_font_description (get_font_for_style (N_("VerboseCanvasCursor")));
48 // _canvas_item->property_anchor() = Gtk::ANCHOR_NW;
52 VerboseCursor::canvas_item () const
58 VerboseCursor::set (string const & text, double x, double y)
65 VerboseCursor::set_text (string const & text)
67 _canvas_item->set (text);
70 /** @param xoffset x offset to be applied on top of any set_position() call
71 * before the next show ().
72 * @param yoffset y offset as above.
75 VerboseCursor::show (double xoffset, double yoffset)
84 _canvas_item->raise_to_top ();
85 _canvas_item->show ();
90 VerboseCursor::hide ()
92 _canvas_item->hide ();
97 VerboseCursor::clamp_x (double x)
99 _editor->clamp_verbose_cursor_x (x);
104 VerboseCursor::clamp_y (double y)
106 _editor->clamp_verbose_cursor_y (y);
111 VerboseCursor::set_time (framepos_t frame, double x, double y)
114 Timecode::Time timecode;
115 Timecode::BBT_Time bbt;
117 framepos_t frame_rate;
120 if (_editor->_session == 0) {
126 if (Profile->get_sae() || Profile->get_small_screen()) {
127 m = ARDOUR_UI::instance()->primary_clock->mode();
129 m = ARDOUR_UI::instance()->secondary_clock->mode();
133 case AudioClock::BBT:
134 _editor->_session->bbt_time (frame, bbt);
135 snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks);
138 case AudioClock::Timecode:
139 _editor->_session->timecode_time (frame, timecode);
140 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
143 case AudioClock::MinSec:
144 /* XXX this is copied from show_verbose_duration_cursor() */
145 frame_rate = _editor->_session->frame_rate();
146 hours = frame / (frame_rate * 3600);
147 frame = frame % (frame_rate * 3600);
148 mins = frame / (frame_rate * 60);
149 frame = frame % (frame_rate * 60);
150 secs = (float) frame / (float) frame_rate;
151 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%07.4f", hours, mins, secs);
155 snprintf (buf, sizeof(buf), "%" PRIi64, frame);
163 VerboseCursor::set_duration (framepos_t start, framepos_t end, double x, double y)
166 Timecode::Time timecode;
167 Timecode::BBT_Time sbbt;
168 Timecode::BBT_Time ebbt;
170 framepos_t distance, frame_rate;
172 Meter meter_at_start (_editor->_session->tempo_map().meter_at(start));
174 if (_editor->_session == 0) {
180 if (Profile->get_sae() || Profile->get_small_screen()) {
181 m = ARDOUR_UI::instance()->primary_clock->mode ();
183 m = ARDOUR_UI::instance()->secondary_clock->mode ();
187 case AudioClock::BBT:
189 _editor->_session->bbt_time (start, sbbt);
190 _editor->_session->bbt_time (end, ebbt);
193 /* XXX this computation won't work well if the
194 user makes a selection that spans any meter changes.
197 /* use signed integers for the working values so that
201 int ticks = ebbt.ticks;
202 int beats = ebbt.beats;
203 int bars = ebbt.bars;
207 ticks += int (Timecode::BBT_Time::ticks_per_beat);
213 beats += int (meter_at_start.divisions_per_bar());
219 snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bars, beats, ticks);
223 case AudioClock::Timecode:
224 _editor->_session->timecode_duration (end - start, timecode);
225 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
228 case AudioClock::MinSec:
229 /* XXX this stuff should be elsewhere.. */
230 distance = end - start;
231 frame_rate = _editor->_session->frame_rate();
232 hours = distance / (frame_rate * 3600);
233 distance = distance % (frame_rate * 3600);
234 mins = distance / (frame_rate * 60);
235 distance = distance % (frame_rate * 60);
236 secs = (float) distance / (float) frame_rate;
237 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%07.4f", hours, mins, secs);
241 snprintf (buf, sizeof(buf), "%" PRIi64, end - start);
249 VerboseCursor::set_color (uint32_t color)
251 _canvas_item->set_color (color);
254 /** Set the position of the verbose cursor. Any x/y offsets
255 * passed to the last call to show() will be applied to the
256 * coordinates passed in here.
259 VerboseCursor::set_position (double x, double y)
261 _canvas_item->set_x_position (clamp_x (x + _xoffset));
262 _canvas_item->set_y_position (clamp_y (y + _yoffset));
266 VerboseCursor::visible () const