From 66e916db195bc58503121c84237ba54c1a0ac36c Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 8 Dec 2019 21:43:15 +0100 Subject: [PATCH] Added a feedback for unknown opcodes in the C wrapper and the LV2 synth --- lv2/sfizz.c | 14 +++++++++++++- src/sfizz.h | 19 +++++++++++++++++++ src/sfizz/sfizz_wrapper.cpp | 23 +++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lv2/sfizz.c b/lv2/sfizz.c index e2b9c7c0..b1abd7f3 100644 --- a/lv2/sfizz.c +++ b/lv2/sfizz.c @@ -802,7 +802,19 @@ work(LV2_Handle instance, { const char *sfz_file_path = LV2_ATOM_BODY_CONST(atom); lv2_log_note(&self->logger, "[work] Loading file: %s\n", sfz_file_path); - sfizz_load_file(self->synth, sfz_file_path); + if (sfizz_load_file(self->synth, sfz_file_path)) + { + char * unknown_opcodes = sfizz_get_unknown_opcodes(self->synth); + if (unknown_opcodes) { + lv2_log_note(&self->logger, "[work] Unknown opcodes: %s\n", unknown_opcodes); + free(unknown_opcodes); + } + } + else + { + lv2_log_error(&self->logger, "[work] Error with %s; no file should be loaded.\n", sfz_file_path); + } + } else if (atom->type == self->sfizz_num_voices_uri) { diff --git a/src/sfizz.h b/src/sfizz.h index 3e185f17..f3aba449 100644 --- a/src/sfizz.h +++ b/src/sfizz.h @@ -324,8 +324,27 @@ int sfizz_get_num_buffers(sfizz_synth_t* synth); */ int sfizz_get_num_bytes(sfizz_synth_t* synth); +/** + * @brief Enables freewheeling on the synth. + * + * @param synth + */ void sfizz_enable_freewheeling(sfizz_synth_t* synth); +/** + * @brief Disables freewheeling on the synth. + * + * @param synth + */ void sfizz_disable_freewheeling(sfizz_synth_t* synth); +/** + * @brief Get a comma separated list of unknown opcodes. The caller has to free() + * the string returned. This function allocates memory, do not call on the + * audio thread. + * + * @param synth + * @return char* + */ +char* sfizz_get_unknown_opcodes(sfizz_synth_t* synth); #ifdef __cplusplus } #endif diff --git a/src/sfizz/sfizz_wrapper.cpp b/src/sfizz/sfizz_wrapper.cpp index 52c593f2..9306cbda 100644 --- a/src/sfizz/sfizz_wrapper.cpp +++ b/src/sfizz/sfizz_wrapper.cpp @@ -216,6 +216,29 @@ void sfizz_disable_freewheeling(sfizz_synth_t* synth) self->disableFreeWheeling(); } +char* sfizz_get_unknown_opcodes(sfizz_synth_t* synth) +{ + auto self = reinterpret_cast(synth); + const auto unknownOpcodes = self->getUnknownOpcodes(); + int totalLength = 0; + for (auto& opcode: unknownOpcodes) + totalLength += opcode.length(); + + if (totalLength == 0) + return nullptr; + + auto opcodeList = (char *)std::malloc(totalLength + unknownOpcodes.size()); + + auto listIterator = opcodeList; + for (auto& opcode: unknownOpcodes) { + std::copy(opcode.begin(), opcode.end(), listIterator); + listIterator += opcode.length(); + *listIterator++ = ','; + } + opcodeList[totalLength] = '\0'; + return opcodeList; +} + #ifdef __cplusplus } #endif