15namespace tracktion {
inline namespace core
18template<
typename PositionType>
47template<
typename SourceRangeType>
62template<
typename PositionType>
66 using Duration =
typename Position::DurationType;
167 void checkInvariants()
const;
172template<
typename PositionType>
176template<
typename PositionType>
180template<
typename PositionType>
184template<
typename PositionType>
189template<
typename PositionType>
202template<
typename PositionType>
203PositionType fromUnderlyingType (
double);
207inline double toUnderlyingType (TimePosition t) {
return t.inSeconds(); }
210template<>
inline BeatPosition fromUnderlyingType<BeatPosition> (
double t) {
return BeatPosition::fromBeats (t); }
211template<>
inline BeatDuration fromUnderlyingType<BeatDuration> (
double t) {
return BeatDuration::fromBeats (t); }
221template<
typename SourceRangeType>
228template<
typename PositionType>
235template<
typename PositionType>
237 : start (s), end (s + d)
242template<
typename PositionType>
248template<
typename PositionType>
255template<
typename PositionType>
275template<
typename PositionType>
282template<
typename PositionType>
285 auto newStart =
std::max (start, o.start);
289template<
typename PositionType>
293 return { anchorTime + fromUnderlyingType<Duration> (toUnderlyingType (start - anchorTime) * factor),
294 anchorTime + fromUnderlyingType<Duration> (toUnderlyingType (end - anchorTime) * factor) };
297template<
typename PositionType>
300 auto otherLen = rangeToConstrain.
getLength();
302 return getLength() <= otherLen
308template<
typename PositionType>
312 return { start - amount, end + amount };
315template<
typename PositionType>
319 amount =
std::min (amount, fromUnderlyingType<Duration> (toUnderlyingType (getLength()) / 2.0));
320 return { start + amount, end - amount };
323template<
typename PositionType>
326 return { newStart, end + (newStart - start) };
329template<
typename PositionType>
332 return { start + (newEnd - end), newEnd };
335template<
typename PositionType>
339 return { newStart,
std::max (end, newStart) };
342template<
typename PositionType>
346 return {
std::min (start, newEnd), newEnd };
349template<
typename PositionType>
357template<
typename PositionType>
369template<
typename PositionType>
371template<
typename PositionType>
374template<
typename PositionType>
376template<
typename PositionType>
379template<
typename PositionType>
411 return tracktion::hash (
h1,
h2);
423 return tracktion::hash (
h1,
h2);
constexpr ValueType getStart() const noexcept
constexpr ValueType getEnd() const noexcept
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
constexpr auto toUnderlyingType(T t) -> std::enable_if_t< std::is_enum_v< T >, std::underlying_type_t< T > >
TimeRange timeRangeFromSamples(juce::Range< int64_t > sampleRange, double sampleRate)
Creates a TimeRange from a range of samples.
TimeRange timeRangeFromSeconds(SourceRangeType)
Creates a TimeRange from a range of seconds.
constexpr int64_t toSamples(TimePosition, double sampleRate)
Converts a TimePosition to a number of samples.
RangeType< PositionType > withEndExtended(RangeType< PositionType > &, typename RangeType< PositionType >::Duration)
Adds an amount to the end of the range and returns a new range.
static constexpr BeatDuration fromBeats(T durationInBeats)
Create a BeatPosition from a number of beats.
static constexpr BeatPosition fromBeats(T positionInBeats)
Create a BeatPosition from a number of beats.
Describes a range of two positions with a duration separating them.
RangeType withLength(Duration) const
Returns a range with the same start position as this one but a new duration length.
static RangeType emptyRange(Position)
Returns a range with the specified start position and a length of zero.
RangeType reduced(Duration) const
Reduces the start and end of this range by the given ammount.
typename Position::DurationType Duration
The duration type of the range.
bool intersects(const RangeType &) const
Returns true if the given range intersects this one.
static RangeType between(Position, Position)
Returns the range that lies between two positions (in either order).
constexpr Position getEnd() const
Returns the end of the range.
bool overlaps(const RangeType &) const
Returns true if this range overlaps the provided one.
RangeType getIntersectionWith(RangeType) const
Returns the intersection of this range with the given one.
bool contains(const RangeType &) const
Returns true if this range contains the provided one.
RangeType()=default
Creates an empty range.
RangeType movedToStartAt(Position) const
Returns a range with the same duration as this one but a new start position.
RangeType(const RangeType &)=default
Creates a copy of another range.
constexpr Position getStart() const
Returns the start of the range.
RangeType movedToEndAt(Position) const
Returns a range with the same duration as this one but a new end position.
Position clipPosition(Position) const
Clamps the given position to this range.
RangeType rescaled(Position anchorTime, double factor) const
Returns a range that has been expanded or contracted around the given position.
static RangeType endingAt(Position end, Duration)
Creates a Range from a duration and an end position.
RangeType constrainRange(RangeType) const
Returns a given range, after moving it forwards or backwards to fit it within this range.
RangeType expanded(Duration) const
Expands the start and end of this range by the given ammount.
constexpr Duration getLength() const
Returns the length of the range.
RangeType withStart(Position) const
Returns a range with the same end position as this one but a new start position.
PositionType Position
The position type of the range.
bool isEmpty() const
Returns true if this range has a 0 length duration.
constexpr Position getCentre() const
Returns the centre position of the range.
RangeType withEnd(Position) const
Returns a range with the same start position as this one but a new end position.
RangeType & operator=(const RangeType &)=default
Creates a copy of another range.
RangeType getUnionWith(RangeType) const
Returns the range that contains both of these ranges.
bool containsInclusive(Position) const
Returns true if this range contains the provided position even if it lies at the end position.
Represents a duration in real-life time.
static constexpr TimeDuration fromSeconds(T positionInSeconds)
Create a TimeDuration from a number of seconds.
Represents a position in real-life time.
static constexpr TimePosition fromSeconds(T positionInSeconds)
Create a TimePosition from a number of seconds.
static constexpr TimePosition fromSamples(IntType numSamples, double sampleRate)
Create a TimePosition from a number of samples and a sample rate.