-
Notifications
You must be signed in to change notification settings - Fork 0
/
CorePlugBase.cpp
232 lines (202 loc) · 5.87 KB
/
CorePlugBase.cpp
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include "CorePlugBase.h"
CorePlugBase::CorePlugBase(
IPlugInstanceInfo instanceInfo,
int nParams,
int nPresets,
IGraphics* pGraphics,
const char* channelIOStr,
const char* effectName,
const char* mfrName,
int vendorVersion,
int uniqueID,
int mfrID,
int latency,
bool plugDoesMidi,
bool plugDoesChunks,
bool plugIsInst,
int plugAPI) :
IPlug(
instanceInfo,
nParams,
channelIOStr,
nPresets,
effectName,
"",
mfrName,
vendorVersion,
uniqueID,
mfrID,
latency,
plugDoesMidi,
plugDoesChunks,
plugIsInst,
plugAPI
)
{
TRACE;
mpGraphics = pGraphics;
}
CorePlugBase::~CorePlugBase()
{
}
void CorePlugBase::Reset()
{
TRACE;
IMutexLock lock(this);
// Reset processors
double sampleRate = GetSampleRate();
int nProcessors = mProcessorRegistry.size();
for (int i = 0; i < nProcessors; i++) {
mProcessorRegistry[i]->SetSampleRate(sampleRate);
mProcessorRegistry[i]->Reset();
}
}
void CorePlugBase::OnParamChange(int paramIndex)
{
IMutexLock lock(this);
// Notify the processors
int nProcessors = mProcessorRegistry.size();
for (int i = 0; i < nProcessors; i++) {
mProcessorRegistry[i]->NotifyParamChange(paramIndex);
}
// Update displays
auto search = mLabelRegistry.find(paramIndex);
if (search != mLabelRegistry.end()) {
ParameterValueLabel* label = search->second;
label->UpdateDisplay();
}
}
void CorePlugBase::CreatePresets()
{
// By default, do nothing
// This method should be overriden when presets are implemented
}
IGraphics* CorePlugBase::GetGraphics()
{
return mpGraphics;
}
void CorePlugBase::SetBackground(int id, std::string name)
{
GetGraphics()->AttachBackground(id, name.c_str());
}
void CorePlugBase::RegisterBitmap(int id, std::string name, int nFrames)
{
IBitmap& bitmap = GetGraphics()->LoadIBitmap(id, name.c_str(), nFrames);
mBitmapRegistry[id] = bitmap;
}
void CorePlugBase::AddParameterList(std::vector<ParameterInfo>& parameterList)
{
int nParams = parameterList.size();
for (int i = 0; i < nParams; i++) {
AddParameter(parameterList[i]);
}
}
void CorePlugBase::AddParameter(ParameterInfo& param)
{
// First check to make sure the parameter is initialied
if (param.IsParam()) {
IParam* pParamObj = GetParam(param.ParamIndex());
IBitmap& bitmap = mBitmapRegistry.find(param.BitmapId())->second;
if (param.IsParamSelection())
AddSelectionParameter(param, pParamObj, bitmap);
if (param.IsParamNumeric())
AddNumericParameter(param, pParamObj, bitmap);
if (param.IsParamLabeled())
AddParameterLabel(param, pParamObj, bitmap);
}
}
void CorePlugBase::RegisterProcessorList(std::vector<ModularProcessor*> processorList)
{
int nProcessors = processorList.size();
for (int i = 0; i < nProcessors; i++) {
RegisterProcessor(processorList[i]);
}
}
void CorePlugBase::RegisterProcessor(ModularProcessor* processor)
{
processor->SetParentPlugin(this);
mProcessorRegistry.push_back(processor);
}
void CorePlugBase::FinishConstruction()
{
AttachGraphics(GetGraphics());
CreatePresets();
ForceUpdateParameters();
}
void CorePlugBase::AddSelectionParameter(ParameterInfo& param, IParam* pParamObj, IBitmap& bitmap)
{
// Initialize the enum
pParamObj->InitEnum(
param.Name().c_str(), 0, param.NumStates(), "");
// Populate the state list
std::vector<std::string>& stateList = param.StateList();
for (int i = 0; i < param.NumStates(); i++) {
pParamObj->SetDisplayText(i, stateList[i].c_str());
}
// Initialize graphics
if (param.IsSelectionDropdown()) {
// TODO: dropdown selections
} else {
GetGraphics()->AttachControl(new ISwitchControl(
this, param.PosX(), param.PosY(), param.ParamIndex(), &bitmap));
}
}
void CorePlugBase::AddNumericParameter(ParameterInfo& param, IParam* pParamObj, IBitmap& bitmap)
{
// Initialize the double
pParamObj->InitDouble(
param.Name().c_str(), param.DefaultValue(), param.MinValue(),
param.MaxValue(), param.ValueStep(), param.UnitLabel().c_str());
pParamObj->SetShape(
param.ValueShapeFactor());
// Add special values
std::vector<std::pair<int, std::string>>& specialValues = param.SpecialDisplayValues();
int nSpecialValues = specialValues.size();
for (int i = 0; i < nSpecialValues; i++) {
int value = specialValues[i].first;
std::string& display = specialValues[i].second;
pParamObj->SetDisplayText(value, display.c_str());
}
// Initialize graphics
GetGraphics()->AttachControl(new IKnobMultiControl(
this, param.PosX(), param.PosY(), param.ParamIndex(), &bitmap));
}
void CorePlugBase::AddParameterLabel(ParameterInfo& param, IParam* pParamObj, IBitmap& bitmap)
{
IRECT labelRect = ConstructLabelRect(param, bitmap);
IRECT editingRect = ConstructEditingRect(param, labelRect);
ParameterValueLabel* label = new ParameterValueLabel(this, param.ParamIndex(),
labelRect, editingRect, param.LabelFontSize());
label->SetTextEntryLength(param.LabelEditChars());
mLabelRegistry[param.ParamIndex()] = label;
GetGraphics()->AttachControl(label);
}
void CorePlugBase::ForceUpdateParameters()
{
int nParams = NParams();
for (int i = 0; i < nParams; i++) {
OnParamChange(i);
}
}
IRECT CorePlugBase::ConstructLabelRect(ParameterInfo& param, IBitmap& bitmap)
{
int controlX = param.PosX();
int controlY = param.PosY();
int controlWidth = bitmap.frameWidth();
int controlHeight = bitmap.frameHeight();
// Commented since label width buffer is on probation
//int sideBuffer = param.LabelWidthBuffer() / 2;
int sideBuffer = 0;
int rectLeft = controlX - sideBuffer;
int rectRight = controlX + controlWidth + sideBuffer;
int rectTop = controlY + controlHeight + param.LabelVerticalOffset();
int rectBottom = rectTop + param.LabelHeight();
return IRECT(rectLeft, rectTop, rectRight, rectBottom);
}
IRECT CorePlugBase::ConstructEditingRect(ParameterInfo& param, IRECT& labelRect)
{
int width = labelRect.R - labelRect.L;
int sideDifference = (width - param.LabelEditWidth()) / 2;
return IRECT(labelRect.L + sideDifference, labelRect.T,
labelRect.R - sideDifference, labelRect.B);
}