Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helpers for implementing CLAP preset discovery #487

Merged
merged 10 commits into from
Jan 29, 2024
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CPMAddPackage(
CPMAddPackage(
NAME clap-juce-extensions
GITHUB_REPOSITORY free-audio/clap-juce-extensions
GIT_TAG 10bc7d4ddb82eab4796b1ce7d1d2dadd46552f27
GIT_TAG e72d59a870ab6dea156d4912cbd004b715fca5f7
)

include(AddJUCEModules)
Expand Down
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,

Check warning on line 14 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L14

Added line #L14 was not covered by tests
const clap_preset_discovery_provider_descriptor& desc,
const clap_preset_discovery_location& location,
const clap_preset_discovery_indexer* indexer)

Check warning on line 17 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L17

Added line #L17 was not covered by tests
: CLAPPresetsProviderBase (&desc, indexer),
this_plugin_id (this_plug_id),
discoveryLocation (location)

Check warning on line 20 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L19-L20

Added lines #L19 - L20 were not covered by tests
{
// CLAP requires that a location containing embedded presets must be nullptr
jassert (discoveryLocation.location == nullptr);

Check warning on line 23 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L23

Added line #L23 was not covered by tests
}

std::vector<Preset> EmbeddedPresetsProvider::getPresets() { return {}; }

Check warning on line 26 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L26

Added line #L26 was not covered by tests

bool EmbeddedPresetsProvider::init() noexcept

Check warning on line 28 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L28

Added line #L28 was not covered by tests
{
indexer()->declare_location (indexer(), &discoveryLocation);
return true;

Check warning on line 31 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L30-L31

Added lines #L30 - L31 were not covered by tests
}

