2011-05-02 09:38:16 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2000-2011 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <gtkmm/enums.h>
|
2011-05-04 10:56:24 -04:00
|
|
|
#include "pbd/stacktrace.h"
|
2011-05-02 09:38:16 -04:00
|
|
|
#include "ardour/profile.h"
|
2011-06-02 13:50:37 -04:00
|
|
|
|
2011-05-02 09:38:16 -04:00
|
|
|
#include "ardour_ui.h"
|
2011-06-02 13:50:37 -04:00
|
|
|
#include "audio_clock.h"
|
|
|
|
#include "editor.h"
|
2011-05-02 09:38:16 -04:00
|
|
|
#include "editor_drag.h"
|
2012-05-31 19:14:03 -04:00
|
|
|
#include "main_clock.h"
|
2011-06-02 13:50:37 -04:00
|
|
|
#include "utils.h"
|
|
|
|
#include "verbose_cursor.h"
|
2011-05-02 09:38:16 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
|
|
|
VerboseCursor::VerboseCursor (Editor* editor)
|
|
|
|
: _editor (editor)
|
|
|
|
, _visible (false)
|
2011-05-04 10:56:24 -04:00
|
|
|
, _xoffset (0)
|
|
|
|
, _yoffset (0)
|
2011-05-02 09:38:16 -04:00
|
|
|
{
|
|
|
|
_canvas_item = new ArdourCanvas::NoEventText (*_editor->track_canvas->root());
|
2011-06-02 13:50:37 -04:00
|
|
|
_canvas_item->property_font_desc() = get_font_for_style (N_("VerboseCanvasCursor"));
|
2011-05-02 09:38:16 -04:00
|
|
|
_canvas_item->property_anchor() = Gtk::ANCHOR_NW;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArdourCanvas::Item *
|
|
|
|
VerboseCursor::canvas_item () const
|
|
|
|
{
|
|
|
|
return _canvas_item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VerboseCursor::set (string const & text, double x, double y)
|
|
|
|
{
|
|
|
|
set_text (text);
|
|
|
|
set_position (x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VerboseCursor::set_text (string const & text)
|
|
|
|
{
|
|
|
|
_canvas_item->property_text() = text.c_str();
|
|
|
|
}
|
|
|
|
|
2011-05-04 10:56:24 -04:00
|
|
|
/** @param xoffset x offset to be applied on top of any set_position() call
|
|
|
|
* before the next show ().
|
|
|
|
* @param yoffset y offset as above.
|
|
|
|
*/
|
2011-05-02 09:38:16 -04:00
|
|
|
void
|
2011-05-04 10:56:24 -04:00
|
|
|
VerboseCursor::show (double xoffset, double yoffset)
|
2011-05-02 09:38:16 -04:00
|
|
|
{
|
2011-05-04 10:56:24 -04:00
|
|
|
_xoffset = xoffset;
|
|
|
|
_yoffset = yoffset;
|
|
|
|
|
|
|
|
if (_visible) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-05-02 09:38:16 -04:00
|
|
|
_canvas_item->raise_to_top ();
|
|
|
|
_canvas_item->show ();
|
|
|
|
_visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VerboseCursor::hide ()
|
|
|
|
{
|
|
|
|
_canvas_item->hide ();
|
|
|
|
_visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
VerboseCursor::clamp_x (double x)
|
|
|
|
{
|
|
|
|
if (x < 0) {
|
|
|
|
x = 0;
|
|
|
|
} else {
|
|
|
|
x = min (_editor->_canvas_width - 200.0, x);
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
VerboseCursor::clamp_y (double y)
|
|
|
|
{
|
|
|
|
if (y < _editor->canvas_timebars_vsize) {
|
|
|
|
y = _editor->canvas_timebars_vsize;
|
|
|
|
} else {
|
|
|
|
y = min (_editor->_canvas_height - 50, y);
|
|
|
|
}
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VerboseCursor::set_time (framepos_t frame, double x, double y)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
Timecode::Time timecode;
|
|
|
|
Timecode::BBT_Time bbt;
|
|
|
|
int hours, mins;
|
|
|
|
framepos_t frame_rate;
|
|
|
|
float secs;
|
|
|
|
|
|
|
|
if (_editor->_session == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioClock::Mode m;
|
|
|
|
|
|
|
|
if (Profile->get_sae() || Profile->get_small_screen()) {
|
2011-06-02 13:50:37 -04:00
|
|
|
m = ARDOUR_UI::instance()->primary_clock->mode();
|
2011-05-02 09:38:16 -04:00
|
|
|
} else {
|
2011-06-02 13:50:37 -04:00
|
|
|
m = ARDOUR_UI::instance()->secondary_clock->mode();
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (m) {
|
|
|
|
case AudioClock::BBT:
|
|
|
|
_editor->_session->bbt_time (frame, bbt);
|
|
|
|
snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AudioClock::Timecode:
|
|
|
|
_editor->_session->timecode_time (frame, timecode);
|
|
|
|
snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AudioClock::MinSec:
|
|
|
|
/* XXX this is copied from show_verbose_duration_cursor() */
|
|
|
|
frame_rate = _editor->_session->frame_rate();
|
|
|
|
hours = frame / (frame_rate * 3600);
|
|
|
|
frame = frame % (frame_rate * 3600);
|
|
|
|
mins = frame / (frame_rate * 60);
|
|
|
|
frame = frame % (frame_rate * 60);
|
|
|
|
secs = (float) frame / (float) frame_rate;
|
|
|
|
snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%07.4f", hours, mins, secs);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
snprintf (buf, sizeof(buf), "%" PRIi64, frame);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
set (buf, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VerboseCursor::set_duration (framepos_t start, framepos_t end, double x, double y)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
Timecode::Time timecode;
|
|
|
|
Timecode::BBT_Time sbbt;
|
|
|
|
Timecode::BBT_Time ebbt;
|
|
|
|
int hours, mins;
|
|
|
|
framepos_t distance, frame_rate;
|
|
|
|
float secs;
|
|
|
|
Meter meter_at_start (_editor->_session->tempo_map().meter_at(start));
|
|
|
|
|
|
|
|
if (_editor->_session == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioClock::Mode m;
|
|
|
|
|
|
|
|
if (Profile->get_sae() || Profile->get_small_screen()) {
|
2011-06-02 13:50:37 -04:00
|
|
|
m = ARDOUR_UI::instance()->primary_clock->mode ();
|
2011-05-02 09:38:16 -04:00
|
|
|
} else {
|
2011-06-02 13:50:37 -04:00
|
|
|
m = ARDOUR_UI::instance()->secondary_clock->mode ();
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (m) {
|
|
|
|
case AudioClock::BBT:
|
|
|
|
{
|
|
|
|
_editor->_session->bbt_time (start, sbbt);
|
|
|
|
_editor->_session->bbt_time (end, ebbt);
|
|
|
|
|
|
|
|
/* subtract */
|
|
|
|
/* XXX this computation won't work well if the
|
|
|
|
user makes a selection that spans any meter changes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* use signed integers for the working values so that
|
|
|
|
we can underflow.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ticks = ebbt.ticks;
|
|
|
|
int beats = ebbt.beats;
|
|
|
|
int bars = ebbt.bars;
|
|
|
|
|
|
|
|
ticks -= sbbt.ticks;
|
|
|
|
if (ticks < 0) {
|
2012-01-06 11:39:40 -05:00
|
|
|
ticks += int (Timecode::BBT_Time::ticks_per_beat);
|
2011-05-02 09:38:16 -04:00
|
|
|
--beats;
|
|
|
|
}
|
|
|
|
|
|
|
|
beats -= sbbt.beats;
|
|
|
|
if (beats < 0) {
|
2011-12-12 21:46:36 -05:00
|
|
|
beats += int (meter_at_start.divisions_per_bar());
|
2011-05-02 09:38:16 -04:00
|
|
|
--bars;
|
|
|
|
}
|
|
|
|
|
|
|
|
bars -= sbbt.bars;
|
|
|
|
|
|
|
|
snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bars, beats, ticks);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AudioClock::Timecode:
|
|
|
|
_editor->_session->timecode_duration (end - start, timecode);
|
|
|
|
snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AudioClock::MinSec:
|
|
|
|
/* XXX this stuff should be elsewhere.. */
|
|
|
|
distance = end - start;
|
|
|
|
frame_rate = _editor->_session->frame_rate();
|
|
|
|
hours = distance / (frame_rate * 3600);
|
|
|
|
distance = distance % (frame_rate * 3600);
|
|
|
|
mins = distance / (frame_rate * 60);
|
|
|
|
distance = distance % (frame_rate * 60);
|
|
|
|
secs = (float) distance / (float) frame_rate;
|
|
|
|
snprintf (buf, sizeof (buf), "%02" PRId32 ":%02" PRId32 ":%07.4f", hours, mins, secs);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
snprintf (buf, sizeof(buf), "%" PRIi64, end - start);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
set (buf, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VerboseCursor::set_color (uint32_t color)
|
|
|
|
{
|
|
|
|
_canvas_item->property_fill_color_rgba() = color;
|
|
|
|
}
|
|
|
|
|
2011-05-04 10:56:24 -04:00
|
|
|
/** Set the position of the verbose cursor. Any x/y offsets
|
|
|
|
* passed to the last call to show() will be applied to the
|
|
|
|
* coordinates passed in here.
|
|
|
|
*/
|
2011-05-02 09:38:16 -04:00
|
|
|
void
|
|
|
|
VerboseCursor::set_position (double x, double y)
|
|
|
|
{
|
2011-05-04 10:56:24 -04:00
|
|
|
_canvas_item->property_x() = clamp_x (x + _xoffset);
|
|
|
|
_canvas_item->property_y() = clamp_y (y + _yoffset);
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VerboseCursor::visible () const
|
|
|
|
{
|
|
|
|
return _visible;
|
|
|
|
}
|