Mana
Loading...
Searching...
No Matches
sound.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "resources/resource.h"
25
26#include <SDL_mixer.h>
27
28#include <string>
29
30class Music;
31class SoundEffect;
32
37class Sound
38{
39 public:
40 Sound();
41 ~Sound();
42
46 void init();
47
51 void close();
52
58 void playMusic(const std::string &fileName);
59
63 void stopMusic();
64
71 void fadeInMusic(const std::string &fileName, int ms = 1000);
72
78 void fadeOutMusic(int ms = 1000);
79
86 void fadeOutAndPlayMusic(const std::string &fileName, int ms = 1000);
87
88 int getMaxVolume() const
89 { return MIX_MAX_VOLUME; }
90
91 void setMusicVolume(int volume);
92 void setSfxVolume(int volume);
93 void setNotificationsVolume(int volume);
94
102 void playSfx(const std::string &path, int x = 0, int y = 0);
103
109 void playNotification(const std::string &path);
110
117 void logic();
118
125
126 private:
128 void info();
129
131 void haltMusic();
132
137 std::string mNextMusicFile;
138
139 bool mInstalled = false;
140
141 int mSfxVolume = 100;
143 int mMusicVolume = 60;
144
145 std::string mCurrentMusicFile;
148};
149
150extern Sound sound;
Defines a class for loading and storing music.
Definition music.h:32
Automatically counting Resource reference.
Definition resource.h:74
Defines a class for loading and storing sound effects.
Definition soundeffect.h:32
Sound engine.
Definition sound.h:38
void fadeOutAndPlayMusic(const std::string &fileName, int ms=1000)
Fades out a background music and play a new one.
Definition sound.cpp:218
~Sound()
Definition sound.cpp:55
void playMusic(const std::string &fileName)
Starts background music.
Definition sound.cpp:166
void fadeOutMusic(int ms=1000)
Fades out currently running background music track.
Definition sound.cpp:197
void init()
Installs the sound engine.
Definition sound.cpp:61
void fadeInMusic(const std::string &fileName, int ms=1000)
Fades in background music.
Definition sound.cpp:181
int getMaxVolume() const
Definition sound.h:88
void setMusicVolume(int volume)
Definition sound.cpp:139
void info()
Logs various info about sound device.
Definition sound.cpp:100
Sound()
Definition sound.cpp:49
bool mInstalled
Definition sound.h:139
@ CHANNEL_NOTIFICATIONS
Definition sound.h:120
@ CHANNEL_COUNT
Definition sound.h:123
@ CHANNEL_RESERVED_COUNT
Definition sound.h:121
void haltMusic()
Halts and frees currently playing music.
Definition sound.cpp:308
void logic()
The sound logic.
Definition sound.cpp:224
int mNotificationsVolume
Definition sound.h:142
void stopMusic()
Stops currently running background music track.
Definition sound.cpp:171
void close()
Removes all sound functionalities.
Definition sound.cpp:296
void setSfxVolume(int volume)
Definition sound.cpp:147
std::string mCurrentMusicFile
Definition sound.h:145
void setNotificationsVolume(int volume)
Definition sound.cpp:158
void playSfx(const std::string &path, int x=0, int y=0)
Plays a sound at the specified location.
Definition sound.cpp:248
ResourceRef< Music > mMusic
Definition sound.h:146
void playNotification(const std::string &path)
Plays a sound on the notification channel.
Definition sound.cpp:283
int mMusicVolume
Definition sound.h:143
ResourceRef< SoundEffect > mSounds[CHANNEL_COUNT]
Definition sound.h:147
int mSfxVolume
Definition sound.h:141
std::string mNextMusicFile
When calling fadeOutAndPlayMusic(), the music file below will then be played.
Definition sound.h:137
Sound sound
Definition client.cpp:109