CUGL 1.2
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 
96  void materialize(const std::string& key, const std::shared_ptr<Sound>& sound,
97  LoaderCallback callback);
98 
117  virtual bool read(const std::string& key, const std::string& source,
118  LoaderCallback callback, bool async) override;
119 
143  virtual bool read(const std::shared_ptr<JsonValue>& json,
144  LoaderCallback callback, bool async) override;
145 
146 
147 public:
148 #pragma mark -
149 #pragma mark Constructors
150 
156  SoundLoader();
157 
169  void dispose() override {
170  _assets.clear();
171  _loader = nullptr;
172  }
173 
186  static std::shared_ptr<SoundLoader> alloc() {
187  std::shared_ptr<SoundLoader> result = std::make_shared<SoundLoader>();
188  return (result->init() ? result : nullptr);
189  }
190 
205  static std::shared_ptr<SoundLoader> alloc(const std::shared_ptr<ThreadPool>& threads) {
206  std::shared_ptr<SoundLoader> result = std::make_shared<SoundLoader>();
207  return (result->init(threads) ? result : nullptr);
208  }
209 
210 #pragma mark -
211 #pragma mark Properties
212 
220  float getVolume() const { return _volume; }
221 
230  void setVolume(float volume) { _volume = volume; }
231 
232 };
233 
234 }
235 #endif /* __CU_SOUND_LOADER_H__ */
std::shared_ptr< ThreadPool > _loader
Definition: CULoader.h:105
void setVolume(float volume)
Definition: CUSoundLoader.h:230
std::unordered_map< std::string, std::shared_ptr< Sound > > _assets
Definition: CULoader.h:736
virtual bool read(const std::string &key, const std::string &source, LoaderCallback callback, bool async) override
void dispose() override
Definition: CUSoundLoader.h:169
Definition: CULoader.h:733
float getVolume() const
Definition: CUSoundLoader.h:220
static std::shared_ptr< SoundLoader > alloc(const std::shared_ptr< ThreadPool > &threads)
Definition: CUSoundLoader.h:205
static std::shared_ptr< SoundLoader > alloc()
Definition: CUSoundLoader.h:186
Definition: CUAction.h:51
Definition: CUSoundLoader.h:70
void materialize(const std::string &key, const std::shared_ptr< Sound > &sound, LoaderCallback callback)
float _volume
Definition: CUSoundLoader.h:77