VAEvent.h 8.27 KB
Newer Older
1 2 3 4 5 6
/*
 *  --------------------------------------------------------------------------------------------
 *
 *    VVV        VVV A           Virtual Acoustics (VA) | http://www.virtualacoustics.org
 *     VVV      VVV AAA          Licensed under the Apache License, Version 2.0
 *      VVV    VVV   AAA
7
 *       VVV  VVV     AAA        Copyright 2015-2018
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *        VVVVVV       AAA       Institute of Technical Acoustics (ITA)
 *         VVVV         AAA      RWTH Aachen University
 *
 *  --------------------------------------------------------------------------------------------
 */

#ifndef IW_VABASE_EVENT
#define IW_VABASE_EVENT

#include <VABaseDefinitions.h>
#include <VABase.h>

#include <string>
#include <vector>

// Forwards
class IVAInterface;

// Helper macro for 64-bit bitmasks
#define VA_BIT64( i ) ( ( ( const uint64_t ) 1 ) << i )

//! Data class encapsulating events of a VA
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
30 31 32 33 34 35 36 37 38 39 40 41
/**
  * Events are emitted by the core and propagated to all atached event handlers.
  * It is up to the event handlers to filter the corresponding types and react upon
  * the data provided by the event. Therefore, the event data is not fixed but is
  * related to the event type. Many of the provided slots are unused for simple
  * events (like a gain change of the core).
  *
  * Use this events to synchronize your application if you are not controlling the
  * core and can not intercept method calls. This way, you still receive information
  * on updates e.g. from real world sound receiver head rotation and so on.
  *
  */
42 43 44 45
class VABASE_API CVAEvent
{
public:

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
	static const uint64_t NOTHING = 0;

	static const uint64_t INITIALIZED = VA_BIT64( 1 );
	static const uint64_t FINALIZED = VA_BIT64( 2 );
	static const uint64_t PROGRESS_UPDATE = VA_BIT64( 3 );

	static const uint64_t DIRECTIVITY_LOADED = VA_BIT64( 4 );
	static const uint64_t DIRECTIVITY_DELETED = VA_BIT64( 5 );

	static const uint64_t SIGNALSOURCE_CREATED = VA_BIT64( 6 );
	static const uint64_t SIGNALSOURCE_DELETED = VA_BIT64( 7 );
	static const uint64_t SIGNALSOURCE_REGISTERED = VA_BIT64( 8 );
	static const uint64_t SIGNALSOURCE_UNREGISTERED = VA_BIT64( 9 );
	static const uint64_t SIGNALSOURCE_STATE_CHANGED = VA_BIT64( 10 );


	static const uint64_t SAMPLE_LOADED = VA_BIT64( 11 );
	static const uint64_t SAMPLE_FREED = VA_BIT64( 12 );

	static const uint64_t SOUND_SOURCE_CREATED = VA_BIT64( 13 );
	static const uint64_t SOUND_SOURCE_DELETED = VA_BIT64( 14 );
	static const uint64_t SOUND_SOURCE_CHANGED_NAME = VA_BIT64( 15 );
	static const uint64_t SOUND_SOURCE_CHANGED_SIGNALSOURCE = VA_BIT64( 16 );
	static const uint64_t SOUND_SOURCE_CHANGED_AURALIZATIONMODE = VA_BIT64( 17 );
	static const uint64_t SOUND_SOURCE_CHANGED_SOUND_POWER = VA_BIT64( 18 );
	static const uint64_t SOUND_SOURCE_CHANGED_MUTING = VA_BIT64( 19 );
	static const uint64_t SOUND_SOURCE_CHANGED_POSE = VA_BIT64( 20 );

	static const uint64_t SOUND_RECEIVER_CREATED = VA_BIT64( 21 );
	static const uint64_t SOUND_RECEIVER_DELETED = VA_BIT64( 22 );
	static const uint64_t SOUND_RECEIVER_CHANGED_NAME = VA_BIT64( 23 );
	static const uint64_t SOUND_RECEIVER_CHANGED_AURALIZATIONMODE = VA_BIT64( 24 );
	static const uint64_t SOUND_RECEIVER_CHANGED_POSE = VA_BIT64( 25 );

