Generate an accompaniement for a given melody
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Track.hpp
1 #ifndef TRACK_HPP_INCLUDED
2 #define TRACK_HPP_INCLUDED
3 
4 #include <string>
5 #include "Music.hpp"
6 #include "Utilities.hpp"
7 #include <memory>
8 extern "C"
9 {
10  #pragma GCC diagnostic push
11  #pragma GCC diagnostic ignored "-Wignored-qualifiers"
12  #include "Fmod/fmod.h"
13  #pragma GCC diagnostic pop
14 }
15 
16 struct FMODSystemWrapper;
17 
18 class Track
19 {
20 public :
28  Track(const std::string& filename);
29 
34  Track();
35  Track(const Track&) = delete;
36  Track& operator=(const Track&) = delete;
37 
41  void play();
42 
46  void pause();
47 
52  Time getDuration() const;
53 
54 
61  void setVolume(float vol);
62 
68  float getVolume() const;
69 
76  void setSound(const std::string& filename);
77 
81  operator bool () const;
82 
86  void mute();
87 
91  void unmute();
92 
96  bool isMute() const;
97 
103  void setSpeed(float s);
104 
108  float getSpeed() const;
109 
113  void close();
114 
118  void setRepeat(bool repeat);
119 
123  bool getRepeat() const;
124 
128  void setPosition(const Time& t);
129 
133  Time getPosition() const;
134 
138  ~Track();
139 
140  void stop();
141 
142  bool isFinished() const;
143  bool isPaused() const;
144 private :
145  std::shared_ptr<FMODSystemWrapper> system;
146  FMOD_SOUND *music;
147  FMOD_CHANNEL *channel;
148  FMOD_SYSTEM*getSystem();
149  FMOD_DSP* dsp;
150  float speed;
151  bool hasSound;
152  float volume;
153  bool repeat;
154  bool muted;
155  std::string ABCFile;
156  void loadChannel();
157  bool paused;
158  float initialFreq;
159 };
160 
162 {
163 public :
164  SongPlayer();
165  SongPlayer(const Melody& m, const ChordProgression& c);
166  SongPlayer(const SongPlayer& o) = delete;
167  SongPlayer& operator=(const SongPlayer& o) = delete;
168 
169  void setSong(const Melody& m, const ChordProgression& c = ChordProgression());
170 
171  void play();
172  void pause();
173 
174  void setGlobalVolume(float vol);
175  void setChordVolume(float vol);
176  void setMelodyVolume(float vol);
177 
178  float getGlobalVolume() const;
179  float getChordVolume() const;
180  float getMelodyVolume() const;
181 
182  void mute();
183  void muteChord();
184  void muteMelody();
185  void unmute();
186  void unmuteChord();
187  void unmuteMelody();
188 
189  bool isMute()const;
190  bool isChordMute() const;
191  bool isMelodyMute() const;
192 
193  void setBPM(unsigned BPM);
194  unsigned getBPM() const;
195 
196  void setPosition(const Time& p);
197  Time getPosition() const;
198  Time getDuration() const;
199 
200  void setRepeat(bool r);
201  bool getRepeat() const;
202  void stop();
203  operator bool() const;
204  bool isFinished() const;
205  ~SongPlayer();
206 private :
207  static unsigned unique;
208  Track chord;
209  Track melody;
210  float globalVolume;
211  unsigned originalBPM;
212  unsigned id;
213 };
214 
215 
216 #endif // TRACK_HPP_INCLUDED
void setRepeat(bool repeat)
Set the repeat option independently of the validity of the track.
Time getPosition() const
Returns the position in the Track (taking the speed into account) if the Track is valid...
Definition: Track.hpp:161
void setVolume(float vol)
Sets the Volume of the sound (or sets the volume for future use). This function does not unmute if it...
bool isMute() const
return whether the sound is muted (independently of its validity)
void pause()
If the Track is valid, pauses the sound.
This file defines all the data structures related to music objects.
float getSpeed() const
returns the speed
Describes a melody.
Definition: Music.hpp:629
void play()
If the Track is valid, plays the sound.
bool getRepeat() const
Return the repeat state independently of the validity of the track.
void setSpeed(float s)
Sets the speed. A speed of 2 corresponds to twice the normal speed.
void setSound(const std::string &filename)
Sets the Track to a new Sound The speed is reset to the speed of the new Sound, the volume...
Definition: Track.hpp:18
void mute()
Mutes the sound.
Track()
Creates an invalid Track The volume is at max, repeat is set to false, speed i set to 1 and mute is s...
std::vector< Chord > ChordProgression
ChordProgression is the class used to give the set of chords used.
Definition: Music.hpp:592
~Track()
The Music stops when the object is destroyed.
float getVolume() const
Returns the volume of the sound independently of its validity The value does not depend on the "mute"...
void unmute()
Unmutes the Sound.
Time getDuration() const
If the track is valid, returns the duration of the sound at the current speed, otherwise, returns 0.
Definition: Utilities.hpp:14
void close()
Closes the sound (The Track becomes invalid)
void setPosition(const Time &t)
If the track is valid, sets the position in the track, otherwise it does nothing. ...