Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
event_manager.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
13#ifndef __GUI_BACKEND_EVENT_MANAGER_H__
14#define __GUI_BACKEND_EVENT_MANAGER_H__
15
16#include "utils/backtrace.h"
17#include "utils/mpmc_queue.h"
18#include "utils/object_pool.h"
19
20#include <glib.h>
21
22class Zrythm;
23typedef struct ZEvent ZEvent;
24
66
67#define EVENT_MANAGER (gZrythm->event_manager)
68
70#define EVENT_QUEUE (EVENT_MANAGER->mqueue)
71
72#define EVENT_MANAGER_MAX_EVENTS 4000
73
74#define event_queue_push_back_event(q, x) mpmc_queue_push_back (q, (void *) x)
75
76#define event_queue_dequeue_event(q, x) mpmc_queue_dequeue (q, (void **) x)
77
81#define EVENTS_PUSH(et, _arg) \
82 if ( \
83 ZRYTHM_HAVE_UI && EVENT_MANAGER && EVENT_QUEUE \
84 && (!PROJECT || !AUDIO_ENGINE || !AUDIO_ENGINE->exporting) \
85 && EVENT_MANAGER->process_source_id) \
86 { \
87 ZEvent * _ev = (ZEvent *) object_pool_get (EVENT_MANAGER->obj_pool); \
88 _ev->file = __FILE__; \
89 _ev->func = __func__; \
90 _ev->lineno = __LINE__; \
91 _ev->type = (et); \
92 _ev->arg = (void *) (_arg); \
93 if ( \
94 zrythm_app->gtk_thread == g_thread_self () /* skip backtrace for now */ \
95 && false) \
96 { \
97 _ev->backtrace = backtrace_get ("", 40, false); \
98 } \
99 /* don't print events that are called \
100 * continuously */ \
101 if ( \
102 (et) != EventType::ET_PLAYHEAD_POS_CHANGED \
103 && g_thread_self () == zrythm_app->gtk_thread) \
104 { \
105 g_debug ("pushing UI event " #et " (%s:%d)", __func__, __LINE__); \
106 } \
107 event_queue_push_back_event (EVENT_QUEUE, _ev); \
108 }
109
110/* runs the event logic now */
111#define EVENTS_PUSH_NOW(et, _arg) \
112 if ( \
113 ZRYTHM_HAVE_UI && EVENT_MANAGER && EVENT_QUEUE \
114 && zrythm_app->gtk_thread == g_thread_self () \
115 && (!PROJECT || !AUDIO_ENGINE || !AUDIO_ENGINE->exporting) \
116 && EVENT_MANAGER->process_source_id) \
117 { \
118 ZEvent * _ev = (ZEvent *) object_pool_get (EVENT_MANAGER->obj_pool); \
119 _ev->file = __FILE__; \
120 _ev->func = __func__; \
121 _ev->lineno = __LINE__; \
122 _ev->type = et; \
123 _ev->arg = (void *) _arg; \
124 if (/* skip backtrace for now */ \
125 false) \
126 { \
127 _ev->backtrace = backtrace_get ("", 40, false); \
128 } \
129 /* don't print events that are called \
130 * continuously */ \
131 if (et != EventType::ET_PLAYHEAD_POS_CHANGED) \
132 { \
133 g_debug ( \
134 "processing UI event now " #et " (%s:%d)", __func__, __LINE__); \
135 } \
136 event_manager_process_event (EVENT_MANAGER, _ev); \
137 object_pool_return (EVENT_MANAGER->obj_pool, _ev); \
138 }
139
146event_manager_new (void);
147
151void
153
157void
159
166void
168
174void
176
181void
183
184void
185event_manager_free (EventManager * self);
186
191#endif
Backtrace utils.
To be used throughout the program.
Definition zrythm.h:216
void event_manager_process_event(EventManager *self, ZEvent *ev)
Processes the given event.
void event_manager_process_now(EventManager *self)
Processes the events now.
void event_manager_start_events(EventManager *self)
Starts accepting events.
EventManager * event_manager_new(void)
Creates the event queue and starts the event loop.
void event_manager_stop_events(EventManager *self)
Stops events from getting fired.
void event_manager_remove_events_for_obj(EventManager *self, void *obj)
Removes events where the arg matches the given object.
Multiple Producer Multiple Consumer lock-free queue.
Thread-safe object pool implementation.
Event manager for the UI.
guint process_source_id
ID of the event processing source func.
bool pending_soft_recalc
A soft recalculation of the routing graph is pending.
ObjectPool * obj_pool
Object pool of event structs to avoid real time allocation.
GPtrArray * events_arr
Events array to use during processing.
MPMCQueue * mqueue
Event queue, mainly for GUI events.
Multiple Producer Multiple Consumer lock-free queue.
Definition mpmc_queue.h:69
A Zrythm event.
Definition event.h:455