	static const uint64_t SOUND_PORTAL_CHANGED_NAME = VA_BIT64( 26 );
	static const uint64_t SOUND_PORTAL_CHANGED_POSE = VA_BIT64( 27 );
	static const uint64_t SOUND_PORTAL_CHANGED_PARAMETER = VA_BIT64( 41 );

	static const uint64_t ACTIVE_SOUND_RECEIVER_CHANGED = VA_BIT64( 28 );
	static const uint64_t INPUT_GAIN_CHANGED = VA_BIT64( 29 );
	static const uint64_t INPUT_MUTING_CHANGED = VA_BIT64( 30 );
	static const uint64_t OUTPUT_GAIN_CHANGED = VA_BIT64( 31 );
	static const uint64_t OUTPUT_MUTING_CHANGED = VA_BIT64( 32 );
	static const uint64_t GLOBAL_AURALIZATION_MODE_CHANGED = VA_BIT64( 33 );

	static const uint64_t UNSPECIFIED_34 = VA_BIT64( 34 );
	static const uint64_t UNSPECIFIED_35 = VA_BIT64( 35 );
	static const uint64_t SOUND_RECEIVER_CHANGED_DIRECTIVITY = VA_BIT64( 36 );
	static const uint64_t MEASURES_UPDATE = VA_BIT64( 37 );
	static const uint64_t RESET = VA_BIT64( 38 );
	static const uint64_t SOUND_SOURCE_CHANGED_DIRECTIVITY = VA_BIT64( 39 );

	static const uint64_t DESTROY = VA_BIT64( 40 );
99

100 101 102 103
	static const uint64_t SOUND_SOURCE_REAL_WORLD_POSE_CHANGED = VA_BIT64( 41 );
	static const uint64_t SOUND_RECEIVER_REAL_WORLD_POSE_CHANGED = VA_BIT64( 42 );

