Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
mutation.hpp
Go to the documentation of this file.
1/*
2 MUTATION.hpp - changing and adjusting time values
3
4 Copyright (C)
5 2011, 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
52#ifndef LIB_TIME_MUTATION_H
53#define LIB_TIME_MUTATION_H
54
55#include "lib/error.hpp"
56#include "lib/nocopy.hpp"
59#include "lib/symbol.hpp"
60
61
62
63namespace lib {
64namespace time {
65
66 using lib::Symbol;
67
68 LUMIERA_ERROR_DECLARE (INVALID_MUTATION);
69
70 class QuTime;
71 class Mutation;
72
73
74 /* The following typedefs allow to hand out
75 * "unspecific" mutation value objects from
76 * factory functions, without disclosing any
77 * implementation details here in this header.
78 */
79 enum{ MUTATION_IMPL_SIZE = sizeof(TimeValue) };
80
83
92 {
93 public:
94 virtual ~Mutation();
95
96 virtual void change (Duration&) const =0;
97 virtual void change (TimeSpan&) const =0;
98 virtual void change (QuTime&) const =0;
99
100 /* === convenience shortcuts for simple cases === */
101
106 static EncapsulatedMutation nudge (int adjustment);
107 static EncapsulatedMutation nudge (int adjustment, Symbol gridID);
108#ifdef LIB_TIME_TIMEQUANT_H
109 static EncapsulatedMutation nudge (int adjustment, PQuant const& grid);
110#endif
111
112 protected:
113 static TimeValue& imposeChange (TimeValue&, TimeValue const&);
114 static TimeValue& imposeChange (TimeValue&, Offset const&);
115 static TimeValue& imposeChange (TimeValue&, int);
117 };
118
119
120 /* === defining the visitation responses === */
121
122 inline void Duration::accept (Mutation const& muta) { muta.change (*this); }
123 inline void TimeSpan::accept (Mutation const& muta) { muta.change (*this); }
124
125#ifdef LIB_TIME_TIMEQUANT_H
126 inline void QuTime::accept (Mutation const& muta) { muta.change (*this); }
127#endif
128
129
130
131 /* === implementing the actual changes === */
132
137 inline TimeValue&
138 Mutation::imposeChange (TimeValue& target, TimeValue const& valueToSet)
139 {
140 return target = valueToSet;
141 }
142
144 inline TimeValue&
145 Mutation::imposeChange (TimeValue& target, Offset const& offset)
146 {
147 return imposeChange (target, TimeVar(target) += offset);
148 }
149
153 inline TimeValue&
155 {
156 return imposeChange (target, TimeVar(target) += Time(FSecs(steps)));
157 }
158
159#ifdef LIB_TIME_TIMEQUANT_H
167 inline TimeValue&
168 Mutation::imposeChange (QuTime& target, int steps)
169 {
170 PQuant const& grid (target);
171 FrameCnt originalGridPoint = grid->gridPoint(target);
172 FrameCnt adjustedGridPoint = originalGridPoint + steps;
173 return imposeChange (target, grid->timeOf (adjustedGridPoint));
174 }
175#endif
176
177
178
179}} // lib::time
180#endif
Template to build polymorphic value objects.
Token or Atom with distinct identity.
Definition symbol.hpp:120
A variation for limited copy support.
Duration is the internal Lumiera time metric.
void accept(Mutation const &)
Definition mutation.hpp:122
Interface: an opaque change imposed onto some time value.
Definition mutation.hpp:92
virtual void change(TimeSpan &) const =0
virtual void change(QuTime &) const =0
virtual ~Mutation()
Definition mutation.cpp:56
static EncapsulatedMutation changeDuration(Duration)
Convenience factory: simple Mutation to adjust the duration or length of a timespan.
Definition mutation.cpp:296
virtual void change(Duration &) const =0
static EncapsulatedMutation materialise(QuTime const &)
Convenience factory: materialise the given quantised time into an explicit fixed internal time value,...
Definition mutation.cpp:319
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:336
static TimeValue & imposeChange(TimeValue &, TimeValue const &)
Definition mutation.hpp:138
static EncapsulatedMutation adjust(Offset)
Convenience factory: simple Mutation to adjust the duration or length of a timespan.
Definition mutation.cpp:307
static TimeValue & imposeChange(QuTime &, int)
static EncapsulatedMutation changeTime(Time)
Convenience factory to yield a simple Mutation changing the absolute start time.
Definition mutation.cpp:285
Offset measures a distance in time.
grid aligned time specification, referring to a specific scale.
Definition timequant.hpp:91
void accept(Mutation const &)
receive change message, which might cause re-quantisation
A time interval anchored at a specific point in time.
void accept(Mutation const &)
may change start / duration
Definition mutation.hpp:123
basic constant internal time value.
a mutable time value, behaving like a plain number, allowing copy and re-accessing
Lumiera's internal time value datatype.
#define LUMIERA_ERROR_DECLARE(err)
Forward declare an error constant.
Definition error.h:62
Lumiera error handling (C++ interface).
int64_t FrameCnt
relative framecount or frame number.
Definition digxel.hpp:310
@ MUTATION_IMPL_SIZE
Definition mutation.hpp:79
lib::polyvalue::CloneValueSupport< Mutation > ClonableMutation
Definition mutation.hpp:81
lib::PolymorphicValue< Mutation, MUTATION_IMPL_SIZE, ClonableMutation > EncapsulatedMutation
Definition mutation.hpp:82
std::shared_ptr< const Quantiser > PQuant
Definition formats.hpp:58
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Implementation namespace for support and library code.
Mix-Ins to allow or prohibit various degrees of copying and cloning.
A mechanism to allow for opaque polymorphic value objects.
Marker types to indicate a literal string and a Symbol.
a family of time value like entities and their relationships.