13#ifndef __GUI_BACKEND_EVENT_MANAGER_H__
14#define __GUI_BACKEND_EVENT_MANAGER_H__
16#include "common/utils/backtrace.h"
17#include "common/utils/mpmc_queue.h"
18#include "common/utils/object_pool.h"
19#include "gui/backend/backend/event.h"
27constexpr int EVENT_MANAGER_MAX_EVENTS = 4000;
80 void clean_duplicate_events_and_copy ();
85 bool soft_recalc_graph_when_paused ();
111 std::vector<ZEvent *> events_arr_;
114#define EVENT_MANAGER (gZrythm->event_manager_)
117#define EVENT_QUEUE (EVENT_MANAGER->mqueue_)
120#define EVENTS_PUSH(et, _arg)
121#define EVENTS_PUSH_NOW(et, _arg)
127# define EVENTS_PUSH(et, _arg) \
130 && (!PROJECT || !AUDIO_ENGINE || !AUDIO_ENGINE->exporting_) \
131 && EVENT_MANAGER->process_source_id_.connected ()) \
133 ZEvent * _ev = EVENT_MANAGER->obj_pool_.acquire (); \
134 _ev->file_ = __FILE__; \
135 _ev->func_ = __func__; \
136 _ev->lineno_ = __LINE__; \
138 _ev->arg_ = (void *) (_arg); \
140 zrythm_app->gtk_thread_id_ == current_thread_id.get ()
145 _ev->backtrace_ = Backtrace ().get_backtrace ("", 40, false); \
150 (et) != EventType::ET_PLAYHEAD_POS_CHANGED \
151 && zrythm_app->gtk_thread_id_ == current_thread_id.get ()) \
153 z_debug ("pushing UI event " #et " ({}:{})", __func__, __LINE__); \
155 EVENT_QUEUE.push_back (_ev); \
159# define EVENTS_PUSH_NOW(et, _arg) \
161 ZRYTHM_HAVE_UI && EVENT_MANAGER \
162 && zrythm_app->gtk_thread_id_ == current_thread_id.get () \
163 && (!PROJECT || !AUDIO_ENGINE || !AUDIO_ENGINE->exporting_) \
164 && EVENT_MANAGER->process_source_id_.connected ()) \
166 ZEvent * _ev = EVENT_MANAGER->obj_pool_.acquire (); \
167 _ev->file_ = __FILE__; \
168 _ev->func_ = __func__; \
169 _ev->lineno_ = __LINE__; \
171 _ev->arg_ = (void *) _arg; \
175 _ev->backtrace_ = Backtrace ().get_backtrace ("", 40, false); \
178 if (et != EventType::ET_PLAYHEAD_POS_CHANGED) \
181 "processing UI event now " #et " ({}:{})", __func__, __LINE__); \
183 EVENT_MANAGER->process_event (*_ev); \
184 EVENT_MANAGER->obj_pool_.release (_ev); \
ObjectPool< ZEvent > obj_pool_
Object pool of event structs to avoid real time allocation.
void stop_events()
Stops events from getting fired.
bool process_events()
Source function to process events.
void process_event(ZEvent &ev)
Processes the given event.
bool pending_soft_recalc_
A soft recalculation of the routing graph is pending.
void start_events()
Starts accepting events.
EventManager()
Creates the event queue and starts the event loop.
MPMCQueue< ZEvent * > mqueue_
Event queue, mainly for GUI events.
void process_now()
Processes the events now.
sigc::scoped_connection process_source_id_
ID of the event processing source func.
Multiple Producer Multiple Consumer lock-free queue.
Thread-safe, realtime-safe object pool.