summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--raul/Quantizer.hpp6
-rw-r--r--raul/RingBuffer.hpp1
-rw-r--r--raul/TimeSlice.hpp28
-rw-r--r--raul/TimeStamp.hpp3
4 files changed, 23 insertions, 15 deletions
diff --git a/raul/Quantizer.hpp b/raul/Quantizer.hpp
index 9a40751..2295ceb 100644
--- a/raul/Quantizer.hpp
+++ b/raul/Quantizer.hpp
@@ -33,6 +33,12 @@ public:
const double td = t.to_double();
return TimeStamp(t.unit(), (qd > 0) ? lrint(td / qd) * qd : td);
}
+
+ inline static double quantize(double q, double t) {
+ return (q > 0)
+ ? lrint(t / q) * q
+ : t;
+ }
};
diff --git a/raul/RingBuffer.hpp b/raul/RingBuffer.hpp
index 518a24b..6f7dcb3 100644
--- a/raul/RingBuffer.hpp
+++ b/raul/RingBuffer.hpp
@@ -19,6 +19,7 @@
#define RAUL_RING_BUFFER_HPP
#include <cassert>
+#include <cstring>
#include <iostream>
#include <glib.h>
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);
diff --git a/raul/TimeStamp.hpp b/raul/TimeStamp.hpp
index 6cbf807..c108fd6 100644
--- a/raul/TimeStamp.hpp
+++ b/raul/TimeStamp.hpp
@@ -41,6 +41,7 @@ public:
* PPQN for BEATS, and ignored for SECONDS.
*/
inline TimeUnit(Type type, uint32_t ppt) {
+ assert(type == SECONDS || ppt != 0);
_type = type;
_ppt = ppt;
}
@@ -106,7 +107,7 @@ public:
}
inline TimeStamp& operator=(const TimeStamp& rhs) {
- assert(_unit == rhs._unit);
+ //assert(_unit == rhs._unit);
_ticks = rhs._ticks;
_subticks = rhs._subticks;
//_unit = rhs._unit;