emilib
music.hpp
1 // By Emil Ernerfeldt 2014-2016
2 // LICENSE:
3 // This software is dual-licensed to the public domain and under the following
4 // license: you are granted a perpetual, irrevocable license to copy, modify,
5 // publish, and distribute this file as you see fit.
6 // HISTORY:
7 // Created in 2014 for Ghostel
8 
9 #pragma once
10 
11 #include <memory>
12 
13 namespace emilib {
14 
16 class Music
17 {
18 public:
19  explicit Music(const char* path);
20  ~Music();
21  Music(Music&&);
22  Music& operator=(Music&&);
23  Music(const Music&) = delete;
24  Music& operator=(const Music&) = delete;
25 
26  const std::string& path() const;
27 
28  void update(float dt);
29 
30  void fade_in(float duration = 0.1f);
31  void fade_out_and_pause(float duration = 0.1f);
32 
33  void play();
34  void pause();
35  void stop();
36 
37  void set_volume(float volume);
38  void set_muted(bool muted);
39 
40 private:
41  struct Fade
42  {
43  float target; // 0 or _volume
44  float speed;
45  };
46 
47  struct MusicImpl;
48 
49  std::unique_ptr<MusicImpl> _impl;
50  float _volume = 1;
51  bool _has_fade = false;
52  Fade _fade;
53 };
54 
55 } // namespace emilib
Stream .mp3 files on iOS and OSX.
Definition: music.hpp:16
void update(float dt)
For fades.
Definition: coroutine.hpp:18