Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Music.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Audio module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_MUSIC_HPP
8 #define NAZARA_MUSIC_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Audio/Enums.hpp>
12 #include <Nazara/Audio/SoundEmitter.hpp>
13 #include <Nazara/Core/MovablePtr.hpp>
14 #include <Nazara/Core/Resource.hpp>
15 #include <Nazara/Core/ResourceLoader.hpp>
16 #include <Nazara/Core/ResourceParameters.hpp>
17 
18 namespace Nz
19 {
20  struct MusicParams : ResourceParameters
21  {
22  bool forceMono = false;
23 
24  bool IsValid() const;
25  };
26 
27  class Music;
28  class SoundStream;
29 
30  using MusicLoader = ResourceLoader<Music, MusicParams>;
31 
32  struct MusicImpl;
33 
34  class NAZARA_AUDIO_API Music : public Resource, public SoundEmitter
35  {
36  friend MusicLoader;
37 
38  public:
39  Music() = default;
40  Music(const Music&) = delete;
41  Music(Music&&) = delete;
42  ~Music();
43 
44  bool Create(SoundStream* soundStream);
45  void Destroy();
46 
47  void EnableLooping(bool loop) override;
48 
49  UInt32 GetDuration() const override;
50  AudioFormat GetFormat() const;
51  UInt32 GetPlayingOffset() const override;
52  UInt64 GetSampleCount() const;
53  UInt32 GetSampleRate() const;
54  SoundStatus GetStatus() const override;
55 
56  bool IsLooping() const override;
57 
58  bool OpenFromFile(const String& filePath, const MusicParams& params = MusicParams());
59  bool OpenFromMemory(const void* data, std::size_t size, const MusicParams& params = MusicParams());
60  bool OpenFromStream(Stream& stream, const MusicParams& params = MusicParams());
61 
62  void Pause() override;
63  void Play() override;
64 
65  void SetPlayingOffset(UInt32 offset);
66 
67  void Stop() override;
68 
69  Music& operator=(const Music&) = delete;
70  Music& operator=(Music&&) = delete;
71 
72  private:
73  MovablePtr<MusicImpl> m_impl = nullptr;
74 
75  bool FillAndQueueBuffer(unsigned int buffer);
76  void MusicThread();
77  void StopThread();
78 
79  static MusicLoader::LoaderList s_loaders;
80  };
81 }
82 
83 #endif // NAZARA_MUSIC_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
AudioFormat
WARNING: The integer value is the number of canals owned by the format.
Definition: Enums.hpp:12
Core class that represents a string.
Definition: String.hpp:22
Audio class that represents a sound stream.
Definition: SoundStream.hpp:16
Core class that represents a loader of resources.
Definition: ResourceLoader.hpp:23
Core class that represents a resource.
Definition: Resource.hpp:15
Audio class that represents a music.
Definition: Music.hpp:34
Audio class that represents a sound source, that emits sound.
Definition: SoundEmitter.hpp:19
Core class that represents a stream.
Definition: Stream.hpp:19