MayaFlux 0.1.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 112 of file Routine.cpp.

113{
114 if (!is_active())
115 return false;
116
117 auto& promise_ref = m_handle.promise();
118
119 if (promise_ref.should_terminate || !promise_ref.auto_resume) {
120 return false;
121 }
122
123 if (context != DelayContext::NONE && promise_ref.active_delay_context == DelayContext::AWAIT) {
124 return initialize_state(current_value);
125 }
126
127 if (promise_ref.active_delay_context != DelayContext::NONE && promise_ref.active_delay_context != context) {
128 return false;
129 }
130
131 bool should_resume = false;
132
133 switch (context) {
135 if (promise_ref.active_delay_context == DelayContext::SAMPLE_BASED) {
136 should_resume = (current_value >= promise_ref.next_sample);
137 if (should_resume) {
138 promise_ref.next_sample = current_value + promise_ref.delay_amount;
139 }
140 } else {
141 should_resume = false;
142 }
143 break;
144
146 if (promise_ref.active_delay_context == DelayContext::BUFFER_BASED) {
147 should_resume = (current_value >= promise_ref.next_buffer_cycle);
148
149 if (should_resume) {
150 promise_ref.next_buffer_cycle = current_value + promise_ref.delay_amount;
151 }
152 } else {
153 should_resume = false;
154 }
155 break;
156
158 should_resume = true;
159 break;
160
161 default:
162 return false;
163 }
164
165 if (should_resume) {
166 m_handle.resume();
167 return true;
168 }
169
170 return false;
171}
std::coroutine_handle< promise_type > m_handle
Handle to the underlying coroutine.
Definition Routine.hpp:460
bool is_active() const override
Checks if the coroutine is still active.
Definition Routine.cpp:79
bool initialize_state(uint64_t current_sample=0U) override
Initializes the coroutine's state for execution.
Definition Routine.cpp:87
@ NONE
No active delay, 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: