Move format_position to utils
This will allow other places to reuse this method.
This commit is contained in:
parent
32ef2d5a0f
commit
09e82c1607
|
@ -46,13 +46,13 @@
|
|||
|
||||
#include "actions.h"
|
||||
#include "ardour_ui.h"
|
||||
#include "audio_clock.h"
|
||||
#include "gui_thread.h"
|
||||
#include "keyboard.h"
|
||||
#include "main_clock.h"
|
||||
#include "public_editor.h"
|
||||
#include "region_list_base.h"
|
||||
#include "ui_config.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "pbd/i18n.h"
|
||||
|
||||
|
@ -441,73 +441,9 @@ RegionListBase::clock_format_changed ()
|
|||
}
|
||||
|
||||
void
|
||||
RegionListBase::format_position (timepos_t const& p, char* buf, size_t bufsize, bool onoff)
|
||||
RegionListBase::format_position (timepos_t const& p, char* buf, size_t bufsize, bool onoff) const
|
||||
{
|
||||
Temporal::BBT_Time bbt;
|
||||
Timecode::Time timecode;
|
||||
samplepos_t pos (p.samples ());
|
||||
|
||||
if (pos < 0) {
|
||||
error << string_compose (_("RegionListBase::format_position: negative timecode position: %1"), pos) << endmsg;
|
||||
snprintf (buf, bufsize, "invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ARDOUR_UI::instance ()->primary_clock->mode ()) {
|
||||
case AudioClock::BBT:
|
||||
bbt = Temporal::TempoMap::use ()->bbt_at (p);
|
||||
if (onoff) {
|
||||
snprintf (buf, bufsize, "%03d|%02d|%04d", bbt.bars, bbt.beats, bbt.ticks);
|
||||
} else {
|
||||
snprintf (buf, bufsize, "(%03d|%02d|%04d)", bbt.bars, bbt.beats, bbt.ticks);
|
||||
}
|
||||
break;
|
||||
|
||||
case AudioClock::MinSec:
|
||||
samplepos_t left;
|
||||
int hrs;
|
||||
int mins;
|
||||
float secs;
|
||||
|
||||
left = pos;
|
||||
hrs = (int)floor (left / (_session->sample_rate () * 60.0f * 60.0f));
|
||||
left -= (samplecnt_t)floor (hrs * _session->sample_rate () * 60.0f * 60.0f);
|
||||
mins = (int)floor (left / (_session->sample_rate () * 60.0f));
|
||||
left -= (samplecnt_t)floor (mins * _session->sample_rate () * 60.0f);
|
||||
secs = left / (float)_session->sample_rate ();
|
||||
if (onoff) {
|
||||
snprintf (buf, bufsize, "%02d:%02d:%06.3f", hrs, mins, secs);
|
||||
} else {
|
||||
snprintf (buf, bufsize, "(%02d:%02d:%06.3f)", hrs, mins, secs);
|
||||
}
|
||||
break;
|
||||
|
||||
case AudioClock::Seconds:
|
||||
if (onoff) {
|
||||
snprintf (buf, bufsize, "%.1f", pos / (float)_session->sample_rate ());
|
||||
} else {
|
||||
snprintf (buf, bufsize, "(%.1f)", pos / (float)_session->sample_rate ());
|
||||
}
|
||||
break;
|
||||
|
||||
case AudioClock::Samples:
|
||||
if (onoff) {
|
||||
snprintf (buf, bufsize, "%" PRId64, pos);
|
||||
} else {
|
||||
snprintf (buf, bufsize, "(%" PRId64 ")", pos);
|
||||
}
|
||||
break;
|
||||
|
||||
case AudioClock::Timecode:
|
||||
default:
|
||||
_session->timecode_time (pos, timecode);
|
||||
if (onoff) {
|
||||
snprintf (buf, bufsize, "%02d:%02d:%02d:%02d", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
|
||||
} else {
|
||||
snprintf (buf, bufsize, "(%02d:%02d:%02d:%02d)", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
|
||||
}
|
||||
break;
|
||||
}
|
||||
ARDOUR_UI_UTILS::format_position (_session, p, buf, bufsize, onoff);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -195,7 +195,7 @@ protected:
|
|||
bool enter_notify (GdkEventCrossing*);
|
||||
bool leave_notify (GdkEventCrossing*);
|
||||
|
||||
void format_position (Temporal::timepos_t const& pos, char* buf, size_t bufsize, bool onoff = true);
|
||||
void format_position (Temporal::timepos_t const& pos, char* buf, size_t bufsize, bool onoff = true) const;
|
||||
|
||||
void add_region (std::shared_ptr<ARDOUR::Region>);
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "ardour/auditioner.h"
|
||||
#include "ardour/audioengine.h"
|
||||
#include "ardour/filesystem_paths.h"
|
||||
#include "ardour/session.h"
|
||||
#include "ardour/search_paths.h"
|
||||
#include "ardour/triggerbox.h"
|
||||
|
||||
|
@ -68,6 +69,7 @@
|
|||
#include "debug.h"
|
||||
#include "public_editor.h"
|
||||
#include "keyboard.h"
|
||||
#include "main_clock.h"
|
||||
#include "utils.h"
|
||||
#include "pbd/i18n.h"
|
||||
#include "gui_thread.h"
|
||||
|
@ -985,3 +987,73 @@ ARDOUR_UI_UTILS::copy_patch_changes (std::shared_ptr<ARDOUR::Auditioner> a, std:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ARDOUR_UI_UTILS::format_position (ARDOUR::Session* s, Temporal::timepos_t const& p, char* buf, size_t bufsize, bool onoff)
|
||||
{
|
||||
Temporal::BBT_Time bbt;
|
||||
Timecode::Time timecode;
|
||||
samplepos_t pos (p.samples ());
|
||||
|
||||
if (pos < 0) {
|
||||
error << string_compose (_("format_position: negative timecode position: %1"), pos) << endmsg;
|
||||
snprintf (buf, bufsize, "invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ARDOUR_UI::instance ()->primary_clock->mode ()) {
|
||||
case AudioClock::BBT:
|
||||
bbt = Temporal::TempoMap::use ()->bbt_at (p);
|
||||
if (onoff) {
|
||||
snprintf (buf, bufsize, "%03d|%02d|%04d", bbt.bars, bbt.beats, bbt.ticks);
|
||||
} else {
|
||||
snprintf (buf, bufsize, "(%03d|%02d|%04d)", bbt.bars, bbt.beats, bbt.ticks);
|
||||
}
|
||||
break;
|
||||
|
||||
case AudioClock::MinSec:
|
||||
samplepos_t left;
|
||||
int hrs;
|
||||
int mins;
|
||||
float secs;
|
||||
|
||||
left = pos;
|
||||
hrs = (int)floor (left / (s->sample_rate () * 60.0f * 60.0f));
|
||||
left -= (samplecnt_t)floor (hrs * s->sample_rate () * 60.0f * 60.0f);
|
||||
mins = (int)floor (left / (s->sample_rate () * 60.0f));
|
||||
left -= (samplecnt_t)floor (mins * s->sample_rate () * 60.0f);
|
||||
secs = left / (float)s->sample_rate ();
|
||||
if (onoff) {
|
||||
snprintf (buf, bufsize, "%02d:%02d:%06.3f", hrs, mins, secs);
|
||||
} else {
|
||||
snprintf (buf, bufsize, "(%02d:%02d:%06.3f)", hrs, mins, secs);
|
||||
}
|
||||
break;
|
||||
|
||||
case AudioClock::Seconds:
|
||||
if (onoff) {
|
||||
snprintf (buf, bufsize, "%.1f", pos / (float)s->sample_rate ());
|
||||
} else {
|
||||
snprintf (buf, bufsize, "(%.1f)", pos / (float)s->sample_rate ());
|
||||
}
|
||||
break;
|
||||
|
||||
case AudioClock::Samples:
|
||||
if (onoff) {
|
||||
snprintf (buf, bufsize, "%" PRId64, pos);
|
||||
} else {
|
||||
snprintf (buf, bufsize, "(%" PRId64 ")", pos);
|
||||
}
|
||||
break;
|
||||
|
||||
case AudioClock::Timecode:
|
||||
default:
|
||||
s->timecode_time (pos, timecode);
|
||||
if (onoff) {
|
||||
snprintf (buf, bufsize, "%02d:%02d:%02d:%02d", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
|
||||
} else {
|
||||
snprintf (buf, bufsize, "(%02d:%02d:%02d:%02d)", timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ namespace ArdourCanvas {
|
|||
|
||||
namespace ARDOUR {
|
||||
class Auditioner;
|
||||
class Session;
|
||||
class Trigger;
|
||||
}
|
||||
|
||||
|
@ -117,5 +118,7 @@ void copy_patch_changes (std::shared_ptr<ARDOUR::Auditioner>, std::shared_ptr<AR
|
|||
|
||||
bool convert_drop_to_paths (std::vector<std::string>&, const Gtk::SelectionData&);
|
||||
|
||||
void format_position (ARDOUR::Session*, Temporal::timepos_t const& pos, char* buf, size_t bufsize, bool onoff = true);
|
||||
|
||||
} // namespace
|
||||
#endif /* __ardour_gtk_utils_h__ */
|
||||
|
|
Loading…
Reference in New Issue
Block a user