13namespace tracktion {
inline namespace graph
19template<
typename IntType>
20constexpr double sampleToTime (IntType samplePosition,
double sampleRate)
22 return samplePosition / sampleRate;
26constexpr int64_t timeToSample (
double timeInSeconds,
double sampleRate)
28 return static_cast<int64_t> ((timeInSeconds * sampleRate) + 0.5);
32template<
typename IntType>
42 return { timeToSample (timeInSeconds.
getStart(), sampleRate),
43 timeToSample (timeInSeconds.
getEnd(), sampleRate) };
47template<
typename RangeType>
50 return { timeToSample (timeInSeconds.
getStart(), sampleRate),
51 timeToSample (timeInSeconds.
getEnd(), sampleRate) };
60template<
typename NodeType,
typename Predicate>
63 auto found =
std::find_if (nodeGraph.sortedNodes.begin(),
64 nodeGraph.sortedNodes.end(),
65 [&pred] (
auto nodeAndID)
67 if (auto foundType = dynamic_cast<NodeType*> (nodeAndID.node))
68 if (pred (*foundType))
74 if (found != nodeGraph.sortedNodes.end())
75 return dynamic_cast<NodeType*
> (found->node);
84template<
typename NodeType>
87 auto found =
std::find_if (nodeGraph.sortedNodes.begin(),
88 nodeGraph.sortedNodes.end(),
89 [nodeIDToLookFor] (
auto nodeAndID)
91 return nodeAndID.id == nodeIDToLookFor
92 && dynamic_cast<NodeType*> (nodeAndID.node) != nullptr;
95 if (found != nodeGraph.sortedNodes.end())
96 return dynamic_cast<NodeType*
> (found->node);
105template<
typename NodeType>
108 return (nodeGraph ==
nullptr || nodeIDToLookFor == 0)
110 : findNodeWithID<NodeType> (*nodeGraph, nodeIDToLookFor);
constexpr ValueType getStart() const noexcept
constexpr ValueType getEnd() const noexcept
NodeType * findNodeWithIDIfNonZero(NodeGraph *nodeGraph, size_t nodeIDToLookFor)
Attempts to find a Node of a given type with a specified ID.
NodeType * findNode(NodeGraph &nodeGraph, Predicate pred)
Attempts to find a Node of a given type with a specified ID.
NodeType * findNodeWithID(NodeGraph &nodeGraph, size_t nodeIDToLookFor)
Attempts to find a Node of a given type with a specified ID.
constexpr double sampleToTime(IntType samplePosition, double sampleRate)
Converts an integer sample number to a time in seconds.
Describes a range of two positions with a duration separating them.
constexpr Position getEnd() const
Returns the end of the range.
constexpr Position getStart() const
Returns the start of the range.
Holds a graph in an order ready for processing and a sorted map for quick lookups.