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

An instance of a sound effect. More...

Public Member Functions

 SoundEffectInstance ()
 Create a SoundEffectInstance referencing nothing. More...
 
 SoundEffectInstance (const QSharedPointer< QSoundEffect > &soundEffect)
 Create a SoundEffectInstance referencing a shared QSoundEffect. More...
 
 SoundEffectInstance (SoundEffectInstance &&other)
 Move-constructs a SoundEffectInstance instance, making it use the same shared QSoundEffect reference that other was using. More...
 
 SoundEffectInstance (const SoundEffectInstance &other)=delete
 Deleted copy constructor. More...
 
SoundEffectInstanceoperator= (SoundEffectInstance &&other)
 Move assigns other to this SoundEffectInstance instance. More...
 
SoundEffectInstanceoperator= (const SoundEffectInstance &other)=delete
 Deleted copy and assign. More...
 
void reset ()
 Releases the reference to the shared QSoundEffect, stopping it if necessary. More...
 
void reset (SoundEffectInstance &&other)
 Releases the current QSoundEffect reference, replacing it with another from other using a move operation. More...
 
void swap (SoundEffectInstance &other)
 Swaps QSoundEffect references and parameters with another SoundEffectInstance. More...
 
void setLooped (bool value)
 Sets property to play looped or as a one-shot sound effect. More...
 
void setVolume (float value)
 Sets play volume property. More...
 
bool isPlaying () const
 Returns whether or not this sample is currently playing. More...
 
void play ()
 Starts playing this instance of the sound effect. More...
 
void stop ()
 Stops the sample if it is currently playing. More...
 

Detailed Description

An instance of a sound effect.

Separate instances of a sound effect can have different properties (i.e. volume, looped, etc.) but share the same sample data (i.e. the same wave file, etc.). This class also automatically stops looped sound effects when destroyed.

Note
With the current implementation, multiple instances of the same sound effect cannot be played concurrently. That is, only once instance can be heard at a time. The last instance to play will override all other instances, silencing them. Instances referencing different sound effect sources can still be played simultaneously.

Constructor & Destructor Documentation

SoundEffectInstance::SoundEffectInstance ( )

Create a SoundEffectInstance referencing nothing.

Note
Playing this empty SoundEffectInstance has no effect.
SoundEffectInstance::SoundEffectInstance ( const QSharedPointer< QSoundEffect > &  soundEffect)
explicit

Create a SoundEffectInstance referencing a shared QSoundEffect.

When this SoundEffectInstance is destroyed, it stops soundEffect, if the sound is looped, and then releases its reference to soundEffect.

Parameters
soundEffectShared QSoundEffect to reference
SoundEffectInstance::SoundEffectInstance ( SoundEffectInstance &&  other)

Move-constructs a SoundEffectInstance instance, making it use the same shared QSoundEffect reference that other was using.

Parameters
otherSoundEffectInstance to move into this
SoundEffectInstance::SoundEffectInstance ( const SoundEffectInstance other)
delete

Deleted copy constructor.

Parameters
otherSoundEffectInstance to copy

Member Function Documentation

bool SoundEffectInstance::isPlaying ( ) const

Returns whether or not this sample is currently playing.

SoundEffectInstance& SoundEffectInstance::operator= ( SoundEffectInstance &&  other)

Move assigns other to this SoundEffectInstance instance.

Parameters
otherSoundEffectInstance to move into this
Returns
Reference to this
SoundEffectInstance& SoundEffectInstance::operator= ( const SoundEffectInstance other)
delete

Deleted copy and assign.

Parameters
otherSoundEffectInstance to copy and assign
Returns
Reference to this
void SoundEffectInstance::play ( )

Starts playing this instance of the sound effect.

If the sound effect is already playing, it will relaunch it at the start of the sample. One-shot sounds will play once, and looped samples will loop until this instance is destroyed, or stop() is called.

void SoundEffectInstance::reset ( )

Releases the reference to the shared QSoundEffect, stopping it if necessary.

void SoundEffectInstance::reset ( SoundEffectInstance &&  other)

Releases the current QSoundEffect reference, replacing it with another from other using a move operation.

Parameters
otherSoundEffectInstance whose shared QSoundEffect reference should be moved
void SoundEffectInstance::setLooped ( bool  value)

Sets property to play looped or as a one-shot sound effect.

Note
Sounds changing from looped to one-shot will be stopped if necessary.
Parameters
valuetrue if the SoundEffectInstance should play looped
void SoundEffectInstance::setVolume ( float  value)

Sets play volume property.

0.0f is silent, 1.0f is max volume, and values in between are linear gain factors.

Note
Currently only the volume of looped sounds can be changed while playing.
Parameters
valueVolume level [0.0f, 1.0f] to set for the sound effect
void SoundEffectInstance::stop ( )

Stops the sample if it is currently playing.

Note
For one-shot sounds, because the current implementation cannot tell whether this is the currently playing instance, this method has no effect. For looped sounds, this method assumes it is the currently playing instance and stops it.
void SoundEffectInstance::swap ( SoundEffectInstance other)

Swaps QSoundEffect references and parameters with another SoundEffectInstance.

Parameters
otherSoundEffectInstance to swap into this