SynthLab SDK
All Classes Files Functions Variables Typedefs Enumerations Modules Pages
synthlabds.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "pluginstructures.h"
4 #include "../../examples/synthlab_examples/synthengine.h"
5 
6 
7 // --------------------------------------
8 // --- OPTIONAL SynthLab SDK File --- //
9 // -------------------------------------
17 // -----------------------------------------------------------------------------
18 
20 
28 const uint32_t CUSTOM_OPTION_MENU = 131072;
29 const uint32_t CUSTOM_KNOB_LABEL = 131073;
30 const uint32_t CUSTOM_KNOB_LABEL_INDEX = 131074;
31 const uint32_t TOTAL_CUSTOM_VIEWS = 64;
32 const uint32_t CUSTOM_BITS = 31;
34 
35 
45 {
46  void clear()
47  {
48  droplistMask = 0;
49  droplistControl_ASPiK = nullptr;
50  droplistControl_RAFX = nullptr;
51  modKnobMask = 0;
52  controlStringCount = 0;
53 
54  for (uint32_t i = 0; i < 4; i++)
55  {
56  modKnobLabel_RAFX[i] = nullptr;
57  modKnobLabel_ASPiK[i] = nullptr;
58  }
59  }
60 
61  // --- need to allow BOTH RackAFX and the custom GUI to store info here
62  uint32_t droplistMask = 0;
63  ICustomView* droplistControl_RAFX = nullptr;
64  ICustomView* droplistControl_ASPiK = nullptr;
66 
67  uint32_t modKnobMask = 0;
68  ICustomView* modKnobLabel_RAFX[4] = { nullptr, nullptr, nullptr, nullptr };
69  ICustomView* modKnobLabel_ASPiK[4] = { nullptr, nullptr, nullptr, nullptr };
70  moodycamel::ReaderWriterQueue<std::string, 2> modKnobLabelDataQueue[4];
71 
72  // --- for drop-list type controls
73  uint32_t controlStringCount = 0;
74 };
75 
86 {
87  moduleAuxParamSet(uint32_t _attValCoreMenu, uint32_t _attValWaveMenu, uint32_t _attValModKnobs,
88  uint32_t _coreMenuCtrlID, uint32_t _waveMenuCtrlID,
89  uint32_t _modKnob_A_CtrlID, uint32_t _modKnob_B_CtrlID,
90  uint32_t _modKnob_C_CtrlID, uint32_t _modKnob_D_CtrlID)
91  : attValCoreMenu(_attValCoreMenu)
92  , attValWaveMenu(_attValWaveMenu)
93  , attValModKnobs(_attValModKnobs)
94  , coreMenuCtrlID(_coreMenuCtrlID)
95  , waveMenuCtrlID(_waveMenuCtrlID)
96  , modKnob_A_CtrlID(_modKnob_A_CtrlID)
97  , modKnob_B_CtrlID(_modKnob_B_CtrlID)
98  , modKnob_C_CtrlID(_modKnob_C_CtrlID)
99  , modKnob_D_CtrlID(_modKnob_D_CtrlID) {}
100 
101  uint32_t attValCoreMenu = SynthLab::LFO1_SOURCE;
102  uint32_t attValWaveMenu = SynthLab::LFO1_WAVEFORMS;
103  uint32_t attValModKnobs = SynthLab::LFO1_MOD_KNOBS;
104 
105  uint32_t coreMenuCtrlID = 0;
106  uint32_t waveMenuCtrlID = 0;
107  uint32_t modKnob_A_CtrlID = 0;
108  uint32_t modKnob_B_CtrlID = 0;
109  uint32_t modKnob_C_CtrlID = 0;
110  uint32_t modKnob_D_CtrlID = 0;
111 };
112 
129 {
130 public:
132  DynamicStringManager(std::shared_ptr<SynthLab::SynthEngine> _synthEngine, void* _pluginCore);
133  virtual ~DynamicStringManager() {}
134 
136 
141  bool setCustomUpdateCodes(uint32_t customUpdateCode_1, uint32_t customUpdateCode_2);
142  bool isCustomViewDataQueueEnabled() const { return queueEnabler.load(std::memory_order_relaxed); }
143  void enableCustomViewDataQueue(bool value) { queueEnabler.store(value, std::memory_order_relaxed); }
144  bool haveCustomUpdates() const { return updateEnabler.load(std::memory_order_relaxed); }
145  void enableCustomUpdates(bool value) { updateEnabler.store(value, std::memory_order_relaxed); }
146  bool updateCustomView(uint32_t slot);
147  bool setModKnobLabelView(uint32_t controlID, ICustomView* modKnobLabelControl, bool isRAFXView);
148  bool setCustomDroplistView(uint32_t controlID, ICustomView* _droplistControl, bool isRAFXView, bool isCoreList);
150 
162  inline std::vector<std::string> getModuleCoreNames(uint32_t moduleType)
163  {
164  std::vector<std::string> names = synthEngine->getModuleCoreNames(moduleType);
165  return names;
166  }
167 
172  inline void clearCustomViewInfo()
173  {
174  for (uint32_t i = 0; i < TOTAL_CUSTOM_VIEWS; i++)
175  {
176  customViewInfo[i].clear();
177  }
178  }
179 
180 protected:
181  std::shared_ptr<SynthLab::SynthEngine> synthEngine = nullptr;
182  void* pluginCore = nullptr;
183  uint32_t customUpdateCode_1 = 0.0;
185 
186 
195  inline int32_t customUpdateCodeToIndex(uint32_t code, uint32_t mask, bool upper32)
196  {
197  if ((code & mask) == 0)
198  return -1;
199 
200  int32_t tz = SynthLab::countTrailingZero(mask);
201  if (upper32)
202  return 31 + tz;
203 
204  return tz;
205  }
206 
214  inline int32_t customUpdateMaskToIndex(uint32_t mask, bool upper32)
215  {
216  int32_t tz = SynthLab::countTrailingZero(mask);
217  if (upper32)
218  return 31 + tz;
219 
220  return tz;
221  }
222 
223 
224  // --- helpers to prevent memory-creep
225  std::atomic<bool> queueEnabler;
226  std::atomic<bool> updateEnabler;
227 
238  inline void enqueueCustomData(uint32_t index)
239  {
240  if (!isCustomViewDataQueueEnabled()) return;
241 
242  if (customViewInfo[index].droplistControl_RAFX || customViewInfo[index].droplistControl_ASPiK)
243  {
244  uint32_t droplistMask = customViewInfo[index].droplistMask;
245 
246  // peeking is not allowed from the producer side!
247  // if(!customViewInfo[index].droplistDataQueue.peek())
248  size_t queueSize = customViewInfo[index].droplistDataQueue.size_approx();
249  if (queueSize == 0)
250  {
251  customViewInfo[index].droplistDataQueue.enqueue(synthEngine->getModuleStrings(droplistMask));
252  }
253  }
254  else
255  {
256  uint32_t modKnobMask = customViewInfo[index].modKnobMask;
257  std::vector<std::string> knobLabels = synthEngine->getModKnobStrings(modKnobMask);
258  uint32_t numLabels = knobLabels.size();
259  numLabels = fmin(numLabels, 4);
260  for (int i = 0; i < numLabels; i++)
261  {
262  // if (!customViewInfo[index].modKnobLabelDataQueue[i].peek())
263  size_t queueSize = customViewInfo[index].modKnobLabelDataQueue[i].size_approx();
264  if (queueSize == 0)
265  {
266  customViewInfo[index].modKnobLabelDataQueue[i].enqueue(knobLabels[i]);
267  }
268  }
269  }
270  }
271 
279  inline bool getWaveformStrings(uint32_t index, std::vector<std::string>& strings)
280  {
281  if (!customViewInfo[index].droplistControl_RAFX && !customViewInfo[index].droplistControl_ASPiK)
282  {
283  return false;
284  }
285 
286  bool success = customViewInfo[index].droplistDataQueue.try_dequeue(strings);
287 
288  // --- pop all
289  while (customViewInfo[index].droplistDataQueue.try_dequeue(strings))
290  /* NOOP */;
291 
292  return success;
293  }
294 
302  inline bool getModKnobLabel(uint32_t slot, uint32_t index, std::string& string)
303  {
304  if (!customViewInfo[slot].modKnobLabel_RAFX[index] && !customViewInfo[slot].modKnobLabel_ASPiK[index])
305  return false;
306 
307  bool success = customViewInfo[slot].modKnobLabelDataQueue[index].try_dequeue(string);
308 
309  // --- pop all
310  while (customViewInfo[slot].modKnobLabelDataQueue[index].try_dequeue(string))
311  /* NOOP */;
312 
313  return success;
314  }
315 
316 };
317 
bool setModKnobLabelView(uint32_t controlID, ICustomView *modKnobLabelControl, bool isRAFXView)
Adds a custom view interface pointer to the list of custom controls for mod knob labels.
Definition: synthlabds.cpp:96
void enableCustomViewDataQueue(bool value)
get atomic variable as float
Definition: synthlabds.h:143
const uint32_t LFO1_MOD_KNOBS
Definition: synthconstants.h:197
bool haveCustomUpdates() const
set atomic variable with float
Definition: synthlabds.h:144
std::atomic< bool > queueEnabler
atomic bool for enabling/disabling the queue
Definition: synthlabds.h:225
Definition: readerwriterqueue.h:60
Definition: synthlabds.h:85
bool isCustomViewDataQueueEnabled() const
set atomic variable with float
Definition: synthlabds.h:142
bool setCustomDroplistView(uint32_t controlID, ICustomView *_droplistControl, bool isRAFXView, bool isCoreList)
Adds a custom view interface pointer to the list of custom controls for drop-lists or list controls...
Definition: synthlabds.cpp:46
void enableCustomUpdates(bool value)
get atomic variable as float
Definition: synthlabds.h:145
int countTrailingZero(int x)
count trailing zeros in a binary number
Definition: synthfunctions.h:1577
void enqueueCustomData(uint32_t index)
Queues up GUI dynamic strings for reloading into the GUI. The operation is asynchronous thus the queu...
Definition: synthlabds.h:238
const uint32_t CUSTOM_BITS
Definition: synthlabds.h:32
const uint32_t CUSTOM_KNOB_LABEL_INDEX
Definition: synthlabds.h:30
bool updateCustomView(uint32_t slot)
Sets information about the custom view including the strings for the controls.
Definition: synthlabds.cpp:186
const uint32_t LFO1_SOURCE
Definition: synthconstants.h:164
Definition: synthlabds.h:44
void clearCustomViewInfo()
simple clearing of data
Definition: synthlabds.h:172
int32_t customUpdateMaskToIndex(uint32_t mask, bool upper32)
Converts a custom update mask (bits in a uint32_t) into an index for the custom view information arra...
Definition: synthlabds.h:214
bool getModKnobLabel(uint32_t slot, uint32_t index, std::string &string)
De-queue the lists to see if there are mod knob labels for a GUI control.
Definition: synthlabds.h:302
DynamicStringManager(std::shared_ptr< SynthLab::SynthEngine > _synthEngine, void *_pluginCore)
Constructs the manager object; the manager needs access to the synth engine to query it for custom GU...
Definition: synthlabds.cpp:27
bool getWaveformStrings(uint32_t index, std::vector< std::string > &strings)
De-queue the lists to see if there are waveform strings for a GUI control.
Definition: synthlabds.h:279
bool setCustomUpdateCodes(uint32_t customUpdateCode_1, uint32_t customUpdateCode_2)
Functions for dealing with a custom update code uint32_t where each bit encodes a particular GUI cont...
Definition: synthlabds.cpp:137
const uint32_t CUSTOM_OPTION_MENU
Definition: synthlabds.h:28
CustomViewInfo customViewInfo[TOTAL_CUSTOM_VIEWS]
one slot per bit * 2 because MSB sets more stuff
Definition: synthlabds.h:184
int32_t customUpdateCodeToIndex(uint32_t code, uint32_t mask, bool upper32)
Converts a custom update code (bits in a uint32_t) into an index for the custom view information arra...
Definition: synthlabds.h:195
const uint32_t CUSTOM_KNOB_LABEL
Definition: synthlabds.h:29
Dynamic string manager - this object connects plugin parameters and their GUI controls with new or di...
Definition: synthlabds.h:128
std::atomic< bool > updateEnabler
atomic bool for enabling/disabling the queue
Definition: synthlabds.h:226
std::vector< std::string > getModuleCoreNames(uint32_t moduleType)
This demonstrates how to get the module core names from the engine.
Definition: synthlabds.h:162
const uint32_t TOTAL_CUSTOM_VIEWS
Definition: synthlabds.h:31
const uint32_t LFO1_WAVEFORMS
Definition: synthconstants.h:153