13
0

add a new type for AnytTime (BBT_Offset) and make it serializable

This commit is contained in:
Paul Davis 2024-10-27 14:52:29 -06:00
parent f59e0cb289
commit 5204a24291
3 changed files with 110 additions and 2 deletions

View File

@ -304,6 +304,7 @@ class AnyTime {
enum Type {
Timecode,
BBT,
BBT_Offset,
Samples,
Seconds
};
@ -311,14 +312,21 @@ class AnyTime {
Type type;
Timecode::Time timecode;
Temporal::BBT_Time bbt;
union {
Temporal::BBT_Time bbt;
Temporal::BBT_Offset bbt_offset;
};
union {
samplecnt_t samples;
double seconds;
};
AnyTime() { type = Samples; samples = 0; }
AnyTime () : type (Samples), samples (0) {}
AnyTime (Temporal::BBT_Offset bt) : type (BBT_Offset), bbt_offset (bt) {}
AnyTime (std::string const &);
std::string str() const;
bool operator== (AnyTime const & other) const {
if (type != other.type) { return false; }
@ -328,6 +336,8 @@ class AnyTime {
return timecode == other.timecode;
case BBT:
return bbt == other.bbt;
case BBT_Offset:
return bbt_offset == other.bbt_offset;
case Samples:
return samples == other.samples;
case Seconds:
@ -344,6 +354,8 @@ class AnyTime {
timecode.seconds != 0 || timecode.frames != 0;
case BBT:
return bbt.bars != 0 || bbt.beats != 0 || bbt.ticks != 0;
case BBT_Offset:
return bbt_offset.bars != 0 || bbt_offset.beats != 0 || bbt_offset.ticks != 0;
case Samples:
return samples != 0;
case Seconds:

View File

@ -94,6 +94,32 @@ DEFINE_ENUM_CONVERT(ARDOUR::CueBehavior)
DEFINE_ENUM_CONVERT(MusicalMode::Type)
template <>
inline bool to_string (ARDOUR::AnyTime const & at, std::string & str)
{
str = at.str();
return true;
}
template <>
inline bool string_to (std::string const & str, ARDOUR::AnyTime & at)
{
at = ARDOUR::AnyTime (str);
return true;
}
template <>
inline std::string to_string (ARDOUR::AnyTime at)
{
return at.str();
}
template <>
inline ARDOUR::AnyTime string_to (std::string const & str)
{
return ARDOUR::AnyTime (str);
}
template <>
inline std::string to_string (ARDOUR::timepos_t val)
{

View File

@ -34,6 +34,8 @@
#include <cstdio> // Needed so that libraptor (included in lrdf) won't complain
#include <cstdlib>
#include <sstream>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
@ -84,6 +86,7 @@
#include "pbd/cpus.h"
#include "pbd/enumwriter.h"
#include "pbd/error.h"
#include "pbd/failed_constructor.h"
#include "pbd/file_utils.h"
#include "pbd/fpu.h"
#include "pbd/id.h"
@ -1074,3 +1077,70 @@ ARDOUR::reset_performance_meters (Session *session)
AudioEngine::instance()->current_backend()->dsp_stats[n].queue_reset ();
}
}
ARDOUR::AnyTime::AnyTime (std::string const & str)
{
char c;
std::stringstream ss;
ss << str;
ss >> c;
switch (c) {
case 't':
type = Timecode;
if (!Timecode::parse_timecode_format (str.substr (1), timecode)) {
throw failed_constructor ();
}
break;
case 'b':
type = BBT;
ss >> bbt;
break;
case 'B':
type = BBT_Offset;
ss >> bbt_offset;
break;
case 's':
type = Samples;
ss >> samples;
break;
case 'S':
type = Seconds;
ss >> seconds;
break;
default:
throw failed_constructor();
}
}
std::string
ARDOUR::AnyTime::str() const
{
std::stringstream ss;
switch (type) {
case Timecode:
ss << 't';
ss << timecode;
break;
case BBT:
ss << 'b';
ss << bbt;
break;
case BBT_Offset:
ss << 'B';
ss << bbt_offset;
break;
case Samples:
ss << 's';
ss << samples;
break;
case Seconds:
ss << 'S';
ss << seconds;
break;
}
return ss.str ();
}