3 #include "ge211_forward.h" 4 #include "ge211_time.h" 5 #include "ge211_util.h" 55 operator bool()
const;
62 static std::shared_ptr<Mix_Music> load_(
const std::string& filename);
64 std::shared_ptr<Mix_Music> ptr_;
95 operator bool()
const;
102 static std::shared_ptr<Mix_Chunk> load_(
const std::string& filename);
104 std::shared_ptr<Mix_Chunk> ptr_;
206 return current_music_;
259 play_effect(Sound_effect effect,
double volume = 1.0);
273 Mixer(
const Mixer&) =
delete;
275 Mixer(
const Mixer&&) =
delete;
279 Mixer&
operator=(
const Mixer&&) =
delete;
288 static std::unique_ptr<Mixer> open_mixer();
293 friend Abstract_game;
296 void poll_channels_();
297 friend detail::Engine;
300 int find_empty_channel_()
const;
304 register_effect_(
int channel, Sound_effect effect);
307 void unregister_effect_(
int channel);
308 friend Sound_effect_handle;
311 Music_track current_music_;
313 Pausable_timer music_position_{
true};
315 std::vector<Sound_effect_handle> channels_;
316 int available_effect_channels_;
322 class Sound_effect_handle
338 operator bool()
const;
393 Impl_(Mixer& m, Sound_effect e,
int c)
395 , effect(
std::move(e))
397 , state(Mixer::State::playing)
408 std::shared_ptr<Impl_> ptr_;
void rewind_music()
Rewinds the music to the beginning.
void resume_all_effects()
Unpauses all currently-paused effects.
Mixer::State get_state() const
Gets the state of this effect.
void pause_all_effects()
Pauses all currently-playing effects.
In the process of fading out from playing to paused (for music) or to halted and detached (for sound ...
Sound_effect_handle play_effect(Sound_effect effect, double volume=1.0)
Plays the given effect track on this mixer, at the specified volume.
void set_volume(double unit_value)
Sets the playing sound effect's volume as a number from 0.0 to 1.0.
The game engine namespace.
double get_music_volume() const
Returns the music volume as a number from 0.0 to 1.0.
bool empty() const
Recognizes the empty sound effect track.
State get_music_state() const
Returns the current state of the attached music, if any.
double get_volume() const
Returns the playing sound effect's volume as a number from 0.0 to 1.0.
A music track, which can be attached to the Mixer and played.
A sound effect track, which can be attached to a Mixer channel and played.
Sound_effect_handle()
Default-constructs the empty sound effect handle.
void pause_music(Duration fade_out=Duration(0))
Pauses the currently attached music, fading out if requested.
void resume_music(Duration fade_in=Duration(0))
Plays the currently attached music from the current saved position, fading in if requested.
int available_effect_channels() const
How many effect channels are currently unused? If this is positive, then we can play an additional so...
void play_music(Music_track)
Attaches the given music track to this mixer and starts it playing.
The entity that coordinates playing all audio tracks.
Mixer & operator=(const Mixer &)=delete
The mixer cannot be copied.
void set_music_volume(double unit_value)
Sets the music volume, on a scale from 0.0 to 1.0.
bool empty() const
Recognizes the empty music track.
Attached but not playing.
const Sound_effect & get_effect() const
Gets the Sound_effect being played by this handle.
const Music_track & get_music() const
Gets the Music_track currently attached to this Mixer, if any.
~Mixer()
Destructor, to clean up the mixer's resources.
State
The state of an audio channel.
bool empty() const
Recognizes the empty sound effect handle.
void stop()
Stops the effect from playing and detaches it.
No track is attached to the channel, or no channel is attached to the handle.
Music_track()
Default-constructs the empty music track.
Sound_effect()
Default-constructs the empty sound effect track.
void resume()
Unpauses the effect.
void pause()
Pauses the effect.
void attach_music(Music_track)
Attaches the given music track to this mixer.