Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
time-grid.cpp
Go to the documentation of this file.
1/*
2 TimeGrid - reference scale for quantised time
3
4 Copyright (C)
5 2010, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
25#include "lib/format-string.hpp"
26#include "common/advice.hpp"
27#include "lib/util.hpp"
28
29#include <string>
30
31using util::_Fmt;
32using util::isnil;
33using std::string;
34
35
36namespace steam {
37namespace asset {
38namespace meta {
39
40 namespace error = lumiera::error;
41
42
43
48 TimeGrid::TimeGrid (GridID const& nameID)
49 : Meta{nameID}
50 { }
51
52
53 using lib::time::Time;
58 using lib::time::FSecs;
59
63 using std::dynamic_pointer_cast;
64
65 namespace advice = lumiera::advice;
66
67 namespace {
68
76 inline PGrid
78 {
79 PGrid gridImplementation = AssetManager::instance().wrap (newGrid);
80 PQuant quantiser (dynamic_pointer_cast<const Quantiser>(gridImplementation));
81 Literal bindingID (cStr(newGrid.ident.name));
82
83 advice::Provision<PGrid>(bindingID).setAdvice(gridImplementation);
84 advice::Provision<PQuant>(bindingID).setAdvice(quantiser);
85 return gridImplementation;
86 }
87 }//(End)Impl helper.
88
89
101 : public TimeGrid
102 , public FixedFrameQuantiser
103 {
104
105 public:
106 SimpleTimeGrid (Time start, Duration frameDuration, GridID const& name)
107 : TimeGrid (name)
108 , FixedFrameQuantiser(frameDuration,start)
109 { }
110
111 SimpleTimeGrid (Time start, FrameRate frames_per_second, GridID const& name)
112 : TimeGrid (name)
113 , FixedFrameQuantiser(frames_per_second,start)
114 { }
115 };
116
117
118
136 {
137 if (predecessor)
138 throw error::Invalid("compound and variable time grids are a planned feature"
139 , error::LUMIERA_ERROR_UNIMPLEMENTED);
140 ENSURE (fps, "infinite grid should have been detected by FrameRate ctor");
141
142 if (isnil (id))
143 {
144 _Fmt gridIdFormat("grid(%f_%d)");
145 id = string(gridIdFormat % fps % _raw(origin));
146 }
147 GridID nameID (id);
148
149 // build new Meta-Asset, registered with AssetManager, and publish into Advice-System
150 return publishWrapped (*new SimpleTimeGrid(origin, fps, nameID));
151 }
152
153
154 /* === TimeGrid shortcut builder functions === */
155
156 PGrid
157 TimeGrid::build (FrameRate frames_per_second)
158 {
159 return build (Symbol::EMPTY,frames_per_second);
160 }
161
162 PGrid
163 TimeGrid::build (Symbol gridID, FrameRate frames_per_second)
164 {
165 return build (gridID,frames_per_second, Time::ZERO);
166 }
167
168
169 PGrid
170 TimeGrid::build (Symbol gridID, FrameRate frames_per_second, Time origin)
171 {
172 string name(gridID);
173 Builder<TimeGrid> spec(name);
174 spec.fps = frames_per_second;
175 spec.origin = origin;
176
177 return spec.commit();
178 }
179
180
181}}} // namespace asset::meta
Expecting Advice and giving Advice: a cross-cutting collaboration of loosely coupled participants.
Steam-Layer Interface: Asset Lookup and Organisation.
Inline string literal.
Definition symbol.hpp:78
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
Token or Atom with distinct identity.
Definition symbol.hpp:120
static Symbol EMPTY
Definition symbol.hpp:123
Duration is the internal Lumiera time metric.
Simple stand-alone Quantiser implementation based on a constant sized gird.
Framerate specified as frames per second.
Offset measures a distance in time.
Facility to create grid-aligned time values.
Definition quantiser.hpp:95
A time interval anchored at a specific point in time.
basic constant internal time value.
Lumiera's internal time value datatype.
static const Time ZERO
Access point for the advising entity (server).
Definition advice.hpp:237
void setAdvice(AD const &pieceOfAdvice)
Definition advice.hpp:274
const Ident ident
Asset identification tuple.
Definition asset.hpp:197
key abstraction: metadata, parametrisation, customisation and similar organisational traits.
TimeGrid implementation: a trivial time grid, starting at a given point in time and using a constant ...
SimpleTimeGrid(Time start, Duration frameDuration, GridID const &name)
SimpleTimeGrid(Time start, FrameRate frames_per_second, GridID const &name)
Interface: a grid and scale definition for time quantisation.
Definition time-grid.hpp:80
static PGrid build(FrameRate frames_per_second)
A front-end for using printf-style formatting.
Front-end for printf-style string template interpolation.
std::shared_ptr< const Quantiser > PQuant
Definition formats.hpp:58
boost::rational< int64_t > FSecs
rational representation of fractional seconds
LumieraError< LERR_(INVALID)> Invalid
Definition error.hpp:211
Building and configuring a meta asset.
The asset subsystem of the Steam-Layer.
Steam-Layer implementation namespace root.
bool isnil(lib::time::Duration const &dur)
Library functions to support the formation of grid-aligned time values.
Naming and labelling scheme for structural assets.
typed symbolic and hash ID for asset-like position accounting.
Definition entry-id.hpp:219
string name
element ID, comprehensible but sanitised.
Definition asset.hpp:151
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
Definition symbol.hpp:60
To establish a reference scale for quantised time values.
a family of time value like entities and their relationships.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...