MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ try_resume_with_context()

bool MayaFlux::Vruta::SoundRoutine::try_resume_with_context ( uint64_t  current_value,
DelayContext   
)
overridevirtual

Attempts to resume the coroutine with explicit temporal context.

Parameters
current_valueCurrent position in the timeline (samples, frames, cycles, etc.)
contextThe temporal context being processed
Returns
True if the coroutine was resumed, false otherwise

This context-aware resume method allows different temporal mechanisms to coexist within the same processing token. For example, both sample-based and buffer-cycle-based delays can use SAMPLE_ACCURATE token without interfering with each other.

The default implementation delegates to try_resume(uint64_t) for backward compatibility. Derived classes can override to implement context-specific resumption logic.

Reimplemented from MayaFlux::Vruta::Routine.

Definition at line 111 of file Routine.cpp.

112{
113 if (!is_active())
114 return false;
115
116 auto& promise_ref = m_handle.promise();
117
118 if (promise_ref.should_terminate || !promise_ref.auto_resume) {
119 return false;
120 }
121
122 if (context != DelayContext::NONE && promise_ref.active_delay_context == DelayContext::AWAIT) {
123 return initialize_state(current_value);
124 }
125
126 if (promise_ref.active_delay_context != DelayContext::NONE && promise_ref.active_delay_context != context) {
127 return false;
128 }
129
130 bool should_resume = false;
131
132 switch (context) {
134 if (promise_ref.active_delay_context == DelayContext::SAMPLE_BASED) {
135 should_resume = (current_value >= promise_ref.next_sample);
136 if (should_resume) {
137 promise_ref.next_sample = current_value + promise_ref.delay_amount;
138 }
139 } else {
140 should_resume = false;
141 }
142 break;
143
145 if (promise_ref.active_delay_context == DelayContext::BUFFER_BASED) {
146 should_resume = (current_value >= promise_ref.next_buffer_cycle);
147 } else {
148 should_resume = false;
149 }
150 break;
151
153 should_resume = true;
154 break;
155
156 default:
157 return false;
158 }
159
160 if (should_resume) {
161 m_handle.resume();
162 return true;
163 }
164
165 return false;
166}
std::coroutine_handle< promise_type > m_handle
Handle to the underlying coroutine.
Definition Routine.hpp:468
bool is_active() const override
Checks if the coroutine is still active.
Definition Routine.cpp:78
bool initialize_state(uint64_t current_sample=0U) override
Initializes the coroutine's state for execution.
Definition Routine.cpp:86
@ NONE
No active delay, try resume immediately.
@ SAMPLE_BASED
Sample-accurate delay (audio domain)
@ BUFFER_BASED
Buffer-cycle delay (audio hardware boundary)
@ AWAIT
Awaiter-induced delay (temporary suspension)

References MayaFlux::Vruta::AWAIT, MayaFlux::Vruta::BUFFER_BASED, initialize_state(), is_active(), m_handle, MayaFlux::Vruta::NONE, and MayaFlux::Vruta::SAMPLE_BASED.

Referenced by try_resume().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: