From aa2d33bf5c241eb199d8a0a81e931d12c1708182 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Tue, 7 Nov 2023 08:02:36 +0900 Subject: [PATCH] StandardExtensions are null checked now. Bump extension version numbers. They can be missing from aap_manifest.xml, and the default UI should not crash because of that. --- include/aap/core/aapxs/standard-extensions.h | 60 +++++++++++++------ include/aap/ext/gui.h | 2 +- include/aap/ext/parameters.h | 2 +- include/aap/ext/port-config.h | 2 +- include/aap/ext/state.h | 2 +- .../src/main/res/xml/aap_metadata.xml | 20 ++----- .../src/main/res/xml/aap_metadata.xml | 6 +- .../src/main/res/xml/aap_metadata.xml | 4 +- 8 files changed, 54 insertions(+), 44 deletions(-) diff --git a/include/aap/core/aapxs/standard-extensions.h b/include/aap/core/aapxs/standard-extensions.h index 24f79c0e..43e44877 100644 --- a/include/aap/core/aapxs/standard-extensions.h +++ b/include/aap/core/aapxs/standard-extensions.h @@ -127,40 +127,62 @@ namespace aap::xs { } // MIDI - int32_t getMidiMappingPolicy() override { return midi->get_mapping_policy(midi, plugin); } + int32_t getMidiMappingPolicy() override { return midi ? midi->get_mapping_policy(midi, plugin) : 0; } // Parameters - int32_t getParameterCount() override { return parameters->get_parameter_count(parameters, plugin); } - aap_parameter_info_t getParameter(int32_t index) override { return parameters->get_parameter(parameters, plugin, index); } - double getParameterProperty(int32_t index, int32_t propertyId) override { return parameters->get_parameter_property(parameters, plugin, index, propertyId); } - int32_t getEnumerationCount(int32_t index) override { return parameters->get_enumeration_count(parameters, plugin, index); } - aap_parameter_enum_t getEnumeration(int32_t index, int32_t enumIndex) override { return parameters->get_enumeration(parameters, plugin, index, enumIndex); } + int32_t getParameterCount() override { return parameters ? parameters->get_parameter_count(parameters, plugin) : 0; } + aap_parameter_info_t getParameter(int32_t index) override { return parameters ? parameters->get_parameter(parameters, plugin, index) : aap_parameter_info_t{}; } + double getParameterProperty(int32_t index, int32_t propertyId) override { return parameters ? parameters->get_parameter_property(parameters, plugin, index, propertyId) : 0.0; } + int32_t getEnumerationCount(int32_t index) override { return parameters ? parameters->get_enumeration_count(parameters, plugin, index) : 0; } + aap_parameter_enum_t getEnumeration(int32_t index, int32_t enumIndex) override { return parameters ? parameters->get_enumeration(parameters, plugin, index, enumIndex) : aap_parameter_enum_t{}; } // Presets - int32_t getPresetCount() override { return presets->get_preset_count(presets, plugin); } - void getPreset(int32_t index, aap_preset_t& preset) override { presets->get_preset(presets, plugin, index, &preset, nullptr, nullptr); } + int32_t getPresetCount() override { return presets ? presets->get_preset_count(presets, plugin) : 0; } + void getPreset(int32_t index, aap_preset_t& preset) override { if (presets) presets->get_preset(presets, plugin, index, &preset, nullptr, nullptr); } std::string getPresetName(int32_t index) override { + if (!presets) + return ""; aap_preset_t preset; + getPreset(index, preset); return preset.name; } - int32_t getCurrentPresetIndex() override { return presets->get_preset_index(presets, plugin); } - void setCurrentPresetIndex(int32_t index) override { presets->set_preset_index(presets, plugin, index); } + int32_t getCurrentPresetIndex() override { return presets ? presets->get_preset_index(presets, plugin) : 0; } + void setCurrentPresetIndex(int32_t index) override { if (presets) presets->set_preset_index(presets, plugin, index); } // State - int32_t getStateSize() override { return state->get_state_size(state, plugin); } + int32_t getStateSize() override { return state ? state->get_state_size(state, plugin) : 0; } aap_state_t getState() override { - aap_state_t stateToSave; - state->get_state(state, plugin, &stateToSave); + aap_state_t stateToSave{}; + if (state) + state->get_state(state, plugin, &stateToSave); return stateToSave; } - void setState(aap_state_t& stateToLoad) override { state->set_state(state, plugin, &stateToLoad); } + void setState(aap_state_t& stateToLoad) override { if (state) state->set_state(state, plugin, &stateToLoad); } // Gui - aap_gui_instance_id createGui(std::string pluginId, int32_t instanceId, void* audioPluginView) override { return gui->create(gui, plugin, pluginId.c_str(), instanceId, audioPluginView); } - int32_t showGui(aap_gui_instance_id guiInstanceId) override { return gui->show(gui, plugin, guiInstanceId); } - int32_t hideGui(aap_gui_instance_id guiInstanceId) override { gui->hide(gui, plugin, guiInstanceId); return 0; } - int32_t resizeGui(aap_gui_instance_id guiInstanceId, int32_t width, int32_t height) override { return gui->resize(gui, plugin, guiInstanceId, width, height); } - int32_t destroyGui(aap_gui_instance_id guiInstanceId) override { gui->destroy(gui, plugin, guiInstanceId); return 0; } + aap_gui_instance_id createGui(std::string pluginId, int32_t instanceId, void* audioPluginView) override { return gui ? gui->create(gui, plugin, pluginId.c_str(), instanceId, audioPluginView) : -1; } + int32_t showGui(aap_gui_instance_id guiInstanceId) override { return gui ? gui->show ? gui->show(gui, plugin, guiInstanceId) : AAP_GUI_ERROR_NO_SHOW_DEFINED : AAP_GUI_ERROR_NO_GUI_DEFINED; } + int32_t hideGui(aap_gui_instance_id guiInstanceId) override { + if (gui) + if (gui->hide) + gui->hide(gui, plugin, guiInstanceId); + else + return AAP_GUI_ERROR_NO_HIDE_DEFINED; + else + return AAP_GUI_ERROR_NO_GUI_DEFINED; + return 0; + } + int32_t resizeGui(aap_gui_instance_id guiInstanceId, int32_t width, int32_t height) override { return gui ? gui->resize ? gui->resize(gui, plugin, guiInstanceId, width, height) : AAP_GUI_ERROR_NO_RESIZE_DEFINED : AAP_GUI_ERROR_NO_GUI_DEFINED; } + int32_t destroyGui(aap_gui_instance_id guiInstanceId) override { + if (gui) + if (gui->destroy) + gui->destroy(gui, plugin, guiInstanceId); + else + return AAP_GUI_ERROR_NO_DESTROY_DEFINED; + else + return AAP_GUI_ERROR_NO_GUI_DEFINED; + return 0; + } }; class StandardHostExtensions { diff --git a/include/aap/ext/gui.h b/include/aap/ext/gui.h index c724c336..26737999 100644 --- a/include/aap/ext/gui.h +++ b/include/aap/ext/gui.h @@ -8,7 +8,7 @@ extern "C" { #endif -#define AAP_GUI_EXTENSION_URI "urn://androidaudioplugin.org/extensions/gui/v2" +#define AAP_GUI_EXTENSION_URI "urn://androidaudioplugin.org/extensions/gui/v3" typedef int32_t aap_gui_instance_id; diff --git a/include/aap/ext/parameters.h b/include/aap/ext/parameters.h index 54acc3da..f9b992c4 100644 --- a/include/aap/ext/parameters.h +++ b/include/aap/ext/parameters.h @@ -8,7 +8,7 @@ extern "C" { #endif -#define AAP_PARAMETERS_EXTENSION_URI "urn://androidaudioplugin.org/extensions/parameters/v2.1" +#define AAP_PARAMETERS_EXTENSION_URI "urn://androidaudioplugin.org/extensions/parameters/v3" #define AAP_PARAMETERS_XMLNS_URI "urn://androidaudioplugin.org/extensions/parameters" #define AAP_MAX_PARAMETER_NAME_CHARS 64 diff --git a/include/aap/ext/port-config.h b/include/aap/ext/port-config.h index b13c883d..01881216 100644 --- a/include/aap/ext/port-config.h +++ b/include/aap/ext/port-config.h @@ -8,7 +8,7 @@ extern "C" { #include "../android-audio-plugin.h" #include -#define AAP_PORT_CONFIG_EXTENSION_URI "urn://androidaudioplugin.org/extensions/port-config/v2" +#define AAP_PORT_CONFIG_EXTENSION_URI "urn://androidaudioplugin.org/extensions/port-config/v3" #define AAP_PORT_CONFIG_DEFAULT_INSTRUMENT "urn://androidaudioplugin.org/port-config/default/instrument/v1" #define AAP_PORT_CONFIG_DEFAULT_EFFECT "urn://androidaudioplugin.org/port-config/default/effect/v1" diff --git a/include/aap/ext/state.h b/include/aap/ext/state.h index 479cad65..b541ff20 100644 --- a/include/aap/ext/state.h +++ b/include/aap/ext/state.h @@ -8,7 +8,7 @@ extern "C" { #include "../android-audio-plugin.h" #include "stdint.h" -#define AAP_STATE_EXTENSION_URI "urn://androidaudioplugin.org/extensions/state/v2" +#define AAP_STATE_EXTENSION_URI "urn://androidaudioplugin.org/extensions/state/v3" typedef struct { void* data; diff --git a/samples/aapbarebonepluginsample/src/main/res/xml/aap_metadata.xml b/samples/aapbarebonepluginsample/src/main/res/xml/aap_metadata.xml index edc426c3..c56699b8 100644 --- a/samples/aapbarebonepluginsample/src/main/res/xml/aap_metadata.xml +++ b/samples/aapbarebonepluginsample/src/main/res/xml/aap_metadata.xml @@ -5,22 +5,10 @@ gui:ui-view-factory="org.androidaudioplugin.ui.compose.ComposeAudioPluginViewFactory" xmlns:gui="urn://androidaudioplugin.org/extensions/gui"> - - - - + + + + - diff --git a/samples/aapinstrumentsample/src/main/res/xml/aap_metadata.xml b/samples/aapinstrumentsample/src/main/res/xml/aap_metadata.xml index 99265dbd..ae6d91d6 100644 --- a/samples/aapinstrumentsample/src/main/res/xml/aap_metadata.xml +++ b/samples/aapinstrumentsample/src/main/res/xml/aap_metadata.xml @@ -7,9 +7,9 @@ - - - + + + diff --git a/samples/aapxssample/src/main/res/xml/aap_metadata.xml b/samples/aapxssample/src/main/res/xml/aap_metadata.xml index c9f4fdcb..578c8845 100644 --- a/samples/aapxssample/src/main/res/xml/aap_metadata.xml +++ b/samples/aapxssample/src/main/res/xml/aap_metadata.xml @@ -1,8 +1,8 @@ - - + +