Pioneer
SoundMusic.h
Go to the documentation of this file.
1 // Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef _MUSIC_H
5 #define _MUSIC_H
6 
7 #include "Sound.h"
8 #include <SDL.h>
9 #include <sigc++/sigc++.h>
10 #include <string>
11 #include <vector>
12 
13 namespace Sound {
14  class MusicEvent : public Event {
15  public:
16  MusicEvent();
17  MusicEvent(Uint32 id);
18  ~MusicEvent();
19  virtual void Play(const char *fx, const float volume_left, const float volume_right, Op op);
20  };
21 
22  class MusicPlayer {
23  public:
24  MusicPlayer();
25  ~MusicPlayer();
26  float GetVolume() const;
27  void SetVolume(const float);
28  void Play(const std::string &, const bool repeat = false, const float fadeDelta = 1.f);
29  void Stop();
30  void FadeOut(const float fadeDelta);
31  void Update();
32  const std::string GetCurrentSongName() const;
33  const std::vector<std::string> GetSongList() const;
34  bool IsPlaying() const;
35  void SetEnabled(bool);
36 
37  sigc::signal<void> onSongFinished;
38 
39  private:
40  float m_volume;
41  //two streams for crossfade
42  MusicEvent m_eventOne;
43  MusicEvent m_eventTwo;
44  bool m_playing;
45  bool m_eventOnePlaying;
46  std::string m_currentSongName;
47  bool m_enabled;
48  };
49 } // namespace Sound
50 
51 #endif
Definition: Sound.h:32
Definition: SoundMusic.h:14
MusicEvent()
Definition: SoundMusic.cpp:11
~MusicEvent()
Definition: SoundMusic.cpp:17
virtual void Play(const char *fx, const float volume_left, const float volume_right, Op op)
Definition: SoundMusic.cpp:19
Definition: SoundMusic.h:22
sigc::signal< void > onSongFinished
Definition: SoundMusic.h:37
void Stop()
Definition: SoundMusic.cpp:76
MusicPlayer()
Definition: SoundMusic.cpp:25
float GetVolume() const
Definition: SoundMusic.cpp:38
bool IsPlaying() const
Definition: SoundMusic.cpp:125
const std::vector< std::string > GetSongList() const
Definition: SoundMusic.cpp:110
void FadeOut(const float fadeDelta)
Definition: SoundMusic.cpp:83
void Play(const std::string &, const bool repeat=false, const float fadeDelta=1.f)
Definition: SoundMusic.cpp:53
void Update()
Definition: SoundMusic.cpp:94
void SetVolume(const float)
Definition: SoundMusic.cpp:43
const std::string GetCurrentSongName() const
Definition: SoundMusic.cpp:105
void SetEnabled(bool)
Definition: SoundMusic.cpp:130
~MusicPlayer()
Definition: SoundMusic.cpp:34
Definition: Pi.h:54
Uint32 Op
Definition: Sound.h:20