Browse Source

Audio: use std::reference_wrapper instead of pointers.

I'm still learning.
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
8b209a24ba
  1. 53
      src/Magnum/Audio/Source.cpp
  2. 105
      src/Magnum/Audio/Source.h

53
src/Magnum/Audio/Source.cpp

@ -40,15 +40,21 @@ Source& Source::setBuffer(Buffer* buffer) {
namespace {
Containers::Array<ALuint> sourceIds(const std::initializer_list<Source*>& sources) {
Containers::Array<ALuint> sourceIds(const std::initializer_list<std::reference_wrapper<Source>>& sources) {
Containers::Array<ALuint> ids(sources.size());
for(auto it = sources.begin(); it != sources.end(); ++it) {
CORRADE_INTERNAL_ASSERT(*it);
ids[it-sources.begin()] = (*it)->id();
}
for(auto it = sources.begin(); it != sources.end(); ++it)
ids[it-sources.begin()] = it->get().id();
return ids;
}
Containers::Array<ALuint> sourceIds(const std::vector<std::reference_wrapper<Source>>& sources) {
Containers::Array<ALuint> ids(sources.size());
for(auto it = sources.begin(); it != sources.end(); ++it)
ids[it-sources.begin()] = it->get().id();
return ids;
}
#ifdef MAGNUM_BUILD_DEPRECATED
Containers::Array<ALuint> sourceIds(const std::vector<Source*>& sources) {
Containers::Array<ALuint> ids(sources.size());
for(auto it = sources.begin(); it != sources.end(); ++it) {
@ -57,48 +63,77 @@ Containers::Array<ALuint> sourceIds(const std::vector<Source*>& sources) {
}
return ids;
}
#endif
}
void Source::play(std::initializer_list<std::reference_wrapper<Source>> sources) {
const auto ids = sourceIds(sources);
alSourcePlayv(ids.size(), ids);
}
void Source::play(std::initializer_list<Source*> sources) {
void Source::play(const std::vector<std::reference_wrapper<Source>>& sources) {
const auto ids = sourceIds(sources);
alSourcePlayv(ids.size(), ids);
}
#ifdef MAGNUM_BUILD_DEPRECATED
void Source::play(const std::vector<Source*>& sources) {
const auto ids = sourceIds(sources);
alSourcePlayv(ids.size(), ids);
}
#endif
void Source::pause(std::initializer_list<Source*> sources) {
void Source::pause(std::initializer_list<std::reference_wrapper<Source>> sources) {
const auto ids = sourceIds(sources);
alSourcePausev(ids.size(), ids);
}
void Source::pause(const std::vector<std::reference_wrapper<Source>>& sources) {
const auto ids = sourceIds(sources);
alSourcePausev(ids.size(), ids);
}
#ifdef MAGNUM_BUILD_DEPRECATED
void Source::pause(const std::vector<Source*>& sources) {
const auto ids = sourceIds(sources);
alSourcePausev(ids.size(), ids);
}
#endif
void Source::stop(std::initializer_list<std::reference_wrapper<Source>> sources) {
const auto ids = sourceIds(sources);
alSourceStopv(ids.size(), ids);
}
void Source::stop(std::initializer_list<Source*> sources) {
void Source::stop(const std::vector<std::reference_wrapper<Source>>& sources) {
const auto ids = sourceIds(sources);
alSourceStopv(ids.size(), ids);
}
#ifdef MAGNUM_BUILD_DEPRECATED
void Source::stop(const std::vector<Source*>& sources) {
const auto ids = sourceIds(sources);
alSourceStopv(ids.size(), ids);
}
#endif
void Source::rewind(std::initializer_list<std::reference_wrapper<Source>> sources) {
const auto ids = sourceIds(sources);
alSourceRewindv(ids.size(), ids);
}
void Source::rewind(std::initializer_list<Source*> sources) {
void Source::rewind(const std::vector<std::reference_wrapper<Source>>& sources) {
const auto ids = sourceIds(sources);
alSourceRewindv(ids.size(), ids);
}
#ifdef MAGNUM_BUILD_DEPRECATED
void Source::rewind(const std::vector<Source*>& sources) {
const auto ids = sourceIds(sources);
alSourceRewindv(ids.size(), ids);
}
#endif
Debug operator<<(Debug debug, const Source::State value) {
switch(value) {

105
src/Magnum/Audio/Source.h

@ -29,6 +29,7 @@
* @brief Class Magnum::Audio::Source
*/
#include <functional>
#include <initializer_list>
#include <vector>
#include <al.h>
@ -377,52 +378,90 @@ class MAGNUM_AUDIO_EXPORT Source {
*
* The operation is guaranteed to be done for all sources at the same
* time. `nullptr` is not allowed.
* @see @ref play(), @ref pause(std::initializer_list<Source*>),
* @ref stop(std::initializer_list<Source*>),
* @ref rewind(std::initializer_list<Source*>),
* @see @ref play(), @ref pause(std::initializer_list<std::reference_wrapper<Source>>),
* @ref stop(std::initializer_list<std::reference_wrapper<Source>>),
* @ref rewind(std::initializer_list<std::reference_wrapper<Source>>),
* @fn_al{SourcePlayv}
*/
static void play(std::initializer_list<Source*> sources);
static void play(const std::vector<Source*>& sources); /**< @overload */
static void play(std::initializer_list<std::reference_wrapper<Source>> sources);
static void play(const std::vector<std::reference_wrapper<Source>>& sources); /**< @overload */
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @copybrief play(const std::vector<std::reference_wrapper<Source>>&)
* @deprecated Use @ref Magnum::Audio::Source::play(const std::<std::reference_wrapper<Source>>&) "play(const std::vector<std::reference_wrapper<Source>>&)" instead.
*/
static CORRADE_DEPRECATED("use play(const std::vector<std::reference_wrapper<Source>>&) instead") void play(const std::vector<Source*>& sources);
#endif
/**
* @brief Pause more sources at once
*
* The operation is guaranteed to be done for all sources at the same
* time. `nullptr` is not allowed.
* @see @ref pause(), @ref play(std::initializer_list<Source*>),
* @ref stop(std::initializer_list<Source*>),
* @ref rewind(std::initializer_list<Source*>),
* time.
* @see @ref pause(), @ref play(std::initializer_list<std::reference_wrapper<Source>>),
* @ref stop(std::initializer_list<std::reference_wrapper<Source>>),
* @ref rewind(std::initializer_list<std::reference_wrapper<Source>>),
* @fn_al{SourcePausev}
*/
static void pause(std::initializer_list<Source*> sources);
static void pause(const std::vector<Source*>& sources); /**< @overload */
static void pause(std::initializer_list<std::reference_wrapper<Source>> sources);
static void pause(const std::vector<std::reference_wrapper<Source>>& sources); /**< @overload */
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @copybrief pause(const std::vector<std::reference_wrapper<Source>>&)
* @deprecated Use @ref Magnum::Audio::Source::pause(const std::<std::reference_wrapper<Source>>&) "pause(const std::vector<std::reference_wrapper<Source>>&)" instead.
*/
static CORRADE_DEPRECATED("use pause(const std::vector<std::reference_wrapper<Source>>&) instead") void pause(const std::vector<Source*>& sources);
#endif
/**
* @brief Stop more sources at once
*
* The operation is guaranteed to be done for all sources at the same
* time. `nullptr` is not allowed.
* @see @ref stop(), @ref play(std::initializer_list<Source*>),
* @ref pause(std::initializer_list<Source*>),
* @ref rewind(std::initializer_list<Source*>),
* time.
* @see @ref stop(), @ref play(std::initializer_list<std::reference_wrapper<Source>>),
* @ref pause(std::initializer_list<std::reference_wrapper<Source>>),
* @ref rewind(std::initializer_list<std::reference_wrapper<Source>>),
* @fn_al{SourceStopv}
*/
static void stop(std::initializer_list<Source*> sources);
static void stop(const std::vector<Source*>& sources); /**< @overload */
static void stop(std::initializer_list<std::reference_wrapper<Source>> sources);
static void stop(const std::vector<std::reference_wrapper<Source>>& sources); /**< @overload */
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @copybrief stop(const std::vector<std::reference_wrapper<Source>>&)
* @deprecated Use @ref Magnum::Audio::Source::stop(const std::<std::reference_wrapper<Source>>&) "stop(const std::vector<std::reference_wrapper<Source>>&)" instead.
*/
static CORRADE_DEPRECATED("use stop(const std::vector<std::reference_wrapper<Source>>&) instead") void stop(const std::vector<Source*>& sources);
#endif
/**
* @brief Rewind more sources at once
*
* The operation is guaranteed to be done for all sources at the same
* time. `nullptr` is not allowed.
* @see @ref rewind(), @ref play(std::initializer_list<Source*>),
* @ref pause(std::initializer_list<Source*>),
* @ref stop(std::initializer_list<Source*>),
* time.
* @see @ref rewind(), @ref play(std::initializer_list<std::reference_wrapper<Source>>),
* @ref pause(std::initializer_list<std::reference_wrapper<Source>>),
* @ref stop(std::initializer_list<std::reference_wrapper<Source>>),
* @fn_al{SourceRewindv}
*/
static void rewind(std::initializer_list<Source*> sources);
static void rewind(const std::vector<Source*>& sources); /**< @overload */
static void rewind(std::initializer_list<std::reference_wrapper<Source>> sources);
static void rewind(const std::vector<std::reference_wrapper<Source>>& sources); /**< @overload */
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @copybrief rewind(std::initializer_list<std::reference_wrapper<Source>>)
* @deprecated Use @ref Magnum::Audio::Source::rewind(std::initializer_list<std::reference_wrapper<Source>>) "rewind(std::initializer_list<std::reference_wrapper<Source>>)" instead.
*/
static CORRADE_DEPRECATED("use rewind(std::initializer_list<std::reference_wrapper<Source>>) instead") void rewind(std::initializer_list<Source*> sources);
/**
* @copybrief rewind(const std::vector<std::reference_wrapper<Source>>&)
* @deprecated Use @ref Magnum::Audio::Source::rewind(const std::<std::reference_wrapper<Source>>&) "rewind(const std::vector<std::reference_wrapper<Source>>&)" instead.
*/
static CORRADE_DEPRECATED("use rewind(const std::vector<std::reference_wrapper<Source>>&) instead") void rewind(const std::vector<Source*>& sources);
#endif
/**
* @brief State
@ -435,32 +474,36 @@ class MAGNUM_AUDIO_EXPORT Source {
/**
* @brief Play
*
* @see @ref play(std::initializer_list<Source*>), @ref state(),
* @ref pause(), @ref stop(), @ref rewind(), @fn_al{SourcePlay}
* @see @ref play(std::initializer_list<std::reference_wrapper<Source>>),
* @ref state(), @ref pause(), @ref stop(), @ref rewind(),
* @fn_al{SourcePlay}
*/
void play() { alSourcePlay(_id); }
/**
* @brief Pause
*
* @see @ref pause(std::initializer_list<Source*>), @ref state(),
* @ref play(), @ref stop(), @ref rewind(), @fn_al{SourcePause}
* @see @ref pause(std::initializer_list<std::reference_wrapper<Source>>),
* @ref state(), @ref play(), @ref stop(), @ref rewind(),
* @fn_al{SourcePause}
*/
void pause() { alSourcePause(_id); }
/**
* @brief Stop
*
* @see @ref stop(std::initializer_list<Source*>), @ref state(),
* @ref play(), @ref pause(), @ref rewind(), @fn_al{SourceStop}
* @see @ref stop(std::initializer_list<std::reference_wrapper<Source>>),
* @ref state(), @ref play(), @ref pause(), @ref rewind(),
* @fn_al{SourceStop}
*/
void stop() { alSourceStop(_id); }
/**
* @brief Rewind
*
* @see @ref rewind(std::initializer_list<Source*>), @ref state(),
* @ref play(), @ref pause(), @ref stop(), @fn_al{SourceRewind}
* @see @ref rewind(std::initializer_list<std::reference_wrapper<Source>>),
* @ref state(), @ref play(), @ref pause(), @ref stop(),
* @fn_al{SourceRewind}
*/
void rewind() { alSourceRewind(_id); }

Loading…
Cancel
Save