-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Helpers for implementing CLAP preset discovery (#487)
* Setting up extensions for CLAP preset discovery and loading * Update CLAP note name API * Add missing HAS_CLAP check * More presets/CLAP interop updates * Apply clang-format * Update CHE version for building examples * Trying to fix test compiler errors * Undo temp thing * Trying to fix warnings on Windows --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
19fd177
commit dfd267c
Showing
12 changed files
with
292 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
.../plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "chowdsp_CLAPPresetDiscoveryProviders.h" | ||
|
||
#include <chowdsp_presets_v2/chowdsp_presets_v2.h> | ||
|
||
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wunused-parameter") | ||
JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4100 4127) | ||
#include <clap/helpers/preset-discovery-provider.hh> | ||
#include <clap/helpers/preset-discovery-provider.hxx> | ||
JUCE_END_IGNORE_WARNINGS_MSVC | ||
JUCE_END_IGNORE_WARNINGS_GCC_LIKE | ||
|
||
namespace chowdsp::presets::discovery | ||
{ | ||
EmbeddedPresetsProvider::EmbeddedPresetsProvider (const clap_universal_plugin_id& this_plug_id, | ||
const clap_preset_discovery_provider_descriptor& desc, | ||
const clap_preset_discovery_location& location, | ||
const clap_preset_discovery_indexer* indexer) | ||
: CLAPPresetsProviderBase (&desc, indexer), | ||
this_plugin_id (this_plug_id), | ||
discoveryLocation (location) | ||
{ | ||
// CLAP requires that a location containing embedded presets must be nullptr | ||
jassert (discoveryLocation.location == nullptr); | ||
} | ||
|
||
std::vector<Preset> EmbeddedPresetsProvider::getPresets() { return {}; } | ||
|
||
bool EmbeddedPresetsProvider::init() noexcept | ||
{ | ||
indexer()->declare_location (indexer(), &discoveryLocation); | ||
return true; | ||
} | ||
|
||
bool EmbeddedPresetsProvider::getMetadata (uint32_t location_kind, | ||
[[maybe_unused]] const char* location, | ||
const clap_preset_discovery_metadata_receiver_t* metadata_receiver) noexcept | ||
{ | ||
if (location_kind != CLAP_PRESET_DISCOVERY_LOCATION_PLUGIN) | ||
return false; | ||
|
||
for (const auto& factoryPreset : getPresets()) | ||
{ | ||
DBG ("Indexing factory preset: " + factoryPreset.getName()); | ||
if (metadata_receiver->begin_preset (metadata_receiver, factoryPreset.getName().toRawUTF8(), factoryPreset.getName().toRawUTF8())) | ||
{ | ||
metadata_receiver->add_plugin_id (metadata_receiver, &this_plugin_id); | ||
metadata_receiver->add_creator (metadata_receiver, factoryPreset.getVendor().toRawUTF8()); | ||
|
||
if (factoryPreset.getCategory().isNotEmpty()) | ||
metadata_receiver->add_feature (metadata_receiver, factoryPreset.getCategory().toRawUTF8()); | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
//============================================================================== | ||
FilePresetsProvider::FilePresetsProvider (const clap_universal_plugin_id& this_plug_id, | ||
const clap_preset_discovery_provider_descriptor& desc, | ||
const clap_preset_discovery_filetype& filetype, | ||
const clap_preset_discovery_indexer* indexer) | ||
: CLAPPresetsProviderBase (&desc, indexer), | ||
this_plugin_id (this_plug_id), | ||
presets_filetype (filetype) | ||
{ | ||
} | ||
|
||
bool FilePresetsProvider::init() noexcept | ||
{ | ||
indexer()->declare_filetype (indexer(), &presets_filetype); | ||
|
||
discoveryLocation.flags = CLAP_PRESET_DISCOVERY_IS_USER_CONTENT; | ||
discoveryLocation.kind = CLAP_PRESET_DISCOVERY_LOCATION_FILE; | ||
if (! fillInLocation (discoveryLocation)) | ||
return false; | ||
|
||
indexer()->declare_location (indexer(), &discoveryLocation); | ||
|
||
return true; | ||
} | ||
|
||
bool FilePresetsProvider::getMetadata (uint32_t location_kind, | ||
const char* location, | ||
const clap_preset_discovery_metadata_receiver_t* metadata_receiver) noexcept | ||
{ | ||
if (location_kind != CLAP_PRESET_DISCOVERY_LOCATION_FILE || location == nullptr) | ||
return false; | ||
|
||
const auto userPresetFile = juce::File { location }; | ||
if (! userPresetFile.existsAsFile()) | ||
return false; | ||
|
||
Preset preset { userPresetFile }; | ||
if (! preset.isValid()) | ||
return false; | ||
|
||
DBG ("Indexing user preset: " + preset.getName() + ", from path: " + userPresetFile.getFullPathName()); | ||
if (metadata_receiver->begin_preset (metadata_receiver, userPresetFile.getFullPathName().toRawUTF8(), "")) | ||
{ | ||
metadata_receiver->add_plugin_id (metadata_receiver, &this_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) userPresetFile.getCreationTime().toMilliseconds() / 1000, | ||
(clap_timestamp) userPresetFile.getLastModificationTime().toMilliseconds() / 1000); | ||
} | ||
|
||
return true; | ||
} | ||
} // namespace chowdsp::presets::discovery |
63 changes: 63 additions & 0 deletions
63
...es/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wunused-parameter") | ||
JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4100) | ||
#include <clap/helpers/preset-discovery-provider.hh> | ||
JUCE_END_IGNORE_WARNINGS_MSVC | ||
JUCE_END_IGNORE_WARNINGS_GCC_LIKE | ||
|
||
namespace chowdsp::presets | ||
{ | ||
class Preset; | ||
} | ||
|
||
namespace chowdsp::presets::discovery | ||
{ | ||
using CLAPPresetsProviderBase = | ||
#if JUCE_DEBUG | ||
clap::helpers::PresetDiscoveryProvider<clap::helpers::MisbehaviourHandler::Terminate, clap::helpers::CheckingLevel::Maximal>; | ||
#else | ||
clap::helpers::PresetDiscoveryProvider<clap::helpers::MisbehaviourHandler::Ignore, clap::helpers::CheckingLevel::Minimal>; | ||
#endif | ||
|
||
/** A CLAP preset provider for presets that are embedded in the plugin's binary data. */ | ||
struct EmbeddedPresetsProvider : CLAPPresetsProviderBase | ||
{ | ||
const clap_universal_plugin_id& this_plugin_id; | ||
const clap_preset_discovery_location& discoveryLocation {}; | ||
|
||
EmbeddedPresetsProvider (const clap_universal_plugin_id& this_plug_id, | ||
const clap_preset_discovery_provider_descriptor& desc, | ||
const clap_preset_discovery_location& location, | ||
const clap_preset_discovery_indexer* indexer); | ||
|
||
/** Users are expected to override this method to provide the relevant presets. */ | ||
virtual std::vector<Preset> getPresets(); | ||
|
||
bool init() noexcept override; | ||
bool getMetadata (uint32_t location_kind, | ||
const char* location, | ||
const clap_preset_discovery_metadata_receiver_t* metadata_receiver) noexcept override; | ||
}; | ||
|
||
/** A CLAP preset provider for presets that are stored in the user's filesystem. */ | ||
struct FilePresetsProvider : CLAPPresetsProviderBase | ||
{ | ||
const clap_universal_plugin_id& this_plugin_id; | ||
const clap_preset_discovery_filetype& presets_filetype; | ||
clap_preset_discovery_location discoveryLocation {}; | ||
|
||
FilePresetsProvider (const clap_universal_plugin_id& this_plug_id, | ||
const clap_preset_discovery_provider_descriptor& desc, | ||
const clap_preset_discovery_filetype& filetype, | ||
const clap_preset_discovery_indexer* indexer); | ||
|
||
/** Users are expected to override this method to fill in the location name and path. */ | ||
virtual bool fillInLocation (clap_preset_discovery_location&) = 0; | ||
|
||
bool init() noexcept override; | ||
bool getMetadata (uint32_t location_kind, | ||
const char* location, | ||
const clap_preset_discovery_metadata_receiver_t* metadata_receiver) noexcept override; | ||
}; | ||
} // namespace chowdsp::presets::discovery |
7 changes: 7 additions & 0 deletions
7
modules/plugin/chowdsp_clap_extensions/chowdsp_clap_extensions.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "chowdsp_clap_extensions.h" | ||
|
||
// LCOV_EXCL_START | ||
#if JUCE_MODULE_AVAILABLE_chowdsp_presets_v2 | ||
#include "PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp" | ||
#endif | ||
// LCOV_EXCL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters