Mana
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Sound Class Reference

Sound engine. More...

#include <sound.h>

Public Types

enum  Channel { CHANNEL_NOTIFICATIONS = 0 , CHANNEL_RESERVED_COUNT , CHANNEL_COUNT = 16 }
 

Public Member Functions

 Sound ()
 
 ~Sound ()
 
void init ()
 Installs the sound engine.
 
void close ()
 Removes all sound functionalities.
 
void playMusic (const std::string &fileName)
 Starts background music.
 
void stopMusic ()
 Stops currently running background music track.
 
void fadeInMusic (const std::string &fileName, int ms=1000)
 Fades in background music.
 
void fadeOutMusic (int ms=1000)
 Fades out currently running background music track.
 
void fadeOutAndPlayMusic (const std::string &fileName, int ms=1000)
 Fades out a background music and play a new one.
 
int getMaxVolume () const
 
void setMusicVolume (int volume)
 
void setSfxVolume (int volume)
 
void setNotificationsVolume (int volume)
 
void playSfx (const std::string &path, int x=0, int y=0)
 Plays a sound at the specified location.
 
void playNotification (const std::string &path)
 Plays a sound on the notification channel.
 
void logic ()
 The sound logic.
 

Private Member Functions

void info ()
 Logs various info about sound device.
 
void haltMusic ()
 Halts and frees currently playing music.
 

Private Attributes

std::string mNextMusicFile
 When calling fadeOutAndPlayMusic(), the music file below will then be played.
 
bool mInstalled = false
 
int mSfxVolume = 100
 
int mNotificationsVolume = 100
 
int mMusicVolume = 60
 
std::string mCurrentMusicFile
 
ResourceRef< MusicmMusic
 
ResourceRef< SoundEffectmSounds [CHANNEL_COUNT]
 

Detailed Description

Sound engine.

Definition at line 37 of file sound.h.

Member Enumeration Documentation

◆ Channel

Enumerator
CHANNEL_NOTIFICATIONS 
CHANNEL_RESERVED_COUNT 
CHANNEL_COUNT 

Definition at line 119 of file sound.h.

Constructor & Destructor Documentation

◆ Sound()

Sound::Sound ( )

Definition at line 49 of file sound.cpp.

◆ ~Sound()

Sound::~Sound ( )

Definition at line 55 of file sound.cpp.

Member Function Documentation

◆ close()

void Sound::close ( )

Removes all sound functionalities.

Definition at line 296 of file sound.cpp.

◆ fadeInMusic()

void Sound::fadeInMusic ( const std::string &  fileName,
int  ms = 1000 
)

Fades in background music.

Parameters
fileNameThe name of the music file.
msDuration of fade-in effect (ms)

Definition at line 181 of file sound.cpp.

◆ fadeOutAndPlayMusic()

void Sound::fadeOutAndPlayMusic ( const std::string &  fileName,
int  ms = 1000 
)

Fades out a background music and play a new one.

Parameters
fileNameThe name of the music file.
msDuration of fade-out effect (ms)

Definition at line 218 of file sound.cpp.

◆ fadeOutMusic()

void Sound::fadeOutMusic ( int  ms = 1000)

Fades out currently running background music track.

Parameters
msDuration of fade-out effect (ms)

Definition at line 197 of file sound.cpp.

◆ getMaxVolume()

int Sound::getMaxVolume ( ) const
inline

Definition at line 88 of file sound.h.

◆ haltMusic()

void Sound::haltMusic ( )
private

Halts and frees currently playing music.

Definition at line 308 of file sound.cpp.

◆ info()

void Sound::info ( )
private

Logs various info about sound device.

Definition at line 100 of file sound.cpp.

◆ init()

void Sound::init ( )

Installs the sound engine.

Definition at line 61 of file sound.cpp.

◆ logic()

void Sound::logic ( )

The sound logic.

Checks whether the music and sound effects can be freed after they finished playing, and whether new music has to be played.

Definition at line 224 of file sound.cpp.

◆ playMusic()

void Sound::playMusic ( const std::string &  fileName)

Starts background music.

Parameters
fileNameThe name of the music file.

Definition at line 166 of file sound.cpp.

◆ playNotification()

void Sound::playNotification ( const std::string &  path)

Plays a sound on the notification channel.

Parameters
pathThe resource path to the sound file.

Definition at line 283 of file sound.cpp.

◆ playSfx()

void Sound::playSfx ( const std::string &  path,
int  x = 0,
int  y = 0 
)

Plays a sound at the specified location.

Parameters
pathThe resource path to the sound file.
xThe vertical distance of the sound in pixels.
yThe horizontal distance of the sound in pixels.

Definition at line 248 of file sound.cpp.

◆ setMusicVolume()

void Sound::setMusicVolume ( int  volume)

Definition at line 139 of file sound.cpp.

◆ setNotificationsVolume()

void Sound::setNotificationsVolume ( int  volume)

Definition at line 158 of file sound.cpp.

◆ setSfxVolume()

void Sound::setSfxVolume ( int  volume)

Definition at line 147 of file sound.cpp.

◆ stopMusic()

void Sound::stopMusic ( )

Stops currently running background music track.

Definition at line 171 of file sound.cpp.

Member Data Documentation

◆ mCurrentMusicFile

std::string Sound::mCurrentMusicFile
private

Definition at line 145 of file sound.h.

◆ mInstalled

bool Sound::mInstalled = false
private

Definition at line 139 of file sound.h.

◆ mMusic

ResourceRef<Music> Sound::mMusic
private

Definition at line 146 of file sound.h.

◆ mMusicVolume

int Sound::mMusicVolume = 60
private

Definition at line 143 of file sound.h.

◆ mNextMusicFile

std::string Sound::mNextMusicFile
private

When calling fadeOutAndPlayMusic(), the music file below will then be played.

Definition at line 137 of file sound.h.

◆ mNotificationsVolume

int Sound::mNotificationsVolume = 100
private

Definition at line 142 of file sound.h.

◆ mSfxVolume

int Sound::mSfxVolume = 100
private

Definition at line 141 of file sound.h.

◆ mSounds

ResourceRef<SoundEffect> Sound::mSounds[CHANNEL_COUNT]
private

Definition at line 147 of file sound.h.


The documentation for this class was generated from the following files: