Skip to content

Commit

Permalink
Function wrappers for std::chrono time usage.
Browse files Browse the repository at this point in the history
Placeholders converting from chrono::seconds to double
for animation. Will eventually replace all use of double with
std::chrono per gh #49.
  • Loading branch information
David Wicks committed Jul 27, 2016
1 parent d57b1e1 commit 93328aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/choreograph/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ class Channel
Channel(T value, Time at_time, Curve::Type curve_type, Keys&&... keys) {
insertKey(value, at_time, curve_type, std::forward<Keys>(keys)...);
}
template <typename ... Keys>
Channel(T value, Seconds at_time, Curve::Type curve_type, Keys&&... keys) {
insertKey(value, at_time, curve_type, std::forward<Keys>(keys)...);
}

/// Return the value of the channel at a given time.
T value(Time at_time) const;
Expand All @@ -202,6 +206,12 @@ class Channel
template <typename ... Keys>
Channel& insertKey(T value, Time at_time, Curve::Type curve_type, Keys&&... keys);

/// Insert a key at the given time using chrono::seconds.
Channel& insertKey(T value, Seconds at_time, Curve::Type curve_type = Curve::Linear) { return insertKey(value, at_time.count(), curve_type); }
/// Insert multiple keys using chrono::seconds.
template <typename ... Keys>
Channel& insertKey(T value, Seconds at_time, Curve::Type curve_type, Keys&&... keys);

bool empty() const { return _keys.empty(); }
Time duration() const { return empty() ? 0 : _keys.back().time; }
const std::vector<Key>& keys() const { return _keys; }
Expand Down Expand Up @@ -296,6 +306,15 @@ Channel<T>& Channel<T>::insertKey(T value, Time at_time, Curve::Type curve_type,
return *this;
}

template <typename T>
template <typename ... Keys>
Channel<T>& Channel<T>::insertKey(T value, Seconds at_time, Curve::Type curve_type, Keys&&... keys)
{
insertKey(value, at_time, curve_type);
insertKey(std::forward<Keys>(keys)...);
return *this;
}

template <typename T>
typename Channel<T>::KeyManipulator Channel<T>::keyControl(size_t desired_index) {
auto index = std::min(desired_index, _keys.size() - 1);
Expand Down
1 change: 1 addition & 0 deletions src/choreograph/TimeType.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace choreograph
///

using Time = double;
using Seconds = std::chrono::duration<double, std::chrono::seconds::period>;

/// Wrap \a time past \a duration around \a inflectionPoint.
inline Time wrapTime( Time time, Time duration, Time inflectionPoint=0.0f )
Expand Down
2 changes: 2 additions & 0 deletions src/choreograph/Timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class Timeline : public TimelineItem
/// Add a cue to the timeline. It will be called after \a delay time elapses on this Timeline.
TimelineOptions cue( const std::function<void ()> &fn, Time delay );

TimelineOptions cue( const std::function<void ()> &fn, Seconds delay ) { return cue( fn, delay.count() ); }

//=================================================
// Adding TimelineItems.
//=================================================
Expand Down

0 comments on commit 93328aa

Please sign in to comment.