Skip to content

Commit

Permalink
Fixing clap-validator preset load for factory presets
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Jul 29, 2023
1 parent fba57e0 commit e71f224
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions src/state/presets/PresetDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "PresetDiscovery.h"
#include "PresetManager.h"
#include "processors/ProcessorStore.h"
#include "processors/chain/ProcessorChain.h"

JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wunused-parameter")
JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4100)
Expand Down Expand Up @@ -77,33 +78,6 @@ struct FactoryPresetsProvider
}

return true;

/*
if (location_kind != CLAP_PRESET_DISCOVERY_LOCATION_FILE || location == nullptr)
return false;
const auto userPresetFile = juce::File { location };
if (! userPresetFile.existsAsFile())
return false;
chowdsp::Preset preset { userPresetFile };
if (! preset.isValid())
return false;
if (metadata_receiver->begin_preset (metadata_receiver, userPresetFile.getFullPathName().toRawUTF8(), ""))
{
metadata_receiver->add_plugin_id (metadata_receiver, &plugin_id);
metadata_receiver->add_creator (metadata_receiver, preset.getVendor().toRawUTF8());
if (preset.getCategory().isNotEmpty())
metadata_receiver->add_feature (metadata_receiver, preset.getCategory().toRawUTF8());
metadata_receiver->set_timestamps (metadata_receiver,
(clap_timestamp_t) userPresetFile.getCreationTime().toMilliseconds() / 1000,
(clap_timestamp_t) userPresetFile.getLastModificationTime().toMilliseconds() / 1000);
}
return true;
*/
}
};

Expand Down Expand Up @@ -223,7 +197,8 @@ const clap_preset_discovery_provider_t* create (

bool presetLoadFromLocation (chowdsp::PresetManager& presetManager, uint32_t location_kind, const char* location, const char* load_key) noexcept
{
juce::ignoreUnused (load_key);
auto& byodPresetManager = static_cast<PresetManager&> (presetManager); // NOLINT

if (location_kind == CLAP_PRESET_DISCOVERY_LOCATION_FILE)
{
const auto presetFile = juce::File { location };
Expand All @@ -237,11 +212,23 @@ bool presetLoadFromLocation (chowdsp::PresetManager& presetManager, uint32_t loc
if (! preset.isValid())
return false;

static_cast<PresetManager&> (presetManager).loadPresetSafe (std::make_unique<chowdsp::Preset> (std::move (preset)), nullptr); //NOLINT
byodPresetManager.loadPresetSafe (std::make_unique<chowdsp::Preset> (std::move (preset)), nullptr);

return true;
}

if (location_kind == CLAP_PRESET_DISCOVERY_LOCATION_PLUGIN)
{
for (auto& preset : byodPresetManager.getFactoryPresets (byodPresetManager.getProcessorChain()->getProcStore()))
{
if (preset.getName() == load_key)
{
byodPresetManager.loadPresetSafe (std::make_unique<chowdsp::Preset> (std::move (preset)), nullptr);
return true;
}
}
}

return false;
}
} // namespace preset_discovery
Expand Down

0 comments on commit e71f224

Please sign in to comment.