diff --git a/plugins/lv2/sfizz.cpp b/plugins/lv2/sfizz.cpp index 912c04b1..ec8e1518 100644 --- a/plugins/lv2/sfizz.cpp +++ b/plugins/lv2/sfizz.cpp @@ -1707,7 +1707,7 @@ midnam_export(LV2_Handle instance) static void midnam_free(char *string) { - free(string); + sfizz_free_memory(string); } static const void * diff --git a/src/sfizz.h b/src/sfizz.h index 6dee8b7b..3c776e1b 100644 --- a/src/sfizz.h +++ b/src/sfizz.h @@ -274,7 +274,7 @@ SFIZZ_EXPORTED_API int sfizz_get_num_curves(sfizz_synth_t* synth); * @param synth The synth. * @param model The model name used if a non-empty string, otherwise generated. * - * @return A newly allocated XML string, which must be freed after use. + * @return A newly allocated XML string, which must be freed after use using sfizz_free_memory(). */ SFIZZ_EXPORTED_API char* sfizz_export_midnam(sfizz_synth_t* synth, const char* model); @@ -1097,6 +1097,14 @@ SFIZZ_EXPORTED_API int sfizz_get_cc_label_number(sfizz_synth_t* synth, int label */ SFIZZ_EXPORTED_API const char * sfizz_get_cc_label_text(sfizz_synth_t* synth, int label_index); +/** + * @brief Free a block of memory allocated by the library. + * @brief 1.0.0 + * + * @param ptr The address of the memory to free. + */ +SFIZZ_EXPORTED_API void sfizz_free_memory(void* ptr); + /** * @addtogroup Messaging * @{ diff --git a/src/sfizz.hpp b/src/sfizz.hpp index 2feb9fe1..7b5a250a 100644 --- a/src/sfizz.hpp +++ b/src/sfizz.hpp @@ -980,7 +980,7 @@ public: * * @return A XML string. */ - std::string exportMidnam(const char* model); + std::string exportMidnam(const std::string& model) const; /** * @addtogroup Messaging diff --git a/src/sfizz/sfizz.cpp b/src/sfizz/sfizz.cpp index 57cb8e24..2a1d2d9d 100644 --- a/src/sfizz/sfizz.cpp +++ b/src/sfizz/sfizz.cpp @@ -338,7 +338,7 @@ void sfz::Sfizz::enableLogging(const std::string& prefix) noexcept void sfz::Sfizz::setLoggingPrefix(const std::string& prefix) noexcept { - + (void)prefix; } void sfz::Sfizz::disableLogging() noexcept @@ -361,7 +361,7 @@ void sfz::Sfizz::clearExternalDefinitions() synth->synth.getParser().clearExternalDefinitions(); } -std::string sfz::Sfizz::exportMidnam(const char* model) +std::string sfz::Sfizz::exportMidnam(const std::string& model) const { return synth->synth.exportMidnam(model); } diff --git a/src/sfizz/sfizz_wrapper.cpp b/src/sfizz/sfizz_wrapper.cpp index 4c5c4ca1..5166081d 100644 --- a/src/sfizz/sfizz_wrapper.cpp +++ b/src/sfizz/sfizz_wrapper.cpp @@ -319,7 +319,8 @@ void sfizz_enable_logging(sfizz_synth_t* synth, const char* prefix) void sfizz_set_logging_prefix(sfizz_synth_t* synth, const char* prefix) { - + (void)synth; + (void)prefix; } void sfizz_disable_logging(sfizz_synth_t* synth) @@ -410,6 +411,11 @@ const char * sfizz_get_cc_label_text(sfizz_synth_t* synth, int label_index) return ccLabels[label_index].second.c_str(); } +void sfizz_free_memory(void* ptr) +{ + free(ptr); +} + sfizz_client_t* sfizz_create_client(void* data) { return reinterpret_cast(new sfz::Client(data)); diff --git a/tests/BindingsT.cpp b/tests/BindingsT.cpp new file mode 100644 index 00000000..5ce32011 --- /dev/null +++ b/tests/BindingsT.cpp @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: BSD-2-Clause + +// This code is part of the sfizz library and is licensed under a BSD 2-clause +// license. You should have receive a LICENSE.md file along with the code. +// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz + +#include "sfizz.h" +#include "sfizz.hpp" +#include "catch2/catch.hpp" +#include "ghc/fs_std.hpp" + +TEST_CASE("[Bindings] Midnam C++") +{ + sfz::Sfizz synth; + const auto path = fs::current_path() / "tests/TestFiles/labels.sfz"; + synth.loadSfzFile(path.string()); + const std::string xmlMidnam = synth.exportMidnam(""); + REQUIRE(xmlMidnam.find("") != xmlMidnam.npos); + REQUIRE(xmlMidnam.find("") != xmlMidnam.npos); + REQUIRE(xmlMidnam.find("") != xmlMidnam.npos); + REQUIRE(xmlMidnam.find("") != xmlMidnam.npos); +} + +TEST_CASE("[Bindings] Midnam C") +{ + sfizz_synth_t* synth = sfizz_create_synth(); + const auto path = fs::current_path() / "tests/TestFiles/labels.sfz"; + const auto strPath = path.string(); + sfizz_load_file(synth, strPath.c_str()); + char* midnamChar = sfizz_export_midnam(synth, ""); + const std::string xmlMidnam = std::string(midnamChar); + REQUIRE(xmlMidnam.find("") != xmlMidnam.npos); + REQUIRE(xmlMidnam.find("") != xmlMidnam.npos); + REQUIRE(xmlMidnam.find("") != xmlMidnam.npos); + REQUIRE(xmlMidnam.find("") != xmlMidnam.npos); + sfizz_free_memory(midnamChar); + sfizz_free(synth); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 013115aa..2e5f70a9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,6 +13,7 @@ set(SFIZZ_TEST_SOURCES TestHelpers.h TestHelpers.cpp ParsingT.cpp + BindingsT.cpp HelpersT.cpp HelpersT.cpp AudioBufferT.cpp @@ -53,7 +54,7 @@ set(SFIZZ_TEST_SOURCES ) add_executable(sfizz_tests ${SFIZZ_TEST_SOURCES}) -target_link_libraries(sfizz_tests PRIVATE sfizz::internal sfizz::spin_mutex sfizz::jsl sfizz::filesystem) +target_link_libraries(sfizz_tests PRIVATE sfizz::internal sfizz::static sfizz::spin_mutex sfizz::jsl sfizz::filesystem) sfizz_enable_lto_if_needed(sfizz_tests) sfizz_enable_fast_math(sfizz_tests) catch_discover_tests(sfizz_tests)