93 return try_resume(current_value);
191 template <
typename... Args>
194 update_params_impl(std::forward<Args>(args)...);
206 template <
typename T>
209 set_state_impl(key, std::move(value));
221 template <
typename T>
224 return get_state_impl<T>(key);
236 template <
typename T>
239 void* raw_ptr = get_state_impl_raw(key);
244 return std::any_cast<T>(
static_cast<std::any*
>(raw_ptr));
245 }
catch (
const std::bad_any_cast&) {
265 template <
typename T,
typename... Args>
268 set_state(key, std::move(value));
269 if constexpr (
sizeof...(args) > 0) {
270 update_params_impl(std::forward<Args>(args)...);
376 [[nodiscard]]
bool is_active()
const override;
378 bool initialize_state(uint64_t current_sample = 0U)
override;
380 bool try_resume(uint64_t current_context)
override;
382 bool try_resume_with_context(uint64_t current_value,
DelayContext context)
override;
386 return m_handle.promise().active_delay_context;
391 m_handle.promise().active_delay_context = context;
394 bool restart()
override;
396 [[nodiscard]] uint64_t next_execution()
const override;
398 [[nodiscard]]
bool requires_clock_sync()
const override;
402 return m_handle.promise().auto_resume;
407 m_handle.promise().auto_resume = auto_resume;
412 return m_handle.promise().should_terminate;
417 m_handle.promise().should_terminate = should_terminate;
422 return m_handle.promise().sync_to_clock;
427 return m_handle.promise().next_sample;
432 m_handle.promise().next_sample = next_sample;
437 return m_handle.promise().next_buffer_cycle;
442 m_handle.promise().next_buffer_cycle = next_cycle;
450 void set_state_impl(
const std::string& key, std::any value)
override;
451 void* get_state_impl_raw(
const std::string& key)
override;
569 [[nodiscard]]
bool is_active()
const override;
571 bool initialize_state(uint64_t current_frame = 0U)
override;
573 bool try_resume(uint64_t current_context)
override;
575 bool try_resume_with_context(uint64_t current_value,
DelayContext context)
override;
579 return m_handle.promise().active_delay_context;
584 m_handle.promise().active_delay_context = context;
587 bool restart()
override;
589 [[nodiscard]] uint64_t next_execution()
const override;
591 [[nodiscard]]
bool requires_clock_sync()
const override;
595 return m_handle.promise().auto_resume;
600 m_handle.promise().auto_resume = auto_resume;
605 return m_handle.promise().should_terminate;
610 m_handle.promise().should_terminate = should_terminate;
615 return m_handle.promise().sync_to_clock;
620 return m_handle.promise().next_frame;
625 m_handle.promise().next_frame = next_frame;
633 void set_state_impl(
const std::string& key, std::any value)
override;
634 void* get_state_impl_raw(
const std::string& key)
override;
680 [[nodiscard]]
bool is_active()
const override {
return false; }
bool restart() override
Restarts the coroutine from the beginning.
bool initialize_state(uint64_t=0U) override
Initializes the coroutine's state for execution.
uint64_t get_next_frame() const override
Get next frame execution time (graphics domain)
std::vector< ProcessingToken > m_secondary_tokens
ProcessingToken m_primary_token
void set_state_impl(const std::string &, std::any) override
void set_auto_resume(bool) override
Set auto_resume flag in promise.
bool get_auto_resume() const override
Get auto_resume flag from promise.
void set_next_frame(uint64_t) override
Set next frame execution time (graphics domain)
void set_next_sample(uint64_t) override
Set next sample execution time (audio domain)
bool is_active() const override
Checks if the coroutine is still active.
uint64_t next_execution() const override
Gets the sample position when this routine should next execute.
void set_should_terminate(bool) override
Set should_terminate flag in promise.
bool get_sync_to_clock() const override
Get sync_to_clock flag from promise.
bool requires_clock_sync() const override
Check if the routine should synchronize with a clock.
bool try_resume(uint64_t) override
Attempts to resume the coroutine if it's ready to execute.
bool get_should_terminate() const override
Get should_terminate flag from promise.
uint64_t get_next_sample() const override
Get next sample execution time (audio domain)
ProcessingToken get_processing_token() const override
Get the processing token that determines how this routine should be scheduled.
void * get_state_impl_raw(const std::string &) override
Multi-domain coroutine that can handle multiple processing rates.
uint64_t get_next_sample() const override
Get next sample execution time (audio domain)
void set_auto_resume(bool auto_resume) override
Set auto_resume flag in promise.
void set_should_terminate(bool should_terminate) override
Set should_terminate flag in promise.
bool get_should_terminate() const override
Get should_terminate flag from promise.
void set_next_frame(uint64_t next_frame) override
Set next frame execution time (graphics domain)
void set_next_sample(uint64_t) override
Set next sample execution time (audio domain)
bool get_auto_resume() const override
Get auto_resume flag from promise.
std::coroutine_handle< promise_type > m_handle
Handle to the underlying coroutine.
uint64_t get_next_frame() const override
Get next frame execution time (graphics domain)
DelayContext get_delay_context() const override
Get the active delay context for this routine.
void set_delay_context(DelayContext context) override
Set the active delay context for this routine.
bool get_sync_to_clock() const override
Get sync_to_clock flag from promise.
A C++20 coroutine-based graphics processing task with frame-accurate timing.
void set_state(const std::string &key, T value)
Sets a named state value in the coroutine.
virtual void set_next_frame(uint64_t next_frame)=0
Set next frame execution time (graphics domain)
virtual uint64_t get_next_sample() const =0
Get next sample execution time (audio domain)
virtual bool try_resume_with_context(uint64_t current_value, DelayContext)
Attempts to resume the coroutine with explicit temporal context.
virtual bool restart()=0
Restarts the coroutine from the beginning.
virtual void set_delay_context(DelayContext)
Set the active delay context for this routine.
void update_params(Args... args)
Updates multiple named parameters in the coroutine's state.
virtual bool is_active() const =0
Checks if the coroutine is still active.
virtual ProcessingToken get_processing_token() const =0
Get the processing token that determines how this routine should be scheduled.
virtual void set_state_impl(const std::string &key, std::any value)=0
virtual ~Routine()=default
Destructor.
virtual bool get_sync_to_clock() const =0
Get sync_to_clock flag from promise.
virtual uint64_t next_execution() const =0
Gets the sample position when this routine should next execute.
virtual void set_should_terminate(bool should_terminate)=0
Set should_terminate flag in promise.
virtual bool requires_clock_sync() const =0
Check if the routine should synchronize with a clock.
virtual void set_next_sample(uint64_t next_sample)=0
Set next sample execution time (audio domain)
virtual void set_auto_resume(bool auto_resume)=0
Set auto_resume flag in promise.
virtual void update_params_impl()
brief Implementation helper for update_params
virtual bool get_should_terminate() const =0
Get should_terminate flag from promise.
virtual void * get_state_impl_raw(const std::string &key)=0
virtual uint64_t get_next_frame() const =0
Get next frame execution time (graphics domain)
T * get_state(const std::string &key)
Gets a named state value from the coroutine.
void update_params_impl(const std::string &key, T value, Args... args)
Implementation helper for update_params.
virtual DelayContext get_delay_context() const
Get the active delay context for this routine.
virtual bool initialize_state(uint64_t current_context=0U)=0
Initializes the coroutine's state for execution.
virtual bool try_resume(uint64_t current_context)=0
Attempts to resume the coroutine if it's ready to execute.
T * get_state_impl(const std::string &key)
Implementation helper for get_state.
virtual bool get_auto_resume() const =0
Get auto_resume flag from promise.
Base class for all coroutine types in the MayaFlux engine.
std::coroutine_handle< promise_type > m_handle
Handle to the underlying coroutine.
bool get_sync_to_clock() const override
Get sync_to_clock flag from promise.
void set_auto_resume(bool auto_resume) override
Set auto_resume flag in promise.
uint64_t get_next_sample() const override
Get next sample execution time (audio domain)
bool get_auto_resume() const override
Get auto_resume flag from promise.
uint64_t get_next_frame() const override
Get next frame execution time (graphics domain)
void set_next_sample(uint64_t next_sample) override
Set next sample execution time (audio domain)
bool get_should_terminate() const override
Get should_terminate flag from promise.
void set_next_frame(uint64_t next_cycle) override
Set next frame execution time (graphics domain)
void set_delay_context(DelayContext context) override
Set the active delay context for this routine.
DelayContext get_delay_context() const override
Get the active delay context for this routine.
void set_should_terminate(bool should_terminate) override
Set should_terminate flag in promise.
A C++20 coroutine-based audio processing task with sample-accurate timing.
@ MULTI_RATE
Coroutine can handle multiple sample rates. Picks the frame-accurate processing token by default.
@ SAMPLE_ACCURATE
Coroutine is sample-accurate.
DelayContext
Discriminator for different temporal delay mechanisms.
Coroutine promise type for audio processing tasks with sample-accurate timing.
Coroutine promise type for graphics processing tasks with frame-accurate timing.