diff --git a/libs/temporal/bbt_time.cc b/libs/temporal/bbt_time.cc index 5c876b0a38..c03b9301a1 100644 --- a/libs/temporal/bbt_time.cc +++ b/libs/temporal/bbt_time.cc @@ -23,6 +23,24 @@ using namespace Temporal; +int64_t +BBT_Time::as_integer () const +{ + /* up to 256 beats in a bar, 4095 ticks in a beat, + and whatever is left for bars (a lot!) + */ + return (((int64_t) bars)<<20)|(beats<<12)|ticks; +} + +BBT_Time +BBT_Time::from_integer (int64_t v) +{ + int32_t B = v>>20; + int32_t b = (v>>12) & 0xff; + int32_t t= v & 0xfff; + return BBT_Time (B, b, t); +} + BBT_Time BBT_Time::round_up_to_bar() const { diff --git a/libs/temporal/temporal/bbt_time.h b/libs/temporal/temporal/bbt_time.h index 010d28ec31..a622f9e1a6 100644 --- a/libs/temporal/temporal/bbt_time.h +++ b/libs/temporal/temporal/bbt_time.h @@ -54,6 +54,9 @@ struct LIBTEMPORAL_API BBT_Time int32_t beats; int32_t ticks; + int64_t as_integer() const; + static BBT_Time from_integer (int64_t); + bool is_bar() const { return beats == 1 && ticks == 0; } bool is_beat() const { return ticks == 0; }