




mDirPreset(juce::File::getSpecialLocation
(juce::File::userDocumentsDirectory).
getChildFile(JucePlugin_Name))
const juce::File& getDirPreset() const noexcept;
The const at the beginning prevents the referenced object from being modified, and the const at the end ensures that member variables are not modified within the function
onChange = [this]()
{
mFileChooser = std::make_unique<juce::FileChooser>(id == IdComboBox::Save ? "Save" : "Load",
mPresetManager.getDirPreset(),
"*.xml",
false);
mFileChooser->launchAsync(flag, callback);
}
onChange = [this]()
{
juce::FileChooser chooser(...); // local variable
chooser.launchAsync(flag, callback); // the callback will be called later
}; // ⚠️ chooser is already destroyed here
int flag = juce::FileBrowserComponent::canSelectFiles;
flag |= id==IdComboBox::Save ? juce::FileBrowserComponent::saveMode :
juce::FileBrowserComponent::openMode;
bitwise OR operation
It is commonly used to combine multiple options (flags) into one, and at each bit position, the result is 1 if either bit is 1
ex)
// Define flags as binary values
constexpr int canSelectFiles = 0b100; // 4
constexpr int saveMode = 0b010; // 2
constexpr int openMode = 0b001; // 1
// Example 1: Combine for "Open File" mode
int flag1 = canSelectFiles | openMode; // 0b100 | 0b001 = 0b101 (5)
// Example 2: Combine for "Save File" mode
int flag2 = canSelectFiles | saveMode; // 0b100 | 0b010 = 0b110 (6)
auto callback = [this,id](const juce::FileChooser& inFileChooser){}
switch(id)
{
case IdComboBox::Save:
{
DBG("Save");
mPresetManager.setStateCopied(file.withFileExtension("xml"));
break;
}
case IdComboBox::Load:
{
DBG("Load");
break;
}
}
yPresetComboBox::MyPresetComboBox()
{
resetByXmlPreset();
onChange = [this]()
{ resetByXmlPrreset();
}