Amuse
SoundMacroState.hpp
1 #ifndef __AMUSE_SOUNDMACROSTATE_HPP__
2 #define __AMUSE_SOUNDMACROSTATE_HPP__
3 
4 #include <stdint.h>
5 #include <vector>
6 #include <list>
7 #include "Entity.hpp"
8 
9 namespace amuse
10 {
11 class Voice;
12 
15 {
16  friend class Voice;
17 
19  struct Header
20  {
21  uint32_t m_size;
22  ObjectId m_macroId;
23  uint8_t m_volume;
24  uint8_t m_pan;
25  void swapBig();
26  } m_header;
27 
29  enum class Op : uint8_t
30  {
31  End,
32  Stop,
33  SplitKey,
34  SplitVel,
35  WaitTicks,
36  Loop,
37  Goto,
38  WaitMs,
39  PlayMacro,
40  SendKeyOff,
41  SplitMod,
42  PianoPan,
43  SetAdsr,
44  ScaleVolume,
45  Panning,
46  Envelope,
47  StartSample,
48  StopSample,
49  KeyOff,
50  SplitRnd,
51  FadeIn,
52  Spanning,
53  SetAdsrCtrl,
54  RndNote,
55  AddNote,
56  SetNote,
57  LastNote,
58  Portamento,
59  Vibrato,
60  PitchSweep1,
61  PitchSweep2,
62  SetPitch,
63  SetPitchAdsr,
64  ScaleVolumeDLS,
65  Mod2Vibrange,
66  SetupTremolo,
67  Return,
68  GoSub,
69  TrapEvent = 0x28,
70  UntrapEvent,
71  SendMessage,
72  GetMessage,
73  GetVid,
74  AddAgeCount = 0x30,
75  SetAgeCount,
76  SendFlag,
77  PitchWheelR,
78  SetPriority,
79  AddPriority,
80  AgeCntSpeed,
81  AgeCntVel,
82  VolSelect = 0x40,
83  PanSelect,
84  PitchWheelSelect,
85  ModWheelSelect,
86  PedalSelect,
87  PortamentoSelect,
88  ReverbSelect,
89  SpanSelect,
90  DopplerSelect,
91  TremoloSelect,
92  PreASelect,
93  PreBSelect,
94  PostBSelect,
95  AuxAFXSelect,
96  AuxBFXSelect,
97  SetupLFO = 0x50,
98  ModeSelect = 0x58,
99  SetKeygroup,
100  SRCmodeSelect,
101  AddVars = 0x60,
102  SubVars,
103  MulVars,
104  DivVars,
105  AddIVars,
106  IfEqual = 0x70,
107  IfLess,
108  };
109 
111  struct Command
112  {
113  Op m_op;
114  char m_data[7];
115  void swapBig();
116  };
117 
119  std::vector<std::pair<const unsigned char*, int>> m_pc;
120 
121  double m_ticksPerSec;
122  uint8_t m_initVel;
123  uint8_t m_initMod;
124  uint8_t m_initKey;
125  uint8_t m_curVel;
126  uint8_t m_curMod;
127  uint32_t m_curPitch;
129  double m_execTime;
130  bool m_keyoff;
131  bool m_sampleEnd;
133  bool m_inWait = false;
134  bool m_indefiniteWait = false;
135  bool m_keyoffWait = false;
136  bool m_sampleEndWait = false;
137  double m_waitCountdown;
139  int m_loopCountdown = -1;
140  int m_lastPlayMacroVid = -1;
142  bool m_useAdsrControllers;
143  uint8_t m_midiAttack;
144  uint8_t m_midiDecay;
145  uint8_t m_midiSustain;
146  uint8_t m_midiRelease;
148  uint8_t m_portamentoMode;
149  uint8_t m_portamentoType;
150  float m_portamentoTime;
153  struct Evaluator
154  {
155  enum class Combine : uint8_t
156  {
157  Set,
158  Add,
159  Mult
160  };
161  enum class VarType : uint8_t
162  {
163  Ctrl,
164  Var
165  };
166 
168  struct Component
169  {
170  uint8_t m_midiCtrl;
171  float m_scale;
172  Combine m_combine;
173  VarType m_varType;
174 
175  Component(uint8_t midiCtrl, float scale, Combine combine, VarType varType)
176  : m_midiCtrl(midiCtrl), m_scale(scale), m_combine(combine), m_varType(varType) {}
177  };
178  std::vector<Component> m_comps;
181  void addComponent(uint8_t midiCtrl, float scale,
182  Combine combine, VarType varType);
183 
185  float evaluate(const Voice& vox, const SoundMacroState& st) const;
186 
188  operator bool() const {return m_comps.size() != 0;}
189  };
190 
191  Evaluator m_volumeSel;
192  Evaluator m_panSel;
193  Evaluator m_pitchWheelSel;
194  Evaluator m_modWheelSel;
195  Evaluator m_pedalSel;
196  Evaluator m_portamentoSel;
197  Evaluator m_reverbSel;
198  Evaluator m_preAuxASel;
199  Evaluator m_preAuxBSel;
200  Evaluator m_auxAFxSel;
201  Evaluator m_auxBFxSel;
202  Evaluator m_postAuxB;
203  Evaluator m_spanSel;
204  Evaluator m_dopplerSel;
205  Evaluator m_tremoloSel;
206 
207  int32_t m_variables[256];
210  struct EventTrap
211  {
212  ObjectId macroId = 0xffff;
213  uint16_t macroStep;
214  };
215 
216 public:
218  void initialize(const unsigned char* ptr, int step);
219  void initialize(const unsigned char* ptr, int step, double ticksPerSec,
220  uint8_t midiKey, uint8_t midiVel, uint8_t midiMod);
221 
225  bool advance(Voice& vox, double dt);
226 
228  void keyoffNotify(Voice& vox);
229 
231  void sampleEndNotify(Voice& vox);
232 };
233 
234 }
235 
236 #endif // __AMUSE_SOUNDMACROSTATE_HPP__
void initialize(const unsigned char *ptr, int step)
void sampleEndNotify(Voice &vox)
bool advance(Voice &vox, double dt)
void keyoffNotify(Voice &vox)