BBT_Time: provide conversion to/from integer format
This is not guaranteed to be lossless, but with 44 bits for bars, 256 beats per bar and up to 4095 ticks per beat, it should be fine.
This commit is contained in:
parent
2c7bfa9ead
commit
6cde958480
@ -23,6 +23,24 @@
|
|||||||
|
|
||||||
using namespace Temporal;
|
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
|
||||||
BBT_Time::round_up_to_bar() const
|
BBT_Time::round_up_to_bar() const
|
||||||
{
|
{
|
||||||
|
@ -54,6 +54,9 @@ struct LIBTEMPORAL_API BBT_Time
|
|||||||
int32_t beats;
|
int32_t beats;
|
||||||
int32_t ticks;
|
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_bar() const { return beats == 1 && ticks == 0; }
|
||||||
bool is_beat() const { return ticks == 0; }
|
bool is_beat() const { return ticks == 0; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user