ASPiK SDK
customcontrols.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ASPiK Custom Controls File: customcontrols.h
3 //
12 // -----------------------------------------------------------------------------
13 #ifndef __CustomControls__
14 #define __CustomControls__
15 
16 #include "vstgui/lib/controls/cbuttons.h"
17 #include "vstgui/lib/controls/cknob.h"
18 #include "vstgui/lib/cframe.h"
19 #include "vstgui/lib/controls/cslider.h"
20 #include "vstgui/lib/controls/cvumeter.h"
21 #include "vstgui/lib/controls/cxypad.h"
22 #include "vstgui/vstgui.h"
23 #include "vstgui/lib/vstguibase.h"
24 #include "guiconstants.h"
25 
26 namespace VSTGUI {
27 
41 enum mouseAction {mouseDirUpAndDown, mouseDirUp, mouseDirDown};
42 
55 class CKickButtonEx : public CKickButton
56 {
57 public:
58  CKickButtonEx(const CRect& size, IControlListener* listener, int32_t tag, CBitmap* background, const CPoint& offset = CPoint (0, 0));
59 
65  virtual CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override;
66 
72  virtual CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override;
73 
78  void setMouseMode(unsigned int mode){mouseBehavior = mode;}
79 
80 private:
81  float entryState = 0.0;
82  unsigned int mouseBehavior = 0;
83 };
84 
97 class TextButtonEx : public CTextButton
98 {
99 public:
100  TextButtonEx(const CRect& size, IControlListener* listener, int32_t tag, UTF8StringPtr title = 0, CTextButton::Style = kKickStyle);
101 
102  void draw(CDrawContext* context) override;
103 
109  virtual CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;
110 
116  virtual CMouseEventResult onMouseMoved(CPoint& where, const CButtonState& buttons) override;
117 
123  virtual CMouseEventResult onMouseUp(CPoint& where, const CButtonState& buttons) override;
124 
129  void setMouseMode(unsigned int uMode) { mouseBehavior = uMode; }
130 
131 private:
132  float entryState = 0.0;
133  unsigned int mouseBehavior = 0;
134 };
135 
148 class CAnimKnobEx : public CAnimKnob
149 {
150 public:
151  CAnimKnobEx(const CRect& size, IControlListener* listener, int32_t tag, int32_t subPixmaps,
152  CCoord heightOfOneImage, CBitmap* background, const CPoint &offset,
153  bool bSwitchKnob = false);
154 
155  virtual void draw (CDrawContext* pContext) override;
156 
162  CMouseEventResult onMouseUp(CPoint& where, const CButtonState& buttons) override;
163 
169  CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;
170 
176  virtual CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
177 
178  bool checkDefaultValue (CButtonState button) override;
179  virtual void valueChanged() override;
180 
185  void setSwitchMax(float f){maxControlValue = f;}
186 
191  bool isSwitchKnob(){return switchKnob;}
192 
197  void setAAXKnob(bool b){aaxKnob = b;}
198 
203  bool isAAXKnob(){return aaxKnob;}
204 
205 protected:
206  bool switchKnob = false;
207  bool aaxKnob = false;
208  float maxControlValue = 1.0;
209  virtual ~CAnimKnobEx(void);
210 
211 private:
212  CPoint firstPoint;
213  CPoint lastPoint;
214  float startValue;
215  float fEntryState;
216  float range;
217  float coef;
218  CButtonState oldButton;
219  bool modeLinear;
220 
221 };
222 
235 class CVerticalSliderEx : public CVerticalSlider
236 {
237 public:
238  CVerticalSliderEx (const CRect& size, IControlListener* listener, int32_t tag, int32_t iMinPos, int32_t iMaxPos, CBitmap* handle, CBitmap* background, const CPoint& offset = CPoint (0, 0), const int32_t style = kBottom);
239 
240  // overrides
241  virtual void draw (CDrawContext*) override;
242 
248  CMouseEventResult onMouseUp(CPoint& where, const CButtonState& buttons) override;
249 
255  CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;
256 
262  virtual CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
263 
264  bool checkDefaultValue (CButtonState button) override;
265 
270  void setSwitchMax(float f){maxControlValue = f;}
271 
276  bool isSwitchSlider(){return switchSlider;}
277 
282  void setSwitchSlider(bool b){switchSlider = b;}
283 
288  void setAAXSlider(bool b){aaxSlider = b;}
289 
294  bool isAAXSlider(){return aaxSlider;}
295 
296  CLASS_METHODS(CVerticalSliderEx, CControl)
297 
298 protected:
299  ~CVerticalSliderEx ();
300  bool switchSlider;
301  bool aaxSlider;
302  float maxControlValue;
303 
304 private:
305  CCoord delta;
306  float oldVal;
307  float startVal;
308  CButtonState oldButton;
309  CPoint mouseStartPoint;
310 };
311 
312 
325 class CHorizontalSliderEx : public CHorizontalSlider
326 {
327 public:
328  CHorizontalSliderEx (const CRect& size, IControlListener* listener, int32_t tag, int32_t iMinPos, int32_t iMaxPos, CBitmap* handle, CBitmap* background, const CPoint& offset = CPoint (0, 0), const int32_t style = kLeft);
329 
330  // overrides
331  virtual void draw (CDrawContext*) override;
332 
338  CMouseEventResult onMouseUp(CPoint& where, const CButtonState& buttons) override;
339 
345  CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;
346 
352  virtual CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
353 
354  bool checkDefaultValue (CButtonState button) override;
355 
360  void setSwitchMax(float f){maxControlValue = f;}
361 
366  void setSwitchSlider(bool b){switchSlider = b;}
367 
372  bool isSwitchSlider(){return switchSlider;}
373 
378  void setAAXSlider(bool b){aaxSlider = b;}
379 
384  bool isAAXSlider(){return aaxSlider;}
385 
386  CLASS_METHODS(CHorizontalSliderEx, CControl)
387 
388 protected:
390  bool switchSlider;
391  float maxControlValue;
392  bool aaxSlider;
393 
394 private:
395  CCoord delta;
396  float oldVal;
397  float startVal;
398  CButtonState oldButton;
399  CPoint mouseStartPoint;
400 };
401 
414 {
415 public:
416  CMeterDetector(void);
417  ~CMeterDetector(void);
418 
419 public:
420 
421  // Call the Init Function to initialize and setup all at once; this can be called as many times
422  // as you want
423  void init(float samplerate, float attack_in_ms, float release_in_ms, bool bAnalogTC, unsigned int uDetect, bool bLogDetector);
424 
425  // these functions allow you to change modes and attack/release one at a time during
426  // realtime operation
427  void setTCModeAnalog(bool _analogTC);
428 
429  // THEN do these after init
430  void setAttackTime(float attack_in_ms);
431  void setReleaseTime(float release_in_ms);
432 
433  // --- see guiconstants.h
434  // ENV_DETECT_MODE_PEAK = 0;
435  // ENV_DETECT_MODE_MS = 1;
436  // ENV_DETECT_MODE_RMS = 2;
437  // ENV_DETECT_MODE_NONE = 3;
438  void setDetectMode(unsigned int _detectMode) {detectMode = _detectMode;}
439 
440  void setSampleRate(float f)
441  {
442  detectorSampleRate = f;
443 
444  setAttackTime(attackTime_mSec);
445  setReleaseTime(releaseTime_mSec);
446  }
447 
448  void setLogDetect(bool b) {logDetector = b;}
449 
450  // call this to detect; it returns the peak ms or rms value at that instant
451  float detect(float input);
452 
453  // call this from your prepareForPlay() function each time to reset the detector
454  void prepareForPlay();
455 
456  void resetPeakHold(){ peakEnvelope = -1.0; }
457  void setPeakHold(bool b) { peakHold = b; }
458 
459 protected:
460  float attackTime;
461  float m_fReleaseTime;
462  float attackTime_mSec;
463  float releaseTime_mSec;
464  float detectorSampleRate;
465  float envelope;
466  float peakEnvelope;
467  bool analogTC;
468  bool logDetector;
469  unsigned int detectMode;
470  bool peakHold;
471 
472  void setEnvelope(float value)
473  {
474  if(!peakHold)
475  {
476  envelope = value;
477  return;
478  }
479 
480  // --- holding peak
481  if(value > peakEnvelope)
482  {
483  peakEnvelope = value;
484  envelope = value;
485  }
486  }
487 };
488 
501 class CVuMeterEx : public CVuMeter
502 {
503 public:
504  CVuMeterEx(const CRect& size, CBitmap* onBitmap, CBitmap* offBitmap, int32_t nbLed, bool bInverted, bool bAnalogVU, int32_t style = kVertical);
505 
506  CVuMeterEx(void);
507  ~CVuMeterEx(void);
508 
509  // --- overrides!
510  virtual void draw(CDrawContext* pContext) override;
511  virtual void setViewSize (const CRect& newSize, bool invalid = true) override;
512 
513  inline void initDetector(float samplerate, float attack_in_ms, float release_in_ms, bool bAnalogTC, unsigned int uDetect, bool bLogDetector)
514  {
515  detector.init(samplerate, attack_in_ms, release_in_ms, bAnalogTC, uDetect, bLogDetector);
516  detector.prepareForPlay();
517  }
518 
519  void setHtOneImage(double d){heightOfOneImage = d;}
520  void setImageCount(double d){subPixMaps = d;}
521  void setZero_dB_Frame(double d){zero_dB_Frame = d;}
522 
523 protected:
524  bool isInverted;
525  bool isAnalogVU;
526  double zero_dB_Frame;
527  double heightOfOneImage;
528  double subPixMaps;
529 
530  CMeterDetector detector;
531 };
532 
545 class CXYPadEx : public CXYPad
546 {
547 public:
548  CXYPadEx(const CRect& size = CRect (0, 0, 0, 0));
549 
550  // --- for easy trackpad and XY stuff
551 public:
552  void setTagX(int32_t tag){tagX = tag;}
553  int32_t getTagX(){return tagX;}
554 
555  void setTagY(int32_t tag){tagY = tag;}
556  int32_t getTagY(){return tagY;}
557 
558  // --- overrides
559  void draw(CDrawContext* context) override;
560 
566  CMouseEventResult onMouseMoved(CPoint& where, const CButtonState& buttons) override;
567 
573  CMouseEventResult onMouseUp(CPoint& where, const CButtonState& buttons) override;
574 
580  CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;
581  virtual void setValue(float val) override;
582 
583  // --- for vector joystick operation
584  inline int pointInPolygon(int nvert, float *vertx, float *verty, float testx, float testy)
585  {
586  int i, j, c = 0;
587  for (i = 0, j = nvert-1; i < nvert; j = i++)
588  {
589  if ( ((verty[i]>testy) != (verty[j]>testy)) &&
590  (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
591  c = !c;
592  }
593  return c;
594  }
595 
596  static void calculateXY (float value, float& x, float& y)
597  {
598  x = std::floor (value * 1000.f + 0.5f) * 0.001f;
599  y = std::floor ((value - x) * 10000000.f + 0.5f) * 0.001f;
600  y = -1.f*y + 1.f;
601  }
602 
603  static float calculateValue (float x, float y)
604  {
605  y = -1.f*y + 1.f;
606  x = std::floor (x * 1000.f + 0.5f) * 0.001f;
607  y = std::floor (y * 1000.f + 0.5f) * 0.0000001f;
608  return x + y;
609  }
610 
611 protected:
612  int32_t tagX;
613  int32_t tagY;
614  bool isJoystickPad;
615 
616  float vertX[4];
617  float vertY[4];
618 
619  float lastX;
620  float lastY;
621 };
622 
623 
624 }
625 
626 #endif
virtual CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
handle mouse moved event
Definition: customcontrols.cpp:97
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:334
virtual CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:37
bool isAAXKnob()
query if control wants Pro Tools keyboard modifiers
Definition: customcontrols.h:203
virtual void setValue(float val) override
Definition: customcontrols.cpp:1189
The CAnimKnobEx object extends the VSTGUI CAnimKnob object with extra functionality. It is used in the PluginGUI object for creating custom views.
Definition: customcontrols.h:148
CKickButtonEx(const CRect &size, IControlListener *listener, int32_t tag, CBitmap *background, const CPoint &offset=CPoint(0, 0))
CKickButtonEx constructor.
Definition: customcontrols.cpp:31
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:278
bool isAAXSlider()
query if control wants Pro Tools keyboard modifiers
Definition: customcontrols.h:294
The TextButtonEx object extends the VSTGUI CTextButton object with extra functionality. It is used in the PluginGUI object for creating custom views.
Definition: customcontrols.h:97
void setSwitchMax(float f)
set max discrete switching value
Definition: customcontrols.h:270
virtual CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:61
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:1222
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:560
void setAAXSlider(bool b)
sets the AAX flag for this control
Definition: customcontrols.h:378
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:808
bool isSwitchKnob()
query if control is in "switch" mode
Definition: customcontrols.h:191
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:1241
bool isSwitchSlider()
query if control is in "switch" mode
Definition: customcontrols.h:372
void setMouseMode(unsigned int uMode)
set the mouse behavior (down, up, or down/up)
Definition: customcontrols.h:129
void setAAXKnob(bool b)
sets the AAX flag for this control
Definition: customcontrols.h:197
virtual CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
handle mouse moved event
Definition: customcontrols.cpp:340
mouseAction
Use this enum to set the mouse behavior for kick button.
Definition: customcontrols.h:41
Definition: customcontrols.cpp:20
void setSwitchMax(float f)
set max discrete switching value
Definition: customcontrols.h:185
virtual CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
handle mouse moved event
Definition: customcontrols.cpp:600
The CVuMeterEx object extends the VSTGUI CVuMeter object with extra functionality. It is used in the PluginGUI object for creating custom views.
Definition: customcontrols.h:501
The CHorizontalSliderEx object extends the VSTGUI CHorizontalSlider object with extra functionality...
Definition: customcontrols.h:325
globally utilized constants and enumerations
virtual CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
handle mouse moved event
Definition: customcontrols.cpp:848
void setSwitchMax(float f)
set max discrete switching value
Definition: customcontrols.h:360
void setSwitchSlider(bool b)
sets the control into "switch" mode
Definition: customcontrols.h:366
TextButtonEx(const CRect &size, IControlListener *listener, int32_t tag, UTF8StringPtr title=0, CTextButton::Style=kKickStyle)
TextButtonEx constructor.
Definition: customcontrols.cpp:90
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:841
void setSwitchSlider(bool b)
sets the control into "switch" mode
Definition: customcontrols.h:282
The CXYPadEx object extends the CXYPad CVuMeter object with extra functionality. It is used in the Pl...
Definition: customcontrols.h:545
virtual CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:184
virtual CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:151
The CVerticalSliderEx object extends the VSTGUI CVerticalSlider object with extra functionality...
Definition: customcontrols.h:235
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
handle mouse moved event
Definition: customcontrols.cpp:1246
bool isAAXSlider()
query if control wants Pro Tools keyboard modifiers
Definition: customcontrols.h:384
bool isSwitchSlider()
query if control is in "switch" mode
Definition: customcontrols.h:276
void setAAXSlider(bool b)
sets the AAX flag for this control
Definition: customcontrols.h:288
void setMouseMode(unsigned int mode)
set the mouse behavior (down, up, or down/up)
Definition: customcontrols.h:78
The CKickButtonEx object extends the VSTGUI CKickButton object with extra functionality. It is used in the PluginGUI object for creating custom views.
Definition: customcontrols.h:55
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:593
The CMeterDetector object provides a dedicated detector for VU meter objects.
Definition: customcontrols.h:413