-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUiControlModules.cpp
More file actions
156 lines (139 loc) · 4.08 KB
/
UiControlModules.cpp
File metadata and controls
156 lines (139 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "uiControlModules.h"
#include "IControls.h"
VuMeterControl::VuMeterControl(const IRECT& bounds, IColor color, int ctrlTag)
: IControl(bounds), mCtrlTag(ctrlTag) {
}
void VuMeterControl::Draw(IGraphics& g)
{
g.FillRect(mColor, mRECT);
g.FillRect(COLOR_BLACK, mRECT.GetPadded(-2).FracRectVertical(mValue));
}
void VuMeterControl::SetValueFromDelegate(double val, int valIdx) {
mValue = val;
mColor = IColor(200, 225 * mValue, 30, 122);
SetDirty(false);
}
dynamicPlot::dynamicPlot(const IRECT& bounds, std::function<double(double)> func, const char* label)
:
IVPlotControl(bounds, {Plot{COLOR_WHITE, func}}, 2048, label) {
}
void dynamicPlot::OnMsgFromDelegate(int msgTag, int dataSize, const void* pData)
{
if (msgTag== kPlotOut) {
const double newGain = *static_cast<const double*>(pData) / 100.;
if (newGain != gainOut)
{
gainOut = newGain;
this->mPlots[0].func = getPlotFunc(mWaveType, gainIn, gainOut, mix, clip);
SetDirty();
}
}
else if (msgTag== kPlotIn)
{
const double newGain = *static_cast<const double*>(pData) / 100.;
if (newGain != gainIn)
{
gainIn = newGain;
this->mPlots[0].func = getPlotFunc(mWaveType, gainIn, gainOut, mix, clip);
SetDirty();
}
}
else if (msgTag== kPlotWaveType)
{
const Waveform newWaveType = static_cast<Waveform>(*static_cast<const int*>(pData));
if (newWaveType != mWaveType)
{
mWaveType = newWaveType;
this->mPlots[0].func = getPlotFunc(mWaveType, gainIn, gainOut, mix, clip);
SetDirty();
}
}
else if (msgTag == kPlotMix)
{
const double newMix = *static_cast<const double*>(pData) / 100.;
if (newMix != mix)
{
mix = newMix;
this->mPlots[0].func = getPlotFunc(mWaveType, gainIn, gainOut, mix, clip);
SetDirty();
}
}
else if (msgTag == kPlotClip)
{
const double newClip = *static_cast<const double*>(pData) / 100.;
if (newClip != clip)
{
clip = newClip;
this->mPlots[0].func = getPlotFunc(mWaveType, gainIn, gainOut, mix, clip);
SetDirty();
}
}
else
{
assert(false);
}
}
std::function<double(double)> dynamicPlot::getPlotFunc(Waveform waveType, double gainIn, double gainOut, double mix, double clip)
{
const auto algo = mAlgo.getAlgo(waveType);
return [algo, gainIn, gainOut, mix, clip](double x) -> double {
double procesed = algo((x * 2. - 1.) * gainIn) * gainOut;
if (clip < 5 && std::abs(procesed) > clip)
{
procesed = procesed / std::abs(procesed) * clip;
}
return procesed * mix + (x * 2. - 1) * (1. - mix);
};
}
void LfoModuleControl::Draw(IGraphics& g)
{
if (isHostClocked)
{
mRatioControl->Draw(g);
}
else
{
mFreqControl->Draw(g);
}
}
void LfoModuleControl::SetValueFromDelegate(double val, int valIdx) {
isHostClocked = static_cast<bool>(val);
if (isHostClocked)
{
mFreqControl->Hide(true);
mRatioControl->Hide(false);
}
else
{
mFreqControl->Hide(false);
mRatioControl->Hide(true);
}
SetDirty(false);
}
void ModKnobControl::DrawWidget(IGraphics& g) {
float widgetRadius; // The radius out to the indicator track arc
if (mWidgetBounds.W() > mWidgetBounds.H())
widgetRadius = (mWidgetBounds.H() / 2.f);
else
widgetRadius = (mWidgetBounds.W() / 2.f);
const float cx = mWidgetBounds.MW(), cy = mWidgetBounds.MH();
widgetRadius -= (mTrackSize / 2.f);
IRECT knobHandleBounds = mWidgetBounds.GetCentredInside((widgetRadius - mTrackToHandleDistance) * 2.f);
const float angle = mAngle1 + (static_cast<float>(GetValue()) * (mAngle2 - mAngle1));
mAnchorAngle = angle;
DrawIndicatorTrack(g, mVal + angle, cx, cy, widgetRadius);
DrawPressableShape(g, /*mShape*/ EVShape::Ellipse, knobHandleBounds, mMouseDown, mMouseIsOver, IsDisabled());
DrawPointer(g, angle, cx, cy, knobHandleBounds.W() / 2.f);
}
void ModKnobControl::OnMsgFromDelegate(int msgTag, int msgSize, const void* msg)
{
if (!IsDisabled())
{
const double newMVal = *static_cast<const double*>(msg);
if (newMVal != mVal)
{
mVal = newMVal;
SetDirty(false);
}
}
}