2011-05-02 09:38:16 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2011-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2011-2014 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2011-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2011-05-02 09:38:16 -04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <gtkmm/enums.h>
|
2021-05-05 11:43:28 -04:00
|
|
|
|
2011-05-02 09:38:16 -04:00
|
|
|
#include "ardour/profile.h"
|
2011-06-02 13:50:37 -04:00
|
|
|
|
2013-04-24 15:42:14 -04:00
|
|
|
#include "canvas/debug.h"
|
2014-06-21 11:44:22 -04:00
|
|
|
#include "canvas/scroll_group.h"
|
2014-06-26 15:07:29 -04:00
|
|
|
#include "canvas/tracking_text.h"
|
2013-04-24 15:42:14 -04:00
|
|
|
|
2011-06-02 13:50:37 -04:00
|
|
|
#include "audio_clock.h"
|
2023-11-18 20:40:50 -05:00
|
|
|
#include "editing_context.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 "verbose_cursor.h"
|
2015-01-02 09:44:54 -05:00
|
|
|
#include "ardour_ui.h"
|
|
|
|
#include "ui_config.h"
|
2011-05-02 09:38:16 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2011-05-02 09:38:16 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace ARDOUR;
|
2020-11-16 13:19:22 -05:00
|
|
|
using namespace Temporal;
|
2011-05-02 09:38:16 -04:00
|
|
|
|
2023-11-18 20:40:50 -05:00
|
|
|
VerboseCursor::VerboseCursor (EditingContext& editor)
|
2011-05-02 09:38:16 -04:00
|
|
|
: _editor (editor)
|
|
|
|
{
|
2023-11-18 20:40:50 -05:00
|
|
|
_canvas_item = new ArdourCanvas::TrackingText (_editor.get_noscroll_group());
|
2013-04-24 15:42:14 -04:00
|
|
|
CANVAS_DEBUG_NAME (_canvas_item, "verbose canvas cursor");
|
2015-01-02 09:44:54 -05:00
|
|
|
_canvas_item->set_font_description (Pango::FontDescription (UIConfiguration::instance().get_LargerBoldFont()));
|
2014-06-30 10:38:03 -04:00
|
|
|
color_handler ();
|
|
|
|
|
2015-01-02 09:44:54 -05:00
|
|
|
UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &VerboseCursor::color_handler));
|
2014-06-30 10:38:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VerboseCursor::color_handler ()
|
|
|
|
{
|
2015-01-02 09:44:54 -05:00
|
|
|
_canvas_item->set_color (UIConfiguration::instance().color_mod ("verbose canvas cursor", "verbose canvas cursor"));
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ArdourCanvas::Item *
|
|
|
|
VerboseCursor::canvas_item () const
|
|
|
|
{
|
|
|
|
return _canvas_item;
|
|
|
|
}
|
|
|
|
|
2014-06-26 15:07:29 -04:00
|
|
|
/** Set the contents of the cursor.
|
2014-06-18 22:48:24 -04:00
|
|
|
*/
|
2011-05-02 09:38:16 -04:00
|
|
|
void
|
2014-06-26 15:07:29 -04:00
|
|
|
VerboseCursor::set (string const & text)
|
2011-05-02 09:38:16 -04:00
|
|
|
{
|
2013-04-04 18:45:27 -04:00
|
|
|
_canvas_item->set (text);
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-26 15:07:29 -04:00
|
|
|
VerboseCursor::show ()
|
2011-05-02 09:38:16 -04:00
|
|
|
{
|
2014-06-26 15:07:29 -04:00
|
|
|
_canvas_item->show_and_track (true, true);
|
|
|
|
_canvas_item->parent()->raise_to_top ();
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VerboseCursor::hide ()
|
|
|
|
{
|
|
|
|
_canvas_item->hide ();
|
2014-06-26 15:07:29 -04:00
|
|
|
_canvas_item->parent()->lower_to_bottom ();
|
|
|
|
/* reset back to a sensible default for the next time we display the VC */
|
|
|
|
_canvas_item->set_offset (ArdourCanvas::Duple (10, 10));
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|
|
|
|
|
2014-06-26 15:07:29 -04:00
|
|
|
void
|
|
|
|
VerboseCursor::set_offset (ArdourCanvas::Duple const & d)
|
2011-05-02 09:38:16 -04:00
|
|
|
{
|
2014-06-26 15:07:29 -04:00
|
|
|
_canvas_item->set_offset (d);
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-09-18 12:39:17 -04:00
|
|
|
VerboseCursor::set_time (samplepos_t sample)
|
2011-05-02 09:38:16 -04:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
Timecode::Time timecode;
|
2020-07-23 19:46:49 -04:00
|
|
|
Temporal::BBT_Time bbt;
|
2011-05-02 09:38:16 -04:00
|
|
|
|
2023-11-18 20:40:50 -05:00
|
|
|
if (_editor.session() == 0) {
|
2011-05-02 09:38:16 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-30 10:47:49 -04:00
|
|
|
/* Take clock mode from the primary clock */
|
2011-05-02 09:38:16 -04:00
|
|
|
|
2014-06-30 10:47:49 -04:00
|
|
|
AudioClock::Mode m = ARDOUR_UI::instance()->primary_clock->mode();
|
2011-05-02 09:38:16 -04:00
|
|
|
|
|
|
|
switch (m) {
|
|
|
|
case AudioClock::BBT:
|
2021-12-14 15:23:19 -05:00
|
|
|
bbt = TempoMap::use()->bbt_at (timepos_t (sample));
|
2011-05-02 09:38:16 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%02" PRIu32 "|%02" PRIu32 "|%02" PRIu32, bbt.bars, bbt.beats, bbt.ticks);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AudioClock::Timecode:
|
2023-11-18 20:40:50 -05:00
|
|
|
_editor.session()->timecode_time (sample, timecode);
|
2014-07-09 19:16:03 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%s", Timecode::timecode_format_time (timecode).c_str());
|
2011-05-02 09:38:16 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AudioClock::MinSec:
|
2023-11-18 20:40:50 -05:00
|
|
|
AudioClock::print_minsec (sample, buf, sizeof (buf), _editor.session()->sample_rate());
|
2011-05-02 09:38:16 -04:00
|
|
|
break;
|
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
case AudioClock::Seconds:
|
2023-11-18 20:40:50 -05:00
|
|
|
snprintf (buf, sizeof(buf), "%.1f", sample / (float)_editor.session()->sample_rate());
|
2017-11-22 14:36:28 -05:00
|
|
|
break;
|
|
|
|
|
2011-05-02 09:38:16 -04:00
|
|
|
default:
|
2017-09-18 12:39:17 -04:00
|
|
|
snprintf (buf, sizeof(buf), "%" PRIi64, sample);
|
2011-05-02 09:38:16 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-26 15:07:29 -04:00
|
|
|
_canvas_item->set (buf);
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-09-18 12:39:17 -04:00
|
|
|
VerboseCursor::set_duration (samplepos_t start, samplepos_t end)
|
2011-05-02 09:38:16 -04:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
Timecode::Time timecode;
|
2020-07-23 19:46:49 -04:00
|
|
|
Temporal::BBT_Time sbbt;
|
|
|
|
Temporal::BBT_Time ebbt;
|
2023-06-12 14:36:16 -04:00
|
|
|
Meter const & meter_at_start (TempoMap::use()->metric_at (timepos_t (start)).meter());
|
2011-05-02 09:38:16 -04:00
|
|
|
|
2023-11-18 20:40:50 -05:00
|
|
|
if (_editor.session() == 0) {
|
2011-05-02 09:38:16 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-09 18:32:41 -04:00
|
|
|
AudioClock::Mode m = ARDOUR_UI::instance()->primary_clock->mode ();
|
2011-05-02 09:38:16 -04:00
|
|
|
|
|
|
|
switch (m) {
|
|
|
|
case AudioClock::BBT:
|
|
|
|
{
|
2021-12-14 15:23:19 -05:00
|
|
|
sbbt = TempoMap::use()->bbt_at (timepos_t (start));
|
|
|
|
ebbt = TempoMap::use()->bbt_at (timepos_t (end));
|
2011-05-02 09:38:16 -04:00
|
|
|
|
|
|
|
/* 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) {
|
2020-07-23 19:46:49 -04:00
|
|
|
ticks += int (Temporal::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:
|
2023-11-18 20:40:50 -05:00
|
|
|
_editor.session()->timecode_duration (end - start, timecode);
|
2014-07-09 19:16:03 -04:00
|
|
|
snprintf (buf, sizeof (buf), "%s", Timecode::timecode_format_time (timecode).c_str());
|
2011-05-02 09:38:16 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AudioClock::MinSec:
|
2023-11-18 20:40:50 -05:00
|
|
|
AudioClock::print_minsec (end - start, buf, sizeof (buf), _editor.session()->sample_rate());
|
2011-05-02 09:38:16 -04:00
|
|
|
break;
|
|
|
|
|
2017-11-22 14:36:28 -05:00
|
|
|
case AudioClock::Seconds:
|
2023-11-18 20:40:50 -05:00
|
|
|
snprintf (buf, sizeof(buf), "%.1f", (end - start) / (float)_editor.session()->sample_rate());
|
2017-11-22 14:36:28 -05:00
|
|
|
break;
|
|
|
|
|
2011-05-02 09:38:16 -04:00
|
|
|
default:
|
|
|
|
snprintf (buf, sizeof(buf), "%" PRIi64, end - start);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-26 15:07:29 -04:00
|
|
|
_canvas_item->set (buf);
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
VerboseCursor::visible () const
|
|
|
|
{
|
2014-06-26 15:07:29 -04:00
|
|
|
return _canvas_item->visible();
|
2011-05-02 09:38:16 -04:00
|
|
|
}
|