ASPiK SDK
Loading...
Searching...
No Matches
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
26namespace VSTGUI {
27
41enum mouseAction {mouseDirUpAndDown, mouseDirUp, mouseDirDown};
42
55class CKickButtonEx : public CKickButton
56{
57public:
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
80private:
81 float entryState = 0.0;
82 unsigned int mouseBehavior = 0;
83};
84
97class TextButtonEx : public CTextButton
98{
99public:
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
131private:
132 float entryState = 0.0;
133 unsigned int mouseBehavior = 0;
134};
135
148class CAnimKnobEx : public CAnimKnob
149{
150public:
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);
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
205protected:
206 bool switchKnob = false;
207 bool aaxKnob = false;
208 float maxControlValue = 1.0;
209 virtual ~CAnimKnobEx(void);
210
211private:
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
235class CVerticalSliderEx : public CVerticalSlider
236{
237public:
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
245 CMouseEventResult onMouseUp(CPoint& where, const CButtonState& buttons) override;
246
252 CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;
253
259 virtual CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
260
261 bool checkDefaultValue (CButtonState button);
262
267 void setSwitchMax(float f){maxControlValue = f;}
268
273 bool isSwitchSlider(){return switchSlider;}
274
279 void setSwitchSlider(bool b){switchSlider = b;}
280
285 void setAAXSlider(bool b){aaxSlider = b;}
286
291 bool isAAXSlider(){return aaxSlider;}
292
293 CLASS_METHODS(CVerticalSliderEx, CControl)
294
295protected:
297 bool switchSlider;
298 bool aaxSlider;
299 float maxControlValue;
300
301private:
302 CCoord delta;
303 float oldVal;
304 float startVal;
305 CButtonState oldButton;
306 CPoint mouseStartPoint;
307};
308
309
322class CHorizontalSliderEx : public CHorizontalSlider
323{
324public:
325 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);
326
332 CMouseEventResult onMouseUp(CPoint& where, const CButtonState& buttons) override;
333
339 CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;
340
346 virtual CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override;
347
348 bool checkDefaultValue (CButtonState button);
349
354 void setSwitchMax(float f){maxControlValue = f;}
355
360 void setSwitchSlider(bool b){switchSlider = b;}
361
366 bool isSwitchSlider(){return switchSlider;}
367
372 void setAAXSlider(bool b){aaxSlider = b;}
373
378 bool isAAXSlider(){return aaxSlider;}
379
380 CLASS_METHODS(CHorizontalSliderEx, CControl)
381
382protected:
384 bool switchSlider;
385 float maxControlValue;
386 bool aaxSlider;
387
388private:
389 CCoord delta;
390 float oldVal;
391 float startVal;
392 CButtonState oldButton;
393 CPoint mouseStartPoint;
394};
395
408{
409public:
410 CMeterDetector(void);
411 ~CMeterDetector(void);
412
413public:
414
415 // Call the Init Function to initialize and setup all at once; this can be called as many times
416 // as you want
417 void init(float samplerate, float attack_in_ms, float release_in_ms, bool bAnalogTC, unsigned int uDetect, bool bLogDetector);
418
419 // these functions allow you to change modes and attack/release one at a time during
420 // realtime operation
421 void setTCModeAnalog(bool _analogTC);
422
423 // THEN do these after init
424 void setAttackTime(float attack_in_ms);
425 void setReleaseTime(float release_in_ms);
426
427 // --- see guiconstants.h
428 // ENV_DETECT_MODE_PEAK = 0;
429 // ENV_DETECT_MODE_MS = 1;
430 // ENV_DETECT_MODE_RMS = 2;
431 // ENV_DETECT_MODE_NONE = 3;
432 void setDetectMode(unsigned int _detectMode) {detectMode = _detectMode;}
433
434 void setSampleRate(float f)
435 {
436 detectorSampleRate = f;
437
438 setAttackTime(attackTime_mSec);
439 setReleaseTime(releaseTime_mSec);
440 }
441
442 void setLogDetect(bool b) {logDetector = b;}
443
444 // call this to detect; it returns the peak ms or rms value at that instant
445 float detect(float input);
446
447 // call this from your prepareForPlay() function each time to reset the detector
448 void prepareForPlay();
449
450 void resetPeakHold(){ peakEnvelope = -1.0; }
451 void setPeakHold(bool b) { peakHold = b; }
452
453protected:
454 float attackTime;
455 float m_fReleaseTime;
456 float attackTime_mSec;
457 float releaseTime_mSec;
458 float detectorSampleRate;
459 float envelope;
460 float peakEnvelope;
461 bool analogTC;
462 bool logDetector;
463 unsigned int detectMode;
464 bool peakHold;
465
466 void setEnvelope(float value)
467 {
468 if(!peakHold)
469 {
470 envelope = value;
471 return;
472 }
473
474 // --- holding peak
475 if(value > peakEnvelope)
476 {
477 peakEnvelope = value;
478 envelope = value;
479 }
480 }
481};
482
495class CVuMeterEx : public CVuMeter
496{
497public:
498 CVuMeterEx(const CRect& size, CBitmap* onBitmap, CBitmap* offBitmap, int32_t nbLed, bool bInverted, bool bAnalogVU, int32_t style = kVertical);
499
500 CVuMeterEx(void);
501 ~CVuMeterEx(void);
502
503 // --- overrides!
504 virtual void draw(CDrawContext* pContext) override;
505 virtual void setViewSize (const CRect& newSize, bool invalid = true) override;
506
507 inline void initDetector(float samplerate, float attack_in_ms, float release_in_ms, bool bAnalogTC, unsigned int uDetect, bool bLogDetector)
508 {
509 detector.init(samplerate, attack_in_ms, release_in_ms, bAnalogTC, uDetect, bLogDetector);
510 detector.prepareForPlay();
511 }
512
513 void setHtOneImage(double d){heightOfOneImage = d;}
514 void setImageCount(double d){subPixMaps = d;}
515 void setZero_dB_Frame(double d){zero_dB_Frame = d;}
516
517protected:
518 bool isInverted;
519 bool isAnalogVU;
520 double zero_dB_Frame;
521 double heightOfOneImage;
522 double subPixMaps;
523
524 CMeterDetector detector;
525};
526
539class CXYPadEx : public CXYPad
540{
541public:
542 CXYPadEx(const CRect& size = CRect (0, 0, 0, 0));
543
544 // --- for easy trackpad and XY stuff
545public:
546 void setTagX(int32_t tag){tagX = tag;}
547 int32_t getTagX(){return tagX;}
548
549 void setTagY(int32_t tag){tagY = tag;}
550 int32_t getTagY(){return tagY;}
551
552 // --- overrides
553 void draw(CDrawContext* context) override;
554
560 CMouseEventResult onMouseMoved(CPoint& where, const CButtonState& buttons) override;
561
567 CMouseEventResult onMouseUp(CPoint& where, const CButtonState& buttons) override;
568
574 CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;
575 virtual void setValue(float val) override;
576
577 // --- for vector joystick operation
578 inline int pointInPolygon(int nvert, float *vertx, float *verty, float testx, float testy)
579 {
580 int i, j, c = 0;
581 for (i = 0, j = nvert-1; i < nvert; j = i++)
582 {
583 if ( ((verty[i]>testy) != (verty[j]>testy)) &&
584 (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
585 c = !c;
586 }
587 return c;
588 }
589
590 static void calculateXY (float value, float& x, float& y)
591 {
592 x = std::floor (value * 1000.f + 0.5f) * 0.001f;
593 y = std::floor ((value - x) * 10000000.f + 0.5f) * 0.001f;
594 y = -1.f*y + 1.f;
595 }
596
597 static float calculateValue (float x, float y)
598 {
599 y = -1.f*y + 1.f;
600 x = std::floor (x * 1000.f + 0.5f) * 0.001f;
601 y = std::floor (y * 1000.f + 0.5f) * 0.0000001f;
602 return x + y;
603 }
604
605protected:
606 int32_t tagX;
607 int32_t tagY;
608 bool isJoystickPad;
609
610 float vertX[4];
611 float vertY[4];
612
613 float lastX;
614 float lastY;
615};
616
617
618class CReadOnlyKnob : public CAnimKnob
619{
620public:
621 CReadOnlyKnob(const CRect& size, IControlListener* listener, int32_t tag, int32_t subPixmaps,
622 CCoord heightOfOneImage, CBitmap* background, const CPoint &offset)
623 : CAnimKnob(size, listener, tag, subPixmaps, heightOfOneImage, background, offset)
624 {}
625
631 CMouseEventResult onMouseUp(CPoint& where, const CButtonState& buttons) override
632 {
633 return kMouseEventHandled;
634 }
635
641 CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override
642 {
643 return kMouseEventHandled;
644 }
645
651 virtual CMouseEventResult onMouseMoved(CPoint& where, const CButtonState& buttons) override
652 {
653 return kMouseEventHandled;
654 }
655
656 virtual void valueChanged() override
657 {
658 return;
659 }
660
661protected:
662 virtual ~CReadOnlyKnob(void) {}
663
664};
665
666
667}
668
669#endif
The CAnimKnobEx object extends the VSTGUI CAnimKnob object with extra functionality....
Definition: customcontrols.h:149
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:339
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:345
bool isSwitchKnob()
query if control is in "switch" mode
Definition: customcontrols.h:191
void setAAXKnob(bool b)
sets the AAX flag for this control
Definition: customcontrols.h:197
bool isAAXKnob()
query if control wants Pro Tools keyboard modifiers
Definition: customcontrols.h:203
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:283
The CHorizontalSliderEx object extends the VSTGUI CHorizontalSlider object with extra functionality....
Definition: customcontrols.h:323
void setAAXSlider(bool b)
sets the AAX flag for this control
Definition: customcontrols.h:372
virtual CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
handle mouse moved event
Definition: customcontrols.cpp:534
void setSwitchSlider(bool b)
sets the control into "switch" mode
Definition: customcontrols.h:360
void setSwitchMax(float f)
set max discrete switching value
Definition: customcontrols.h:354
bool isSwitchSlider()
query if control is in "switch" mode
Definition: customcontrols.h:366
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:527
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:516
bool isAAXSlider()
query if control wants Pro Tools keyboard modifiers
Definition: customcontrols.h:378
The CKickButtonEx object extends the VSTGUI CKickButton object with extra functionality....
Definition: customcontrols.h:56
virtual CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:61
virtual CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:37
void setMouseMode(unsigned int mode)
set the mouse behavior (down, up, or down/up)
Definition: customcontrols.h:78
The CMeterDetector object provides a dedicated detector for VU meter objects.
Definition: customcontrols.h:408
Definition: customcontrols.h:619
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.h:641
virtual CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
handle mouse moved event
Definition: customcontrols.h:651
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.h:631
The CVerticalSliderEx object extends the VSTGUI CVerticalSlider object with extra functionality....
Definition: customcontrols.h:236
void setSwitchMax(float f)
set max discrete switching value
Definition: customcontrols.h:267
virtual CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
handle mouse moved event
Definition: customcontrols.cpp:460
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:453
void setSwitchSlider(bool b)
sets the control into "switch" mode
Definition: customcontrols.h:279
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:442
bool isSwitchSlider()
query if control is in "switch" mode
Definition: customcontrols.h:273
bool isAAXSlider()
query if control wants Pro Tools keyboard modifiers
Definition: customcontrols.h:291
void setAAXSlider(bool b)
sets the AAX flag for this control
Definition: customcontrols.h:285
The CVuMeterEx object extends the VSTGUI CVuMeter object with extra functionality....
Definition: customcontrols.h:496
The CXYPadEx object extends the CXYPad CVuMeter object with extra functionality. It is used in the Pl...
Definition: customcontrols.h:540
CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:894
CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:875
CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
handle mouse moved event
Definition: customcontrols.cpp:899
virtual void setValue(float val) override
Definition: customcontrols.cpp:842
The TextButtonEx object extends the VSTGUI CTextButton object with extra functionality....
Definition: customcontrols.h:98
virtual CMouseEventResult onMouseUp(CPoint &where, const CButtonState &buttons) override
handle mouse up event
Definition: customcontrols.cpp:151
void setMouseMode(unsigned int uMode)
set the mouse behavior (down, up, or down/up)
Definition: customcontrols.h:129
virtual CMouseEventResult onMouseMoved(CPoint &where, const CButtonState &buttons) override
handle mouse moved event
Definition: customcontrols.cpp:97
virtual CMouseEventResult onMouseDown(CPoint &where, const CButtonState &buttons) override
handle mouse down event
Definition: customcontrols.cpp:184
mouseAction
Use this enum to set the mouse behavior for kick button.
Definition: customcontrols.h:41
globally utilized constants and enumerations