Stream music files from disk. More...
#include <Music.h>
Public Member Functions | |
Music () | |
Default constructor. More... | |
Music (const Music &)=delete | |
Copy constructor. More... | |
Music & | operator= (const Music &)=delete |
Copy assignment operator. More... | |
Music (Music &&) noexcept | |
Move constructor. More... | |
Music & | operator= (Music &&) noexcept |
Move assignment operator. More... | |
void | setSource (const std::string &source) override |
Set the music file to be played. More... | |
const std::string & | getSource () const override |
Get music source. More... | |
void | setVolume (float volume) override |
Set the volume of the music. More... | |
float | getVolume () const override |
Get the volume of the music. More... | |
void | setPitch (float pitch) override |
Set the pitch of the music. More... | |
float | getPitch () const override |
Get the pitch of the music. More... | |
void | setLoop (bool isLooped) override |
Set whether or not the music should loop after reaching the end. More... | |
bool | isLooped () const override |
Check if music is looped or not. More... | |
void | seek (Time position) override |
Change the current playing position of the music. More... | |
Time | getPlayingPosition () const override |
Get the current playing position of the music. More... | |
void | play () override |
Play music. More... | |
void | pause () override |
Pause music. More... | |
void | stop () override |
Stop playing the music. More... | |
Time | getDuration () const override |
Get the total duration of the music. More... | |
Status | getStatus () const override |
Get the current status of the music (stopped, paused, playing) More... | |
std::string | getType () override |
Get the type of the music. More... | |
~Music () override | |
Destructor. More... | |
void | adjustVolume (float offset) |
Turn the volume up/down by a given offset. More... | |
void | setMute (bool mute) |
Set whether or not the audio should be audible. More... | |
bool | isMuted () const |
Check if audio is muted or not. More... | |
void | restart () |
Reset the playing position to the beginning. More... | |
template<typename... Args> | |
void | emit (const std::string &event, Args...args) |
Fire an event. More... | |
template<typename... Args> | |
int | addEventListener (const std::string &event, Callback< Args... > callback) |
Add an event listener (callback) to an event. More... | |
template<typename... Args> | |
int | on (const std::string &event, Callback< Args... > callback) |
Add an event listener to an event. More... | |
template<typename ... Args> | |
int | addOnceEventListener (const std::string &event, Callback< Args... > callback) |
Add an event listener to an event. More... | |
bool | removeEventListener (const std::string &event, int id) |
Remove an event listener from an event. More... | |
bool | removeAllEventListeners (const std::string &event) |
Remove all event listeners of an event. More... | |
bool | hasEvent (const std::string &event) const |
Check if an event exists or not. More... | |
std::size_t | getEventListenerCount (const std::string &event) const |
Get the number of event listeners currently registered to an event. More... | |
std::size_t | getEventsCount () const |
Get the current number of created events. More... | |
bool | hasEventListener (const std::string &event, int id) const |
Check if an event has a certain event listener. More... | |
Protected Member Functions | |
template<typename... Args> | |
void | emit (const std::string &event, Args...args) |
Prevent external publishing of events. More... | |
Stream music files from disk.
This class is ideal for playing long and big audio file such as background music. The audio file is not loaded in memory but rather streamed from the disk. Therefore, The file must remain accessible on the disk for as long as its being used. You can use Audio::SoundEffect to play short sounds such as gun shots and explosions
ime::audio::Music::Music | ( | ) |
Default constructor.
|
delete |
Copy constructor.
|
noexcept |
Move constructor.
|
override |
Destructor.
|
inherited |
Add an event listener (callback) to an event.
event | Event to add event listener to |
callback | Function to execute when the event is fired |
Every event listener has a unique identification number. This number must be remembered in order to remove the event listener.
|
inherited |
Add an event listener to an event.
event | Event to add event listener to |
callback | Function to execute when the event is fired |
The event listener will be invoked once and subsequently removed from the event. This means that the callback will only execute when an event is fired for the first time. To execute a callback each time the an event is fired
|
inherited |
Turn the volume up/down by a given offset.
offset | Value to increase/decrease the volume by |
This function adds on to the current volume. A positive offset increases the volume while a negative offset decreases the volume. This function will unmmute the audio if its muted
|
protectedinherited |
Prevent external publishing of events.
Only the class knows the conditions under which an event may be fired. Therefore, events must not be raised externally as this may result in events being raised at the wong time, resulting in undesired and incorrect behavior
|
inherited |
Fire an event.
event | Name of the event to fire |
args | Arguments to be passed to event listeners |
|
overridevirtual |
Get the total duration of the music.
Implements ime::audio::Audio.
|
inherited |
Get the number of event listeners currently registered to an event.
event | Event to get number of event listeners for |
|
inherited |
Get the current number of created events.
|
overridevirtual |
|
overridevirtual |
Get the current playing position of the music.
Implements ime::audio::Audio.
|
overridevirtual |
|
overridevirtual |
Get the current status of the music (stopped, paused, playing)
Implements ime::audio::Audio.
|
overridevirtual |
|
overridevirtual |
Get the volume of the music.
Implements ime::audio::Audio.
|
inherited |
Check if an event exists or not.
event | Name of the event to check |
|
inherited |
Check if an event has a certain event listener.
event | Name of the event |
id | Identification number of the listener to be checked |
|
overridevirtual |
Check if music is looped or not.
Implements ime::audio::Audio.
|
inherited |
Check if audio is muted or not.
|
inherited |
Add an event listener to an event.
event | Event to add event listener to |
callback | Function to execute when the event is fired |
This function does the same thing as the addEventListener() function. It just provides a slightly more readable syntax:
|
overridevirtual |
Pause music.
This function pauses the stream if it was playing, otherwise (music already paused or stopped) it has no effect
Implements ime::audio::Audio.
|
overridevirtual |
Play music.
This function starts the music if it was stopped, resumes it if it was paused, and restarts it from the beginning if it was already playing. This function uses its own thread so that it doesn't block the rest of the program while the music is played
Implements ime::audio::Audio.
|
inherited |
Remove all event listeners of an event.
event | Event to remove all listeners from |
|
inherited |
Remove an event listener from an event.
event | Event to remove listener from |
id | Identification number of the event listener to be removed |
|
inherited |
Reset the playing position to the beginning.
This function will reset the playing position without stopping the audio (unlike stop function), which would require play to be called to get the audio to play again
|
overridevirtual |
Change the current playing position of the music.
position | New playing position of the music |
The playing position can be changed when the music is either paused or playing. Changing the playing position when the music is stopped has no effect, since playing the music would reset its position
Implements ime::audio::Audio.
|
overridevirtual |
Set whether or not the music should loop after reaching the end.
isLooped | True to play in loop, false to play once |
Implements ime::audio::Audio.
|
inherited |
Set whether or not the audio should be audible.
mute | True to make audio inaudible, or false to make audio audible |
When set to true the audio will not be audible but will continue to play if currently playing
|
overridevirtual |
Set the pitch of the music.
pitch | The new pitch of the music |
The pitch represents the perceived fundamental frequency of a sound; thus you can make a sound more acute or grave by changing its pitch. Changing the pitch also changes the playing speed of the music.
The default value for the pitch is 1
Implements ime::audio::Audio.
|
overridevirtual |
Set the music file to be played.
source | Filename of an audio file |
The source must refer to an actual music file on the disk. This music file is the one to be played, pitched and done all sorts of things. This function doesn't start the music, it sets the music that will be played when play() is called
Implements ime::audio::Audio.
|
overridevirtual |
Set the volume of the music.
volume | Volume to set |
The volume is a value between 0 (mute) and 100 (full volume).
The default value for the volume is 100
Implements ime::audio::Audio.
|
overridevirtual |
Stop playing the music.
This function stops the music if it was playing or paused, and does nothing if it was already stopped. It also resets the playing position
Implements ime::audio::Audio.