Added public API bindings
This commit is contained in:
parent
5a0aafa793
commit
c075e40c23
5 changed files with 152 additions and 2 deletions
51
src/sfizz.h
51
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
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
*/
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -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<std::pair<uint8_t, std::string>>& getNoteLabels() const noexcept;
|
||||
/**
|
||||
* @brief Get the CC labels, if any
|
||||
* @version 0.4.0-dev
|
||||
*
|
||||
*/
|
||||
const std::vector<std::pair<uint16_t, std::string>>& getCCLabels() const noexcept;
|
||||
private:
|
||||
std::unique_ptr<sfz::Synth> synth;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
namespace sfz
|
||||
{
|
||||
|
||||
using CCNamePair = std::pair<decltype(config::numCCs), std::string>;
|
||||
using CCNamePair = std::pair<uint16_t, std::string>;
|
||||
using NoteNamePair = std::pair<uint8_t, std::string>;
|
||||
|
||||
template <class T>
|
||||
|
|
|
|||
|
|
@ -220,3 +220,13 @@ void sfz::Sfizz::clearExternalDefinitions()
|
|||
{
|
||||
synth->getParser().clearExternalDefinitions();
|
||||
}
|
||||
|
||||
const std::vector<std::pair<uint8_t, std::string>>& sfz::Sfizz::getNoteLabels() const noexcept
|
||||
{
|
||||
return synth->getNoteLabels();
|
||||
}
|
||||
|
||||
const std::vector<std::pair<uint16_t, std::string>>& sfz::Sfizz::getCCLabels() const noexcept
|
||||
{
|
||||
return synth->getCCLabels();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "Macros.h"
|
||||
#include "Synth.h"
|
||||
#include "sfizz.h"
|
||||
#include <limits>
|
||||
|
||||
#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<sfz::Synth*>(synth);
|
||||
return self->getNoteLabels().size();
|
||||
}
|
||||
|
||||
int sfizz_get_note_label_number(sfizz_synth_t* synth, int label_index)
|
||||
{
|
||||
auto self = reinterpret_cast<sfz::Synth*>(synth);
|
||||
const auto noteLabels = self->getNoteLabels();
|
||||
if (label_index < 0)
|
||||
return SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX;
|
||||
|
||||
if (static_cast<unsigned int>(label_index) >= noteLabels.size())
|
||||
return SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX;
|
||||
|
||||
// Sanity checks for the future or platforms
|
||||
static_assert(
|
||||
std::numeric_limits<sfz::NoteNamePair::first_type>::max() < std::numeric_limits<int>::max(),
|
||||
"The C API sends back an int but the note index in NoteNamePair can overflow it on this platform"
|
||||
);
|
||||
return static_cast<int>(noteLabels[label_index].first);
|
||||
}
|
||||
|
||||
const char * sfizz_get_note_label_text(sfizz_synth_t* synth, int label_index)
|
||||
{
|
||||
auto self = reinterpret_cast<sfz::Synth*>(synth);
|
||||
const auto noteLabels = self->getNoteLabels();
|
||||
if (label_index < 0)
|
||||
return NULL;
|
||||
|
||||
if (static_cast<unsigned int>(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<sfz::Synth*>(synth);
|
||||
return self->getCCLabels().size();
|
||||
}
|
||||
|
||||
int sfizz_get_cc_label_number(sfizz_synth_t* synth, int label_index)
|
||||
{
|
||||
auto self = reinterpret_cast<sfz::Synth*>(synth);
|
||||
const auto ccLabels = self->getCCLabels();
|
||||
if (label_index < 0)
|
||||
return SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX;
|
||||
|
||||
if (static_cast<unsigned int>(label_index) >= ccLabels.size())
|
||||
return SFIZZ_OUT_OF_BOUNDS_LABEL_INDEX;
|
||||
|
||||
// Sanity checks for the future or platforms
|
||||
static_assert(
|
||||
std::numeric_limits<sfz::CCNamePair::first_type>::max() < std::numeric_limits<int>::max(),
|
||||
"The C API sends back an int but the cc index in CCNamePair can overflow it on this platform"
|
||||
);
|
||||
return static_cast<int>(ccLabels[label_index].first);
|
||||
}
|
||||
|
||||
const char * sfizz_get_cc_label_text(sfizz_synth_t* synth, int label_index)
|
||||
{
|
||||
auto self = reinterpret_cast<sfz::Synth*>(synth);
|
||||
const auto ccLabels = self->getCCLabels();
|
||||
if (label_index < 0)
|
||||
return NULL;
|
||||
|
||||
if (static_cast<unsigned int>(label_index) >= ccLabels.size())
|
||||
return NULL;
|
||||
|
||||
return ccLabels[label_index].second.c_str();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue