draft how a SMPTE-Timecode element could be implemented

passes Compiler, but thats about all...
This commit is contained in:
Fischlurch 2011-01-18 05:01:25 +01:00
parent ce420a1570
commit 95a1687a5b
6 changed files with 136 additions and 47 deletions

View file

@ -144,9 +144,9 @@ namespace time {
template<>
struct Formatter<int>
: PrintfFormatter<int, 6>
: PrintfFormatter<int, 9>
{
Formatter() : PrintfFormatter<int,6>("%3d") { }
Formatter() : PrintfFormatter<int,9>("%3d") { }
};
template<>
@ -271,6 +271,14 @@ namespace time {
//---Supporting-increments--------------
Digxel& operator+= (NUM inc) { value_ += inc; return *this; }
Digxel& operator-= (NUM dec) { value_ -= dec; return *this; }
Digxel& operator++ () { value_ += 1; return *this; }
Digxel& operator-- () { value_ -= 1; return *this; }
NUM operator++ (int) { NUM p(value_++); return p; }
NUM operator-- (int) { NUM p(value_--); return p; }
//---Supporting-totally_ordered---------
bool operator< (Digxel const& o) const { return value_ < NUM(o); }
bool operator== (Digxel const& o) const { return value_ == NUM(o); }

View file

@ -81,7 +81,7 @@ namespace time {
struct Smpte
: NoInstance<Smpte>
{
static void rebuild (SmpteTC&, QuantR);
static void rebuild (SmpteTC&, QuantR, TimeValue const&);
static TimeValue evaluate (SmpteTC const&, QuantR);
};
@ -96,7 +96,7 @@ namespace time {
struct Hms
: NoInstance<Hms>
{
static void rebuild (HmsTC&, QuantR);
static void rebuild (HmsTC&, QuantR, TimeValue const&);
static TimeValue evaluate (HmsTC const&, QuantR);
};
@ -113,7 +113,7 @@ namespace time {
struct Seconds
: NoInstance<Seconds>
{
static void rebuild (Secs&, QuantR);
static void rebuild (Secs&, QuantR, TimeValue const&);
static TimeValue evaluate (Secs const&, QuantR);
};

View file

@ -27,8 +27,10 @@
#include "lib/time/timequant.hpp"
#include "lib/time/formats.hpp"
#include "lib/time.h"
#include "lib/util.hpp"
using util::unConst;
using std::string;
@ -56,6 +58,25 @@ namespace time {
return quantiser.timeOf (framecnt);
}
/** build up a frame count
* by quantising the given time value
*/
void
Smpte::rebuild (SmpteTC& tc, QuantR quantiser, TimeValue const& rawTime)
{
// framecnt.setValueRaw(quantiser.gridPoint (rawTime));
UNIMPLEMENTED("build smpte components from raw time");
}
/** calculate the time point denoted by this frame count */
TimeValue
Smpte::evaluate (SmpteTC const& tc, QuantR quantiser)
{
// return quantiser.timeOf (framecnt);
UNIMPLEMENTED("calculate time from smpte");
}
}
@ -72,7 +93,6 @@ namespace time {
/** */
SmpteTC::SmpteTC (QuTime const& quantisedTime)
: TCode(quantisedTime)
// : tpoint_(quantisedTime) /////////////////////////////TODO eternal bullshit
{ }
@ -91,32 +111,41 @@ namespace time {
/** */
int
SmpteTC::getSecs() const
void
SmpteTC::rebuild() const
{
return lumiera_time_seconds (tpoint_);
TimeValue point = Format::evaluate(*this, *quantiser_);
Format::rebuild(unConst(*this), *quantiser_, point);
}
/** */
int
SmpteTC::getMins() const
string
SmpteTC::show() const
{
return lumiera_time_minutes (tpoint_);
rebuild();
string tc;
tc.reserve(15);
tc += sgn.show();
tc += hours.show();
tc += ':';
tc += mins.show();
tc += ':';
tc += secs.show();
tc += ':';
tc += frames.show();
return tc;
}
/** */
int
SmpteTC::getHours() const
SmpteTC&
SmpteTC::operator++ ()
{
return lumiera_time_hours (tpoint_);
UNIMPLEMENTED ("SMPTE unit increment");
}
/** */
int
SmpteTC::getFrames() const
SmpteTC&
SmpteTC::operator-- ()
{
UNIMPLEMENTED ("Frame-Quantisation");
UNIMPLEMENTED ("SMPTE unit decrement");
}
/** */

View file

@ -30,7 +30,7 @@
#include "lib/symbol.hpp"
//#include <iostream>
//#include <boost/operators.hpp>
#include <boost/operators.hpp>
#include <boost/lexical_cast.hpp> ///////////////TODO
#include <string>
@ -105,22 +105,28 @@ namespace time {
*/
class SmpteTC
: public TCode
, boost::unit_steppable<SmpteTC>
{
TimeVar tpoint_;
virtual string show() const { return string(tpoint_); }
virtual string show() const ;
virtual Literal tcID() const { return "SMPTE"; }
virtual TimeValue value() const { return tpoint_; }
virtual TimeValue value() const { return Format::evaluate (*this, *quantiser_); }
public:
typedef format::Smpte Format;
SmpteTC (QuTime const& quantisedTime);
int getSecs () const;
int getMins () const;
int getHours () const;
int getFrames () const;
void rebuild() const;
Digxel<int> hours;
SexaDigit mins;
SexaDigit secs;
SexaDigit frames;
Signum sgn;
SmpteTC& operator++();
SmpteTC& operator--();
};

View file

@ -23,24 +23,28 @@
#include "lib/test/run.hpp"
//#include "lib/test/test-helper.hpp"
#include "proc/asset/meta/time-grid.hpp"
#include "lib/time/timequant.hpp"
#include "lib/time/timecode.hpp"
#include "lib/time/display.hpp"
#include "lib/util.hpp"
#include <boost/lexical_cast.hpp>
//#include <iostream>
#include <iostream>
//#include <cstdlib>
using boost::lexical_cast;
using util::isnil;
//using std::rand;
//using std::cout;
//using std::endl;
using std::cout;
using std::endl;
namespace lib {
namespace time{
namespace test{
using asset::meta::TimeGrid;
/********************************************************
* @test verify handling of grid aligned timecode values.
@ -52,28 +56,33 @@ namespace test{
class TimeFormats_test : public Test
{
virtual void
run (Arg arg)
run (Arg)
{
long refval= isnil(arg)? 1 : lexical_cast<long> (arg[1]);
TimeGrid::build("pal0", FrameRate::PAL);
TimeValue ref (refval);
checkTimecodeUsageCycle (ref);
checkFrames ();
checkSeconds ();
checkHms ();
// checkTimecodeUsageCycle ();
// checkFrames ();
// checkSeconds ();
// checkHms ();
checkSmpte();
checkDropFrame();
// checkDropFrame();
}
void
checkTimecodeUsageCycle (TimeValue ref)
checkTimecodeUsageCycle ()
{
UNIMPLEMENTED ("full usage cycle for a timecode value");
}
template<class TC>
void
showTimeCode (TC timecode)
{
cout << timecode.describe()<<"=\""<<timecode<<"\" time = "<< timecode.getTime() << endl;
}
void
checkFrames ()
{
@ -98,7 +107,44 @@ namespace test{
void
checkSmpte ()
{
UNIMPLEMENTED ("verify SMPTE timecode format");
Time raw(0.5,23,42,5);
QuTime t1 (raw, "pal0");
SmpteTC smpte(t1);
showTimeCode(smpte);
CHECK ("5:42:23:13" == string(smpte));
CHECK (raw + Time(0.02,0) == smpte.getTime());
CHECK (13 == smpte.frames);
CHECK (23 == smpte.secs);
CHECK (42 == smpte.mins);
CHECK ( 5 == smpte.hours);
CHECK ( 1 == smpte.sgn);
CHECK ("SMPTE" == smpte.describe());
++smpte;
CHECK ("5:42:23:14" == string(smpte));
smpte.frames += 12;
CHECK ("5:42:24:01" == string(smpte));
smpte.secs = -120;
CHECK ("5:40:00:01" == string(smpte));
CHECK (smpte.mins-- == 40);
CHECK (--smpte.mins == 38);
CHECK ("5:38:00:01" == string(smpte));
Time tx = smpte.getTime();
smpte.hours -= 6;
CHECK ("-0:21:59:24"== string(smpte));
CHECK (tx - Time(6*60*60) == smpte.getTime());
CHECK (-1 == smpte.sgn);
smpte.sgn += 123;
CHECK ("0:21:59:24"== string(smpte));
smpte.secs.setValueRaw(61);
CHECK (smpte.secs == 61);
CHECK (smpte.getTime() == Time(24.0/25,01,22));
CHECK (smpte.secs == 61);
smpte.hours += 0;
CHECK (smpte.secs == 1);
CHECK (smpte.mins == 22);
}

View file

@ -162,8 +162,8 @@ namespace test{
int cnt = funny.formatAs<format::Frames>();
// and now performing quantisation is OK
SmpteTC smpte (funny); // also converting into SMPTE (which implies frame quantisation)
CHECK (0 == smpte.getFrames()); // we have 1fps, thus the frame part is always zero!
CHECK (cnt % 60 == smpte.getSecs()); // and the seconds part will be in sync with the frame count
CHECK (0 == smpte.frames); // we have 1fps, thus the frame part is always zero!
CHECK (cnt % 60 == smpte.secs); // and the seconds part will be in sync with the frame count
}
};