I made saving a path to the file. "openFile" is my void with WDL_FileRead. To create blobs, set settings and calling DumpPresetBlob(filename), like in IPlugChunks.
Code:
WDL_String filepath;
IFileSelectorControl *mFileDialog;
...
MakePresetFromBlob("Preset 1", "AAAAAAAAAA", 512);
MakePresetFromBlob("Preset 2", "AAAAAAAAAA", 512);
// File Dialog
IRECT tmpRect0(136, 65, 176, 105);
//mFileDialog = new IFileSelectorControl(this, tmpRect0, -1, &toggle2, kFileOpen, "C:\\","txt");
mFileDialog = new IFileSelectorControl(this, tmpRect0, -1, &toggle2, kFileOpen, "C:\\","*");
pGraphics->AttachControl(mFileDialog);
RestorePreset(0);
...
bool MyEffect::SerializeState(ByteChunk* pChunk)
{
TRACE;
IMutexLock lock(this);
mFileDialog->GetLastSelectedFileForPlug(&filepath);
openFile(filepath.Get());
int plugVersion = GetEffectVersion(false);
pChunk->Put(&plugVersion);
// for controls
int i, n = kNumParams;
double v = 0.0;
for (i = 0; i < n; ++i)
{
v = GetParam(i)->Type();
pChunk->Put(&v);
}
pChunk->PutStr(filepath.Get()); // for file path
return IPlugBase::SerializeParams(pChunk);
}
int MyEffect::UnserializeState(ByteChunk* pChunk, int startPos)
{
TRACE;
IMutexLock lock(this);
int plugVersionInState;
startPos = pChunk->Get(&plugVersionInState, startPos);
// for controls
double v = 0.0;
int i, n = kNumParams;
for (i = 0; i < n; ++i)
{
startPos = pChunk->Get(&v, startPos);
}
startPos = pChunk->GetStr(&filepath, startPos); // for file path
mFileDialog->SetLastSelectedFileFromPlug(filepath.Get());
openFile(filepath.Get());
return IPlugBase::UnserializeParams(pChunk, startPos);
}
Also added a line to controls (knob, switch):
Code:
void OnMouseUp(int x, int y, IMouseMod* pMod)
{
//TODO: check this isn't going to cause problems... this will happen from the gui thread
mPlug->ModifyCurrentPreset();
mPlug->DirtyPTCompareState();
}
And to void IFileSelectorControl:
Code:
...
mPlug->GetGUI()->PromptForFile(&mFile, mFileAction, &mDir, mExtensions.Get());
//TODO: check this isn't going to cause problems... this will happen from the gui thread
mPlug->ModifyCurrentPreset();
mPlug->DirtyPTCompareState();
...
And to resource.h:
Code:
#define PLUG_DOES_STATE_CHUNKS 1