From 2d3b62b69c6826b9bef8c45346e2eafe978deb23 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Thu, 15 Apr 2021 22:25:17 +0200 Subject: [PATCH] Add Midnam bindings in C++ And a couple tests... --- src/sfizz.hpp | 10 ++++++++++ src/sfizz/sfizz.cpp | 5 +++++ tests/BindingsT.cpp | 38 ++++++++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 3 ++- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/BindingsT.cpp diff --git a/src/sfizz.hpp b/src/sfizz.hpp index 2feb9fe1..f06e1867 100644 --- a/src/sfizz.hpp +++ b/src/sfizz.hpp @@ -242,6 +242,16 @@ public: */ int getNumCurves() const noexcept; + /** + * @brief Export a MIDI Name document describing the currently loaded SFZ file. + * @since 0.3.1 + * + * @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. + */ + std::string exportMidnam(const std::string& model) const noexcept; + /** * @brief Return a list of unsupported opcodes, if any. * @since 0.2.0 diff --git a/src/sfizz/sfizz.cpp b/src/sfizz/sfizz.cpp index 57cb8e24..d4e301ae 100644 --- a/src/sfizz/sfizz.cpp +++ b/src/sfizz/sfizz.cpp @@ -110,6 +110,11 @@ int sfz::Sfizz::getNumCurves() const noexcept return synth->synth.getNumCurves(); } +std::string sfz::Sfizz::exportMidnam(const std::string& model) const noexcept +{ + return synth->synth.exportMidnam(model); +} + const std::vector& sfz::Sfizz::getUnknownOpcodes() const noexcept { return synth->synth.getUnknownOpcodes(); diff --git a/tests/BindingsT.cpp b/tests/BindingsT.cpp new file mode 100644 index 00000000..095c57ac --- /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); + free(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)