hydrogen 1.1.1
EventQueue Class Reference

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

#include <EventQueue.h>

Inheritance diagram for EventQueue:
Object

Data Structures

struct  AddMidiNoteVector
 

Public Member Functions

 ~EventQueue ()
 
void push_event (const EventType type, const int nValue)
 Queues the next event into the EventQueue. More...
 
Event pop_event ()
 Reads out the next event of the EventQueue. More...
 
- Public Member Functions inherited from Object
 ~Object ()
 destructor More...
 
 Object (const Object &obj)
 copy constructor More...
 
 Object (const char *class_name)
 constructor More...
 
const char * class_name () const
 return the class name More...
 
virtual QString toQString (const QString &sPrefix, bool bShort=true) const
 Formatted string version for debugging purposes. More...
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG. More...
 

Static Public Member Functions

static void create_instance ()
 If __instance equals 0, a new EventQueue singleton will be created and stored in it. More...
 
static EventQueueget_instance ()
 Returns a pointer to the current EventQueue singleton stored in __instance. More...
 
- Static Public Member Functions inherited from Object
static void set_count (bool flag)
 enable/disable class instances counting More...
 
static bool count_active ()
 return true if class instances counting is enabled More...
 
static unsigned objects_count ()
 return the number of objects More...
 
static void write_objects_map_to (std::ostream &out)
 output the full objects map to a given ostream More...
 
static void write_objects_map_to_cerr ()
 output objects map to stderr More...
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation ! More...
 
static Loggerlogger ()
 return the logger instance More...
 

Data Fields

std::vector< AddMidiNoteVectorm_addMidiNoteVector
 

Private Member Functions

 EventQueue ()
 Constructor of the EventQueue class. More...
 

Private Attributes

unsigned int __read_index
 Continuously growing number indexing the event, which has been read from the EventQueue most recently. More...
 
unsigned int __write_index
 Continuously growing number indexing the event, which has been written to the EventQueue most recently. More...
 
Event __events_buffer [MAX_EVENTS]
 Array of all events contained in the EventQueue. More...
 

Static Private Attributes

static EventQueue__instance = nullptr
 Object holding the current EventQueue singleton. More...
 

Additional Inherited Members

- Static Public Attributes inherited from Object
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes. More...
 
- Static Protected Attributes inherited from Object
static Logger__logger = nullptr
 logger instance pointer More...
 

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().

Constructor & Destructor Documentation

◆ ~EventQueue()

~EventQueue ( )

◆ 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().

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().

◆ get_instance()

static EventQueue * get_instance ( )
inlinestatic

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

◆ 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.

◆ 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.

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().

◆ __instance

EventQueue * __instance = nullptr
staticprivate

Object holding the current EventQueue singleton.

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

◆ __read_index

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().

◆ __write_index

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().

◆ m_addMidiNoteVector

std::vector<AddMidiNoteVector> m_addMidiNoteVector