GithubHelp home page GithubHelp logo

timeline's People

Contributors

jeremycorren avatar jsbean avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

timeline's Issues

Implement Timer protocol

Define an interface for objects that can perform closures rapidly at (as-)even(-as-possible) intervals.

protocol Timer {
    init(interval: Double, advance: () -> ())
    func start()
    func stop()
}

This could be Timer, DispatchSourceTimer, or perhaps something done in the audio realm (counting samples in buffers at a sampling rate).

Implement merge and +

It would be nice to be able to create local timeline, then merge it into another one.

Regression in pause functionality

To ensure greater accuracy, the internal modeling of currentFrame became something calculated from the secondsElapsed instance property, as opposed to something which was manually incremented.

This disabled the deterministic behavior in the Frames domain (useful when testing the pause method), but without the potential for drift.

Implement a mutable playback rate

In usage:

timeline.playbackRate = 1.25 // 25% faster

Will require adding:

extension Timeline {
    public var playbackRate: Double {
        didSet {
            // regenerate Timer
            // update position model (TODO: implement position model)
        }
    } 
}

Migrate to closure-based Timer API

We currently use Timer.sheduledTimer(timerInterval:target:selector:userInfo:repeats:), which has objc all over it.

Transfer to this API, which looks like it won't require @objc-declared selector.

Create better model for looping actions

Currently, looping actions are just added to the schedule. They are also not purged upon stop(), which means they will keep popping up, leading to things blowing up!

Refine naming of function, protocol, and struct types

Currently, we are using:

typealias Action = () -> ()
protocol ActionType { } 
struct AtomicAction { }
struct LoopingAction { }

Where, ActionType structs contain an Action, wrapped with either an offset time stamp or looping interval.

The naming doesn't seem to appropriately convey the graph of relationships.

Implement Schedule protocol

Define an interface for storing closures to be performed at given offsets.

protocol Schedule {
    mutating func add(_ action: Action, at: Frames)
    mutating func removeAll(identifier: String)
}

Richer model of intervallic events and gaps

Create a richer model of duration spanning events, and therefore gaps between.

This will enable a more streamlined approach to generating ProgressBar actions when one has no events.

Make Timeline protocol

Make Timeline merely a protocol. Then, implement a default timeline given a certain Timer API.

Audit `fileprivate` properties

There may be instances of properties here that were converted to fileprivate when they can maintain their private status.

Create internal model representation isolated from execution

Currently, the model of the events in the timeline and the execution of this model are entangled.

This has made it so the refinement of accuracy in the timing has muddied up the model (and therefore breaking the pause functionality).

Break these apart.

Implement Clock protocol

Define an interface for objects that can measure time accurately. Keeps the Timer in check, avoids drift.

protocol Clock {
    static var now: Seconds { get }
    var elapsed: Seconds { get }
    func start()
}

Implement Timeline protocol

protocol Timeline {

    // MARK: - Associated Types

    associatedtype Schedule: ScheduleProtocol
    associatedtype Timer: TimerProtocol
    associatedtype Clock: ClockProtocol

    // MARK: - Instance Properties

    var playbackRate: Double { get set }

    // MARK: - Initializers

    init(schedule: Schedule, timer: Timer, clock: Clock)

    // MARK: - Instance Methods

    func start()
    func stop()
    func pause()
    func resume()
    func skip(to: Seconds)
}

Store events with identifier

To remove events with a given identifier:

E.g.,

timeline.removeActions(identifier: "autoPlay")
timeline.removeActions(identifier: "metronome")

Fix drifting of internal timer

We are using the Foundation Timer API, which is not super accurate:

Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds.

More importantly, it drifts. In an initial implementation, I was counteracting the drift by continuously checking against CACurrentMediaTime(). At some point, this was reverted, and currentFrame is merely incremented during the internal advance() method.

We need to implement a check against the current time at the beginning of the advance() method, then calculate and set the currentFrame at that point.

Related, look into using the DispatchTime API rather than having a CoreGraphics dependency.

Consider using OrderedDictionary for registry

Currently, actions (() -> ()) are stored by UInt keys. When iterating over the registry, the events are in the order in which they were added, but not ordered by time.

Implement OrderedDictionary from DictionaryTools.

First, conform OrderedDictionary to CollectionType protocol.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.