hydrogen 1.2.6
EventQueue Class Reference

Object handling the communication between the core of Hydrogen and its GUI. More...

#include <EventQueue.h>

Inheritance diagram for EventQueue:
Object< EventQueue > Base

Data Structures

struct  AddMidiNoteVector
 

Public Member Functions

 ~EventQueue ()
 
bool getSilent () const
 
Event pop_event ()
 Reads out the next event of the EventQueue.
 
void push_event (const EventType type, const int nValue)
 Queues the next event into the EventQueue.
 
void setSilent (bool bSilent)
 
- Public Member Functions inherited from Object< EventQueue >
 Object ()
 
 Object (const Object< EventQueue > &other)
 
- Public Member Functions inherited from Base
 Base ()
 
 Base (const Base &other)
 
virtual const char * class_name () const
 
void logBacktrace () const
 Print the current stack at point into the debug log.
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG.
 
virtual QString toQString (const QString &sPrefix="", bool bShort=true) const
 Formatted string version for debugging purposes.
 

Static Public Member Functions

static void create_instance ()
 If __instance equals 0, a new EventQueue singleton will be created and stored in it.
 
static EventQueueget_instance ()
 Returns a pointer to the current EventQueue singleton stored in __instance.
 
- Static Public Member Functions inherited from Base
static const char * _class_name ()
 return the class name
 
static QString base_clock (const QString &sMsg)
 Measures the current time and stores it in __last_clock.
 
static QString base_clock_in (const QString &sMsg)
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation !
 
static bool count_active ()
 
static int getAliveObjectCount ()
 
static object_map_t getObjectMap ()
 
static Loggerlogger ()
 return the logger instance
 
static int objects_count ()
 
static void printObjectMapDiff (object_map_t map)
 Creates the difference between a snapshot of the object map and its current state and prints it to std::cout.
 
static void set_count (bool flag)
 enable/disable class instances counting
 
static void write_objects_map_to (std::ostream &out, object_map_t *map=nullptr)
 output the full objects map to a given ostream
 
static void write_objects_map_to_cerr ()
 output objects map to stderr
 

Data Fields

std::vector< AddMidiNoteVectorm_addMidiNoteVector
 

Private Member Functions

 EventQueue ()
 Constructor of the EventQueue class.
 

Private Attributes

Event __events_buffer [MAX_EVENTS]
 Array of all events contained in the EventQueue.
 
volatile unsigned int __read_index
 Continuously growing number indexing the event, which has been read from the EventQueue most recently.
 
volatile unsigned int __write_index
 Continuously growing number indexing the event, which has been written to the EventQueue most recently.
 
bool m_bSilent
 Whether or not to push log messages.
 
std::mutex m_mutex
 Mutex to lock access to queue.
 

Static Private Attributes

static EventQueue__instance = nullptr
 Object holding the current EventQueue singleton.
 

Additional Inherited Members

- Static Public Attributes inherited from Base
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes.
 
- Protected Member Functions inherited from Object< EventQueue >
 ~Object ()
 
- Protected Member Functions inherited from Base
 ~Base ()
 
- Static Protected Member Functions inherited from Base
static void registerClass (const char *name, const atomic_obj_cpt_t *counters)
 
- Static Protected Attributes inherited from Base
static bool __count = false
 should we count class instances
 
static timeval __last_clock = { 0, 0 }
 
static Logger__logger = nullptr
 
static bool bLogColors = true
 

Detailed Description

Object handling the communication between the core of Hydrogen and its GUI.

Whenever a specific condition is met or occasion happens within the core part of Hydrogen (its engine), an Event will be added to the EventQueue singleton. The GUI checks the content of this queue on a regular basis using HydrogenApp::onEventQueueTimer(). The actual frequency is set in the constructor HydrogenApp::HydrogenApp() to 20 times per second. Now, whenever an Event of a certain EventType is encountered, the corresponding function in the EventListener will be invoked to respond to the condition of the engine. For details about the mapping of EventTypes to functions please see the documentation of HydrogenApp::onEventQueueTimer().

Definition at line 210 of file EventQueue.h.

Constructor & Destructor Documentation

◆ ~EventQueue()

~EventQueue ( )

Definition at line 52 of file EventQueue.cpp.

◆ EventQueue()

EventQueue ( )
private

Constructor of the EventQueue class.

It fills all MAX_EVENTS slots of the __events_buffer with H2Core::EVENT_NONE and assigns itself to __instance. Called by create_instance().

Definition at line 38 of file EventQueue.cpp.

Member Function Documentation

◆ create_instance()

void create_instance ( )
static

If __instance equals 0, a new EventQueue singleton will be created and stored in it.

It is called in Hydrogen::create_instance().

Definition at line 30 of file EventQueue.cpp.

◆ get_instance()

static EventQueue * get_instance ( )
inlinestatic

Returns a pointer to the current EventQueue singleton stored in __instance.

Definition at line 224 of file EventQueue.h.

◆ getSilent()

bool getSilent ( ) const
inline

Definition at line 326 of file EventQueue.h.

◆ pop_event()

Event pop_event ( )

Reads out the next event of the EventQueue.

Since the event read out most recently is indexed with __read_index, this variable is incremented once and its modulo with respect to MAX_EVENTS is calculated to determine the event returned from __events_buffer.

The modulo operation is necessary because __read_index will be only incremented and does not respect the actual length of __events_buffer itself.

Returns
Next event in line.

Definition at line 88 of file EventQueue.cpp.

◆ push_event()

void push_event ( const EventType type,
const int nValue )

Queues the next event into the EventQueue.

The event itself will be constructed inside the function and will be two properties: an EventType type and a value nValue. Since the event written to the queue most recently is indexed with __write_index, this variable is incremented once and its modulo with respect to MAX_EVENTS is calculated to determine the position of insertion into __events_buffer.

The modulo operation is necessary because __write_index will be only incremented and does not respect the actual length of __events_buffer itself.

Parameters
typeType of the event, which will be queued.
nValueValue specifying the content of the new event.

Definition at line 58 of file EventQueue.cpp.

◆ setSilent()

void setSilent ( bool bSilent)
inline

Definition at line 329 of file EventQueue.h.

Field Documentation

◆ __events_buffer

Event __events_buffer[MAX_EVENTS]
private

Array of all events contained in the EventQueue.

Its length is set to MAX_EVENTS and it gets initialized with H2Core::EVENT_NONE in EventQueue().

Definition at line 315 of file EventQueue.h.

◆ __instance

EventQueue * __instance = nullptr
staticprivate

Object holding the current EventQueue singleton.

It is initialized with nullptr, set in EventQueue(), and accessed via get_instance().

Definition at line 293 of file EventQueue.h.

◆ __read_index

volatile unsigned int __read_index
private

Continuously growing number indexing the event, which has been read from the EventQueue most recently.

It is incremented with each call to pop_event().

Definition at line 301 of file EventQueue.h.

◆ __write_index

volatile unsigned int __write_index
private

Continuously growing number indexing the event, which has been written to the EventQueue most recently.

It is incremented with each call to push_event().

Definition at line 308 of file EventQueue.h.

◆ m_addMidiNoteVector

std::vector<AddMidiNoteVector> m_addMidiNoteVector

Definition at line 274 of file EventQueue.h.

◆ m_bSilent

bool m_bSilent
private

Whether or not to push log messages.

Definition at line 323 of file EventQueue.h.

◆ m_mutex

std::mutex m_mutex
private

Mutex to lock access to queue.

Definition at line 320 of file EventQueue.h.