MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BroadcastEvents.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Core {
7class Window;
8}
9
10namespace MayaFlux::Vruta {
11class Event;
12}
13
14namespace MayaFlux::Kriya {
15
16/**
17 * @brief Creates an Event coroutine that fires on every signal from a BroadcastSource.
18 *
19 * @param source Shared ownership of the BroadcastSource; lifetime is tied to the coroutine frame.
20 * @param callback Invoked with each delivered value.
21 * @return Event coroutine suitable for EventManager::add_event().
22 *
23 * @code
24 * auto src = make_persistent_shared<Vruta::BroadcastSource<float>>();
25 *
26 * get_event_manager()->add_event(std::make_shared<Vruta::Event>(
27 * Kriya::on_signal(src, [](const float& val) {
28 * // handle val
29 * })));
30 * @endcode
31 */
32template <typename T, typename Callback>
34 std::shared_ptr<Vruta::BroadcastSource<T>> source,
35 Callback callback);
36
37/**
38 * @brief Creates an Event coroutine that fires only when a predicate matches.
39 *
40 * @param source Shared ownership of the BroadcastSource.
41 * @param predicate Returns true for values that should trigger the callback.
42 * @param callback Invoked with each matching value.
43 * @return Event coroutine suitable for EventManager::add_event().
44 *
45 * @code
46 * get_event_manager()->add_event(std::make_shared<Vruta::Event>(
47 * Kriya::on_signal_matching(src,
48 * [](const float& v) { return v > 0.5f; },
49 * [](const float& v) { })));
50 * @endcode
51 */
52template <typename T, typename Predicate, typename Callback>
54 std::shared_ptr<Vruta::BroadcastSource<T>> source,
55 Predicate predicate,
56 Callback callback);
57
58/**
59 * @brief Create a BroadcastSource<bool> ticking once per audio output cycle.
60 *
61 * Registers an observer with AudioBackendService and returns the source.
62 * The returned observer id is stored inside the source's shared state via
63 * a custom deleter on the shared_ptr - unregistration is automatic when
64 * the last owner drops the source.
65 *
66 * @code
67 * auto src = Kriya::audio_output_tick();
68 * get_event_manager()->add_event(std::make_shared<Vruta::Event>(
69 * Kriya::on_signal(src, [ct](bool) {
70 * ct->process_default();
71 * })));
72 * @endcode
73 */
74[[nodiscard]] MAYAFLUX_API std::shared_ptr<Vruta::BroadcastSource<bool>> audio_output_tick();
75
77 std::shared_ptr<std::vector<uint8_t>> data;
78 uint32_t width {};
79 uint32_t height {};
80 uint32_t format {};
81};
82
83/**
84 * @brief Create a BroadcastSource<bool> ticking once per captured window frame.
85 *
86 * Registers a frame observer with DisplayService for the given window.
87 * The window must have capture enabled and the capture state must have been
88 * initialized (either via WindowAccessProcessor or set_capture_enabled before
89 * the first rendered frame).
90 *
91 * Returns nullptr if the DisplayService is unavailable, the window is null,
92 * or capture state is not yet active for the window.
93 *
94 * The observer callback is non-blocking. Signal delivery is safe across
95 * thread boundaries; the BroadcastSource handles the coroutine resume path.
96 *
97 * @code
98 * auto src = Kriya::window_frame_tick(window);
99 * get_event_manager()->add_event(std::make_shared<Vruta::Event>(
100 * Kriya::on_signal(src, [](const Kriya::WindowFrame& frame) {
101 * // frame.data, frame.width, frame.height, frame.format
102 * })));
103 * @endcode
104 */
105[[nodiscard]] MAYAFLUX_API std::shared_ptr<Vruta::BroadcastSource<WindowFrame>> window_frame_tick(
106 const std::shared_ptr<Core::Window>& window);
107
108} // namespace MayaFlux::Kriya
109
110#include "BroadcastEvents.inl"
Awaitable single-value broadcast channel for cross-thread signal delivery.
Coroutine type for event-driven suspension.
Definition Event.hpp:26
Vruta::Event on_signal_matching(std::shared_ptr< Vruta::BroadcastSource< T > > source, Predicate predicate, Callback callback)
Creates an Event coroutine that fires only when a predicate matches.
std::shared_ptr< Vruta::BroadcastSource< WindowFrame > > window_frame_tick(const std::shared_ptr< Core::Window > &window)
Create a BroadcastSource<bool> ticking once per captured window frame.
Vruta::Event on_signal(std::shared_ptr< Vruta::BroadcastSource< T > > source, Callback callback)
Creates an Event coroutine that fires on every signal from a BroadcastSource.
std::shared_ptr< Vruta::BroadcastSource< bool > > audio_output_tick()
Create a BroadcastSource<bool> ticking once per audio output cycle.
std::shared_ptr< std::vector< uint8_t > > data