MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Awaiters.cpp
Go to the documentation of this file.
1#include "Awaiters.hpp"
3
4namespace MayaFlux::Kriya {
5
6void SampleDelay::await_suspend(std::coroutine_handle<promise_handle> h) noexcept
7{
8 if constexpr (std::is_same_v<promise_handle, Vruta::audio_promise>
9 || std::is_same_v<promise_handle, Vruta::complex_promise>) {
10 if constexpr (requires { h.promise().next_sample; }) {
11 h.promise().next_sample += samples_to_wait;
12 h.promise().active_delay_context = Vruta::DelayContext::SAMPLE_BASED;
13 }
14 } else {
15 if constexpr (requires { h.promise().domain_mismatch_error("", ""); }) {
16 h.promise().domain_mismatch_error("SampleDelay",
17 "This awaitable is not compatible with the current coroutine promise type.");
18 }
19 }
20}
21
22void FrameDelay::await_suspend(std::coroutine_handle<Vruta::graphics_promise> h) noexcept
23{
24 if constexpr (std::is_same_v<promise_handle, Vruta::graphics_promise>
25 || std::is_same_v<promise_handle, Vruta::complex_promise>) {
26 if constexpr (requires { h.promise().next_frame; }) {
27 h.promise().next_frame += frames_to_wait;
28 h.promise().active_delay_context = Vruta::DelayContext::FRAME_BASED;
29 }
30 } else {
31 if constexpr (requires { h.promise().domain_mismatch_error("", ""); }) {
32 h.promise().domain_mismatch_error("FrameDelay",
33 "This awaitable is not compatible with the current coroutine promise type.");
34 }
35 }
36}
37
38void MultiRateDelay::await_suspend(std::coroutine_handle<Vruta::complex_promise> h) noexcept
39{
40 if constexpr (requires { h.promise().next_sample; }) {
41 h.promise().next_sample += samples_to_wait;
42 }
43 if constexpr (requires { h.promise().next_frame; }) {
44 h.promise().next_frame += frames_to_wait;
45 }
46}
47
54
56{
57 if (auto event = m_source.pop_event(m_filter)) {
58 m_result = *event;
59 return true;
60 }
61 return false;
62}
63
64void EventAwaiter::await_suspend(std::coroutine_handle<> handle)
65{
66 m_handle = handle;
67 m_is_suspended = true;
69}
70
76
78{
79 if (auto event = m_source.pop_event(m_filter)) {
80 m_result = *event;
82 m_is_suspended = false;
83 m_handle.resume();
84 }
85}
86
87}
void try_resume()
Called by EventSource when event arrives.
Definition Awaiters.cpp:77
std::coroutine_handle m_handle
Definition Awaiters.hpp:319
Vruta::EventSource & m_source
Definition Awaiters.hpp:316
void await_suspend(std::coroutine_handle<> handle)
Suspend coroutine, register for event notification.
Definition Awaiters.cpp:64
std::optional< Core::WindowEventType > m_filter
Definition Awaiters.hpp:317
Core::WindowEvent await_resume()
Resume with event data.
Definition Awaiters.cpp:71
Core::WindowEvent m_result
Definition Awaiters.hpp:318
bool await_ready()
Check if event already available.
Definition Awaiters.cpp:55
std::optional< Core::WindowEvent > pop_event(std::optional< Core::WindowEventType > filter)
void register_waiter(Kriya::EventAwaiter *awaiter)
void unregister_waiter(Kriya::EventAwaiter *awaiter)
@ FRAME_BASED
Frame-rate delay (Graphics domain)
@ SAMPLE_BASED
Sample-accurate delay (audio domain)
Event data for window and input events.
void await_suspend(std::coroutine_handle< Vruta::graphics_promise > h) noexcept
Definition Awaiters.cpp:22
void await_suspend(std::coroutine_handle< Vruta::complex_promise > h) noexcept
Definition Awaiters.cpp:38
void await_suspend(std::coroutine_handle< promise_handle > h) noexcept
Schedules the coroutine to resume after the delay.
Definition Awaiters.cpp:6