diff options
author | David Robillard <d@drobilla.net> | 2014-11-22 21:49:42 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2014-11-22 21:49:42 -0500 |
commit | 57c1b6e261076cae9b61e74aa0aff47a9f296c0f (patch) | |
tree | 0ed8e37d0fe4bdc7c49437062d16045d1d9b3881 /libs/evoral/evoral | |
parent | 231e0009b40464ed0c74efcb4585c6ace1336b59 (diff) |
Fix quantization and other time-related ops.
Diffstat (limited to 'libs/evoral/evoral')
-rw-r--r-- | libs/evoral/evoral/types.hpp | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/libs/evoral/evoral/types.hpp b/libs/evoral/evoral/types.hpp index ee93bc3998..719007abe5 100644 --- a/libs/evoral/evoral/types.hpp +++ b/libs/evoral/evoral/types.hpp @@ -126,14 +126,35 @@ public: } inline bool operator>=(const MusicalTime& b) const { + return operator==(b) || operator>(b); + } + + inline bool operator<(double b) const { /* Acceptable tolerance is 1 tick. */ - if (fabs(_time - b._time) <= (1.0 / PPQN)) { - return true; /* Effectively identical. */ + if (fabs(_time - b) <= (1.0 / PPQN)) { + return false; /* Effectively identical. */ + } else { + return _time < b; + } + } + + inline bool operator<=(double b) const { + return operator==(b) || operator<(b); + } + + inline bool operator>(double b) const { + /* Acceptable tolerance is 1 tick. */ + if (fabs(_time - b) <= (1.0 / PPQN)) { + return false; /* Effectively identical. */ } else { - return _time >= b._time; + return _time > b; } } + inline bool operator>=(double b) const { + return operator==(b) || operator>(b); + } + MusicalTime operator+(const MusicalTime& b) const { return MusicalTime(_time + b._time); } @@ -142,6 +163,14 @@ public: return MusicalTime(_time - b._time); } + MusicalTime operator+(double d) const { + return MusicalTime(_time + d); + } + + MusicalTime operator-(double d) const { + return MusicalTime(_time - d); + } + MusicalTime operator-() const { return MusicalTime(-_time); } @@ -165,7 +194,10 @@ public: uint64_t to_ticks() const { return lrint(_time * PPQN); } uint64_t to_ticks(uint32_t ppqn) const { return lrint(_time * ppqn); } - operator bool() const { return _time != 0; } + uint32_t get_beats() const { return floor(_time); } + uint32_t get_ticks() const { return (uint32_t)lrint(fmod(_time, 1.0) * PPQN); } + + bool operator!() const { return _time == 0; } static MusicalTime min() { return MusicalTime(DBL_MIN); } static MusicalTime max() { return MusicalTime(DBL_MAX); } |