From d287e5e3d23a5dfd9fda0da83ea6ec512e386655 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 17 Nov 2008 05:23:13 +0000 Subject: Run... almost git-svn-id: http://svn.drobilla.net/lad/trunk/raul@1756 a436a847-0d15-0410-975c-d299462d15a1 --- raul/TimeSlice.hpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'raul/TimeSlice.hpp') 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(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); -- cgit v1.2.1