From 704b06a7308233116e6d438066a2d901197d53fe Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Thu, 18 Mar 2021 16:50:23 +0100 Subject: [PATCH] Add tool: importer --- devtools/CMakeLists.txt | 3 +++ devtools/Importer.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 devtools/Importer.cpp diff --git a/devtools/CMakeLists.txt b/devtools/CMakeLists.txt index e1bc85f6..b561045f 100644 --- a/devtools/CMakeLists.txt +++ b/devtools/CMakeLists.txt @@ -11,5 +11,8 @@ endif() add_executable(sfizz_preprocessor Preprocessor.cpp) target_link_libraries(sfizz_preprocessor PRIVATE sfizz::parser sfizz::pugixml sfizz::cxxopts) +add_executable(sfizz_importer Importer.cpp) +target_link_libraries(sfizz_importer PRIVATE sfizz::import) + add_executable(sfizz_hiir_designer HIIRDesigner.cpp) target_link_libraries(sfizz_hiir_designer PRIVATE sfizz::hiir_polyphase_iir2designer) diff --git a/devtools/Importer.cpp b/devtools/Importer.cpp new file mode 100644 index 00000000..2b2f8b75 --- /dev/null +++ b/devtools/Importer.cpp @@ -0,0 +1,35 @@ +#include "sfizz/import/ForeignInstrument.h" +#include + +int main(int argc, char* argv[]) +{ + if (argc != 2) { + std::cerr << "Usage: sfizz_importer \n"; + return 1; + } + + const fs::path foreignPath = fs::u8path(argv[1]); + + const sfz::InstrumentFormatRegistry& formatRegistry = sfz::InstrumentFormatRegistry::getInstance(); + const sfz::InstrumentFormat* format = formatRegistry.getMatchingFormat(foreignPath); + + if (!format) { + std::cerr << "There is no support for files of this format.\n"; + return 1; + } + + auto importer = format->createImporter(); + std::string text = importer->convertToSfz(foreignPath); + + if (text.empty()) { + std::cerr << "The conversion has failed.\n"; + return 1; + } + + std::cout << text; + if (text.back() != '\n') + std::cout << '\n'; + std::cout << std::flush; + + return 0; +}