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"
30 #include "verbose_cursor.h"
35 using namespace ARDOUR
;
37 VerboseCursor::VerboseCursor (Editor
* editor
)
43 _canvas_item
= new ArdourCanvas::NoEventText (*_editor
->track_canvas
->root());
44 _canvas_item
->property_font_desc() = get_font_for_style (N_("VerboseCanvasCursor"));
45 _canvas_item
->property_anchor() = Gtk::ANCHOR_NW
;
49 VerboseCursor::canvas_item () const
55 VerboseCursor::set (string
const & text
, double x
, double y
)
62 VerboseCursor::set_text (string
const & text
)
64 _canvas_item
->property_text() = text
.c_str();
67 /** @param xoffset x offset to be applied on top of any set_position() call
68 * before the next show ().
69 * @param yoffset y offset as above.
72 VerboseCursor::show (double xoffset
, double yoffset
)
81 _canvas_item
->raise_to_top ();
82 _canvas_item
->show ();
87 VerboseCursor::hide ()
89 _canvas_item
->hide ();
94 VerboseCursor::clamp_x (double x
)
99 x
= min (_editor
->_canvas_width
- 200.0, x
);
105 VerboseCursor::clamp_y (double y
)
107 if (y
< _editor
->canvas_timebars_vsize
) {
108 y
= _editor
->canvas_timebars_vsize
;
110 y
= min (_editor
->_canvas_height
- 50, y
);
116 VerboseCursor::set_time (framepos_t frame
, double x
, double y
)
119 Timecode::Time timecode
;
120 Timecode::BBT_Time bbt
;
122 framepos_t frame_rate
;
125 if (_editor
->_session
== 0) {
131 if (Profile
->get_sae() || Profile
->get_small_screen()) {
132 m
= ARDOUR_UI::instance()->primary_clock
->mode();
134 m
= ARDOUR_UI::instance()->secondary_clock
->mode();
138 case AudioClock::BBT
:
139 _editor
->_session
->bbt_time (frame
, bbt
);
140 snprintf (buf
, sizeof (buf
), "%02" PRIu32
"|%02" PRIu32
"|%02" PRIu32
, bbt
.bars
, bbt
.beats
, bbt
.ticks
);
143 case AudioClock::Timecode
:
144 _editor
->_session
->timecode_time (frame
, timecode
);
145 snprintf (buf
, sizeof (buf
), "%02" PRId32
":%02" PRId32
":%02" PRId32
":%02" PRId32
, timecode
.hours
, timecode
.minutes
, timecode
.seconds
, timecode
.frames
);
148 case AudioClock::MinSec
:
149 /* XXX this is copied from show_verbose_duration_cursor() */
150 frame_rate
= _editor
->_session
->frame_rate();
151 hours
= frame
/ (frame_rate
* 3600);
152 frame
= frame
% (frame_rate
* 3600);
153 mins
= frame
/ (frame_rate
* 60);
154 frame
= frame
% (frame_rate
* 60);
155 secs
= (float) frame
/ (float) frame_rate
;
156 snprintf (buf
, sizeof (buf
), "%02" PRId32
":%02" PRId32
":%07.4f", hours
, mins
, secs
);
160 snprintf (buf
, sizeof(buf
), "%" PRIi64
, frame
);
168 VerboseCursor::set_duration (framepos_t start
, framepos_t end
, double x
, double y
)
171 Timecode::Time timecode
;
172 Timecode::BBT_Time sbbt
;
173 Timecode::BBT_Time ebbt
;
175 framepos_t distance
, frame_rate
;
177 Meter
meter_at_start (_editor
->_session
->tempo_map().meter_at(start
));
179 if (_editor
->_session
== 0) {
185 if (Profile
->get_sae() || Profile
->get_small_screen()) {
186 m
= ARDOUR_UI::instance()->primary_clock
->mode ();
188 m
= ARDOUR_UI::instance()->secondary_clock
->mode ();
192 case AudioClock::BBT
:
194 _editor
->_session
->bbt_time (start
, sbbt
);
195 _editor
->_session
->bbt_time (end
, ebbt
);
198 /* XXX this computation won't work well if the
199 user makes a selection that spans any meter changes.
202 /* use signed integers for the working values so that
206 int ticks
= ebbt
.ticks
;
207 int beats
= ebbt
.beats
;
208 int bars
= ebbt
.bars
;
212 ticks
+= int (Timecode::BBT_Time::ticks_per_beat
);
218 beats
+= int (meter_at_start
.beats_per_bar());
224 snprintf (buf
, sizeof (buf
), "%02" PRIu32
"|%02" PRIu32
"|%02" PRIu32
, bars
, beats
, ticks
);
228 case AudioClock::Timecode
:
229 _editor
->_session
->timecode_duration (end
- start
, timecode
);
230 snprintf (buf
, sizeof (buf
), "%02" PRId32
":%02" PRId32
":%02" PRId32
":%02" PRId32
, timecode
.hours
, timecode
.minutes
, timecode
.seconds
, timecode
.frames
);
233 case AudioClock::MinSec
:
234 /* XXX this stuff should be elsewhere.. */
235 distance
= end
- start
;
236 frame_rate
= _editor
->_session
->frame_rate();
237 hours
= distance
/ (frame_rate
* 3600);
238 distance
= distance
% (frame_rate
* 3600);
239 mins
= distance
/ (frame_rate
* 60);
240 distance
= distance
% (frame_rate
* 60);
241 secs
= (float) distance
/ (float) frame_rate
;
242 snprintf (buf
, sizeof (buf
), "%02" PRId32
":%02" PRId32
":%07.4f", hours
, mins
, secs
);
246 snprintf (buf
, sizeof(buf
), "%" PRIi64
, end
- start
);
254 VerboseCursor::set_color (uint32_t color
)
256 _canvas_item
->property_fill_color_rgba() = color
;
259 /** Set the position of the verbose cursor. Any x/y offsets
260 * passed to the last call to show() will be applied to the
261 * coordinates passed in here.
264 VerboseCursor::set_position (double x
, double y
)
266 _canvas_item
->property_x() = clamp_x (x
+ _xoffset
);
267 _canvas_item
->property_y() = clamp_y (y
+ _yoffset
);
271 VerboseCursor::visible () const