12 TaskEntry(std::shared_ptr<Routine> r,
const std::string& n)
61 TaskScheduler(uint32_t default_sample_rate = 48000, uint32_t default_frame_rate = 60);
73 void add_task(std::shared_ptr<Routine> routine,
const std::string& name =
"",
bool initialize =
false);
80 std::shared_ptr<Routine> get_task(
const std::string& name)
const;
132 void process_all_tokens();
151 uint64_t seconds_to_units(
double seconds,
ProcessingToken token = ProcessingToken::SAMPLE_ACCURATE)
const;
175 uint64_t seconds_to_samples(
double seconds)
const;
186 return get_typed_clock<SampleClock>(ProcessingToken::SAMPLE_ACCURATE);
214 template <
typename ClockType>
217 return dynamic_cast<const ClockType&
>(get_clock(
token));
227 template <
typename... Args>
230 auto it = find_task_by_name(name);
231 if (it != m_tasks.end() && it->routine && it->routine->is_active()) {
232 it->routine->update_params(std::forward<Args>(args)...);
245 template <
typename T>
248 auto it = find_task_by_name(name);
249 if (it != m_tasks.end() && it->routine && it->routine->is_active()) {
250 return it->routine->get_state<T>(state_key);
262 template <
typename T>
265 return [
this, name, state_key]() -> T {
266 if (
auto value = get_task_state<T>(name, state_key)) {
277 uint64_t get_next_task_id()
const;
295 void pause_all_tasks();
300 void resume_all_tasks();
305 void terminate_all_tasks();
329 return m_current_buffer_cycle;
338 m_current_buffer_cycle++;
341 void process_buffer_cycle_tasks();
349 std::string auto_generate_name(std::shared_ptr<Routine> routine)
const;
356 std::vector<TaskEntry>::iterator find_task_by_name(
const std::string& name);
363 std::vector<TaskEntry>::const_iterator find_task_by_name(
const std::string& name)
const;
370 std::vector<TaskEntry>::iterator find_task_by_routine(std::shared_ptr<Routine> routine);
396 void cleanup_completed_tasks();
432 mutable std::atomic<uint64_t> m_next_task_id { 1 };
453 uint64_t m_current_buffer_cycle {};
static MayaFlux::Nodes::ProcessingToken token
Abstract base interface for all clock types in the multimodal scheduling system.
Sample-accurate timing system for audio processing domain.
std::function< T()> create_value_accessor(const std::string &name, const std::string &state_key) const
Create value accessor function for named task.
uint64_t get_current_buffer_cycle() const
Get current buffer cycle for task scheduling Updated by AudioSubsystem at each buffer boundary.
SampleClock m_clock
The master sample clock for the processing engine.
uint32_t get_cleanup_threshold() const
Get the task cleanup threshold.
std::unordered_map< ProcessingToken, unsigned int > m_token_rates
Default processing rates for each domain.
std::vector< TaskEntry > m_tasks
void tick_buffer_cycle()
Increment buffer cycle counter Called by AudioSubsystem at start of each buffer processing.
const SampleClock & get_sample_clock() const
Get the audio domain's SampleClock (legacy interface)
uint32_t m_cleanup_threshold
Threshold for task cleanup.
std::unordered_map< ProcessingToken, token_processing_func_t > m_token_processors
Custom processors for specific domains.
bool update_task_params(const std::string &name, Args &&... args)
Update parameters of a named task.
T * get_task_state(const std::string &name, const std::string &state_key) const
Get task state value by name and key.
const ClockType & get_typed_clock(ProcessingToken token=ProcessingToken::SAMPLE_ACCURATE) const
Get a typed clock for a specific processing domain.
std::vector< std::string > get_task_names() const
Get all task names for debugging/inspection.
void set_cleanup_threshold(uint32_t threshold)
Set the task cleanup threshold.
std::unordered_map< ProcessingToken, std::unique_ptr< IClock > > m_token_clocks
Clock instances for each processing domain.
const SampleClock & get_clock() const
Gets the primary clock (audio domain for legacy compatibility)
Token-based multimodal task scheduling system for unified coroutine processing.
std::function< void(const std::vector< std::shared_ptr< Routine > > &, uint64_t)> token_processing_func_t
Function type for processing tasks in a specific token domain.
bool restart_task(const std::string &name)
Restarts a scheduled task.
bool cancel_task(const std::string &name)
Cancels a scheduled task.
std::shared_ptr< Routine > routine
TaskEntry(std::shared_ptr< Routine > r, const std::string &n)