Lumiera  0.pre.03
»edit your freedom«
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 
105 #ifndef LIB_TIME_CONTROL_H
106 #define LIB_TIME_CONTROL_H
107 
108 #include "lib/time/mutation.hpp"
109 #include "lib/time/timevalue.hpp"
110 #include "lib/time/control-impl.hpp"
111 
112 
113 
114 namespace lib {
115 namespace time {
116 
117 
118 
133  template<class TI>
134  class Control
135  : public mutation::Mutator<TI>
136  {
137  mutation::Propagator<TI> notifyListeners_;
138 
139  virtual void change (Duration&) const;
140  virtual void change (TimeSpan&) const;
141  virtual void change (QuTime&) const;
142 
143  public:
144  void operator() (TI const&) const;
145  void operator() (Offset const&) const;
146  void operator() (int) const;
147 
148 
152  template<class SIG>
153  void connectChangeNotification (SIG const& toNotify);
154 
157  void disconnect();
158  };
159 
160 
161 
162 
163  /* === forward to implementation === */
164 
175  template<class TI>
176  void
177  Control<TI>::operator () (TI const& newValue) const
178  {
179  this->ensure_isArmed();
180  notifyListeners_(
181  this->setVal_(newValue));
182  }
183 
189  template<class TI>
190  void
191  Control<TI>::operator () (Offset const& adjustment) const
192  {
193  this->ensure_isArmed();
194  notifyListeners_(
195  this->offset_(adjustment));
196  }
197 
203  template<class TI>
204  void
205  Control<TI>::operator () (int offset_by_steps) const
206  {
207  this->ensure_isArmed();
208  notifyListeners_(
209  this->nudge_(offset_by_steps));
210  }
211 
212 
213  template<class TI>
214  void
216  {
217  notifyListeners_.disconnect();
218  this->unbind();
219  }
220 
221  template<class TI>
222  template<class SIG>
223  void
225  {
226  if (this->offset_)
227  { // we're already connected: thus propagate current value
228  TI currentValue = this->offset_(Offset::ZERO);
229  toNotify (currentValue);
230  }
231  notifyListeners_.attach (toNotify);
232  }
233 
234 
235  /* ==== Implementation of the Mutation interface ==== */
236 
237  template<class TI>
238  void
239  Control<TI>::change (Duration& targetDuration) const
240  {
241  this->bind_to (targetDuration);
242  }
243 
244  template<class TI>
245  void
246  Control<TI>::change (TimeSpan& targetInterval) const
247  {
248  this->bind_to (targetInterval);
249  }
250 
251  template<class TI>
252  void
253  Control<TI>::change (QuTime& targetQuTime) const
254  {
255  this->bind_to (targetQuTime);
256  }
257 
258 }} // lib::time
259 #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:224
void operator()(TI const &) const
impose a new value to the connected target.
Definition: control.hpp:177
Modifying time and timecode values.
Frontend/Interface: controller-element to retrieve and change running time values.
Definition: control.hpp:134
Implementation building blocks for time modification and propagation.
Implementation namespace for support and library code.
void disconnect()
disconnect from observed entity and cease any change notification
Definition: control.hpp:215
Offset measures a distance in time.
Definition: timevalue.hpp:367
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
A time interval anchored at a specific point in time.
Definition: timevalue.hpp:582
Implementation building block: impose changes to a Time element.
a family of time value like entities and their relationships.
grid aligned time specification, referring to a specific scale.
Definition: timequant.hpp:99