CUGL
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUMusicLoader.h
1 //
2 // CUMusicLoader.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides a specific implementation of the Loader class to load
6 // music assets (e.g. streaming audio files). A music asset is identified by
7 // both its source file and its volume.
8 //
9 // As with all of our loaders, this loader is designed to be attached to an
10 // asset manager. In addition, this class uses our standard shared-pointer
11 // architecture.
12 //
13 // 1. The constructor does not perform any initialization; it just sets all
14 // attributes to their defaults.
15 //
16 // 2. All initialization takes place via init methods, which can fail if an
17 // object is initialized more than once.
18 //
19 // 3. All allocation takes place via static constructors which return a shared
20 // pointer.
21 //
22 //
23 // CUGL zlib License:
24 // This software is provided 'as-is', without any express or implied
25 // warranty. In no event will the authors be held liable for any damages
26 // arising from the use of this software.
27 //
28 // Permission is granted to anyone to use this software for any purpose,
29 // including commercial applications, and to alter it and redistribute it
30 // freely, subject to the following restrictions:
31 //
32 // 1. The origin of this software must not be misrepresented; you must not
33 // claim that you wrote the original software. If you use this software
34 // in a product, an acknowledgment in the product documentation would be
35 // appreciated but is not required.
36 //
37 // 2. Altered source versions must be plainly marked as such, and must not
38 // be misrepresented as being the original software.
39 //
40 // 3. This notice may not be removed or altered from any source distribution.
41 //
42 // Author: Walker White
43 // Version: 1/7/16
44 //
45 #ifndef __CU_MUSIC_LOADER_H__
46 #define __CU_MUSIC_LOADER_H__
47 #include <cugl/assets/CULoader.h>
48 #include <cugl/audio/CUMusic.h>
49 
50 namespace cugl {
51 
69 class MusicLoader : public Loader<Music> {
70 private:
72  CU_DISALLOW_COPY_AND_ASSIGN(MusicLoader);
73 
74 protected:
76  float _volume;
77 
94  void materialize(const std::string& key, const std::shared_ptr<Music>& music,
95  float volume, LoaderCallback callback);
96 
115  virtual bool read(const std::string& key, const std::string& source,
116  LoaderCallback callback, bool async) override;
117 
141  virtual bool read(const std::shared_ptr<JsonValue>& json,
142  LoaderCallback callback, bool async) override;
143 
144 public:
145 #pragma mark -
146 #pragma mark Constructors
147 
153  MusicLoader();
154 
166  void dispose() override {
167  _assets.clear();
168  _loader = nullptr;
169  }
170 
183  static std::shared_ptr<MusicLoader> alloc() {
184  std::shared_ptr<MusicLoader> result = std::make_shared<MusicLoader>();
185  return (result->init() ? result : nullptr);
186  }
187 
202  static std::shared_ptr<MusicLoader> alloc(const std::shared_ptr<ThreadPool>& threads) {
203  std::shared_ptr<MusicLoader> result = std::make_shared<MusicLoader>();
204  return (result->init(threads) ? result : nullptr);
205  }
206 
207 #pragma mark -
208 #pragma mark Properties
209 
217  float getVolume() const { return _volume; }
218 
227  void setVolume(float volume) { _volume = volume; }
228 };
229 
230 }
231 #endif /* __CU_MUSIC_LOADER_H__ */
void setVolume(float volume)
Definition: CUMusicLoader.h:227
std::shared_ptr< ThreadPool > _loader
Definition: CULoader.h:102
void dispose() override
Definition: CUMusicLoader.h:166
void materialize(const std::string &key, const std::shared_ptr< Music > &music, float volume, LoaderCallback callback)
static std::shared_ptr< MusicLoader > alloc()
Definition: CUMusicLoader.h:183
float getVolume() const
Definition: CUMusicLoader.h:217
float _volume
Definition: CUMusicLoader.h:76
std::unordered_map< std::string, std::shared_ptr< Music > > _assets
Definition: CULoader.h:678
std::function< void(const std::string &key, bool success)> LoaderCallback
Definition: CULoader.h:81
static std::shared_ptr< MusicLoader > alloc(const std::shared_ptr< ThreadPool > &threads)
Definition: CUMusicLoader.h:202
Definition: CULoader.h:675
Definition: CUAnimationNode.h:52
Definition: CUMusicLoader.h:69
virtual bool read(const std::string &key, const std::string &source, LoaderCallback callback, bool async) override