Lumiera  0.pre.03
»edit your freedom«
mutation.hpp
Go to the documentation of this file.
1 /*
2  MUTATION.hpp - changing and adjusting time values
3 
4  Copyright (C) Lumiera.org
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
61 #ifndef LIB_TIME_MUTATION_H
62 #define LIB_TIME_MUTATION_H
63 
64 #include "lib/error.hpp"
65 #include "lib/nocopy.hpp"
66 #include "lib/time/timevalue.hpp"
68 #include "lib/symbol.hpp"
69 
70 
71 
72 namespace lib {
73 namespace time {
74 
75  using lib::Symbol;
76 
77  LUMIERA_ERROR_DECLARE (INVALID_MUTATION);
78 
79  class QuTime;
80  class Mutation;
81 
82 
83  /* The following typedefs allow to hand out
84  * "unspecific" mutation value objects from
85  * factory functions, without disclosing any
86  * implementation details here in this header.
87  */
88  enum{ MUTATION_IMPL_SIZE = sizeof(TimeValue) };
89 
90  typedef lib::polyvalue::CloneValueSupport<Mutation> ClonableMutation;
92 
100  class Mutation
101  {
102  public:
103  virtual ~Mutation();
104 
105  virtual void change (Duration&) const =0;
106  virtual void change (TimeSpan&) const =0;
107  virtual void change (QuTime&) const =0;
108 
109  /* === convenience shortcuts for simple cases === */
110 
111  static EncapsulatedMutation changeTime (Time);
112  static EncapsulatedMutation changeDuration (Duration);
113  static EncapsulatedMutation adjust (Offset);
114  static EncapsulatedMutation materialise (QuTime const&);
115  static EncapsulatedMutation nudge (int adjustment);
116  static EncapsulatedMutation nudge (int adjustment, Symbol gridID);
117 #ifdef LIB_TIME_TIMEQUANT_H
118  static EncapsulatedMutation nudge (int adjustment, PQuant const& grid);
119 #endif
120 
121  protected:
122  static TimeValue& imposeChange (TimeValue&, TimeValue const&);
123  static TimeValue& imposeChange (TimeValue&, Offset const&);
124  static TimeValue& imposeChange (TimeValue&, int);
125  static TimeValue& imposeChange (QuTime&, int);
126  };
127 
128 
129  /* === defining the visitation responses === */
130 
131  inline void Duration::accept (Mutation const& muta) { muta.change (*this); }
132  inline void TimeSpan::accept (Mutation const& muta) { muta.change (*this); }
133 
134 #ifdef LIB_TIME_TIMEQUANT_H
135  inline void QuTime::accept (Mutation const& muta) { muta.change (*this); }
136 #endif
137 
138 
139 
140  /* === implementing the actual changes === */
141 
146  inline TimeValue&
147  Mutation::imposeChange (TimeValue& target, TimeValue const& valueToSet)
148  {
149  return target = valueToSet;
150  }
151 
153  inline TimeValue&
154  Mutation::imposeChange (TimeValue& target, Offset const& offset)
155  {
156  return imposeChange (target, TimeVar(target) += offset);
157  }
158 
162  inline TimeValue&
163  Mutation::imposeChange (TimeValue& target, int steps)
164  {
165  return imposeChange (target, TimeVar(target) += Time(FSecs(steps)));
166  }
167 
168 #ifdef LIB_TIME_TIMEQUANT_H
169 
176  inline TimeValue&
177  Mutation::imposeChange (QuTime& target, int steps)
178  {
179  PQuant const& grid (target);
180  FrameCnt originalGridPoint = grid->gridPoint(target);
181  FrameCnt adjustedGridPoint = originalGridPoint + steps;
182  return imposeChange (target, grid->timeOf (adjustedGridPoint));
183  }
184 #endif
185 
186 
187 
188 }} // lib::time
189 #endif
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:241
static EncapsulatedMutation changeTime(Time)
Convenience factory to yield a simple Mutation changing the absolute start time.
Definition: mutation.cpp:294
void accept(Mutation const &)
may change start / duration
Definition: mutation.hpp:132
A variation for limited copy support.
static EncapsulatedMutation adjust(Offset)
Convenience factory: simple Mutation to adjust the duration or length of a timespan.
Definition: mutation.cpp:316
Interface: an opaque change imposed onto some time value.
Definition: mutation.hpp:100
A mechanism to allow for opaque polymorphic value objects.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition: error.h:71
static TimeValue & imposeChange(TimeValue &, TimeValue const &)
Definition: mutation.hpp:147
void accept(Mutation const &)
receive change message, which might cause re-quantisation
Implementation namespace for support and library code.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
Token or Atom with distinct identity.
Definition: symbol.hpp:126
Mix-Ins to allow or prohibit various degrees of copying and cloning.
static EncapsulatedMutation materialise(QuTime const &)
Convenience factory: materialise the given quantised time into an explicit fixed internal time value...
Definition: mutation.cpp:328
Marker types to indicate a literal string and a Symbol.
Template to build polymorphic value objects.
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:229
Lumiera error handling (C++ interface).
Offset measures a distance in time.
Definition: timevalue.hpp:367
static EncapsulatedMutation nudge(int adjustment)
build a time mutation to nudge the target time value by an offset, defined as number of steps on an i...
Definition: mutation.cpp:345
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
static EncapsulatedMutation changeDuration(Duration)
Convenience factory: simple Mutation to adjust the duration or length of a timespan.
Definition: mutation.cpp:305
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:582
int64_t FrameCnt
relative framecount or frame number.
Definition: digxel.hpp:321
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:142
grid aligned time specification, referring to a specific scale.
Definition: timequant.hpp:99