Amuse
Sequencer.hpp
1 #ifndef __AMUSE_SEQUENCER_HPP__
2 #define __AMUSE_SEQUENCER_HPP__
3 
4 #include "Entity.hpp"
5 #include "AudioGroupProject.hpp"
6 #include "SongState.hpp"
7 #include "optional.hpp"
8 #include <unordered_map>
9 #include <unordered_set>
10 #include <memory>
11 #include <list>
12 
13 namespace amuse
14 {
15 class Submix;
16 class Voice;
17 
19 enum class SequencerState
20 {
21  Playing,
22  Interactive,
23  Dead
24 };
25 
27 class Sequencer : public Entity
28 {
29  friend class Engine;
30  const SongGroupIndex& m_songGroup;
31  const SongGroupIndex::MIDISetup* m_midiSetup = nullptr;
32  Submix* m_submix = nullptr;
33  std::list<std::shared_ptr<Sequencer>>::iterator m_engineIt;
35  const unsigned char* m_arrData = nullptr;
36  SongState m_songState;
37  double m_ticksPerSec = 1000.0;
38  SequencerState m_state = SequencerState::Interactive;
39  bool m_dieOnEnd = false;
41  float m_curVol = 1.f;
44  struct ChannelState
45  {
46  Sequencer& m_parent;
47  uint8_t m_chanId;
48  const SongGroupIndex::MIDISetup& m_setup;
49  const SongGroupIndex::PageEntry* m_page = nullptr;
50  Submix* m_submix = nullptr;
51  ~ChannelState();
52  ChannelState(Sequencer& parent, uint8_t chanId);
53 
55  std::unordered_map<uint8_t, std::shared_ptr<Voice>> m_chanVoxs;
56  std::unordered_set<std::shared_ptr<Voice>> m_keyoffVoxs;
57  int8_t m_ctrlVals[128];
58  float m_curPitchWheel = 0.f;
59  int8_t m_curProgram = 0;
60  float m_curVol = 1.f;
61  float m_curPan = 0.f;
63  void _bringOutYourDead();
64  size_t getVoiceCount() const;
65  std::shared_ptr<Voice> keyOn(uint8_t note, uint8_t velocity);
66  void keyOff(uint8_t note, uint8_t velocity);
67  void setCtrlValue(uint8_t ctrl, int8_t val);
68  bool programChange(int8_t prog);
69  void nextProgram();
70  void prevProgram();
71  void setPitchWheel(float pitchWheel);
72  void setVolume(float vol);
73  void setPan(float pan);
74  void allOff();
75  void killKeygroup(uint8_t kg, bool now);
76  std::shared_ptr<Voice> findVoice(int vid);
77  void sendMacroMessage(ObjectId macroId, int32_t val);
78  };
79  std::array<std::experimental::optional<ChannelState>, 16> m_chanStates;
81  void _bringOutYourDead();
82  void _destroy();
83 public:
84  ~Sequencer();
85  Sequencer(Engine& engine, const AudioGroup& group, int groupId,
86  const SongGroupIndex& songGroup, int setupId, Submix* smx);
87 
89  void advance(double dt);
90 
92  Submix* getSubmix() {return m_submix;}
93 
95  SequencerState state() const {return m_state;}
96 
98  size_t getVoiceCount() const;
99 
101  std::shared_ptr<Voice> keyOn(uint8_t chan, uint8_t note, uint8_t velocity);
102 
104  void keyOff(uint8_t chan, uint8_t note, uint8_t velocity);
105 
107  void setCtrlValue(uint8_t chan, uint8_t ctrl, int8_t val);
108 
110  void setPitchWheel(uint8_t chan, float pitchWheel);
111 
113  void allOff(bool now=false);
114 
116  void killKeygroup(uint8_t kg, bool now);
117 
119  std::shared_ptr<Voice> findVoice(int vid);
120 
122  void sendMacroMessage(ObjectId macroId, int32_t val);
123 
125  void setTempo(double ticksPerSec);
126 
128  void playSong(const unsigned char* arrData, bool dieOnEnd=true);
129 
131  void setVolume(float vol);
132 
134  int8_t getChanProgram(int8_t chanId) const;
135 
137  bool setChanProgram(int8_t chanId, int8_t prog);
138 
140  void nextChanProgram(int8_t chanId);
141 
143  void prevChanProgram(int8_t chanId);
144 
146  void kill() {m_state = SequencerState::Dead;}
147 };
148 
149 }
150 
151 #endif // __AMUSE_SEQUENCER_HPP__
Submix * getSubmix()
Definition: Sequencer.hpp:92
SequencerState state() const
Definition: Sequencer.hpp:95