diff options
author | David Robillard <d@drobilla.net> | 2008-11-17 05:23:13 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2008-11-17 05:23:13 +0000 |
commit | d287e5e3d23a5dfd9fda0da83ea6ec512e386655 (patch) | |
tree | 1614ca51891550d60c1e1ccf3b7532b55d36c6b0 /raul/TimeSlice.hpp | |
parent | 4f43c8357f109ab8f7b0886a41ae11ac4d07a830 (diff) | |
download | raul-d287e5e3d23a5dfd9fda0da83ea6ec512e386655.tar.gz raul-d287e5e3d23a5dfd9fda0da83ea6ec512e386655.tar.bz2 raul-d287e5e3d23a5dfd9fda0da83ea6ec512e386655.zip |
Run... almost
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@1756 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul/TimeSlice.hpp')
-rw-r--r-- | raul/TimeSlice.hpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/raul/TimeSlice.hpp b/raul/TimeSlice.hpp index 8f1ba66..e345c37 100644 --- a/raul/TimeSlice.hpp +++ b/raul/TimeSlice.hpp @@ -71,9 +71,12 @@ public: update_beat_time(); } - void set_start(TimeStamp time) { _start_ticks = time; update_beat_time(); } - - void set_length(TimeDuration length) { _length_ticks = length; update_beat_time(); } + void set_slice(TimeStamp start, TimeDuration length) { + assert(start.unit() == length.unit()); + _start_ticks = start; + _length_ticks = length; + update_beat_time(); + } bool contains(TimeStamp time) { return (time >= start_ticks() && time < start_ticks() + length_ticks()); @@ -93,26 +96,20 @@ public: update_beat_time(); } - // FIXME - inline TimeStamp beats_to_seconds(TimeStamp beats) const { - //return (beats * _beat_rate); - throw; + return TimeStamp(real_unit(), beats.to_double() * 1/(double)_beat_rate); } inline TimeStamp beats_to_ticks(TimeStamp beats) const { - //return static_cast<TimeStamp>(floor(beats_to_seconds(beats) / _tick_rate)); - throw; + return TimeStamp(ticks_unit(), beats.to_double() / (double)_beat_rate * _tick_rate); } inline TimeStamp ticks_to_seconds(TimeStamp ticks) const { - //return (ticks * _tick_rate); - throw; + return TimeStamp(real_unit(), ticks.ticks() * 1/(double)_tick_rate); } inline TimeStamp ticks_to_beats(TimeStamp ticks) const { - //return ticks_to_seconds(ticks) / _beat_rate; - throw; + return TimeStamp(beats_unit(), ticks.ticks() * 1/(double)_tick_rate * _beat_rate); } /** Start of current sub-cycle in ticks */ @@ -132,9 +129,12 @@ public: /** Offset relative to external (e.g Jack) time */ inline TimeDuration offset_ticks() const { return _offset_ticks; } + + inline TimeUnit beats_unit() const { return _start_beats.unit(); } + inline TimeUnit ticks_unit() const { return _start_ticks.unit(); } + inline TimeUnit real_unit() const { return TimeUnit(TimeUnit::SECONDS, 0); } private: - inline void update_beat_time() { _start_beats = ticks_to_beats(_start_ticks); _length_beats = ticks_to_beats(_length_ticks); |