Merge pull request #926 from jpcima/importer

Enable the importer in JACK and Puredata
This commit is contained in:
JP Cimalando 2021-06-22 21:52:13 +02:00 committed by GitHub
commit c3ee3982ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 30 deletions

View file

@ -1,6 +1,6 @@
if(SFIZZ_JACK)
add_executable(sfizz_jack MidiHelpers.h jack_client.cpp)
target_link_libraries(sfizz_jack PRIVATE sfizz::sfizz sfizz::jack sfizz::spin_mutex absl::flags_parse)
target_link_libraries(sfizz_jack PRIVATE sfizz::import sfizz::sfizz sfizz::jack sfizz::spin_mutex absl::flags_parse)
sfizz_enable_lto_if_needed(sfizz_jack)
install(TARGETS sfizz_jack DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT "jack" OPTIONAL)

View file

@ -22,6 +22,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "sfizz.hpp"
#include "sfizz/import/sfizz_import.h"
#include "MidiHelpers.h"
#include <absl/flags/parse.h>
#include <absl/flags/flag.h>
@ -188,7 +189,13 @@ int main(int argc, char** argv)
sfz::Sfizz synth;
synth.setOversamplingFactor(factor);
synth.setPreloadSize(preload_size);
synth.loadSfzFile(filesToParse[0]);
const char *importFormat = nullptr;
if (!sfizz_load_or_import_file(synth.handle(), filesToParse[0], &importFormat)) {
std::cout << "Could not load the instrument file: " << filesToParse[0] << '\n';
return 1;
}
std::cout << "==========" << '\n';
std::cout << "Total:" << '\n';
std::cout << "\tMasters: " << synth.getNumMasters() << '\n';
@ -211,6 +218,10 @@ int main(int argc, char** argv)
for (auto& opcode : synth.getUnknownOpcodes())
std::cout << opcode << ',';
std::cout << '\n';
if (importFormat) {
std::cout << "==========" << '\n';
std::cout << "Import format: " << importFormat << '\n';
}
// std::cout << std::flush;
jack_status_t status;

View file

@ -35,7 +35,7 @@
#include "sfizz_lv2.h"
#include "sfizz_lv2_plugin.h"
#include "sfizz/import/ForeignInstrument.h"
#include "sfizz/import/sfizz_import.h"
#include "plugin/InstrumentDescription.h"
#include <math.h>
@ -1231,8 +1231,6 @@ sfizz_lv2_update_sfz_info(sfizz_plugin_t *self)
static bool
sfizz_lv2_load_file(sfizz_plugin_t *self, const char *file_path)
{
bool status;
char buf[MAX_PATH_SIZE];
if (file_path[0] == '\0')
{
@ -1241,18 +1239,7 @@ sfizz_lv2_load_file(sfizz_plugin_t *self, const char *file_path)
}
///
const sfz::InstrumentFormatRegistry& formatRegistry = sfz::InstrumentFormatRegistry::getInstance();
const sfz::InstrumentFormat* format = formatRegistry.getMatchingFormat(file_path);
if (!format)
status = sfizz_load_file(self->synth, file_path);
else {
auto importer = format->createImporter();
std::string virtual_path = std::string(file_path) + ".sfz";
std::string sfz_text = importer->convertToSfz(file_path);
status = sfizz_load_string(self->synth, virtual_path.c_str(), sfz_text.c_str());
}
bool status = sfizz_load_or_import_file(self->synth, file_path, nullptr);
sfizz_lv2_update_sfz_info(self);
sfizz_lv2_update_file_info(self, file_path);
return status;

View file

@ -27,7 +27,7 @@ add_pd_external(sfizz_puredata "sfizz_puredata.c")
target_compile_definitions(sfizz_puredata PRIVATE
"SFIZZ_NUM_CCS=${SFIZZ_NUM_CCS}"
"SFIZZ_VERSION=\"${CMAKE_PROJECT_VERSION}\"")
target_link_libraries(sfizz_puredata PRIVATE sfizz::sfizz)
target_link_libraries(sfizz_puredata PRIVATE sfizz::import sfizz::sfizz)
set_target_properties(sfizz_puredata PROPERTIES
OUTPUT_NAME "sfizz"

View file

@ -7,6 +7,7 @@
#include "GitBuildId.h"
#include <m_pd.h>
#include <sfizz.h>
#include <sfizz/import/sfizz_import.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@ -62,7 +63,7 @@ static bool sfizz_tilde_do_load(t_sfizz_tilde* self)
{
bool loaded;
if (self->filepath[0] != '\0')
loaded = sfizz_load_file(self->synth, self->filepath);
loaded = sfizz_load_or_import_file(self->synth, self->filepath, NULL);
else
loaded = sfizz_load_string(self->synth, "default.sfz", "<region>sample=*sine");
return loaded;

View file

@ -9,7 +9,7 @@
#include "SfizzVstState.h"
#include "SfizzVstParameters.h"
#include "SfizzVstIDs.h"
#include "sfizz/import/ForeignInstrument.h"
#include "sfizz/import/sfizz_import.h"
#include "plugin/SfizzFileScan.h"
#include "plugin/InstrumentDescription.h"
#include "base/source/fstreamer.h"
@ -682,16 +682,7 @@ void SfizzVstProcessor::loadSfzFileOrDefault(const std::string& filePath, bool i
sfz::Sfizz& synth = *_synth;
if (!filePath.empty()) {
const sfz::InstrumentFormatRegistry& formatRegistry = sfz::InstrumentFormatRegistry::getInstance();
const sfz::InstrumentFormat* format = formatRegistry.getMatchingFormat(filePath);
if (!format)
synth.loadSfzFile(filePath);
else {
auto importer = format->createImporter();
std::string virtualPath = filePath + ".sfz";
std::string sfzText = importer->convertToSfz(filePath);
synth.loadSfzString(virtualPath, sfzText);
}
sfizz_load_or_import_file(synth.handle(), filePath.c_str(), nullptr);
}
else {
synth.loadSfzString("default.sfz", defaultSfzText);

View file

@ -251,11 +251,13 @@ endif()
# Import library
set(SFIZZ_IMPORT_HEADERS
sfizz/import/sfizz_import.h
sfizz/import/ForeignInstrument.h
sfizz/import/foreign_instruments/AudioFile.h
sfizz/import/foreign_instruments/DecentSampler.h)
set(SFIZZ_IMPORT_SOURCES
sfizz/import/sfizz_import.cpp
sfizz/import/ForeignInstrument.cpp
sfizz/import/foreign_instruments/AudioFile.cpp
sfizz/import/foreign_instruments/DecentSampler.cpp)

View file

@ -0,0 +1,32 @@
// 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_import.h"
#include "ForeignInstrument.h"
bool sfizz_load_or_import_file(sfizz_synth_t* synth, const char* path, const char** format)
{
const sfz::InstrumentFormatRegistry& ireg = sfz::InstrumentFormatRegistry::getInstance();
const sfz::InstrumentFormat* ifmt = ireg.getMatchingFormat(path);
if (!ifmt) {
if (!sfizz_load_file(synth, path))
return false;
if (format)
*format = nullptr;
}
else {
auto importer = ifmt->createImporter();
std::string virtualPath = std::string(path) + ".sfz";
std::string sfzText = importer->convertToSfz(path);
if (!sfizz_load_string(synth, virtualPath.c_str(), sfzText.c_str()))
return false;
if (format)
*format = ifmt->name();
}
return true;
}

View 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
#pragma once
#include <sfizz.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Loads or imports an instrument file.
*
* The file path can be absolute or relative.
* @since 1.0.1
*
* @param synth The synth.
* @param path A null-terminated string representing a path to an instrument
* in SFZ format, or another format which can be imported.
* @param format An optional pointer to a string pointer, which receives the
* null-terminated name of the format if the file was imported,
* or null if the file was loaded directly as SFZ.
*
* @return @true when file loading went OK,
* @false if some error occured while loading.
*
* @par Thread-safety constraints
* - @b CT: the function must be invoked from the Control thread
* - @b OFF: the function cannot be invoked while a thread is calling @b RT functions
*/
bool sfizz_load_or_import_file(sfizz_synth_t* synth, const char* path, const char** format);
#ifdef __cplusplus
} // extern "C"
#endif