Add Midnam bindings in C++
And a couple tests...
This commit is contained in:
parent
c96700937b
commit
2d3b62b69c
4 changed files with 55 additions and 1 deletions
|
|
@ -242,6 +242,16 @@ public:
|
||||||
*/
|
*/
|
||||||
int getNumCurves() const noexcept;
|
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.
|
* @brief Return a list of unsupported opcodes, if any.
|
||||||
* @since 0.2.0
|
* @since 0.2.0
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,11 @@ int sfz::Sfizz::getNumCurves() const noexcept
|
||||||
return synth->synth.getNumCurves();
|
return synth->synth.getNumCurves();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string sfz::Sfizz::exportMidnam(const std::string& model) const noexcept
|
||||||
|
{
|
||||||
|
return synth->synth.exportMidnam(model);
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<std::string>& sfz::Sfizz::getUnknownOpcodes() const noexcept
|
const std::vector<std::string>& sfz::Sfizz::getUnknownOpcodes() const noexcept
|
||||||
{
|
{
|
||||||
return synth->synth.getUnknownOpcodes();
|
return synth->synth.getUnknownOpcodes();
|
||||||
|
|
|
||||||
38
tests/BindingsT.cpp
Normal file
38
tests/BindingsT.cpp
Normal file
|
|
@ -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("<Note Number=\"12\" Name=\"Cymbals\" />") != xmlMidnam.npos);
|
||||||
|
REQUIRE(xmlMidnam.find("<Note Number=\"65\" Name=\"Crash\" />") != xmlMidnam.npos);
|
||||||
|
REQUIRE(xmlMidnam.find("<Control Type=\"7bit\" Number=\"54\" Name=\"Gain\" />") != xmlMidnam.npos);
|
||||||
|
REQUIRE(xmlMidnam.find("<Control Type=\"7bit\" Number=\"2\" Name=\"Other\" />") != 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("<Note Number=\"12\" Name=\"Cymbals\" />") != xmlMidnam.npos);
|
||||||
|
REQUIRE(xmlMidnam.find("<Note Number=\"65\" Name=\"Crash\" />") != xmlMidnam.npos);
|
||||||
|
REQUIRE(xmlMidnam.find("<Control Type=\"7bit\" Number=\"54\" Name=\"Gain\" />") != xmlMidnam.npos);
|
||||||
|
REQUIRE(xmlMidnam.find("<Control Type=\"7bit\" Number=\"2\" Name=\"Other\" />") != xmlMidnam.npos);
|
||||||
|
free(midnamChar);
|
||||||
|
sfizz_free(synth);
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,7 @@ set(SFIZZ_TEST_SOURCES
|
||||||
TestHelpers.h
|
TestHelpers.h
|
||||||
TestHelpers.cpp
|
TestHelpers.cpp
|
||||||
ParsingT.cpp
|
ParsingT.cpp
|
||||||
|
BindingsT.cpp
|
||||||
HelpersT.cpp
|
HelpersT.cpp
|
||||||
HelpersT.cpp
|
HelpersT.cpp
|
||||||
AudioBufferT.cpp
|
AudioBufferT.cpp
|
||||||
|
|
@ -53,7 +54,7 @@ set(SFIZZ_TEST_SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(sfizz_tests ${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_lto_if_needed(sfizz_tests)
|
||||||
sfizz_enable_fast_math(sfizz_tests)
|
sfizz_enable_fast_math(sfizz_tests)
|
||||||
catch_discover_tests(sfizz_tests)
|
catch_discover_tests(sfizz_tests)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue