+
+ /* it would be nice to provide operator+(BBT_Time const&) and
+ * operator-(BBT_Time const&) but this math requires knowledge of the
+ * meter (time signature) used to define 1 bar, and so cannot be
+ * carried out with only two BBT_Time values.
+ */
+
+ BBT_Time round_to_beat () const { return ticks >= (ticks_per_beat/2) ? BBT_Time (bars, beats+1, 0) : BBT_Time (bars, beats, 0); }
+ BBT_Time round_down_to_beat () const { return BBT_Time (bars, beats, 0); }
+ BBT_Time round_up_to_beat () const { return ticks ? BBT_Time (bars, beats+1, 0) : *this; }
+
+ /* cannot implement round_to_bar() without knowing meter (time
+ * signature) information.
+ */
+};
+
+struct LIBTIMECODE_API BBT_Offset
+{
+ int32_t bars;
+ int32_t beats;
+ int32_t ticks;
+
+ /* this is a variant for which bars==0 and/or beats==0 is legal. It
+ * represents an offset from a given BBT_Time and is used when doing
+ * add/subtract operations on a BBT_Time.
+ */
+
+ BBT_Offset () : bars (0), beats (0), ticks (0) {}
+ BBT_Offset (int32_t ba, uint32_t be, uint32_t t) : bars (ba), beats (be), ticks (t) {}
+ BBT_Offset (BBT_Time const & bbt) : bars (bbt.bars), beats (bbt.beats), ticks (bbt.ticks) {}
+ BBT_Offset (double beats);