Lumiera  0.pre.03
»edityourfreedom«
control.hpp
Go to the documentation of this file.
1 /*
2  CONTROL.hpp - a life time control for feedback and mutation
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 
102 #ifndef LIB_TIME_CONTROL_H
103 #define LIB_TIME_CONTROL_H
104 
105 #include "lib/time/mutation.hpp"
106 #include "lib/time/timevalue.hpp"
107 #include "lib/time/control-impl.hpp"
108 
109 
110 
111 namespace lib {
112 namespace time {
113 
114 
115 
130  template<class TI>
131  class Control
132  : public mutation::Mutator<TI>
133  {
135 
136  virtual void change (Duration&) const;
137  virtual void change (TimeSpan&) const;
138  virtual void change (QuTime&) const;
139 
140  public:
141  void operator() (TI const&) const;
142  void operator() (Offset const&) const;
143  void operator() (int) const;
144 
145 
149  template<class SIG>
150  void connectChangeNotification (SIG const& toNotify);
151 
154  void disconnect();
155  };
156 
157 
158 
159 
160  /* === forward to implementation === */
161 
172  template<class TI>
173  void
174  Control<TI>::operator () (TI const& newValue) const
175  {
176  this->ensure_isArmed();
178  this->setVal_(newValue));
179  }
180 
186  template<class TI>
187  void
188  Control<TI>::operator () (Offset const& adjustment) const
189  {
190  this->ensure_isArmed();
192  this->offset_(adjustment));
193  }
194 
200  template<class TI>
201  void
202  Control<TI>::operator () (int offset_by_steps) const
203  {
204  this->ensure_isArmed();
206  this->nudge_(offset_by_steps));
207  }
208 
209 
210  template<class TI>
211  void
213  {
214  notifyListeners_.disconnect();
215  this->unbind();
216  }
217 
218  template<class TI>
219  template<class SIG>
220  void
222  {
223  if (this->offset_)
224  { // we're already connected: thus propagate current value
225  TI currentValue = this->offset_(Offset::ZERO);
226  toNotify (currentValue);
227  }
228  notifyListeners_.attach (toNotify);
229  }
230 
231 
232  /* ==== Implementation of the Mutation interface ==== */
233 
234  template<class TI>
235  void
236  Control<TI>::change (Duration& targetDuration) const
237  {
238  this->bind_to (targetDuration);
239  }
240 
241  template<class TI>
242  void
243  Control<TI>::change (TimeSpan& targetInterval) const
244  {
245  this->bind_to (targetInterval);
246  }
247 
248  template<class TI>
249  void
250  Control<TI>::change (QuTime& targetQuTime) const
251  {
252  this->bind_to (targetQuTime);
253  }
254 
255 }} // lib::time
256 #endif
Implementation building block: propagate changes to listeners.
void connectChangeNotification(SIG const &toNotify)
install a callback functor to be invoked as notification for any changes imposed onto the observed ti...
Definition: control.hpp:221
void operator()(TI const &) const
impose a new value to the connected target.
Definition: control.hpp:174
Modifying time and timecode values.
Frontend/Interface: controller-element to retrieve and change running time values.
Definition: control.hpp:131
Implementation building blocks for time modification and propagation.
Implementation namespace for support and library code.
virtual void change(Duration &) const
Definition: control.hpp:236
void disconnect()
disconnect from observed entity and cease any change notification
Definition: control.hpp:212
void bind_to(TAR &target) const
mutation::Propagator< TI > notifyListeners_
Definition: control.hpp:134
Offset measures a distance in time.
Definition: timevalue.hpp:283
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:380
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:467
Implementation building block: impose changes to a Time element.
a family of time value like entities and their relationships.
static const Offset ZERO
Definition: timevalue.hpp:309
grid aligned time specification, referring to a specific scale.
Definition: timequant.hpp:71