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 "canvas/debug.h"
26 #include "canvas/scroll_group.h"
27 #include "canvas/tracking_text.h"
29 #include "ardour_ui.h"
30 #include "audio_clock.h"
32 #include "editor_drag.h"
33 #include "global_signals.h"
34 #include "main_clock.h"
35 #include "verbose_cursor.h"
40 using namespace ARDOUR;
42 VerboseCursor::VerboseCursor (Editor* editor)
45 _canvas_item = new ArdourCanvas::TrackingText (_editor->get_noscroll_group());
46 CANVAS_DEBUG_NAME (_canvas_item, "verbose canvas cursor");
47 _canvas_item->set_font_description (Pango::FontDescription (ARDOUR_UI::config()->get_canvasvar_LargerBoldFont()));
50 ARDOUR_UI_UTILS::ColorsChanged.connect (sigc::mem_fun (*this, &VerboseCursor::color_handler));
54 VerboseCursor::color_handler ()
56 _canvas_item->set_color (ARDOUR_UI::config()->get_canvasvar_VerboseCanvasCursor());
60 VerboseCursor::canvas_item () const
65 /** Set the contents of the cursor.
68 VerboseCursor::set (string const & text)
70 _canvas_item->set (text);
74 VerboseCursor::show ()
76 _canvas_item->show_and_track (true, true);
77 _canvas_item->parent()->raise_to_top ();
81 VerboseCursor::hide ()
83 _canvas_item->hide ();
84 _canvas_item->parent()->lower_to_bottom ();
85 /* reset back to a sensible default for the next time we display the VC */
86 _canvas_item->set_offset (ArdourCanvas::Duple (10, 10));
90 VerboseCursor::set_offset (ArdourCanvas::Duple const & d)
92 _canvas_item->set_offset (d);
96 VerboseCursor::set_time (framepos_t frame)
99 Timecode::Time timecode;
100 Timecode::BBT_Time bbt;
102 framepos_t frame_rate;
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 (frame, 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 (frame, timecode);
121 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
124 case AudioClock::MinSec:
125 /* XXX this is copied from show_verbose_duration_cursor() */
126 frame_rate = _editor->_session->frame_rate();
127 hours = frame / (frame_rate * 3600);
128 frame = frame % (frame_rate * 3600);
129 mins = frame / (frame_rate * 60);
130 frame = frame % (frame_rate * 60);
131 secs = (float) frame / (float) frame_rate;
132 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%07.4f", hours, mins, secs);
136 snprintf (buf, sizeof(buf), "%" PRIi64, frame);
140 _canvas_item->set (buf);
144 VerboseCursor::set_duration (framepos_t start, framepos_t end)
147 Timecode::Time timecode;
148 Timecode::BBT_Time sbbt;
149 Timecode::BBT_Time ebbt;
151 framepos_t distance, frame_rate;
153 Meter meter_at_start (_editor->_session->tempo_map().meter_at(start));
155 if (_editor->_session == 0) {
161 if (Profile->get_sae() || Profile->get_small_screen() || Profile->get_trx()) {
162 m = ARDOUR_UI::instance()->primary_clock->mode ();
164 m = ARDOUR_UI::instance()->secondary_clock->mode ();
168 case AudioClock::BBT:
170 _editor->_session->bbt_time (start, sbbt);
171 _editor->_session->bbt_time (end, ebbt);
174 /* XXX this computation won't work well if the
175 user makes a selection that spans any meter changes.
178 /* use signed integers for the working values so that
182 int ticks = ebbt.ticks;
183 int beats = ebbt.beats;
184 int bars = ebbt.bars;
188 ticks += int (Timecode::BBT_Time::ticks_per_beat);
194 beats += int (meter_at_start.divisions_per_bar());
200 snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bars, beats, ticks);
204 case AudioClock::Timecode:
205 _editor->_session->timecode_duration (end - start, timecode);
206 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
209 case AudioClock::MinSec:
210 /* XXX this stuff should be elsewhere.. */
211 distance = end - start;
212 frame_rate = _editor->_session->frame_rate();
213 hours = distance / (frame_rate * 3600);
214 distance = distance % (frame_rate * 3600);
215 mins = distance / (frame_rate * 60);
216 distance = distance % (frame_rate * 60);
217 secs = (float) distance / (float) frame_rate;
218 snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%07.4f", hours, mins, secs);
222 snprintf (buf, sizeof(buf), "%" PRIi64, end - start);
226 _canvas_item->set (buf);
230 VerboseCursor::visible () const
232 return _canvas_item->visible();