VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Types | Signals | Public Member Functions | Properties | List of all members
SoundManager Class Reference

Controls the sound effects and background music (BGM) audio tracks needed to be played during the game. More...

Inheritance diagram for SoundManager:
QObject

Public Types

enum  BGMPriority { InvalidPriority = -1, MenuPriority, EnvironmentalPriority, MaxPriority }
 Ordered priority levels for background music tracks. More...
 

Signals

void bgmMutedChanged ()
 Emitted when bgmMuted changes. More...
 
void pausedChanged ()
 Emitted when paused changes. More...
 

Public Member Functions

 SoundManager (QObject *parent=nullptr)
 Constructs a SoundManager. More...
 
bool isBGMMuted () const
 Returns bgmMuted. More...
 
void setBGMMuted (bool value)
 Sets bgmMuted. More...
 
bool isPaused () const
 Returns paused. More...
 
void setPaused (bool value)
 Sets paused. More...
 
SoundEffectInstance getSoundEffect (const QString &path)
 Loads a sound effect with sample data obtained from file. More...
 
Q_INVOKABLE void playSoundEffect (const QString &path)
 Plays a one-shot sound effect. More...
 
Q_INVOKABLE void clearBGMTrack (BGMPriority priority)
 Clears the audio track of the specified background music priority level. More...
 
Q_INVOKABLE void setBGMTrack (BGMPriority priority, const QString &path)
 Sets the audio track of the specified background priority level. More...
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
virtual const QMetaObjectmetaObject () const
 
QString objectName () const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const
 
bool blockSignals (bool block)
 
QThreadthread () const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, QFlags< Qt::FindChildOption > options) const
 
QList< T > findChildren (const QString &name, QFlags< Qt::FindChildOption > options) const
 
QList< T > findChildren (const QRegExp &regExp, QFlags< Qt::FindChildOption > options) const
 
QList< T > findChildren (const QRegularExpression &re, QFlags< Qt::FindChildOption > options) const
 
const QObjectList & children () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const
 
bool disconnect (const QObject *receiver, const char *method) const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const
 
bool inherits (const char *className) const
 
void deleteLater ()
 

Properties

bool bgmMuted
 Whether or not the background music is currently muted. More...
 
bool paused
 Whether or not the SoundManager is currently paused (i.e. not playing audio). More...
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 

Detailed Description

Controls the sound effects and background music (BGM) audio tracks needed to be played during the game.

The SoundManager defines methods for:

Note
Currently, true gapless looping and track change fading are only implemented on Android.

Member Enumeration Documentation

Ordered priority levels for background music tracks.

Audio tracks of higher priority should automatically take precedence for playing.

Enumerator
InvalidPriority 

Represents an invalid priority level and serves as a lower bound on priority.

MenuPriority 

Represents a priority level for audio playing on menus.

EnvironmentalPriority 

Represents a priority level for audio playing in game Environments.

MaxPriority 

Represents the highest priority level an audio track can have.

Constructor & Destructor Documentation

SoundManager::SoundManager ( QObject parent = nullptr)
explicit

Constructs a SoundManager.

Note
It is expected that there will only ever exist one instance of SoundManager at a time.
Parameters
parentParent object

Member Function Documentation

void SoundManager::bgmMutedChanged ( )
signal

Emitted when bgmMuted changes.

Q_INVOKABLE void SoundManager::clearBGMTrack ( BGMPriority  priority)

Clears the audio track of the specified background music priority level.

If priority was currently the highest priority level with an audio track set, then the background music is transitioned to the next highest priority level for which an audio track is set, or faded out if none are available.

Parameters
priorityBackground music priority level to clear the audio track for
SoundEffectInstance SoundManager::getSoundEffect ( const QString path)

Loads a sound effect with sample data obtained from file.

Note
Actual file IO happens in the background.
This method caches sound effect data of file for reuse.
Only 44.1kHz wav files have been extensively tested. Other formats may encounter odd issues.
Parameters
pathSound file asset path to load for the sound effect
Returns
A SoundEffectInstance of the loaded sound effect
bool SoundManager::isBGMMuted ( ) const

Returns bgmMuted.

bool SoundManager::isPaused ( ) const
inline

Returns paused.

void SoundManager::pausedChanged ( )
signal

Emitted when paused changes.

Q_INVOKABLE void SoundManager::playSoundEffect ( const QString path)

Plays a one-shot sound effect.

Note
This method caches sound effect data of file for reuse.
Only 44.1kHz wav files have been extensively tested. Other formats may encounter odd issues.
Parameters
pathSound file asset path to play for the sound effect
void SoundManager::setBGMMuted ( bool  value)

Sets bgmMuted.

Parameters
valueBoolean to set bgmMuted to
Q_INVOKABLE void SoundManager::setBGMTrack ( BGMPriority  priority,
const QString path 
)

Sets the audio track of the specified background priority level.

Parameters
priorityBackground music priority level to set the audio track for
pathAudio track asset path to load for the sound effect
void SoundManager::setPaused ( bool  value)

Sets paused.

This method will either stop background music from playing or resume it.

Note
This method currently has no effect on SoundEffectInstances.
Parameters
valueBoolean to set paused to

Property Documentation

bool SoundManager::bgmMuted
readwrite

Whether or not the background music is currently muted.

bool SoundManager::paused
readwrite

Whether or not the SoundManager is currently paused (i.e. not playing audio).

Note
Currently, the paused state only affects background music and not SoundEffectInstances.