Amuse
Engine.hpp
1 #ifndef __AMUSE_ENGINE_HPP__
2 #define __AMUSE_ENGINE_HPP__
3 
4 #include <memory>
5 #include <list>
6 #include <random>
7 #include <unordered_map>
8 #include <unordered_set>
9 #include "Emitter.hpp"
10 #include "AudioGroupSampleDirectory.hpp"
11 #include "Sequencer.hpp"
12 
13 namespace amuse
14 {
15 class IBackendVoiceAllocator;
16 class Voice;
17 class Submix;
18 class Emitter;
19 class AudioGroup;
20 class AudioGroupData;
21 
23 class Engine
24 {
25  friend class Voice;
26  friend class Emitter;
27  friend class Sequencer;
28  friend class Sequencer::ChannelState;
29 
30  IBackendVoiceAllocator& m_backend;
31  std::unordered_map<const AudioGroupData*, std::unique_ptr<AudioGroup>> m_audioGroups;
32  std::list<std::shared_ptr<Voice>> m_activeVoices;
33  std::list<std::shared_ptr<Emitter>> m_activeEmitters;
34  std::list<std::shared_ptr<Sequencer>> m_activeSequencers;
35  std::list<Submix> m_activeSubmixes;
36  std::unordered_map<uint16_t, std::tuple<AudioGroup*, int, const SFXGroupIndex::SFXEntry*>> m_sfxLookup;
37  std::linear_congruential_engine<uint32_t, 0x41c64e6d, 0x3039, UINT32_MAX> m_random;
38  int m_nextVid = 0;
39 
40  std::pair<AudioGroup*, const SongGroupIndex*> _findSongGroup(int groupId) const;
41  std::pair<AudioGroup*, const SFXGroupIndex*> _findSFXGroup(int groupId) const;
42 
43  std::shared_ptr<Voice> _allocateVoice(const AudioGroup& group, int groupId, double sampleRate,
44  bool dynamicPitch, bool emitter, Submix* smx);
45  std::shared_ptr<Sequencer> _allocateSequencer(const AudioGroup& group, int groupId,
46  int setupId, Submix* smx);
47  Submix* _allocateSubmix(Submix* smx);
48  std::list<std::shared_ptr<Voice>>::iterator _destroyVoice(Voice* voice);
49  std::list<std::shared_ptr<Sequencer>>::iterator _destroySequencer(Sequencer* sequencer);
50  std::list<Submix>::iterator _destroySubmix(Submix* smx);
51  std::list<Submix>::iterator _removeSubmix(Submix* smx);
52  void _bringOutYourDead();
53 public:
54  ~Engine();
56 
58  IBackendVoiceAllocator& getBackend() {return m_backend;}
59 
61  void pumpEngine(double dt);
62 
64  const AudioGroup* addAudioGroup(const AudioGroupData& data);
65 
67  void removeAudioGroup(const AudioGroupData& data);
68 
70  Submix* addSubmix(Submix* parent=nullptr);
71 
73  void removeSubmix(Submix* smx);
74 
76  std::shared_ptr<Voice> fxStart(int sfxId, float vol, float pan, Submix* smx=nullptr);
77 
79  std::shared_ptr<Emitter> addEmitter(const Vector3f& pos, const Vector3f& dir, float maxDist,
80  float falloff, int sfxId, float minVol, float maxVol,
81  Submix* smx=nullptr);
82 
84  std::shared_ptr<Sequencer> seqPlay(int groupId, int songId, const unsigned char* arrData,
85  Submix* smx=nullptr);
86 
88  std::shared_ptr<Voice> findVoice(int vid);
89 
91  void killKeygroup(uint8_t kg, bool now);
92 
94  void sendMacroMessage(ObjectId macroId, int32_t val);
95 
97  uint32_t nextRandom() {return m_random();}
98 };
99 
100 }
101 
102 #endif // __AMUSE_ENGINE_HPP__
const AudioGroup * addAudioGroup(const AudioGroupData &data)
void killKeygroup(uint8_t kg, bool now)
uint32_t nextRandom()
Definition: Engine.hpp:97
std::shared_ptr< Voice > fxStart(int sfxId, float vol, float pan, Submix *smx=nullptr)
Submix * addSubmix(Submix *parent=nullptr)
void pumpEngine(double dt)
void sendMacroMessage(ObjectId macroId, int32_t val)
std::shared_ptr< Sequencer > seqPlay(int groupId, int songId, const unsigned char *arrData, Submix *smx=nullptr)
std::shared_ptr< Emitter > addEmitter(const Vector3f &pos, const Vector3f &dir, float maxDist, float falloff, int sfxId, float minVol, float maxVol, Submix *smx=nullptr)
void removeAudioGroup(const AudioGroupData &data)
IBackendVoiceAllocator & getBackend()
Definition: Engine.hpp:58
std::shared_ptr< Voice > findVoice(int vid)
void removeSubmix(Submix *smx)