2010-12-21 02:05:13 +01:00
|
|
|
/*
|
|
|
|
|
Quantiser - aligning time values to a time grid
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2010, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program 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 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program 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 this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
2011-01-04 01:45:11 +01:00
|
|
|
#include "lib/time/quantiser.hpp"
|
2010-12-21 02:05:13 +01:00
|
|
|
#include "lib/time/timevalue.hpp"
|
2011-01-05 18:15:44 +01:00
|
|
|
#include "lib/time/timequant.hpp"
|
2011-01-06 13:31:13 +01:00
|
|
|
#include "lib/time.h"
|
|
|
|
|
|
|
|
|
|
#include <boost/rational.hpp>
|
|
|
|
|
|
|
|
|
|
using boost::rational_cast;
|
2010-12-21 02:05:13 +01:00
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
2011-01-06 13:31:13 +01:00
|
|
|
namespace error = lumiera::error;
|
|
|
|
|
|
2010-12-21 02:05:13 +01:00
|
|
|
namespace lib {
|
|
|
|
|
namespace time {
|
|
|
|
|
|
|
|
|
|
|
2011-01-06 13:31:13 +01:00
|
|
|
namespace { // implementation helpers...
|
|
|
|
|
|
|
|
|
|
template<typename NUM>
|
|
|
|
|
inline NUM
|
|
|
|
|
__ensure_notZero (NUM n)
|
|
|
|
|
{
|
|
|
|
|
if (!n)
|
|
|
|
|
throw error::Logic ("Impossible to quantise to an zero spaced grid"
|
|
|
|
|
, error::LUMIERA_ERROR_BOTTOM_VALUE);
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}//(End) implementation helpers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-06 04:21:18 +01:00
|
|
|
Quantiser::~Quantiser() { } // hint to emit the VTable here...
|
|
|
|
|
|
2011-01-06 13:31:13 +01:00
|
|
|
|
2010-12-21 02:05:13 +01:00
|
|
|
/** */
|
2011-01-05 18:15:44 +01:00
|
|
|
QuTime::QuTime (TimeValue raw, Symbol gridID)
|
|
|
|
|
: Time(raw) /////////////////////////////////////////////////TODO fetch quantiser
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** */
|
|
|
|
|
QuTime::QuTime (TimeValue raw, Quantiser const& quantisation_to_use)
|
|
|
|
|
: Time(raw) /////////////////////////////////////////////////TODO fetch quantiser
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-06 13:31:13 +01:00
|
|
|
/** Create a quantiser based on a fixed constant spaced grid, rooted at the reference point
|
|
|
|
|
* as origin of the scale. Quantisation then means to determine the grid interval containing
|
|
|
|
|
* a given raw time value. Here, the grid interval number zero \em starts at the origin;
|
|
|
|
|
* each interval includes its lower bound and excludes its upper bound.*/
|
2011-01-09 04:56:46 +01:00
|
|
|
FixedFrameQuantiser::FixedFrameQuantiser (FrameRate const& frames_per_second, TimeValue referencePoint)
|
2011-01-06 13:31:13 +01:00
|
|
|
: origin_(referencePoint)
|
2011-01-09 04:56:46 +01:00
|
|
|
, raster_(frames_per_second.duration())
|
2011-01-05 18:15:44 +01:00
|
|
|
{ }
|
|
|
|
|
|
2010-12-21 02:05:13 +01:00
|
|
|
|
|
|
|
|
|
2011-01-06 13:31:13 +01:00
|
|
|
/** alignment to a simple fixed size grid.
|
|
|
|
|
* The actual calculation first determines the number
|
|
|
|
|
* of the grid interval containing the given rawTime,
|
|
|
|
|
* then followed by multiplying this interval number
|
|
|
|
|
* with the grid spacing.
|
|
|
|
|
* @return time of the start point of the grid interval
|
|
|
|
|
* containing the rawTime, relative to the origin
|
|
|
|
|
* of the time scale used by this quantiser.
|
|
|
|
|
* @warning returned time values are limited by the
|
|
|
|
|
* range of an 64bit integer
|
|
|
|
|
* @see #lumiera_quantise_time
|
|
|
|
|
*/
|
|
|
|
|
TimeValue
|
|
|
|
|
FixedFrameQuantiser::gridAlign (TimeValue const& rawTime)
|
2011-01-06 04:21:18 +01:00
|
|
|
{
|
2011-01-09 04:56:46 +01:00
|
|
|
return TimeValue (lumiera_quantise_time (_raw(rawTime), _raw(origin_), _raw(raster_)));
|
2011-01-06 04:21:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-12-21 02:05:13 +01:00
|
|
|
|
2011-01-04 01:45:11 +01:00
|
|
|
LUMIERA_ERROR_DEFINE (UNKNOWN_GRID, "referring to an undefined grid or scale in value quantisation");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-21 02:05:13 +01:00
|
|
|
}} // lib::time
|
2011-01-06 13:31:13 +01:00
|
|
|
|