19 #ifndef __libtemporal_bbt_time_h__
20 #define __libtemporal_bbt_time_h__
41 virtual const char*
what()
const throw() {
return "illegal BBT time (bars or beats were zero, or ticks was too large)"; }
60 bool is_bar()
const {
return beats == 1 && ticks == 0; }
61 bool is_beat()
const {
return ticks == 0; }
63 BBT_Time () : bars (1), beats (1), ticks (0) {}
64 BBT_Time (int32_t ba, uint32_t be, uint32_t t) : bars (ba), beats (be), ticks (t) {
65 if (!bars || !beats) {
71 return bars < other.
bars ||
72 (bars == other.
bars && beats < other.
beats) ||
73 (bars == other.
bars && beats == other.
beats && ticks < other.
ticks);
76 bool operator<= (
const BBT_Time& other)
const {
77 return bars < other.
bars ||
78 (bars <= other.
bars && beats < other.
beats) ||
79 (bars <= other.
bars && beats <= other.
beats && ticks <= other.
ticks);
83 return bars > other.
bars ||
84 (bars == other.
bars && beats > other.
beats) ||
85 (bars == other.
bars && beats == other.
beats && ticks > other.
ticks);
88 bool operator>= (
const BBT_Time& other)
const {
89 return bars > other.
bars ||
90 (bars >= other.
bars && beats > other.
beats) ||
91 (bars >= other.
bars && beats >= other.
beats && ticks >= other.
ticks);
95 return bars == other.
bars && beats == other.
beats && ticks == other.
ticks;
98 bool operator!= (
const BBT_Time& other)
const {
99 return bars != other.
bars || beats != other.
beats || ticks != other.
ticks;
102 bool operator< (
const BBT_Offset& other)
const;
103 bool operator<= (
const BBT_Offset& other)
const;
104 bool operator> (
const BBT_Offset& other)
const;
105 bool operator>= (
const BBT_Offset& other)
const;
107 bool operator!= (
const BBT_Offset& other)
const;
132 o << std::setfill (
'0') << std::right
133 << std::setw (3) << bars <<
"|"
134 << std::setw (2) << beats <<
"|"
135 << std::setw (4) << ticks;
138 std::string
str ()
const {
139 std::ostringstream os;
140 os << bars <<
'|' << beats <<
'|' << ticks;
158 BBT_Offset (int32_t ba, uint32_t be, uint32_t t) : bars (ba), beats (be), ticks (t) {}
182 beats += other.
beats;
183 ticks += other.
ticks;
189 beats -= other.
beats;
190 ticks -= other.
ticks;
202 bars = (int32_t) lrint (bars * factor);
203 beats = (int32_t) lrint (beats * factor);
204 ticks = (int32_t) lrint (ticks * factor);
216 bars = (int32_t) lrint (bars / factor);
217 beats = (int32_t) lrint (beats / factor);
218 ticks = (int32_t) lrint (ticks / factor);
223 return bars < other.
bars ||
224 (bars == other.
bars && beats < other.
beats) ||
225 (bars == other.
bars && beats == other.
beats && ticks < other.
ticks);
229 return bars < other.
bars ||
230 (bars <= other.
bars && beats <= other.
beats) ||
231 (bars <= other.
bars && beats <= other.
beats && ticks <= other.
ticks);
235 return bars > other.
bars ||
236 (bars == other.
bars && beats > other.
beats) ||
237 (bars == other.
bars && beats == other.
beats && ticks > other.
ticks);
241 return bars > other.
bars ||
242 (bars >= other.
bars && beats >= other.
beats) ||
243 (bars >= other.
bars && beats >= other.
beats && ticks >= other.
ticks);
247 return bars == other.
bars && beats == other.
beats && ticks == other.
ticks;
251 return bars != other.
bars || beats != other.
beats || ticks != other.
ticks;
254 operator bool()
const {
255 return bars == 0 && beats == 0 && ticks == 0;
258 std::string
str ()
const {
259 std::ostringstream os;
260 os << bars <<
'|' << beats <<
'|' << ticks;
337 std::numeric_limits<int32_t>::max(),
338 std::numeric_limits<int32_t>::max());
354 std::numeric_limits<int32_t>::max(),
355 std::numeric_limits<int32_t>::max());
367 std::ostringstream ostr;
376 std::ostringstream ostr;
384 std::istringstream istr (str);
400 std::ostringstream ostr;
409 std::ostringstream ostr;
417 std::istringstream istr (str);
std::string to_string(ARDOUR::timepos_t val)
ARDOUR::timepos_t string_to(std::string const &str)
BBT_Offset bbt_delta(Temporal::BBT_Time const &a, Temporal::BBT_Time const &b)
static const int32_t ticks_per_beat
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
BBT_Offset operator+(const BBT_Offset &other) const
BBT_Offset & operator/=(double factor)
BBT_Offset & operator*=(double factor)
BBT_Offset & operator/=(int factor)
BBT_Offset(int32_t ba, uint32_t be, uint32_t t)
BBT_Offset & operator+=(const BBT_Offset &other)
BBT_Offset operator-(const BBT_Offset &other) const
BBT_Offset operator-() const
BBT_Offset & operator*=(int factor)
BBT_Offset(BBT_Time const &bbt)
BBT_Offset & operator-=(const BBT_Offset &other)
BBT_Time round_up_to_beat() const
void print_padded(std::ostream &o) const
int64_t as_integer() const
BBT_Time(int32_t ba, uint32_t be, uint32_t t)
BBT_Time round_down_to_beat() const
BBT_Time round_up_to_beat_div(int beat_div) const
bool operator<(const BBT_Time &other) const
BBT_Time round_down_to_bar() const
static BBT_Time from_integer(int64_t)
bool operator<=(const BBT_Time &other) const
BBT_Time round_to_beat() const
BBT_Time round_up_to_bar() const
BBT_Time prev_bar() const
bool operator==(const BBT_Time &other) const
bool operator>(const BBT_Time &other) const
bool operator>=(const BBT_Time &other) const
bool operator!=(const BBT_Time &other) const
BBT_Time next_bar() const
virtual const char * what() const
static Temporal::BBT_Offset min()
static Temporal::BBT_Time max()
static Temporal::BBT_Offset lowest()
static Temporal::BBT_Time min()
static Temporal::BBT_Time max()
static Temporal::BBT_Time lowest()