ManaPlus
Public Member Functions | Protected Attributes
SDLMusic Class Reference

#include <sdlmusic.h>

Inheritance diagram for SDLMusic:
Resource MemoryCounter

Public Member Functions

 SDLMusic ()
 
 SDLMusic (Mix_Music *const music, SDL_RWops *const rw, const std::string &name)
 
 ~SDLMusic ()
 
bool play (const int loops, const int fadeIn) const
 
int calcMemoryLocal () const
 
std::string getCounterName () const
 
- Public Member Functions inherited from Resource
 Resource ()
 
 ~Resource ()
 
virtual void incRef ()
 
virtual void decRef ()
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 
virtual int calcMemoryChilds (const int level) const
 

Protected Attributes

std::string mName
 
Mix_Music * mMusic
 
SDL_RWops * mRw
 

Additional Inherited Members

- Data Fields inherited from Resource
time_t mTimeStamp
 
std::string mIdPath
 
std::string mSource
 
unsigned int mRefCount
 
bool mProtected
 
bool mNotCount
 

Detailed Description

Defines a class for loading and storing music.

Definition at line 39 of file sdlmusic.h.

Constructor & Destructor Documentation

◆ SDLMusic() [1/2]

SDLMusic::SDLMusic ( )
inline

Definition at line 42 of file sdlmusic.h.

42  :
43  Resource(),
44  mName(),
45  mMusic(nullptr),
46  mRw(nullptr)
47  { }
Resource()
Definition: resource.h:40
std::string mName
Definition: sdlmusic.h:79
Mix_Music * mMusic
Definition: sdlmusic.h:80
SDL_RWops * mRw
Definition: sdlmusic.h:81

Referenced by calcMemoryLocal().

◆ SDLMusic() [2/2]

SDLMusic::SDLMusic ( Mix_Music *const  music,
SDL_RWops *const  rw,
const std::string &  name 
)

Definition at line 40 of file sdlmusic.cpp.

42  :
43  Resource(),
44  mName(name),
45  mMusic(music),
46  mRw(rw)
47 {
48 }

◆ ~SDLMusic()

SDLMusic::~SDLMusic ( )

Destructor.

Definition at line 50 of file sdlmusic.cpp.

51 {
52  Mix_FreeMusic(mMusic);
53 #ifndef USE_SDL2
54 #if SDL_MIXER_VERSION_ATLEAST(1, 2, 12)
55  if (mRw != nullptr)
56  {
57  SDL_RWclose(mRw);
58  mRw = nullptr;
59  }
60 #endif // SDL_MIXER_VERSION_ATLEAST(1, 2, 12)
61 #endif // USE_SDL2
62 }

References mMusic, and mRw.

Member Function Documentation

◆ calcMemoryLocal()

int SDLMusic::calcMemoryLocal ( ) const
virtual

Reimplemented from Resource.

Definition at line 72 of file sdlmusic.cpp.

73 {
74  // +++ not used size of SDL_RWops
75  return static_cast<int>(sizeof(SDLMusic)) +
77 }
int calcMemoryLocal() const
Definition: resource.cpp:76
SDLMusic()
Definition: sdlmusic.h:42

References Resource::calcMemoryLocal(), and SDLMusic().

◆ getCounterName()

std::string SDLMusic::getCounterName ( ) const
inlinevirtual

Reimplemented from Resource.

Definition at line 75 of file sdlmusic.h.

76  { return mName; }

References mName.

◆ play()

bool SDLMusic::play ( const int  loops,
const int  fadeIn 
) const

Plays the music.

Parameters
loopsNumber of times to repeat the playback (-1 means forever).
fadeInDuration in milliseconds to fade in the music.
Returns
true if the playback started properly false otherwise.

Definition at line 64 of file sdlmusic.cpp.

66 {
67  if (fadeIn > 0)
68  return Mix_FadeInMusicPos(mMusic, loops, fadeIn, 0.0) != 0;
69  return Mix_FadeInMusicPos(mMusic, loops, 0, 0.0) != 0;
70 }

References mMusic.

Referenced by SoundManager::playMusic().

Field Documentation

◆ mMusic

Mix_Music* SDLMusic::mMusic
protected

Definition at line 80 of file sdlmusic.h.

Referenced by play(), and ~SDLMusic().

◆ mName

std::string SDLMusic::mName
protected

Definition at line 79 of file sdlmusic.h.

Referenced by getCounterName().

◆ mRw

SDL_RWops* SDLMusic::mRw
protected

Definition at line 81 of file sdlmusic.h.

Referenced by ~SDLMusic().


The documentation for this class was generated from the following files: