From 7091e4d54f29a01c191179174c96bbca9a2c3a44 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Thu, 18 Mar 2021 16:40:33 +0100 Subject: [PATCH 1/3] Make the importer a library of its own --- plugins/CMakeLists.txt | 9 ++------- plugins/lv2/CMakeLists.txt | 2 +- plugins/lv2/sfizz.cpp | 2 +- plugins/vst/CMakeLists.txt | 4 +++- plugins/vst/SfizzVstProcessor.cpp | 2 +- src/CMakeLists.txt | 18 ++++++++++++++++++ .../sfizz/import}/ForeignInstrument.cpp | 0 .../sfizz/import}/ForeignInstrument.h | 0 .../import}/foreign_instruments/AudioFile.cpp | 0 .../import}/foreign_instruments/AudioFile.h | 0 10 files changed, 26 insertions(+), 11 deletions(-) rename {plugins/common/plugin => src/sfizz/import}/ForeignInstrument.cpp (100%) rename {plugins/common/plugin => src/sfizz/import}/ForeignInstrument.h (100%) rename {plugins/common/plugin => src/sfizz/import}/foreign_instruments/AudioFile.cpp (100%) rename {plugins/common/plugin => src/sfizz/import}/foreign_instruments/AudioFile.h (100%) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index f69bbe0f..a1fe191b 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,15 +1,10 @@ add_library(plugins-common STATIC EXCLUDE_FROM_ALL "common/plugin/MessageUtils.h" - "common/plugin/MessageUtils.cpp" - "common/plugin/ForeignInstrument.h" - "common/plugin/ForeignInstrument.cpp" - "common/plugin/foreign_instruments/AudioFile.h" - "common/plugin/foreign_instruments/AudioFile.cpp") + "common/plugin/MessageUtils.cpp") target_include_directories(plugins-common PUBLIC "common") target_link_libraries(plugins-common PUBLIC sfizz::spin_mutex - PUBLIC sfizz::filesystem absl::strings - PRIVATE sfizz::pugixml absl::memory) + PUBLIC sfizz::filesystem absl::strings) add_library(sfizz::plugins-common ALIAS plugins-common) if((SFIZZ_LV2 AND SFIZZ_LV2_UI) OR SFIZZ_VST) diff --git a/plugins/lv2/CMakeLists.txt b/plugins/lv2/CMakeLists.txt index ee07b3da..ff97e859 100644 --- a/plugins/lv2/CMakeLists.txt +++ b/plugins/lv2/CMakeLists.txt @@ -21,7 +21,7 @@ source_group("Turtle Files" FILES add_library(${LV2PLUGIN_PRJ_NAME} MODULE ${PROJECT_NAME}.cpp ${LV2PLUGIN_TTL_SRC_FILES}) -target_link_libraries(${LV2PLUGIN_PRJ_NAME} PRIVATE sfizz::sfizz sfizz::plugins-common) +target_link_libraries(${LV2PLUGIN_PRJ_NAME} PRIVATE sfizz::sfizz sfizz::import sfizz::plugins-common) if(SFIZZ_LV2_UI) add_library(${LV2PLUGIN_PRJ_NAME}_ui MODULE diff --git a/plugins/lv2/sfizz.cpp b/plugins/lv2/sfizz.cpp index a1467ec2..4ba2503c 100644 --- a/plugins/lv2/sfizz.cpp +++ b/plugins/lv2/sfizz.cpp @@ -34,7 +34,7 @@ #include "sfizz_lv2.h" -#include "plugin/ForeignInstrument.h" +#include "sfizz/import/ForeignInstrument.h" #include #include diff --git a/plugins/vst/CMakeLists.txt b/plugins/vst/CMakeLists.txt index a3cba79b..f6bd7724 100644 --- a/plugins/vst/CMakeLists.txt +++ b/plugins/vst/CMakeLists.txt @@ -62,6 +62,7 @@ if(WIN32) endif() target_link_libraries(${VSTPLUGIN_PRJ_NAME} PRIVATE sfizz::sfizz + PRIVATE sfizz::import PRIVATE sfizz::editor PRIVATE sfizz::plugins-common PRIVATE sfizz::pugixml sfizz::filesystem) @@ -200,7 +201,8 @@ elseif(SFIZZ_AU) "${APPLE_COREMIDI_LIBRARY}") target_link_libraries(${AUPLUGIN_PRJ_NAME} - PRIVATE ${PROJECT_NAME}::${PROJECT_NAME} + PRIVATE sfizz::sfizz + PRIVATE sfizz::import PRIVATE sfizz::editor PRIVATE sfizz::plugins-common PRIVATE sfizz::pugixml sfizz::filesystem) diff --git a/plugins/vst/SfizzVstProcessor.cpp b/plugins/vst/SfizzVstProcessor.cpp index b1707fb7..4fd0c917 100644 --- a/plugins/vst/SfizzVstProcessor.cpp +++ b/plugins/vst/SfizzVstProcessor.cpp @@ -9,7 +9,7 @@ #include "SfizzVstState.h" #include "SfizzVstParameters.h" #include "SfizzFileScan.h" -#include "plugin/ForeignInstrument.h" +#include "sfizz/import/ForeignInstrument.h" #include "base/source/fstreamer.h" #include "pluginterfaces/vst/ivstevents.h" #include "pluginterfaces/vst/ivstparameterchanges.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 709c6990..0d94d7d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -242,6 +242,24 @@ if(SFIZZ_RELEASE_ASSERTS) target_compile_definitions(sfizz_messaging PUBLIC "SFIZZ_ENABLE_RELEASE_ASSERT=1") endif() +# Import library +set(SFIZZ_IMPORT_HEADERS + sfizz/import/ForeignInstrument.h + sfizz/import/foreign_instruments/AudioFile.h) + +set(SFIZZ_IMPORT_SOURCES + sfizz/import/ForeignInstrument.cpp + sfizz/import/foreign_instruments/AudioFile.cpp) + +add_library(sfizz_import STATIC) +add_library(sfizz::import ALIAS sfizz_import) +target_sources(sfizz_import PRIVATE + ${SFIZZ_IMPORT_HEADERS} ${SFIZZ_IMPORT_SOURCES}) +target_include_directories(sfizz_import PUBLIC ".") +target_link_libraries(sfizz_import + PUBLIC absl::strings absl::memory sfizz::filesystem + PRIVATE sfizz::pugixml) + # Sfizz spinlock mutex add_library(sfizz_spin_mutex STATIC sfizz/utility/spin_mutex/spin_mutex.h diff --git a/plugins/common/plugin/ForeignInstrument.cpp b/src/sfizz/import/ForeignInstrument.cpp similarity index 100% rename from plugins/common/plugin/ForeignInstrument.cpp rename to src/sfizz/import/ForeignInstrument.cpp diff --git a/plugins/common/plugin/ForeignInstrument.h b/src/sfizz/import/ForeignInstrument.h similarity index 100% rename from plugins/common/plugin/ForeignInstrument.h rename to src/sfizz/import/ForeignInstrument.h diff --git a/plugins/common/plugin/foreign_instruments/AudioFile.cpp b/src/sfizz/import/foreign_instruments/AudioFile.cpp similarity index 100% rename from plugins/common/plugin/foreign_instruments/AudioFile.cpp rename to src/sfizz/import/foreign_instruments/AudioFile.cpp diff --git a/plugins/common/plugin/foreign_instruments/AudioFile.h b/src/sfizz/import/foreign_instruments/AudioFile.h similarity index 100% rename from plugins/common/plugin/foreign_instruments/AudioFile.h rename to src/sfizz/import/foreign_instruments/AudioFile.h From 704b06a7308233116e6d438066a2d901197d53fe Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Thu, 18 Mar 2021 16:50:23 +0100 Subject: [PATCH 2/3] 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; +} From 61e73fd1a19ac65c914a7014f01915379874266a Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Thu, 18 Mar 2021 16:53:15 +0100 Subject: [PATCH 3/3] Display the list of available import formats --- devtools/Importer.cpp | 6 +++++- src/sfizz/import/ForeignInstrument.h | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/devtools/Importer.cpp b/devtools/Importer.cpp index 2b2f8b75..44d5bb35 100644 --- a/devtools/Importer.cpp +++ b/devtools/Importer.cpp @@ -3,14 +3,18 @@ int main(int argc, char* argv[]) { + const sfz::InstrumentFormatRegistry& formatRegistry = sfz::InstrumentFormatRegistry::getInstance(); + if (argc != 2) { std::cerr << "Usage: sfizz_importer \n"; + std::cerr << "--\n" "Supported formats:\n"; + for (const sfz::InstrumentFormat* format : formatRegistry.getAllFormats()) + std::cerr << " * " << format->name() << '\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) { diff --git a/src/sfizz/import/ForeignInstrument.h b/src/sfizz/import/ForeignInstrument.h index 94baacf8..cba75b66 100644 --- a/src/sfizz/import/ForeignInstrument.h +++ b/src/sfizz/import/ForeignInstrument.h @@ -34,6 +34,11 @@ public: */ const InstrumentFormat* getMatchingFormat(const fs::path& path) const; + /** + * @brief Get the list of registered formats. + */ + const std::vector& getAllFormats() const noexcept { return formats_; } + private: std::vector formats_; };