	// Next free slot: 43
104

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
105
	//!< Selector mask for signal source related events
106 107 108 109 110 111
	static const uint64_t SIGNALSOURCE_EVENT = SIGNALSOURCE_CREATED |
		SIGNALSOURCE_DELETED |
		SIGNALSOURCE_REGISTERED |
		SIGNALSOURCE_UNREGISTERED |
		SIGNALSOURCE_STATE_CHANGED |
		SOUND_SOURCE_CHANGED_SIGNALSOURCE;
112

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
113
	//!< Selector mask for sound source related events
114 115 116 117 118 119 120 121 122
	static const uint64_t SOUNDSOURCE_EVENT = SOUND_SOURCE_CREATED |
		SOUND_SOURCE_DELETED |
		SOUND_SOURCE_CHANGED_NAME |
		SOUND_SOURCE_CHANGED_SIGNALSOURCE |
		SOUND_SOURCE_CHANGED_AURALIZATIONMODE |
		SOUND_SOURCE_CHANGED_SOUND_POWER |
		SOUND_SOURCE_CHANGED_MUTING |
		SOUND_SOURCE_CHANGED_POSE |
		SOUND_SOURCE_CHANGED_DIRECTIVITY;
123

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
124
	//!< Selector mask for sound receiver related events
125 126 127 128 129 130
	static const uint64_t SOUND_RECEIVER_EVENT = SOUND_RECEIVER_CREATED |
		SOUND_RECEIVER_DELETED |
		SOUND_RECEIVER_CHANGED_NAME |
		SOUND_RECEIVER_CHANGED_AURALIZATIONMODE |
		SOUND_RECEIVER_CHANGED_DIRECTIVITY |
		SOUND_RECEIVER_CHANGED_POSE;
131

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
132
	//!< Selector mask for portal related events
133 134
	static const uint64_t PORTAL_EVENT = SOUND_PORTAL_CHANGED_NAME |
		SOUND_PORTAL_CHANGED_PARAMETER;
135 136


Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
137
	//!< Selector mask for sound source modification event
138 139 140 141 142 143 144
	static const uint64_t SOUNDSOURCE_MODIFICATION = SOUND_SOURCE_CHANGED_NAME |
		SOUND_SOURCE_CHANGED_SIGNALSOURCE |
		SOUND_SOURCE_CHANGED_AURALIZATIONMODE |
		SOUND_SOURCE_CHANGED_SOUND_POWER |
		SOUND_SOURCE_CHANGED_MUTING |
		SOUND_SOURCE_CHANGED_POSE |
		SOUND_SOURCE_CHANGED_DIRECTIVITY;
145

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
146
	//!< Selector mask for sound receiver modification event
147 148 149 150
	static const uint64_t SOUND_RECEIVER_MODIFICATION = SOUND_RECEIVER_CHANGED_NAME |
		SOUND_RECEIVER_CHANGED_AURALIZATIONMODE |
		SOUND_RECEIVER_CHANGED_DIRECTIVITY |
		SOUND_RECEIVER_CHANGED_POSE;
151 152


Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
	IVAInterface* pSender;			//!< Sender interface
	int iEventID; //!< Event identifier
	uint64_t iEventType; //!< Event type (bit vector)
	int iObjectID;			//!< Integer-ID (Standard)
	std::string sObjectID;	//!< String-ID (z.B. für Signalquellen)
	int iParamID; //!< Parameter identifier
	std::string sParam; //!< Parameter string
	int iIndex; //!< Index value
	int iAuralizationMode; //!< Auralization mode
	double dVolume; //!< Volume, gain, sound power
	double dState; //!< Floating point state
	bool bMuted; //!< Mute flag
	std::string sName; //!< Name
	std::string sFilenPath; //!< File path
	VAVec3 vPos; //!< Position vector
	VAVec3 vView; //!< View vector
	VAVec3 vUp; //!< Up vector
	VAQuat qHATO; //!< Head-above-torso quaternion orientation
	VAQuat oOrientation; //!< Quaternion orientation
	std::vector< float > vfInputPeaks;	//!< Peak values of the input channels [factor]
	std::vector< float > vfInputRMSs;	//!< RMS values of the input channels [factor]
	std::vector< float > vfOutputPeaks;	//!< Peak values of the output channels [factor]
	std::vector< float > vfOutputRMSs;	//!< RMS values of the output channels [factor]
	float fSysLoad, fDSPLoad;			//!< System and DSP load [percent]
	double dCoreClock;					//!< Current value of the core clock [s]

	//!< Progress data
180 181
	CVAProgress oProgress;

182 183
	CVAStruct oPrototypeParams;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
184
	//! Create empty event
185 186 187 188 189 190 191 192 193 194 195 196 197
	inline CVAEvent()
		: pSender( NULL )
		, iEventID( 0 )
		, iEventType( 0 )
		, iObjectID( -1 )
		, iParamID( -1 )
		, iIndex( -1 )
		, iAuralizationMode( 0 )
		, dVolume( 0 )
		, dState( 0 )
		, bMuted( false )
	{};

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
198
	//! Destroy event
199 200
	inline virtual ~CVAEvent() {};

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
201 202 203 204
	//! Convert to string
	/**
	  * @return String formatted event (for debugging output)
	  */
205 206 207
	virtual std::string ToString() const;
};

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
208 209

//! Event handler interface class
210
/**
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
211 212 213 214
 * This purely abstract class defines an interface to receive
 * core events, e.g. for a graphical user intface. Derive your
 * class and implement the handler. Attach your instance to the VA
 * class (also works with network connections, event will be transmitted).
215 216 217 218
 */
class VABASE_API IVAEventHandler
{
public:
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
219
	//! Destructor
220 221
	inline virtual ~IVAEventHandler() {};

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
222 223 224 225
	//! Event handler hook
	/**
	  * @param[in] pEvent Event pointer
	  */
226 227 228 229
	virtual void HandleVAEvent( const CVAEvent* pEvent ) = 0;
};

#endif // IW_VABASE_EVENT