Make setters return reference to self: AudioDevice

This commit is contained in:
Dmitry Marakasov 2015-01-19 00:58:22 +03:00
parent 713f42fe1d
commit e2c1333987
2 changed files with 22 additions and 9 deletions

View File

@ -1,6 +1,6 @@
/* /*
libSDL2pp - C++11 bindings/wrapper for SDL2 libSDL2pp - C++11 bindings/wrapper for SDL2
Copyright (C) 2014 Dmitry Marakasov <amdmi3@amdmi3.ru> Copyright (C) 2014-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
@ -88,19 +88,22 @@ SDL_AudioDeviceID AudioDevice::Get() const {
return device_id_; return device_id_;
} }
void AudioDevice::Pause(bool pause_on) { AudioDevice& AudioDevice::Pause(bool pause_on) {
SDL_PauseAudioDevice(device_id_, pause_on ? 1 : 0); SDL_PauseAudioDevice(device_id_, pause_on ? 1 : 0);
return *this;
} }
SDL_AudioStatus AudioDevice::GetStatus() const { SDL_AudioStatus AudioDevice::GetStatus() const {
return SDL_GetAudioDeviceStatus(device_id_); return SDL_GetAudioDeviceStatus(device_id_);
} }
void AudioDevice::ChangeCallback(AudioDevice::AudioCallback&& callback) { AudioDevice& AudioDevice::ChangeCallback(AudioDevice::AudioCallback&& callback) {
// make sure callback is not called while it's being replaced // make sure callback is not called while it's being replaced
LockHandle lock = Lock(); LockHandle lock = Lock();
callback_ = std::move(callback); callback_ = std::move(callback);
return *this;
} }
AudioDevice::LockHandle AudioDevice::Lock() { AudioDevice::LockHandle AudioDevice::Lock() {
@ -108,13 +111,15 @@ AudioDevice::LockHandle AudioDevice::Lock() {
} }
#ifdef SDL2PP_WITH_2_0_4 #ifdef SDL2PP_WITH_2_0_4
void AudioDevice::QueueAudio(const void* data, Uint32 len) { AudioDevice& AudioDevice::QueueAudio(const void* data, Uint32 len) {
if (SDL_QueueAudio(device_id_, data, len) == 0) if (SDL_QueueAudio(device_id_, data, len) == 0)
throw Exception("SDL_QueueAudio failed"); throw Exception("SDL_QueueAudio failed");
return *this;
} }
void AudioDevice::ClearQueuedAudio() { AudioDevice& AudioDevice::ClearQueuedAudio() {
SDL_ClearQueuedAudio(device_id_); SDL_ClearQueuedAudio(device_id_);
return *this;
} }
Uint32 GetQueuedAudioSize() const { Uint32 GetQueuedAudioSize() const {

View File

@ -263,10 +263,12 @@ public:
/// ///
/// \param[in] pause_on Whether audio should be paused /// \param[in] pause_on Whether audio should be paused
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_PauseAudioDevice /// \see http://wiki.libsdl.org/SDL_PauseAudioDevice
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Pause(bool pause_on); AudioDevice& Pause(bool pause_on);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get playback status /// \brief Get playback status
@ -283,8 +285,10 @@ public:
/// ///
/// \param[in] callback New audio callback /// \param[in] callback New audio callback
/// ///
/// \returns Reference to self
///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void ChangeCallback(AudioCallback&& callback); AudioDevice& ChangeCallback(AudioCallback&& callback);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Lock audio device to prevent it from calling audio callback /// \brief Lock audio device to prevent it from calling audio callback
@ -307,20 +311,24 @@ public:
/// \param[in] data Data to queue for later playback /// \param[in] data Data to queue for later playback
/// \param[in] len Data length in bytes (not samples!) /// \param[in] len Data length in bytes (not samples!)
/// ///
/// \returns Reference to self
///
/// \throws SDL2pp::Exception /// \throws SDL2pp::Exception
/// ///
/// \see http://wiki.libsdl.org/SDL_QueueAudio /// \see http://wiki.libsdl.org/SDL_QueueAudio
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void QueueAudio(const void* data, Uint32 len); AudioDevice& QueueAudio(const void* data, Uint32 len);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Drop queued audio /// \brief Drop queued audio
/// ///
/// \returns Reference to self
///
/// \see http://wiki.libsdl.org/SDL_ClearQueuedAudio /// \see http://wiki.libsdl.org/SDL_ClearQueuedAudio
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void ClearQueuedAudio(); AudioDevice& ClearQueuedAudio();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get number of bytes of still-queued audio /// \brief Get number of bytes of still-queued audio