diff --git a/backends/playback/fluidsynth/fluidsynth_backend.cpp b/backends/playback/fluidsynth/fluidsynth_backend.cpp index d32d607..2c8e23a 100644 --- a/backends/playback/fluidsynth/fluidsynth_backend.cpp +++ b/backends/playback/fluidsynth/fluidsynth_backend.cpp @@ -10,7 +10,21 @@ #include #include #include +#include namespace fs = std::filesystem; +using Looper::Log::LogStream; +static void log_fn(int level, const char *msg, void *data) { + LogStream *stream; + switch (level) { + case FLUID_ERR: + case FLUID_PANIC: stream = &ERROR; break; + case FLUID_WARN: stream = &WARNING; break; + default: + case FLUID_INFO: stream = &INFO; break; + case FLUID_DBG: stream = &DEBUG; break; + } + stream->writeln(msg); +} void FluidSynthBackend::fluidsynth_get_property_list_wrapper(void *udata, const char *name, int type) { ((FluidSynthBackend*)udata)->fluidsynth_get_property_list(name, type); } @@ -48,11 +62,20 @@ void FluidSynthBackend::fluidsynth_get_property_list(const char *name, int type) property.set_id(PropertyId::BackendSpecific); fluidsynth_properties.push_back(property); } +static bool log_fn_registered = false; std::vector FluidSynthBackend::get_property_list() { return fluidsynth_properties; } void FluidSynthBackend::load(const char *filename) { memset(&spec, 0, sizeof(spec)); + if (!log_fn_registered) { + fluid_set_log_function(FLUID_PANIC, &log_fn, nullptr); + fluid_set_log_function(FLUID_ERR, &log_fn, nullptr); + fluid_set_log_function(FLUID_WARN, &log_fn, nullptr); + fluid_set_log_function(FLUID_INFO, &log_fn, nullptr); + fluid_set_log_function(FLUID_DBG, &log_fn, nullptr); + log_fn_registered = true; + } current_file = filename; spec.format = AUDIO_F32SYS; spec.samples = 100;