Add tool: importer

This commit is contained in:
Jean Pierre Cimalando 2021-03-18 16:50:23 +01:00
parent 7091e4d54f
commit 704b06a730
2 changed files with 38 additions and 0 deletions

View file

@ -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)

35
devtools/Importer.cpp Normal file
View file

@ -0,0 +1,35 @@
#include "sfizz/import/ForeignInstrument.h"
#include <iostream>
int main(int argc, char* argv[])
{
if (argc != 2) {
std::cerr << "Usage: sfizz_importer <foreign-instrument>\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;
}