CorrelatedClock

@interface CorrelatedClock : ClockBase

CorrelatedClock is a clock locked to the tick count of the parent clock by a correlation and frequency setting. Correlation is a tuple (parentTicks, selfTicks). When the parent clock ticks property has the value parentTicks, the ticks property of this clock shall have the value selfTicks.

@discussion You can alter the correlation and tickRate and speed of this clock dynamically. Changes to tickRate and speed will not shift the point of correlation. This means that a change in tickRate or speed will probably cause the current tick value of the clock to jump. The amount it jumps by will be proportional to the distance the current time is from the point of correlation.

If you want a speed change to only affect the ticks from a particular point (e.g. the current tick value) onwards then you must re-base the correlation.

Warning

The maths to calculate and convert tick values will be performed, by default, as integer maths unless the parameters controlling the clock (tickRate etc) are floating point, or the ticks property of the parent clock supplies floating point values.

There is a function provided to do that in some circumstances:

@code c = CorrelatedClock(parentClock=parent, tickRate=1000, correlation=(50,78))

    ... time passes ...

    // now freeze the clock AT ITS CURRENT TICK VALUE

    c.rebaseCorrelationAtTicks(c.ticks)
    c.speed = 0

    // now resume the clock but at half speed, but again without the tick value jumping
    c.correlation = ( parent.ticks, c.ticks )
    c.speed = 0.5;
  • The underlying correlation for the timeline represented by this clock with respect to its parent timeline (clock)

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) Correlation correlation;

    Swift

    var correlation: Correlation { get set }
  • Default-value init method disallowed. Use initWithTickRate() method instead.

    Declaration

    Objective-C

    - (instancetype)init;
  • initialise a CorrelatedClock instance

    Declaration

    Objective-C

    - (instancetype)initWithParentClock:(ClockBase *)parentClock
                               TickRate:(uint64_t)tickRate
                            Correlation:(Correlation *)correl;

    Swift

    init!(parentClock: ClockBase!, tickRate: UInt64, correlation correl: UnsafeMutablePointer

    Parameters

    parentClock

    this clock’s immediate parent

    tickRate

    tickrate/frequency for this clock

    correl

    correlation tuple (parent_tick_value)

    Return Value

    CorrelatedClock instance

  • Returns a string representation of this object

    Declaration

    Objective-C

    - (NSString *)description;

    Swift

    func description() -> String!

    Return Value

    string representation of this object

    • Changes the correlation property to an equivalent correlation (that does not change the timing relationship between parent clock and this clock) where the tick value for this clock is the provided tick value.
    • @discussion If you want a change (e.g. speed change) to only affect the ticks from a particular point (e.g. the current tick value) onwards then you must re-base the correlation. *
    • - parameter: newTicks tickvalue of this clock from which the new correlation applies
    • @code CorrelatedClock *c = [CorrelatedClock alloc] initWithParentClock:parent TickRate: tickRate, correlation=(50,78))

    … time passes …

    now freeze the clock AT ITS CURRENT TICK VALUE

    c.rebaseCorrelationAtTicks(c.ticks) c.speed = 0

    now resume the clock but at half speed, but again without the tick value jumping

    c.correlation = ( parent.ticks, c.ticks ) c.speed = 0.5

    Declaration

    Objective-C

    - (void)rebaseCorrelationAtTicks:(int64_t)newTicks;

    Swift

    func rebaseCorrelation(atTicks newTicks: Int64)

    Parameters

    newTicks

    tickvalue of this clock from which the new correlation applies