1 #include "IPlugChunks.h"
2 #include "IPlug_include_in_plug_src.h"
7 // The number of presets/programs
8 const int kNumPrograms
= 8;
10 // An enumerated list for all the parameters of the plugin
14 kNumParams
, // the last element is used to store the total number of parameters
17 const int kDummyParamForMultislider
= -2;
25 class ITempPresetSaveButtonControl
: public IPanelControl
28 ITempPresetSaveButtonControl(IPlugBase
*pPlug
, IRECT pR
)
29 : IPanelControl(pPlug
, pR
, &COLOR_RED
) {}
31 void OnMouseDown(int x
, int y
, IMouseMod
* pMod
)
33 WDL_String presetFilePath
;
34 mPlug
->GetGUI()->DesktopPath(&presetFilePath
);
36 presetFilePath
.Append("\\IPlugChunksPreset.txt");
38 presetFilePath
.Append("IPlugChunksPreset.txt");
40 mPlug
->DumpPresetBlob(presetFilePath
.Get());
45 class PresetFunctionsMenu
: public IPanelControl
48 WDL_String mPreviousPath
;
51 PresetFunctionsMenu(IPlugBase
*pPlug
, IRECT pR
)
52 : IPanelControl(pPlug
, pR
, &COLOR_BLUE
)
55 bool Draw(IGraphics
* pGraphics
)
57 pGraphics
->FillIRect(&COLOR_WHITE
, &mRECT
);
66 pGraphics
->FillTriangle(&COLOR_GRAY
, ax
, ay
, bx
, by
, cx
, cy
, &mBlend
);
71 void OnMouseDown(int x
, int y
, IMouseMod
* pMod
)
78 Redraw(); // seems to need this
86 IGraphics
* gui
= mPlug
->GetGUI();
88 menu
.AddItem("Save Program...");
89 menu
.AddItem("Save Bank...");
91 menu
.AddItem("Load Program...");
92 menu
.AddItem("Load Bank...");
94 if(gui
->CreateIPopupMenu(&menu
, &mRECT
))
96 int itemChosen
= menu
.GetChosenItemIdx();
99 //printf("chosen %i /n", itemChosen);
102 case 0: //Save Program
103 fileName
.Set(mPlug
->GetPresetName(mPlug
->GetCurrentPresetIdx()));
104 GetGUI()->PromptForFile(&fileName
, kFileSave
, &mPreviousPath
, "fxp");
105 mPlug
->SaveProgramAsFXP(&fileName
);
108 fileName
.Set("IPlugChunksBank");
109 GetGUI()->PromptForFile(&fileName
, kFileSave
, &mPreviousPath
, "fxb");
110 mPlug
->SaveBankAsFXB(&fileName
);
112 case 3: //Load Preset
113 GetGUI()->PromptForFile(&fileName
, kFileOpen
, &mPreviousPath
, "fxp");
114 mPlug
->LoadProgramFromFXP(&fileName
);
117 GetGUI()->PromptForFile(&fileName
, kFileOpen
, &mPreviousPath
, "fxb");
118 mPlug
->LoadBankFromFXB(&fileName
);
127 IPlugChunks::IPlugChunks(IPlugInstanceInfo instanceInfo
)
128 : IPLUG_CTOR(kNumParams
, kNumPrograms
, instanceInfo
), mGain(1.)
132 memset(mSteps
, 0, NUM_SLIDERS
*sizeof(double));
134 // Define parameter ranges, display units, labels.
135 //arguments are: name, defaultVal, minVal, maxVal, step, label
136 GetParam(kGain
)->InitDouble("Gain", 0.0, -70.0, 12.0, 0.1, "dB");
138 MakePresetFromBlob("Ramp Up", "AAAAAJqZqT8AAAAAmpm5PwAAAIA9Csc/AAAAAAAA0D8AAABA4XrUPwAAAIDC9dg/AAAAwMzM3D8AAAAQ16PgPwAAALBH4eI/AAAA0MzM5D8AAADwUbjmPwAAAAjXo+g/AAAAKFyP6j8AAADMzMzsPwAAAOxRuO4/AAAAAAAA8D8AAAAAAAC8Pg==", 136);
139 MakePresetFromBlob("Ramp Down", "AAAA7FG47j8AAABI4XrsPwAAALBH4eo/AAAAGK5H6T8AAABwPQrnPwAAANDMzOQ/AAAAwB6F4z8AAAAghevhPwAAAAB7FN4/AAAAgOtR2D8AAABAuB7VPwAAAACuR9E/AAAAgEfhyj8AAAAAhevBPwAAAABSuK4/AAAAAOB6hD8AAAAAAAC8Pg==", 136);
140 MakePresetFromBlob("Triangle", "AAAAAIXrwT8AAACAR+HKPwAAAEBcj9I/AAAAgBSu1z8AAADA9SjcPwAAABDXo+A/AAAAsEfh4j8AAABQuB7lPwAAAGBmZuY/AAAAMDMz4z8AAAAAAADgPwAAAMD1KNw/AAAAQI/C1T8AAAAArkfRPwAAAICPwsU/AAAAAJqZuT8AAAAAAAAAAA==", 136);
141 MakePresetFromBlob("Inv Triangle", "AAAAAAAA8D8AAABQuB7tPwAAAKBwPeo/AAAAcD0K5z8AAABA4XrkPwAAAJDC9eA/AAAAwEfh2j8AAABAj8LVPwAAAECPwtU/AAAAwMzM3D8AAAAghevhPwAAANDMzOQ/AAAAgBSu5z8AAACYmZnpPwAAAFyPwu0/AAAAAAAA8D8AAAAAAAAAAA==", 136);
142 MakePresetFromBlob("Da Endz", "AAAAAAAA8D8AAAAA4HqEPwAAAADgeoQ/AAAAAOB6hD8AAAAA4HqEPwAAAADgeoQ/AAAAAOB6hD8AAAAA4HqEPwAAAADgeoQ/AAAAAOB6hD8AAAAA4HqEPwAAAADgeoQ/AAAAAOB6hD8AAAAA4HqEPwAAAADgeoQ/AAAAAAAA8D8AAAAAAAAAAA==", 136);
143 MakePresetFromBlob("Alternate", "AAAAAAAA8D8AAAAA4HqEPwAAAAAAAPA/AAAAAOB6hD8AAAAAAADwPwAAAADgeoQ/AAAAAAAA8D8AAAAA4HqEPwAAAAAAAPA/AAAAAOB6hD8AAAAAAADwPwAAAADgeoQ/AAAAAAAA8D8AAAAA4HqEPwAAAAAAAPA/AAAAAOB6hD8AAAAAAAAAAA==", 136);
144 MakePresetFromBlob("Alt Ramp Down", "AAAAAAAA8D8AAAAA4HqEPwAAALgehes/AAAAAOB6hD8AAACI61HoPwAAAADgeoQ/AAAAQArX4z8AAAAA4HqEPwAAAAAAAOA/AAAAAOB6hD8AAABAuB7VPwAAAADgeoQ/AAAAAKRwzT8AAAAA4HqEPwAAAAAzM8M/AAAAAOB6hD8AAAAAAAAAAA==", 136);
145 MakePresetFromBlob("Alt Ramp Up", "AAAAgJmZyT8AAAAA4HqEPwAAAIBmZtY/AAAAAOB6hD8AAAAAKVzfPwAAAADgeoQ/AAAAMFyP4j8AAAAA4HqEPwAAAEDheuQ/AAAAAOB6hD8AAADwKFznPwAAAADgeoQ/AAAAIIXr6T8AAAAA4HqEPwAAANijcO0/AAAAAOB6hD8AAAAAAAAAAA==", 136);
147 IGraphics
* pGraphics
= MakeGraphics(this, kW
, kH
);
148 pGraphics
->AttachPanelBackground(&COLOR_BLUE
);
150 mMSlider
= new MultiSliderControlV(this, IRECT(10, 10, 170, 110), kDummyParamForMultislider
, NUM_SLIDERS
, 10, &COLOR_WHITE
, &COLOR_BLACK
, &COLOR_RED
);
152 pGraphics
->AttachControl(mMSlider
);
153 pGraphics
->AttachControl(new IVSliderControl(this, IRECT(200, 10, 220, 110), kGain
, 20, &COLOR_WHITE
, &COLOR_GREEN
));
155 //pGraphics->AttachControl(new ITempPresetSaveButtonControl(this, IRECT(350, 250, 390, 290)));
156 pGraphics
->AttachControl(new PresetFunctionsMenu(this, IRECT(350, 250, 390, 290)));
158 AttachGraphics(pGraphics
);
160 // call RestorePreset(0) here which will initialize the multislider in the gui and the mSteps array
164 IPlugChunks::~IPlugChunks() {}
166 void IPlugChunks::ProcessDoubleReplacing(double** inputs
, double** outputs
, int nFrames
)
168 // Mutex is already locked for us.
170 double* in1
= inputs
[0];
171 double* in2
= inputs
[1];
172 double* out1
= outputs
[0];
173 double* out2
= outputs
[1];
175 int samplesPerBeat
= (int) GetSamplesPerBeat();
176 int samplePos
= (int) GetSamplePos();
179 int prevcount
= mPrevCount
;
181 for (int s
= 0; s
< nFrames
; ++s
, ++in1
, ++in2
, ++out1
, ++out2
)
183 int mod
= (samplePos
+ s
) % (samplesPerBeat
* BEAT_DIV
);
185 count
= mod
/ (samplesPerBeat
/ BEAT_DIV
);
187 if (count
>= NUM_SLIDERS
)
192 if (count
!= prevcount
)
196 mMSlider
->SetHighlight(count
);
202 *out1
= *in1
* mSteps
[count
] * mGain
;
203 *out2
= *in2
* mSteps
[count
] * mGain
;
207 mPrevCount
= prevcount
;
211 void IPlugChunks::Reset()
214 IMutexLock
lock(this);
217 mPrevCount
= ULONG_MAX
;
220 void IPlugChunks::OnParamChange(int paramIdx
)
224 IMutexLock
lock(this);
228 case kDummyParamForMultislider
:
229 mMSlider
->GetLatestChange(mSteps
);
232 mGain
= GetParam(kGain
)->DBToAmp();
239 // this over-ridden method is called when the host is trying to store the plug-in state and needs to get the current data from your algorithm
240 bool IPlugChunks::SerializeState(ByteChunk
* pChunk
)
243 IMutexLock
lock(this);
246 // serialize the multi-slider state state before serializing the regular params
247 for (int i
= 0; i
< NUM_SLIDERS
; i
++)
253 return IPlugBase::SerializeParams(pChunk
); // must remember to call SerializeParams at the end
256 // this over-ridden method is called when the host is trying to load the plug-in state and you need to unpack the data into your algorithm
257 int IPlugChunks::UnserializeState(ByteChunk
* pChunk
, int startPos
)
260 IMutexLock
lock(this);
263 // unserialize the multi-slider state before unserializing the regular params
264 for (int i
= 0; i
< NUM_SLIDERS
; i
++)
267 startPos
= pChunk
->Get(&v
, startPos
);
271 // update values in control, will set dirty
273 mMSlider
->SetState(mSteps
);
275 return IPlugBase::UnserializeParams(pChunk
, startPos
); // must remember to call UnserializeParams at the end
278 bool IPlugChunks::CompareState(const unsigned char* incomingState
, int startPos
)
281 const double* data
= (const double*) incomingState
;
282 startPos
= NUM_SLIDERS
* sizeof(double);
283 isEqual
= (memcmp(data
, mSteps
, startPos
) == 0);
284 isEqual
&= IPlugBase::CompareState(incomingState
, startPos
); // fuzzy compare regular params
289 void IPlugChunks::PresetsChangedByHost()
292 IMutexLock
lock(this);
295 mMSlider
->SetState(mSteps
);
298 GetGUI()->SetAllControlsDirty();