clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit 094da6ed0e4fe740cb9d05ac05644c56a6b3d874
parent a4e1605d37dae9c6943b288ea6a73bbbccb53f7e
Author: Alexandre Bique <bique.alexandre@gmail.com>
Date:   Tue, 15 Aug 2023 11:14:25 +0200

Merge branch 'next' into incremental-state
Diffstat:
M.github/workflows/cmake.yml | 11++++++++++-
MCMakeLists.txt | 4++++
MCMakePresets.json | 30++++++++++++++++++++++++++++++
MChangeLog.md | 7++++++-
Minclude/clap/clap.h | 1+
Minclude/clap/ext/audio-ports.h | 2+-
Minclude/clap/ext/draft/audio-ports-activation.h | 8++++++--
Minclude/clap/ext/draft/resource-directory.h | 2+-
Ainclude/clap/ext/draft/undo.h | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Minclude/clap/ext/gui.h | 2+-
Minclude/clap/factory/draft/preset-discovery.h | 2+-
Minclude/clap/plugin.h | 2+-
Minclude/clap/private/macros.h | 12+++++++++---
Msrc/main.cc | 12++++++++++++
14 files changed, 158 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml @@ -39,8 +39,17 @@ jobs: - name: Run CMake+Ninja+CTest to generate/build/test. uses: lukka/run-cmake@v10 - id: runcmake + id: runcmake-ninja with: configurePreset: 'ninja' buildPreset: 'ninja-release' testPreset: 'ninja-release' + + - name: Run CMake+MSVC+CTest to generate/build/test. + uses: lukka/run-cmake@v10 + if: startsWith(matrix.os, 'win') + id: runcmake-msvc + with: + configurePreset: 'msvc' + buildPreset: 'msvc-release' + testPreset: 'msvc-release' diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -60,6 +60,10 @@ if (${CLAP_BUILD_TESTS}) add_test(NAME test-clap-compile-${SUFFIX} COMMAND clap-compile-${SUFFIX}) add_dependencies(clap-tests clap-compile-${SUFFIX}) + if (${EXT} STREQUAL "cc") + target_compile_definitions(clap-compile-${SUFFIX} PRIVATE CLAP_COMPILE_TEST_CXX_VERSION=${STDCPP}) + endif() + if (${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang") target_compile_options(clap-compile-${SUFFIX} PRIVATE -Wall -Wextra -pedantic) endif() diff --git a/CMakePresets.json b/CMakePresets.json @@ -22,6 +22,23 @@ "value": true } } + }, + { + "name": "msvc", + "displayName": "MSVC", + "description": "Configure and generate MSVC project files for all configurations", + "binaryDir": "${sourceDir}/builds/${presetName}", + "generator": "Visual Studio 17 2022", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": { + "type": "boolean", + "value": true + }, + "CLAP_BUILD_TESTS": { + "type": "boolean", + "value": true + } + } } ], "buildPresets": [ @@ -32,6 +49,14 @@ "description": "Build ninja Release configuration", "configuration": "RelWithDebInfo", "targets": ["clap-tests"] + }, + { + "name": "msvc-release", + "configurePreset": "msvc", + "displayName": "Build msvc-release", + "description": "Build msvc Release configuration", + "configuration": "RelWithDebInfo", + "targets": ["clap-tests"] } ], "testPresets": [ @@ -39,6 +64,11 @@ "name": "ninja-release", "configurePreset": "ninja", "configuration": "RelWithDebInfo" + }, + { + "name": "msvc-release", + "configurePreset": "msvc", + "configuration": "RelWithDebInfo" } ] } \ No newline at end of file diff --git a/ChangeLog.md b/ChangeLog.md @@ -5,6 +5,11 @@ * [configurable-audio-ports.h](include/clap/ext/draft/configurable-audio-ports.h): simplify the design * [gui.h](include/clap/ext/gui.h): documentation clarifications * [entry.h](include/clap/entry.h): documentation clarifications +* [audio-ports-activation.h](include/clap/ext/draft/audio-ports-activation.h): specify the sample size to be used when activating the audio port. + +## Draft extensions + +* [undo.h](include/clap/ext/draft/undo.h): undo support ## Draft Extensions @@ -142,7 +147,7 @@ it is now **required** to deactivate the plugin before destroying it. * [params.h](include/clap/ext/params.h): improve documentation for `clap_host_params->request_flush()`. * [entry.h](include/clap/entry.h): improve documentation regarding `init()`, `deinit()` and CLAP search path. -* [gui.h](inclued/clap/gui.h): fix typo `clap_gui_resize_hints.preserve_aspect_ratio` +* [gui.h](include/clap/gui.h): fix typo `clap_gui_resize_hints.preserve_aspect_ratio` * [plugin-template](src/plugin-template.c): missing impl of plugin destroy. * various documentation improvements diff --git a/include/clap/clap.h b/include/clap/clap.h @@ -70,3 +70,4 @@ #include "ext/draft/configurable-audio-ports.h" #include "ext/draft/extensible-audio-ports.h" #include "ext/draft/incremental-state.h" +#include "ext/draft/undo.h" diff --git a/include/clap/ext/audio-ports.h b/include/clap/ext/audio-ports.h @@ -49,7 +49,7 @@ typedef struct clap_audio_port_info { uint32_t channel_count; // If null or empty then it is unspecified (arbitrary audio). - // This filed can be compared against: + // This field can be compared against: // - CLAP_PORT_MONO // - CLAP_PORT_STEREO // - CLAP_PORT_SURROUND (defined in the surround extension) diff --git a/include/clap/ext/draft/audio-ports-activation.h b/include/clap/ext/draft/audio-ports-activation.h @@ -26,7 +26,7 @@ /// clap_host_audio_ports.rescan(CLAP_AUDIO_PORTS_RESCAN_LIST). static CLAP_CONSTEXPR const char CLAP_EXT_AUDIO_PORTS_ACTIVATION[] = - "clap.audio-ports-activation/draft-1"; + "clap.audio-ports-activation/draft-2"; #ifdef __cplusplus extern "C" { @@ -42,12 +42,16 @@ typedef struct clap_plugin_audio_ports_activation { // It is only possible to activate and de-activate on the audio-thread if // can_activate_while_processing() returns true. // + // sample_size indicate if the host will provide 32 bit audio buffers or 64 bits one. + // Possible values are: 32, 64 or 0 if unspecified. + // // returns false if failed, or invalid parameters // [active ? audio-thread : main-thread] bool(CLAP_ABI *set_active)(const clap_plugin_t *plugin, bool is_input, uint32_t port_index, - bool is_active); + bool is_active, + uint32_t sample_size); } clap_plugin_audio_ports_activation_t; #ifdef __cplusplus diff --git a/include/clap/ext/draft/resource-directory.h b/include/clap/ext/draft/resource-directory.h @@ -44,7 +44,7 @@ extern "C" { typedef struct clap_plugin_resource_directory { // Sets the directory in which the plugin can save its resources. - // The directory remains valid until it is overriden or the plugin is destroyed. + // The directory remains valid until it is overridden or the plugin is destroyed. // If path is null or blank, it clears the directory location. // path must be absolute. // [main-thread] diff --git a/include/clap/ext/draft/undo.h b/include/clap/ext/draft/undo.h @@ -0,0 +1,75 @@ +#pragma once + +#include "../../plugin.h" +#include "../../string-sizes.h" + +static CLAP_CONSTEXPR const char CLAP_EXT_UNDO[] = "clap.undo.draft/0"; + +// Describes a change which can be undone or redone +typedef struct clap_undo_change_info { + // This is the unique identifier of this undo step. + // It is valid until loading a state or destroying the plugin. + clap_id change_id; + + // A short string which describes the corresponding change. + char description[CLAP_NAME_SIZE]; +} clap_undo_change_info_t; + +typedef struct clap_plugin_undo { + // returns true if an undo/redo step exists and the info were provided + // [main-thread] + bool (*get_current_undo_info)(clap_plugin_t *plugin, clap_undo_change_info_t *info); + bool (*get_current_redo_info)(clap_plugin_t *plugin, clap_undo_change_info_t *info); + + // Request the plugin to perform an undo operation (async). + // + // Returns true if the request is being processed, false otherwise. + // When returning true, the plugin **must** call clap_host_undo->after_undo_request() once the + // request is completed or failed. + // + // The plugin should only perform the operation if the current undo/redo operation matches the + // given id; this is because of the asynchronous nature of the task and to avoid race conditions + // if the plugin's undo manager lives in a different thread. + // + // Call sequence: + // 1. plugin->request_undo(change_id=X) -> returns true + // 2. later on host->begin_undo(change_id=X) + // 3. later on host->end_undo(change_id=X), host->after_undo(change_id=X, true, nullptr) + // [main-thread] + bool (*request_undo)(clap_plugin_t *plugin, clap_id change_id); + bool (*request_redo)(clap_plugin_t *plugin, clap_id change_id); +} clap_plugin_undo_t; + +typedef struct clap_host_undo { + // Marks the begining and end of a change which will lead to the creation of an undo step. + // [main-thread] + void (*begin_change)(clap_host_t *host, const clap_undo_change_info_t *info); + void (*end_change)(clap_host_t *host, const clap_undo_change_info_t *info); + + // Marks the beginning and end of processing an undo change. + // [main-thread] + void (*begin_undo)(clap_host_t *host, const clap_undo_change_info_t *info); + void (*end_undo)(clap_host_t *host, const clap_undo_change_info_t *info); + + // Marks the beginning and end of processing a redo change. + // [main-thread] + void (*begin_redo)(clap_host_t *host, const clap_undo_change_info_t *info); + void (*end_redo)(clap_host_t *host, const clap_undo_change_info_t *info); + + // A destructive change happened which makes it impossible to perform an undo. + // The entire plugin's undo/redo stack has been cleared. + // [main-thread] + void (*after_destructive_change)(clap_host_t *host); + + // Callbacks for clap_plugin_undo->request_*() + // If succeed is true, then error_msg is ignored and may be null. + // [main-thread] + void (*after_undo_request)(clap_host_t *host, + clap_id change_id, + bool succeed, + const char *error_msg); + void (*after_redo_request)(clap_host_t *host, + clap_id change_id, + bool succeed, + const char *error_msg); +} clap_host_undo_t; diff --git a/include/clap/ext/gui.h b/include/clap/ext/gui.h @@ -118,7 +118,7 @@ typedef struct clap_plugin_gui { // // After this call, the GUI may not be visible yet; don't forget to call show(). // - // Returns true if the GUI is successfuly created. + // Returns true if the GUI is successfully created. // [main-thread] bool(CLAP_ABI *create)(const clap_plugin_t *plugin, const char *api, bool is_floating); diff --git a/include/clap/factory/draft/preset-discovery.h b/include/clap/factory/draft/preset-discovery.h @@ -61,7 +61,7 @@ enum clap_preset_discovery_location_kind { CLAP_PRESET_DISCOVERY_LOCATION_FILE = 0, // The preset is bundled within the plugin DSO itself. - // The location must then be null, as the preset are within the plugin itsel and then the plugin + // The location must then be null, as the preset are within the plugin itself and then the plugin // will act as a preset container. CLAP_PRESET_DISCOVERY_LOCATION_PLUGIN = 1, }; diff --git a/include/clap/plugin.h b/include/clap/plugin.h @@ -16,7 +16,7 @@ typedef struct clap_plugin_descriptor { // Otherwise the fields can be null or blank, though it is safer to make them blank. // // Some indications regarding id and version - // - id is an arbritrary string which should be unique to your plugin, + // - id is an arbitrary string which should be unique to your plugin, // we encourage you to use a reverse URI eg: "com.u-he.diva" // - version is an arbitrary string which describes a plugin, // it is useful for the host to understand and be able to compare two different diff --git a/include/clap/private/macros.h b/include/clap/private/macros.h @@ -25,20 +25,26 @@ # endif #endif -#if defined(__cplusplus) && __cplusplus >= 201103L +#if defined(_MSVC_LANG) +# define CLAP_CPLUSPLUS _MSVC_LANG +#elif defined(__cplusplus) +# define CLAP_CPLUSPLUS __cplusplus +#endif + +#if defined(CLAP_CPLUSPLUS) && CLAP_CPLUSPLUS >= 201103L # define CLAP_HAS_CXX11 # define CLAP_CONSTEXPR constexpr #else # define CLAP_CONSTEXPR #endif -#if defined(__cplusplus) && __cplusplus >= 201703L +#if defined(CLAP_CPLUSPLUS) && CLAP_CPLUSPLUS >= 201703L # define CLAP_HAS_CXX17 # define CLAP_NODISCARD [[nodiscard]] #else # define CLAP_NODISCARD #endif -#if defined(__cplusplus) && __cplusplus >= 202002L +#if defined(CLAP_CPLUSPLUS) && CLAP_CPLUSPLUS >= 202002L # define CLAP_HAS_CXX20 #endif diff --git a/src/main.cc b/src/main.cc @@ -48,6 +48,18 @@ #error CLAP_VERSION_LT is inconsistent (REVISION) #endif +#if (CLAP_COMPILE_TEST_CXX_VERSION >= 11) && ! defined(CLAP_HAS_CXX11) +#error CLAP_HAS_CXX11 is not defined correctly +#endif + +#if (CLAP_COMPILE_TEST_CXX_VERSION >= 17) && ! defined(CLAP_HAS_CXX17) +#error CLAP_HAS_CXX17 is not defined correctly +#endif + +#if (CLAP_COMPILE_TEST_CXX_VERSION >= 20) && ! defined(CLAP_HAS_CXX20) +#error CLAP_HAS_CXX20 is not defined correctly +#endif + static const CLAP_CONSTEXPR clap_version m = CLAP_VERSION; int main(int, char **) {