ManaPlus
sdlmusic.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "resources/sdlmusic.h"
25 
26 #include "debug.h"
27 
28 #ifndef USE_SDL2
29 #ifndef SDL_MIXER_COMPILEDVERSION
30 #define SDL_MIXER_COMPILEDVERSION \
31  SDL_VERSIONNUM(SDL_MIXER_MAJOR_VERSION, \
32  SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL)
33 #endif // SDL_MIXER_COMPILEDVERSION
34 #ifndef SDL_MIXER_VERSION_ATLEAST
35 #define SDL_MIXER_VERSION_ATLEAST(X, Y, Z) \
36  (SDL_MIXER_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
37 #endif // SDL_MIXER_VERSION_ATLEAST
38 #endif // USE_SDL2
39 
40 SDLMusic::SDLMusic(Mix_Music *const music,
41  SDL_RWops *const rw,
42  const std::string &name) :
43  Resource(),
44  mName(name),
45  mMusic(music),
46  mRw(rw)
47 {
48 }
49 
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 }
63 
64 bool SDLMusic::play(const int loops,
65  const int fadeIn) const
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 }
71 
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
int calcMemoryLocal() const
Definition: sdlmusic.cpp:72
~SDLMusic()
Definition: sdlmusic.cpp:50
bool play(const int loops, const int fadeIn) const
Definition: sdlmusic.cpp:64
Mix_Music * mMusic
Definition: sdlmusic.h:80
SDL_RWops * mRw
Definition: sdlmusic.h:81