From 8e69778466c3d80d0eb86b38891d74fbc769951e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 2 Jan 2021 15:42:50 +0100 Subject: Remove TimeSlice and TimeStamp --- NEWS | 3 +- include/raul/TimeSlice.hpp | 167 ----------------------------- include/raul/TimeStamp.hpp | 254 --------------------------------------------- test/build_test.cpp | 7 -- test/time_test.cpp | 45 -------- wscript | 3 +- 6 files changed, 3 insertions(+), 476 deletions(-) delete mode 100644 include/raul/TimeSlice.hpp delete mode 100644 include/raul/TimeStamp.hpp delete mode 100644 test/time_test.cpp diff --git a/NEWS b/NEWS index 7485b70..bfe9a7f 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ raul (0.8.10) unstable; * Improve RingBuffer * Improve test suite * Remove OSC and RDF library dependent code + * Remove TimeSlice and TimeStamp * Remove URI class * Remove boost dependency * Remove features now provided by C++11 @@ -16,7 +17,7 @@ raul (0.8.10) unstable; * Remove several questionable classes * Update license to GPL3+ - -- David Robillard Sun, 23 Jul 2017 10:40:39 +0000 + -- David Robillard Sat, 02 Jan 2021 14:42:30 +0000 raul (0.8.0) stable; diff --git a/include/raul/TimeSlice.hpp b/include/raul/TimeSlice.hpp deleted file mode 100644 index 3efa180..0000000 --- a/include/raul/TimeSlice.hpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - Copyright 2007-2012 David Robillard - - Raul is free software: you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or any later version. - - Raul is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Raul. If not, see . -*/ - -#ifndef RAUL_TIMESLICE_HPP -#define RAUL_TIMESLICE_HPP - -#include "raul/Noncopyable.hpp" -#include "raul/TimeStamp.hpp" - -#include -#include - -namespace Raul { - -/* FIXME: all the conversion here is wrong now */ - -/** A duration of time, with conversion between tick time and beat time. - * - * This is a slice along a single timeline (ie t=0 in ticks and t=0 in beats - * are equal). Relation to an external time base (e.g. Jack frame time) is - * represented by frame_offset (the idea is that this holds all the information - * necessary for passing to run() methods so they know the current state of - * things WRT time). - * - * This class handles conversion between two units of time: musical - * (beat) time, and real (tick) time. Real time is discrete, the smallest - * unit of time is the 'tick' (usually audio frames or MIDI ticks). Beat time - * is stored as a double (to be independent of any rates or timer precision). - * - * This caches as many values as possible to make calls less expensive, pass it - * around by reference, not value. - * - * \ingroup raul - */ -class TimeSlice : public Noncopyable -{ -public: - TimeSlice(uint32_t rate, uint32_t ppqn, double bpm) - : _tick_rate(rate) - , _beat_rate(60.0 / bpm) - , _start_ticks(Raul::TimeUnit(Raul::TimeUnit::FRAMES, rate), 0, 0) - , _length_ticks(TimeUnit(TimeUnit::FRAMES, rate), 0, 0) - , _start_beats(TimeUnit(TimeUnit::BEATS, ppqn), 0, 0) - , _length_beats(TimeUnit(TimeUnit::BEATS, ppqn), 0, 0) - , _offset_ticks(TimeUnit(TimeUnit::FRAMES, rate), 0, 0) - {} - - /** Set the start and length of the slice. - * - * Note that external offset is not affected by this, don't forget to reset - * the offset each cycle! - */ - void set_slice(TimeStamp start, TimeDuration length) - { - assert(start.unit() == ticks_unit()); - assert(length.unit() == ticks_unit()); - _start_ticks = start; - _length_ticks = length; - update_beat_time(); - } - - void set_length(TimeDuration length) - { - assert(length.unit() == ticks_unit()); - _length_ticks = length; - _length_beats = ticks_to_beats(_length_ticks); - } - - bool contains(TimeStamp time) const - { - return (time >= start_ticks() && time < start_ticks() + length_ticks()); - } - - double tick_rate() const { return _tick_rate; } - double beat_rate() const { return _beat_rate; } - double bpm() const { return 60 / _beat_rate; } - - void set_tick_rate(double tick_rate) - { - _tick_rate = tick_rate; - update_beat_time(); - } - - void set_bpm(double bpm) - { - _beat_rate = 60.0 / bpm; - update_beat_time(); - } - - inline TimeStamp beats_to_seconds(TimeStamp beats) const - { - return {real_unit(), beats.to_double() * 1 / _beat_rate}; - } - - inline TimeStamp beats_to_ticks(TimeStamp beats) const - { - return {ticks_unit(), beats.to_double() * _beat_rate * _tick_rate}; - } - - inline TimeStamp ticks_to_seconds(TimeStamp ticks) const - { - return {real_unit(), ticks.ticks() * 1 / _tick_rate}; - } - - inline TimeStamp ticks_to_beats(TimeStamp ticks) const - { - return {beats_unit(), ticks.ticks() * 1 / _tick_rate * _beat_rate}; - } - - /** Start of current sub-cycle in ticks */ - inline TimeStamp start_ticks() const { return _start_ticks; } - - /** Length of current sub-cycle in ticks */ - inline TimeDuration length_ticks() const { return _length_ticks; } - - /** Start of current sub-cycle in beats */ - inline TimeStamp start_beats() const { return _start_beats; } - - /** Length of current sub-cycle in beats */ - inline TimeDuration length_beats() const { return _length_beats; } - - /** Set the offset between real-time and timeslice-time. */ - inline void set_offset(TimeDuration offset) { _offset_ticks = offset; } - - /** 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(); } - - static inline TimeUnit real_unit() { return {TimeUnit::SECONDS, 0}; } - -private: - inline void update_beat_time() - { - _start_beats = ticks_to_beats(_start_ticks); - _length_beats = ticks_to_beats(_length_ticks); - } - - // Rate/Tempo - double _tick_rate; ///< Tick rate in Hz (e.g. sample rate) - double _beat_rate; ///< Beat rate in Hz - - // Current time - TimeStamp _start_ticks; ///< Current window start in ticks - TimeDuration _length_ticks; ///< Current window length in ticks - TimeStamp _start_beats; ///< Current window start in beats - TimeDuration _length_beats; ///< Current window length in beats - - TimeDuration _offset_ticks; ///< Offset to global time -}; - -} // namespace Raul - -#endif // RAUL_TIMESLICE_HPP diff --git a/include/raul/TimeStamp.hpp b/include/raul/TimeStamp.hpp deleted file mode 100644 index 0385ef3..0000000 --- a/include/raul/TimeStamp.hpp +++ /dev/null @@ -1,254 +0,0 @@ -/* - Copyright 2007-2014 David Robillard - - Raul is free software: you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or any later version. - - Raul is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Raul. If not, see . -*/ - -#ifndef RAUL_TIMESTAMP_HPP -#define RAUL_TIMESTAMP_HPP - -#include -#include -#include -#include -#include -#include - -namespace Raul { - -/** A type of time stamp - * \ingroup raul - */ -class TimeUnit -{ -public: - enum Type { FRAMES, BEATS, SECONDS }; - - /** `ppt` (parts per tick) is the sample rate for FRAMES, PPQN for BEATS, - * and ignored for SECONDS. - */ - inline TimeUnit(Type type, uint32_t ppt) - : _type(type) - , _ppt(ppt) - { - assert(type == SECONDS || ppt != 0); - _type = type; - _ppt = ppt; - } - - static inline TimeUnit frames(uint32_t srate) { return {FRAMES, srate}; } - static inline TimeUnit beats(uint32_t ppqn) { return {BEATS, ppqn}; } - static inline TimeUnit seconds() - { - return {BEATS, std::numeric_limits::max()}; - } - - inline Type type() const { return _type; } - inline uint32_t ppt() const { return _ppt; } - - inline bool operator==(const TimeUnit& rhs) const - { - return (_type == rhs._type && _ppt == rhs._ppt); - } - - inline bool operator!=(const TimeUnit& rhs) const - { - return (_type != rhs._type || _ppt != rhs._ppt); - } - -private: - Type _type; - uint32_t _ppt; -}; - -/** A real-time time stamp (possible units: frame, absolute (s), or beat). - * - * This is a uint32_t:uint32_t fixed point representation, capable of - * sub-sample accurate frame time, beat time (at any remotely sane - * tempo and sample rate), and absolute time. The absolute time (seconds) - * is compatible with standard OSC/NTP time stamps. - * - * \ingroup raul - */ -class TimeStamp -{ -public: - explicit TimeStamp(TimeUnit unit, uint32_t ticks = 0, uint32_t subticks = 0) - : _ticks(ticks) - , _subticks(subticks) - , _unit(unit) - {} - - inline TimeStamp(TimeUnit unit, double dec) - : _ticks(0u) - , _subticks(0u) - , _unit(unit) - { - dec = std::max(0.0, dec); - dec = std::min(double(std::numeric_limits::max()), dec); - double integral = 0.0; - const double fractional = modf(dec, &integral); - _ticks = static_cast(integral); - _subticks = static_cast(fractional * unit.ppt()); - } - - TimeStamp(const TimeStamp&) = default; - TimeStamp& operator=(const TimeStamp&) = default; - - TimeStamp(TimeStamp&&) = default; - TimeStamp& operator=(TimeStamp&&) = default; - - ~TimeStamp() = default; - - inline TimeUnit unit() const { return _unit; } - inline uint32_t ticks() const { return _ticks; } - inline uint32_t subticks() const { return _subticks; } - - inline double to_double() const - { - return _ticks + (_subticks / static_cast(_unit.ppt())); - } - - inline bool is_zero() const { return _ticks == 0 && _subticks == 0; } - - inline TimeStamp& operator=(uint32_t ticks) - { - _ticks = ticks; - _subticks = 0; - return *this; - } - - inline bool operator==(const TimeStamp& rhs) const - { - return _ticks == rhs._ticks && _subticks == rhs._subticks && - _unit == rhs._unit; - } - - inline bool operator!=(const TimeStamp& rhs) const - { - return !operator==(rhs); - } - - inline bool operator<(const TimeStamp& rhs) const - { - assert(_unit == rhs._unit); - return (_ticks < rhs._ticks || - (_ticks == rhs._ticks && _subticks < rhs._subticks)); - } - - inline bool operator>(const TimeStamp& rhs) const - { - assert(_unit == rhs._unit); - return (_ticks > rhs._ticks || - (_ticks == rhs._ticks && _subticks > rhs._subticks)); - } - - inline bool operator<=(const TimeStamp& rhs) const - { - return (*this == rhs) || ((*this) < rhs); - } - - inline bool operator>=(const TimeStamp& rhs) const - { - return (*this == rhs) || ((*this) > rhs); - } - - inline TimeStamp& operator+=(const TimeStamp& rhs) - { - assert(_unit == rhs._unit); - _ticks += rhs._ticks; - if (_subticks + rhs._subticks <= _unit.ppt()) { - _subticks += rhs._subticks; - } else if (rhs._subticks > 0) { - ++_ticks; - _subticks = rhs._subticks + _subticks - _unit.ppt(); - } - return *this; - } - - inline TimeStamp& operator-=(const TimeStamp& rhs) - { - assert(_unit == rhs._unit); - assert(rhs <= *this); - _ticks -= rhs._ticks; - if (_subticks >= rhs._subticks) { - _subticks -= rhs._subticks; - } else if (rhs._subticks > 0) { - --_ticks; - _subticks = _unit.ppt() - (rhs._subticks - _subticks); - } - return *this; - } - - inline TimeStamp operator+(const TimeStamp& rhs) const - { - assert(_unit == rhs._unit); - TimeStamp result = *this; - result += rhs; - return result; - } - - inline TimeStamp operator-(const TimeStamp& rhs) const - { - assert(_unit == rhs._unit); - TimeStamp result = *this; - result -= rhs; - return result; - } - -private: - uint32_t _ticks; - uint32_t _subticks; - TimeUnit _unit; -}; - -inline std::ostream& -operator<<(std::ostream& os, const TimeStamp& t) -{ - os << t.ticks() << ":" << t.subticks(); - switch (t.unit().type()) { - case TimeUnit::FRAMES: - os << " frames"; - break; - case TimeUnit::BEATS: - os << " beats"; - break; - case TimeUnit::SECONDS: - os << " seconds"; - break; - } - return os; -} - -class FrameStamp : public TimeStamp -{ -public: - explicit FrameStamp(uint32_t rate, uint32_t ticks = 0, uint32_t subticks = 0) - : TimeStamp(TimeUnit(TimeUnit::FRAMES, rate), ticks, subticks) - {} -}; - -class BeatStamp : public TimeStamp -{ -public: - explicit BeatStamp(uint32_t ppqn, uint32_t ticks = 0, uint32_t subticks = 0) - : TimeStamp(TimeUnit(TimeUnit::BEATS, ppqn), ticks, subticks) - {} -}; - -/** Same thing as TimeStamp really, but makes code clearer and enforces - * correct semantics via type safety */ -using TimeDuration = TimeStamp; - -} // namespace Raul - -#endif // RAUL_TIMESTAMP_HPP diff --git a/test/build_test.cpp b/test/build_test.cpp index 69ddf36..72c9793 100644 --- a/test/build_test.cpp +++ b/test/build_test.cpp @@ -23,8 +23,6 @@ #include "raul/RingBuffer.hpp" #include "raul/Semaphore.hpp" #include "raul/Symbol.hpp" -#include "raul/TimeSlice.hpp" -#include "raul/TimeStamp.hpp" #ifndef _WIN32 # include "raul/Process.hpp" @@ -49,9 +47,6 @@ main() Raul::RingBuffer ring_buffer(64u); Raul::Semaphore semaphore(0u); Raul::Symbol symbol("foo"); - Raul::TimeSlice time_slice(48000u, 960u, 120.0); - - Raul::TimeStamp time_stamp(Raul::TimeUnit(Raul::TimeUnit::BEATS, 960u)); try { Raul::Symbol bad_symbol("not a valid symbol!"); @@ -76,8 +71,6 @@ main() (void)path; (void)ring_buffer; (void)symbol; - (void)time_slice; - (void)time_stamp; return 0; } diff --git a/test/time_test.cpp b/test/time_test.cpp deleted file mode 100644 index 1746a7e..0000000 --- a/test/time_test.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright 2007-2015 David Robillard - - Raul is free software: you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or any later version. - - Raul is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Raul. If not, see . -*/ - -#include "raul/TimeSlice.hpp" -#include "raul/TimeStamp.hpp" - -#include -#include - -int -main() -{ - Raul::TimeUnit unit(Raul::TimeUnit::BEATS, 19200); - Raul::TimeSlice ts(48000, 19200, 120.0); - - double in_double = 2.5; - - Raul::TimeStamp t( - unit, - static_cast(in_double), - static_cast((in_double - static_cast(in_double)) * - unit.ppt())); - - std::cout << "\tSeconds: "; - std::cout << ts.beats_to_seconds(t); - std::cout << std::endl; - - std::cout << "\tTicks: "; - std::cout << ts.beats_to_ticks(t); - std::cout << std::endl; - - return 0; -} diff --git a/wscript b/wscript index 293d9db..7f8cd77 100644 --- a/wscript +++ b/wscript @@ -83,8 +83,7 @@ tests = ['array_test', 'ringbuffer_test', 'sem_test', 'symbol_test', - 'thread_test', - 'time_test'] + 'thread_test'] if sys.platform != 'win32': tests += ['socket_test'] -- cgit v1.2.1