bool EmbeddedPresetsProvider::getMetadata (uint32_t location_kind,

Check warning on line 34 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L34

Added line #L34 was not covered by tests
[[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;

Check warning on line 39 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L38-L39

Added lines #L38 - L39 were not covered by tests

for (const auto& factoryPreset : getPresets())

Check warning on line 41 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L41

Added line #L41 was not covered by tests
{
DBG ("Indexing factory preset: " + factoryPreset.getName());
if (metadata_receiver->begin_preset (metadata_receiver, factoryPreset.getName().toRawUTF8(), factoryPreset.getName().toRawUTF8()))

Check warning on line 44 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L43-L44

Added lines #L43 - L44 were not covered by tests
{
metadata_receiver->add_plugin_id (metadata_receiver, &this_plugin_id);
metadata_receiver->add_creator (metadata_receiver, factoryPreset.getVendor().toRawUTF8());

Check warning on line 47 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L46-L47

Added lines #L46 - L47 were not covered by tests

if (factoryPreset.getCategory().isNotEmpty())
metadata_receiver->add_feature (metadata_receiver, factoryPreset.getCategory().toRawUTF8());

Check warning on line 50 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L49-L50

Added lines #L49 - L50 were not covered by tests
}
else
{
break;

Check warning on line 54 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L54

Added line #L54 was not covered by tests
}
}

return true;

Check warning on line 58 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L58

Added line #L58 was not covered by tests
}

//==============================================================================
FilePresetsProvider::FilePresetsProvider (const clap_universal_plugin_id& this_plug_id,

Check warning on line 62 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L62

Added line #L62 was not covered by tests
const clap_preset_discovery_provider_descriptor& desc,
const clap_preset_discovery_filetype& filetype,
const clap_preset_discovery_indexer* indexer)

Check warning on line 65 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L65

Added line #L65 was not covered by tests
: CLAPPresetsProviderBase (&desc, indexer),
this_plugin_id (this_plug_id),
presets_filetype (filetype)

Check warning on line 68 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L67-L68

Added lines #L67 - L68 were not covered by tests
{
}

bool FilePresetsProvider::init() noexcept

Check warning on line 72 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L72

Added line #L72 was not covered by tests
{
indexer()->declare_filetype (indexer(), &presets_filetype);

Check warning on line 74 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L74

Added line #L74 was not covered by tests

discoveryLocation.flags = CLAP_PRESET_DISCOVERY_IS_USER_CONTENT;
discoveryLocation.kind = CLAP_PRESET_DISCOVERY_LOCATION_FILE;
if (! fillInLocation (discoveryLocation))
return false;

Check warning on line 79 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L76-L79

Added lines #L76 - L79 were not covered by tests

indexer()->declare_location (indexer(), &discoveryLocation);

Check warning on line 81 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L81

Added line #L81 was not covered by tests

return true;

Check warning on line 83 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L83

Added line #L83 was not covered by tests
}

bool FilePresetsProvider::getMetadata (uint32_t location_kind,

Check warning on line 86 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L86

Added line #L86 was not covered by tests
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;

Check warning on line 91 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L90-L91

Added lines #L90 - L91 were not covered by tests

const auto userPresetFile = juce::File { location };
if (! userPresetFile.existsAsFile())
return false;

Check warning on line 95 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L93-L95

Added lines #L93 - L95 were not covered by tests

Preset preset { userPresetFile };
if (! preset.isValid())
return false;

Check warning on line 99 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L97-L99

Added lines #L97 - L99 were not covered by tests

DBG ("Indexing user preset: " + preset.getName() + ", from path: " + userPresetFile.getFullPathName());
if (metadata_receiver->begin_preset (metadata_receiver, userPresetFile.getFullPathName().toRawUTF8(), ""))

Check warning on line 102 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L101-L102

Added lines #L101 - L102 were not covered by tests
{
metadata_receiver->add_plugin_id (metadata_receiver, &this_plugin_id);
metadata_receiver->add_creator (metadata_receiver, preset.getVendor().toRawUTF8());

Check warning on line 105 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L104-L105

Added lines #L104 - L105 were not covered by tests

if (preset.getCategory().isNotEmpty())
metadata_receiver->add_feature (metadata_receiver, preset.getCategory().toRawUTF8());

Check warning on line 108 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L107-L108

Added lines #L107 - L108 were not covered by tests

metadata_receiver->set_timestamps (metadata_receiver,
(clap_timestamp) userPresetFile.getCreationTime().toMilliseconds() / 1000,
(clap_timestamp) userPresetFile.getLastModificationTime().toMilliseconds() / 1000);

Check warning on line 112 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L110-L112

Added lines #L110 - L112 were not covered by tests
}

return true;

Check warning on line 115 in modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_clap_extensions/PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.cpp#L115

Added line #L115 was not covered by tests
}
} // namespace chowdsp::presets::discovery
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ namespace CLAPExtensions
// LCOV_EXCL_START
#include "ParameterExtensions/chowdsp_ModParamMixin.h"
#include "PluginExtensions/chowdsp_CLAPInfoExtensions.h"

#if JUCE_MODULE_AVAILABLE_chowdsp_presets_v2
#include "PresetExtensions/chowdsp_CLAPPresetDiscoveryProviders.h"
#endif
// LCOV_EXCL_END
18 changes: 18 additions & 0 deletions modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@
virtual juce::String getWrapperTypeString() const;
bool supportsParameterModulation() const;

#if HAS_CLAP_JUCE_EXTENSIONS && JUCE_MODULE_AVAILABLE_chowdsp_presets_v2
bool supportsPresetLoad() const noexcept override

Check warning on line 121 in modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h#L121

Added line #L121 was not covered by tests
{
return presetManager != nullptr;

Check warning on line 123 in modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h#L123

Added line #L123 was not covered by tests
}
bool presetLoadFromLocation (uint32_t location_kind, const char* location, const char* load_key) noexcept override;
#endif

protected:
#if JUCE_MODULE_AVAILABLE_chowdsp_plugin_state
PluginStateType state;
Expand Down Expand Up @@ -311,4 +319,14 @@
return false;
#endif
}

#if HAS_CLAP_JUCE_EXTENSIONS && JUCE_MODULE_AVAILABLE_chowdsp_presets_v2
template <class P>
bool PluginBase<P>::presetLoadFromLocation (uint32_t location_kind, const char* location, const char* load_key) noexcept

Check warning on line 325 in modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h#L325

Added line #L325 was not covered by tests
{
if (presetManager == nullptr)
return false;
return presetManager->loadCLAPPreset (location_kind, location, load_key);

Check warning on line 329 in modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_plugin_base/PluginBase/chowdsp_PluginBase.h#L327-L329

Added lines #L327 - L329 were not covered by tests
}
#endif
} // namespace chowdsp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class SynthBase : public PluginBase<Processor>
{
return true;
}
int noteNameCount() noexcept override { return 0; }
bool noteNameGet (int /*index*/, clap_note_name* /*noteName*/) noexcept override { return false; }
uint32_t noteNameCount() noexcept override { return 0; }
bool noteNameGet (uint32_t /*index*/, clap_note_name* /*noteName*/) noexcept override { return false; }
#endif

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ namespace chowdsp
FileListener::FileListener (const juce::File& file, int timerSeconds) : fileToListenTo (file)
{
fileModificationTime = fileToListenTo.getLastModificationTime().toMilliseconds();
startTimer (timerSeconds * 1000);
if (timerSeconds > 0)
startTimer (timerSeconds * 1000);
}

