diff --git a/src/sfizz.h b/src/sfizz.h index 69faa3ed..63482393 100644 --- a/src/sfizz.h +++ b/src/sfizz.h @@ -394,6 +394,57 @@ SFIZZ_EXPORTED_API void sfizz_add_external_definitions(sfizz_synth_t* synth, con */ SFIZZ_EXPORTED_API void sfizz_clear_external_definitions(sfizz_synth_t* synth); +#define SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX -1 + +/** + * @brief Get the number of note labels registered in the current sfz file + * @version 0.4.0-dev + */ +SFIZZ_EXPORTED_API unsigned int sfizz_get_num_note_labels(sfizz_synth_t* synth); + +/** + * @brief Get the note number for the label registered at index label_index. + * @version 0.4.0-dev + * + * @returns SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX if the index is out of bounds. + * @returns the number + */ +SFIZZ_EXPORTED_API int sfizz_get_note_label_number(sfizz_synth_t* synth, int label_index); + +/** + * @brief Get the note text for the label registered at index label_index. + * @version 0.4.0-dev + * + * @returns NULL if the index is out of bounds. + * @returns the label + */ +SFIZZ_EXPORTED_API const char * sfizz_get_note_label_text(sfizz_synth_t* synth, int label_index); + +/** + * @brief Get the number of note labels registered in the current sfz file + * @version 0.4.0-dev + * + */ +SFIZZ_EXPORTED_API unsigned int sfizz_get_num_cc_labels(sfizz_synth_t* synth); + +/** + * @brief Get the CC number for the label registered at index label_index. + * @version 0.4.0-dev + * + * @returns SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX if the index is out of bounds. + * @returns the number + */ + +SFIZZ_EXPORTED_API int sfizz_get_cc_label_number(sfizz_synth_t* synth, int label_index); +/** + * @brief Get the CC text for the label registered at index label_index. + * @version 0.4.0-dev + * + * @returns NULL if the index is out of bounds. + * @returns the label + */ +SFIZZ_EXPORTED_API const char * sfizz_get_cc_label_text(sfizz_synth_t* synth, int label_index); + #ifdef __cplusplus } #endif diff --git a/src/sfizz.hpp b/src/sfizz.hpp index 49e9cd7a..d726d6c5 100644 --- a/src/sfizz.hpp +++ b/src/sfizz.hpp @@ -10,6 +10,7 @@ */ #include +#include #include #include @@ -287,7 +288,8 @@ public: void setLoggingPrefix(const std::string& prefix) noexcept; /** - * @brief Disable logging. + * @brief + * */ void disableLogging() noexcept; @@ -312,6 +314,18 @@ public: */ void clearExternalDefinitions(); + /** + * @brief Get the note labels, if any + * @version 0.4.0-dev + * + */ + const std::vector>& getNoteLabels() const noexcept; + /** + * @brief Get the CC labels, if any + * @version 0.4.0-dev + * + */ + const std::vector>& getCCLabels() const noexcept; private: std::unique_ptr synth; }; diff --git a/src/sfizz/SfzHelpers.h b/src/sfizz/SfzHelpers.h index 57bf109f..5d581a74 100644 --- a/src/sfizz/SfzHelpers.h +++ b/src/sfizz/SfzHelpers.h @@ -20,7 +20,7 @@ namespace sfz { -using CCNamePair = std::pair; +using CCNamePair = std::pair; using NoteNamePair = std::pair; template diff --git a/src/sfizz/sfizz.cpp b/src/sfizz/sfizz.cpp index 3e17af01..97e52cd4 100644 --- a/src/sfizz/sfizz.cpp +++ b/src/sfizz/sfizz.cpp @@ -220,3 +220,13 @@ void sfz::Sfizz::clearExternalDefinitions() { synth->getParser().clearExternalDefinitions(); } + +const std::vector>& sfz::Sfizz::getNoteLabels() const noexcept +{ + return synth->getNoteLabels(); +} + +const std::vector>& sfz::Sfizz::getCCLabels() const noexcept +{ + return synth->getCCLabels(); +} diff --git a/src/sfizz/sfizz_wrapper.cpp b/src/sfizz/sfizz_wrapper.cpp index 3c9d88f0..c614bf44 100644 --- a/src/sfizz/sfizz_wrapper.cpp +++ b/src/sfizz/sfizz_wrapper.cpp @@ -8,6 +8,7 @@ #include "Macros.h" #include "Synth.h" #include "sfizz.h" +#include #ifdef __cplusplus extern "C" { @@ -268,6 +269,80 @@ void sfizz_clear_external_definitions(sfizz_synth_t* synth) self->getParser().clearExternalDefinitions(); } +unsigned int sfizz_get_num_note_labels(sfizz_synth_t* synth) +{ + auto self = reinterpret_cast(synth); + return self->getNoteLabels().size(); +} + +int sfizz_get_note_label_number(sfizz_synth_t* synth, int label_index) +{ + auto self = reinterpret_cast(synth); + const auto noteLabels = self->getNoteLabels(); + if (label_index < 0) + return SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX; + + if (static_cast(label_index) >= noteLabels.size()) + return SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX; + + // Sanity checks for the future or platforms + static_assert( + std::numeric_limits::max() < std::numeric_limits::max(), + "The C API sends back an int but the note index in NoteNamePair can overflow it on this platform" + ); + return static_cast(noteLabels[label_index].first); +} + +const char * sfizz_get_note_label_text(sfizz_synth_t* synth, int label_index) +{ + auto self = reinterpret_cast(synth); + const auto noteLabels = self->getNoteLabels(); + if (label_index < 0) + return NULL; + + if (static_cast(label_index) >= noteLabels.size()) + return NULL; + + return noteLabels[label_index].second.c_str(); +} + +unsigned int sfizz_get_num_cc_labels(sfizz_synth_t* synth) +{ + auto self = reinterpret_cast(synth); + return self->getCCLabels().size(); +} + +int sfizz_get_cc_label_number(sfizz_synth_t* synth, int label_index) +{ + auto self = reinterpret_cast(synth); + const auto ccLabels = self->getCCLabels(); + if (label_index < 0) + return SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX; + + if (static_cast(label_index) >= ccLabels.size()) + return SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX; + + // Sanity checks for the future or platforms + static_assert( + std::numeric_limits::max() < std::numeric_limits::max(), + "The C API sends back an int but the cc index in CCNamePair can overflow it on this platform" + ); + return static_cast(ccLabels[label_index].first); +} + +const char * sfizz_get_cc_label_text(sfizz_synth_t* synth, int label_index) +{ + auto self = reinterpret_cast(synth); + const auto ccLabels = self->getCCLabels(); + if (label_index < 0) + return NULL; + + if (static_cast(label_index) >= ccLabels.size()) + return NULL; + + return ccLabels[label_index].second.c_str(); +} + #ifdef __cplusplus } #endif