2010-12-21 02:05:13 +01:00
|
|
|
/*
|
|
|
|
|
TIMECODE.hpp - grid aligned and fixed format time specifications
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef LIB_TIME_TIMECODE_H
|
|
|
|
|
#define LIB_TIME_TIMECODE_H
|
|
|
|
|
|
2010-12-27 02:04:34 +01:00
|
|
|
#include "lib/time/timevalue.hpp"
|
2011-01-02 01:21:39 +01:00
|
|
|
#include "lib/time/formats.hpp"
|
2011-01-13 23:56:52 +01:00
|
|
|
#include "lib/time/digxel.hpp"
|
2011-01-05 18:15:44 +01:00
|
|
|
#include "lib/symbol.hpp"
|
2010-12-27 02:04:34 +01:00
|
|
|
|
2011-01-05 05:14:10 +01:00
|
|
|
//#include <iostream>
|
2011-01-18 05:01:25 +01:00
|
|
|
#include <boost/operators.hpp>
|
2011-01-05 18:15:44 +01:00
|
|
|
#include <boost/lexical_cast.hpp> ///////////////TODO
|
2010-12-21 02:05:13 +01:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
namespace time {
|
|
|
|
|
|
2011-01-04 01:45:11 +01:00
|
|
|
using std::string;
|
2011-01-05 18:15:44 +01:00
|
|
|
using lib::Literal;
|
|
|
|
|
using boost::lexical_cast; /////////TODO
|
2011-01-04 01:45:11 +01:00
|
|
|
|
2010-12-21 02:05:13 +01:00
|
|
|
|
|
|
|
|
/**
|
2011-01-05 02:43:29 +01:00
|
|
|
* Interface: fixed format timecode specification.
|
2011-01-02 01:21:39 +01:00
|
|
|
* @see time::Format
|
2010-12-21 02:05:13 +01:00
|
|
|
* @todo WIP-WIP-WIP
|
|
|
|
|
*/
|
|
|
|
|
class TCode
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public:
|
2011-01-05 02:43:29 +01:00
|
|
|
virtual ~TCode();
|
2011-01-04 01:45:11 +01:00
|
|
|
|
2011-01-05 05:14:10 +01:00
|
|
|
operator string() const { return show(); }
|
2011-01-05 18:15:44 +01:00
|
|
|
string describe() const { return string(tcID()); }
|
|
|
|
|
Time getTime() const { return Time(value()); }
|
2011-01-05 05:14:10 +01:00
|
|
|
|
|
|
|
|
protected:
|
2011-01-15 00:52:02 +01:00
|
|
|
TCode (PQuant const& quant)
|
|
|
|
|
: quantiser_(quant)
|
2011-01-13 23:56:52 +01:00
|
|
|
{ }
|
|
|
|
|
|
2011-01-05 05:14:10 +01:00
|
|
|
virtual string show() const =0;
|
2011-01-05 18:15:44 +01:00
|
|
|
virtual Literal tcID() const =0;
|
|
|
|
|
virtual TimeValue value() const =0;
|
2011-01-14 05:33:50 +01:00
|
|
|
|
|
|
|
|
protected:
|
2011-01-15 00:52:02 +01:00
|
|
|
PQuant quantiser_;
|
2010-12-21 02:05:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2011-01-02 01:21:39 +01:00
|
|
|
class QuTime;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A frame counting timecode value.
|
|
|
|
|
* This is an hard-coded representation of
|
|
|
|
|
* TCode<format::Frames>, with additional convenience
|
|
|
|
|
* constructors and conversions, which basically make
|
|
|
|
|
* FrameNr values interchangeable with integral numbers.
|
|
|
|
|
*/
|
|
|
|
|
class FrameNr
|
2011-01-05 02:43:29 +01:00
|
|
|
: public TCode
|
2011-01-14 05:33:50 +01:00
|
|
|
, public CountVal
|
2011-01-02 01:21:39 +01:00
|
|
|
{
|
2011-01-05 18:15:44 +01:00
|
|
|
|
2011-01-17 07:25:22 +01:00
|
|
|
string show() const { return string(CountVal::show())+"fr"; }
|
2011-01-05 18:15:44 +01:00
|
|
|
Literal tcID() const { return "Frame-count"; }
|
2011-01-15 00:52:02 +01:00
|
|
|
TimeValue value() const { return Format::evaluate (*this, *quantiser_); }
|
2011-01-02 01:21:39 +01:00
|
|
|
|
|
|
|
|
public:
|
2011-01-13 23:56:52 +01:00
|
|
|
typedef format::Frames Format;
|
|
|
|
|
|
2011-01-14 05:33:50 +01:00
|
|
|
FrameNr (QuTime const& quantisedTime);
|
2011-01-02 01:21:39 +01:00
|
|
|
|
2011-01-14 05:33:50 +01:00
|
|
|
// CountVal implicitly convertible to long
|
2011-01-02 01:21:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2010-12-21 02:05:13 +01:00
|
|
|
|
2011-01-04 01:45:11 +01:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class SmpteTC
|
2011-01-05 02:43:29 +01:00
|
|
|
: public TCode
|
2011-01-18 05:01:25 +01:00
|
|
|
, boost::unit_steppable<SmpteTC>
|
2011-01-04 01:45:11 +01:00
|
|
|
{
|
2011-01-21 11:42:29 +01:00
|
|
|
uint effectiveFramerate_;
|
2011-01-18 05:01:25 +01:00
|
|
|
|
|
|
|
|
virtual string show() const ;
|
2011-01-05 18:15:44 +01:00
|
|
|
virtual Literal tcID() const { return "SMPTE"; }
|
2011-01-18 05:01:25 +01:00
|
|
|
virtual TimeValue value() const { return Format::evaluate (*this, *quantiser_); }
|
2011-01-05 05:14:10 +01:00
|
|
|
|
2011-01-04 01:45:11 +01:00
|
|
|
public:
|
2011-01-13 23:56:52 +01:00
|
|
|
typedef format::Smpte Format;
|
|
|
|
|
|
2011-01-04 01:45:11 +01:00
|
|
|
SmpteTC (QuTime const& quantisedTime);
|
2011-01-21 16:22:01 +01:00
|
|
|
SmpteTC (SmpteTC const&);
|
|
|
|
|
SmpteTC& operator= (SmpteTC const&);
|
2011-01-04 01:45:11 +01:00
|
|
|
|
2011-01-21 11:42:29 +01:00
|
|
|
uint getFps() const;
|
2011-01-18 05:01:25 +01:00
|
|
|
|
2011-01-21 20:24:41 +01:00
|
|
|
void clear();
|
|
|
|
|
void rebuild();
|
|
|
|
|
|
2011-01-21 16:22:01 +01:00
|
|
|
HourDigit hours;
|
|
|
|
|
SexaDigit mins;
|
|
|
|
|
SexaDigit secs;
|
|
|
|
|
SexaDigit frames;
|
|
|
|
|
Signum sgn;
|
2011-01-18 05:01:25 +01:00
|
|
|
|
|
|
|
|
SmpteTC& operator++();
|
|
|
|
|
SmpteTC& operator--();
|
2011-01-04 01:45:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-05 02:43:29 +01:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class HmsTC
|
|
|
|
|
: public TCode
|
|
|
|
|
{
|
2011-01-05 18:15:44 +01:00
|
|
|
TimeVar tpoint_;
|
2011-01-05 02:43:29 +01:00
|
|
|
|
2011-01-05 18:15:44 +01:00
|
|
|
virtual string show() const { return string(tpoint_); }
|
|
|
|
|
virtual Literal tcID() const { return "Timecode"; }
|
|
|
|
|
virtual TimeValue value() const { return tpoint_; }
|
2011-01-05 05:14:10 +01:00
|
|
|
|
2011-01-05 02:43:29 +01:00
|
|
|
public:
|
2011-01-13 23:56:52 +01:00
|
|
|
typedef format::Hms Format;
|
|
|
|
|
|
2011-01-05 02:43:29 +01:00
|
|
|
HmsTC (QuTime const& quantisedTime);
|
|
|
|
|
|
|
|
|
|
double getMillis () const;
|
|
|
|
|
int getSecs () const;
|
|
|
|
|
int getMins () const;
|
|
|
|
|
int getHours () const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class Secs
|
|
|
|
|
: public TCode
|
|
|
|
|
{
|
2011-01-05 18:15:44 +01:00
|
|
|
FSecs sec_;
|
2011-01-05 02:43:29 +01:00
|
|
|
|
2011-01-05 18:15:44 +01:00
|
|
|
virtual string show() const { return string(Time(sec_)); }
|
|
|
|
|
virtual Literal tcID() const { return "Seconds"; }
|
|
|
|
|
virtual TimeValue value() const { return Time(sec_); }
|
2011-01-05 05:14:10 +01:00
|
|
|
|
2011-01-05 02:43:29 +01:00
|
|
|
public:
|
2011-01-13 23:56:52 +01:00
|
|
|
typedef format::Seconds Format;
|
|
|
|
|
|
2011-01-05 02:43:29 +01:00
|
|
|
Secs (QuTime const& quantisedTime);
|
|
|
|
|
|
|
|
|
|
operator FSecs() const;
|
|
|
|
|
};
|
|
|
|
|
|
2011-01-05 05:14:10 +01:00
|
|
|
|
|
|
|
|
/** writes time value, formatted as HH:MM:SS:mmm */
|
2011-01-05 02:43:29 +01:00
|
|
|
|
2011-01-05 05:14:10 +01:00
|
|
|
|
2011-01-05 02:43:29 +01:00
|
|
|
|
2010-12-21 02:05:13 +01:00
|
|
|
}} // lib::time
|
|
|
|
|
#endif
|