FileListener::~FileListener()
{
stopTimer();
if (isTimerRunning())
stopTimer();
}

void FileListener::timerCallback()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
namespace chowdsp
{
/** Abstract class to allow the derived class to listen for changes to a file. */
class FileListener : private juce::Timer
class FileListener : public juce::Timer
{
public:
/** Initialize this FileListener for a given file and update time. */
/**
* Initialize this FileListener for a given file and update time.
*
* If the given update time is less than or equal to zero, then
* the timer will not be started.
*/
FileListener (const juce::File& file, int timerSeconds);

~FileListener() override;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#include "chowdsp_PresetManager.h"

#if HAS_CLAP_JUCE_EXTENSIONS
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
#endif

namespace chowdsp::presets
{
PresetManager::PresetManager (PluginState& state,
Expand Down Expand Up @@ -124,4 +132,52 @@

addPresets (std::move (presets), false);
}

void PresetManager::loadPreset (const Preset& preset)
{
saverLoader.loadPreset (preset);

#if HAS_CLAP_JUCE_EXTENSIONS
if (preset.getPresetFile() == juce::File {})
clapPresetLoadedBroadcaster (CLAP_PRESET_DISCOVERY_LOCATION_PLUGIN,

Check warning on line 142 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L142

Added line #L142 was not covered by tests
nullptr,
preset.getName().toRawUTF8());
clapPresetLoadedBroadcaster (CLAP_PRESET_DISCOVERY_LOCATION_FILE,

Check warning on line 145 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L145

Added line #L145 was not covered by tests
preset.getPresetFile().getFullPathName().toRawUTF8(),
nullptr);
#endif
}

#if HAS_CLAP_JUCE_EXTENSIONS
bool PresetManager::loadCLAPPreset (uint32_t location_kind, const char* location, const char* load_key) noexcept

Check warning on line 152 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L152

Added line #L152 was not covered by tests
{
if (location_kind == CLAP_PRESET_DISCOVERY_LOCATION_FILE)

Check warning on line 154 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L154

Added line #L154 was not covered by tests
{
const auto presetFile = juce::File { location };
if (! presetFile.existsAsFile())
return false;

Check warning on line 158 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L156-L158

Added lines #L156 - L158 were not covered by tests

const auto preset = Preset { presetFile };
if (! preset.isValid())
return false;

Check warning on line 162 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L160-L162

Added lines #L160 - L162 were not covered by tests

loadPreset (preset);
return true;

Check warning on line 165 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L164-L165

Added lines #L164 - L165 were not covered by tests
}

if (location_kind == CLAP_PRESET_DISCOVERY_LOCATION_PLUGIN)

Check warning on line 168 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L168

Added line #L168 was not covered by tests
{
for (const auto& preset : getFactoryPresets())

Check warning on line 170 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L170

Added line #L170 was not covered by tests
{
if (preset.getName() == load_key)

Check warning on line 172 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L172

Added line #L172 was not covered by tests
{
loadPreset (preset);
return true;

Check warning on line 175 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L174-L175

Added lines #L174 - L175 were not covered by tests
}
}
}

return false;

Check warning on line 180 in modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp

View check run for this annotation

Codecov / codecov/patch

modules/plugin/chowdsp_presets_v2/Backend/chowdsp_PresetManager.cpp#L180

Added line #L180 was not covered by tests
}
#endif
} // namespace chowdsp::presets
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ class PresetManager
virtual ~PresetManager() = default;

/** Loads a preset by reference. */
void loadPreset (const Preset& preset) { saverLoader.loadPreset (preset); }
void loadPreset (const Preset& preset);

#if HAS_CLAP_JUCE_EXTENSIONS
/** Loads a preset based on information provided by the CLAP preset-load extension. */
virtual bool loadCLAPPreset (uint32_t location_kind, const char* location, const char* load_key) noexcept;

Broadcaster<void (uint32_t location_kind, const char* location, const char* load_key)> clapPresetLoadedBroadcaster {};
#endif

/** Returns the currently loaded preset, or nullptr if no preset is loaded. */
[[nodiscard]] const Preset* getCurrentPreset() const { return saverLoader.getCurrentPreset(); }
Expand Down
6 changes: 5 additions & 1 deletion tests/plugin_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ setup_juce_lib(plugin_tests_lib
)

if(TARGET clap_juce_extensions)
target_link_libraries(plugin_tests_lib PUBLIC clap_juce_extensions)
target_link_libraries(plugin_tests_lib
PUBLIC
clap_juce_extensions
chowdsp::chowdsp_clap_extensions
)
endif()

target_compile_definitions(plugin_tests_lib
Expand Down
Loading