You use clock surrogates to synchronize one clock to another. Surrogates can be passed across task boundaries, so you can synchronize clocks that reside in separate tasks. A syncable clock can also be synchronized directly to a time source using a syncable clock surrogate that represents the time source.
The rate of a syncable clock represents how fast its time is flowing with respect to the clock it is synchronized to--for example, it might be going the same speed (rate = 1.0), twice as fast (rate = 2.0), or half as fast (rate = 0.5). The rate acts as a floating-point multiplier for the amount of time that is flowing. The default rate is 1.0, but you can change it with TSyncableClock::SetRate.
You can implement tempo maps or shuttle knobs by changing the rate of a clock at different points in time. Tempo maps are commonly used in Musical Instrument Digital Interface (MIDI) applications to specify changes in the playback rate of a sequence. It is important that the tempo map be used to back out of a sequence when the sequence is reversed, rewound, or restarted. Figure 15
The clock time is the current time on a clock. Two clocks can be synchronized to the same master clock and run at the same rate but still have different clock times because they count time from different points.
For example, you might use different clocks to represent different time zones and synchronize them all to a clock that represents Greenwich Mean Time (GMT). The clock that represents Pacific Standard Time (PST) and the clock that represents Eastern Standard Time (EST) have different clock times, but they are both synchronized to the GMT clock and run at the same rate.
To synchronize the EST and PST clocks to the GMT clock, you use the clock surrogate for the GMT clock:
This synchronization relationship is a simple clock hierarchy. You could change one of the slave clocks to represent a different time zone by simply resetting the time with TSyncableClock::SetTime. One of the advantages of building clock hierarchies is that it is easy to change the relationships. For more about clock hierarchies, see "Representing timing dependencies" on page 81.
Rate
Clock times
NOTE
This example is provided to illustrate different clock times; you do not have to perform your own conversions between time zones. The date and time formatting classes allow you to easily convert between UTC time and local times. For more information about converting and formatting dates and times for particular locales, see Text, Native Language Support, and Time Media. TDateTimeCLock gmtClock;
TSyncableClock estClock;
TSyncableClockSurrogate gmtClockSurrogate;
gmtClock.GetClockSurrogate(gmtClockSurrogate);
estClock.SyncTo(gmtClockSurrogate, 1.0, (THours) -5);
TSyncableClock pstClock;
pstClock.SyncTo(gmtClockSurrogate, 1.0, (THours) -8);
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Generated with WebMaker