CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUSoundLoader.h
1 //
2 // CUSoundLoader.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides a specific implementation of the Loader class to load
6 // sound assets (e.g. in-memory audio files). A sound 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 MIT License:
24 //
25 // This software is provided 'as-is', without any express or implied
26 // warranty. In no event will the authors be held liable for any damages
27 // arising from the use of this software.
28 //
29 // Permission is granted to anyone to use this software for any purpose,
30 // including commercial applications, and to alter it and redistribute it
31 // freely, subject to the following restrictions:
32 //
33 // 1. The origin of this software must not be misrepresented; you must not
34 // claim that you wrote the original software. If you use this software
35 // in a product, an acknowledgment in the product documentation would be
36 // appreciated but is not required.
37 //
38 // 2. Altered source versions must be plainly marked as such, and must not
39 // be misrepresented as being the original software.
40 //
41 // 3. This notice may not be removed or altered from any source distribution.
42 //
43 // Author: Walker White
44 // Version: 12/20/18
45 //
46 #ifndef __CU_SOUND_LOADER_H__
47 #define __CU_SOUND_LOADER_H__
48 #include <cugl/assets/CULoader.h>
49 #include <cugl/audio/CUSound.h>
50 
51 namespace cugl {
52 
70 class SoundLoader : public Loader<Sound> {
71 private:
73  CU_DISALLOW_COPY_AND_ASSIGN(SoundLoader);
74 
75 protected:
77  float _volume;
78 
79 #pragma mark Asset Loading
80 
95  void materialize(const std::string& key, const std::shared_ptr<Sound>& sound,
96  LoaderCallback callback);
97 
116  virtual bool read(const std::string& key, const std::string& source,
117  LoaderCallback callback, bool async) override;
118 
142  virtual bool read(const std::shared_ptr<JsonValue>& json,
143  LoaderCallback callback, bool async) override;
144 
145 
146 public:
147 #pragma mark -
148 #pragma mark Constructors
149 
155  SoundLoader();
156 
168  void dispose() override {
169  _assets.clear();
170  _loader = nullptr;
171  }
172 
185  static std::shared_ptr<SoundLoader> alloc() {
186  std::shared_ptr<SoundLoader> result = std::make_shared<SoundLoader>();
187  return (result->init() ? result : nullptr);
188  }
189 
204  static std::shared_ptr<SoundLoader> alloc(const std::shared_ptr<ThreadPool>& threads) {
205  std::shared_ptr<SoundLoader> result = std::make_shared<SoundLoader>();
206  return (result->init(threads) ? result : nullptr);
207  }
208 
209 #pragma mark -
210 #pragma mark Properties
211 
219  float getVolume() const { return _volume; }
220 
229  void setVolume(float volume) { _volume = volume; }
230 
231 };
232 
233 }
234 #endif /* __CU_SOUND_LOADER_H__ */
cugl::SoundLoader::materialize
void materialize(const std::string &key, const std::shared_ptr< Sound > &sound, LoaderCallback callback)
cugl::Loader
Definition: CULoader.h:749
cugl::SoundLoader::read
virtual bool read(const std::string &key, const std::string &source, LoaderCallback callback, bool async) override
cugl::SoundLoader::SoundLoader
SoundLoader()
cugl::SoundLoader::alloc
static std::shared_ptr< SoundLoader > alloc(const std::shared_ptr< ThreadPool > &threads)
Definition: CUSoundLoader.h:204
cugl::BaseLoader::_loader
std::shared_ptr< ThreadPool > _loader
Definition: CULoader.h:105
cugl::SoundLoader::alloc
static std::shared_ptr< SoundLoader > alloc()
Definition: CUSoundLoader.h:185
cugl::SoundLoader::setVolume
void setVolume(float volume)
Definition: CUSoundLoader.h:229
cugl::SoundLoader::_volume
float _volume
Definition: CUSoundLoader.h:77
cugl::Loader< Sound >::_assets
std::unordered_map< std::string, std::shared_ptr< Sound > > _assets
Definition: CULoader.h:752
cugl::SoundLoader::dispose
void dispose() override
Definition: CUSoundLoader.h:168
cugl::SoundLoader
Definition: CUSoundLoader.h:70
cugl::SoundLoader::getVolume
float getVolume() const
Definition: CUSoundLoader.h:219