13 : m_Scheduler(scheduler)
28 if (timer_ptr && timer_ptr->is_active()) {
29 timer_ptr->m_callback();
30 timer_ptr->m_active =
false;
34 m_routine = std::make_shared<Vruta::SoundRoutine>(
42 m_routine->initialize_state(current_time);
55 : m_Scheduler(scheduler)
60void TimedAction::execute(std::function<
void()> start_func, std::function<
void()> end_func,
double duration_seconds)
78 : m_scheduler(scheduler)
85 : m_scheduler(scheduler)
86 , m_node_graph_manager(graph_manager)
93 play_for(node, duration_seconds, std::vector<uint32_t> { channel });
96void NodeTimer::play_for(std::shared_ptr<Nodes::Node> node,
double duration_seconds, std::vector<uint32_t> channels)
103 for (
auto& channel : channels) {
114 auto source_mask = node->get_channel_mask().load(std::memory_order_relaxed);
115 std::vector<uint32_t> channels;
117 if (source_mask == 0) {
121 channels.push_back(channel);
125 play_for(node, duration_seconds, channels);
128void NodeTimer::play_with_processing(std::shared_ptr<Nodes::Node> node, std::function<
void(std::shared_ptr<Nodes::Node>)> setup_func, std::function<
void(std::shared_ptr<Nodes::Node>)> cleanup_func,
double duration_seconds, uint32_t channel)
130 play_with_processing(node, setup_func, cleanup_func, duration_seconds, std::vector<uint32_t> { channel });
133void NodeTimer::play_with_processing(std::shared_ptr<Nodes::Node> node, std::function<
void(std::shared_ptr<Nodes::Node>)> setup_func, std::function<
void(std::shared_ptr<Nodes::Node>)> cleanup_func,
double duration_seconds, std::vector<uint32_t> channels)
142 for (
auto channel : channels) {
153 std::function<
void(std::shared_ptr<Nodes::Node>)> setup_func,
154 std::function<
void(std::shared_ptr<Nodes::Node>)> cleanup_func,
155 double duration_seconds)
157 auto source_mask = node->get_channel_mask().load(std::memory_order_relaxed);
158 std::vector<uint32_t> channels;
160 if (source_mask == 0) {
164 channels.push_back(channel);
static MayaFlux::Nodes::ProcessingToken token
std::shared_ptr< Nodes::Node > m_current_node
The currently active node being played.
NodeTimer(Vruta::TaskScheduler &scheduler)
Constructs a NodeTimer with the specified scheduler.
Nodes::NodeGraphManager & m_node_graph_manager
Reference to the graph manager that manages processing nodes.
void play_with_processing(std::shared_ptr< Nodes::Node > node, std::function< void(std::shared_ptr< Nodes::Node >)> setup_func, std::function< void(std::shared_ptr< Nodes::Node >)> cleanup_func, double duration_seconds, std::vector< uint32_t > channels)
Activates a processing node with custom setup and cleanup functions.
void cleanup_current_operation()
Cleans up the current operation, disconnecting the node and resetting state.
void play_for(std::shared_ptr< Nodes::Node > node, double duration_seconds, std::vector< uint32_t > channels)
Activates a processing node for a specific duration.
void cancel()
Cancels any currently active node.
std::vector< uint32_t > m_channels
The output channels the current node is connected to.
Timer m_timer
The timer used to schedule node disconnection.
void execute(std::function< void()> start_func, std::function< void()> end_func, double duration_seconds)
Executes a pair of functions with a time interval between them.
void cancel()
Cancels any active action.
bool is_pending() const
Checks if an action is currently in progress.
Timer m_timer
The timer used to schedule the end function.
TimedAction(Vruta::TaskScheduler &scheduler)
Constructs a TimedAction with the specified scheduler.
bool m_active
Flag indicating whether a callback is currently scheduled.
bool is_active() const
Checks if a callback is currently scheduled.
Timer(Vruta::TaskScheduler &scheduler)
Constructs a Timer with the specified scheduler.
std::function< void()> m_callback
The callback function to execute when the timer fires.
Vruta::TaskScheduler & m_Scheduler
Reference to the scheduler that manages this timer.
std::shared_ptr< Vruta::SoundRoutine > m_routine
The underlying computational routine that implements the timer.
void schedule(double delay_seconds, std::function< void()> callback)
Schedules a callback to execute after a delay.
void cancel()
Cancels any scheduled callback.
High-level utility for scheduling one-shot timed callbacks.
void add_to_root(const std::shared_ptr< Node > &node, ProcessingToken token, unsigned int channel=0)
Add node to specific processing token and channel.
RootNode & get_root_node(ProcessingToken token, unsigned int channel)
Gets or creates the root node for a specific token and channel.
Central manager for the computational processing node graph.
void unregister_node(const std::shared_ptr< Node > &node)
Removes a node from this root node.
A C++20 coroutine-based audio processing task with sample-accurate timing.
bool cancel_task(std::shared_ptr< Routine > task)
Cancels and removes a task from the scheduler.
void add_task(std::shared_ptr< Routine > routine, const std::string &name="", bool initialize=false)
Add a routine to the scheduler based on its processing token.
uint64_t seconds_to_samples(double seconds) const
Converts a time in seconds to a number of samples.
uint64_t current_units(ProcessingToken token=ProcessingToken::SAMPLE_ACCURATE) const
Get current processing units for a domain.
Token-based multimodal task scheduling system for unified coroutine processing.
ProcessingToken
Enumerates the different processing domains for nodes.
@ AUDIO_RATE
Nodes that process at the audio sample rate.
std::vector< uint32_t > get_active_channels(const std::shared_ptr< Nodes::Node > &node, uint32_t fallback_channel)
Extracts active channel list from a node's channel mask.
std::shared_ptr< Nodes::NodeGraphManager > get_node_graph_manager()
Gets the node graph manager from the default engine.
Main namespace for the Maya Flux audio engine.
Templated awaitable for accessing a coroutine's promise object.
Awaitable object for precise sample-accurate timing delays.