Merge pull request #217 from jpcima/load-string
Add the string loading API
This commit is contained in:
commit
e7c462403e
6 changed files with 86 additions and 2 deletions
15
src/sfizz.h
15
src/sfizz.h
|
|
@ -70,6 +70,21 @@ SFIZZ_EXPORTED_API void sfizz_free(sfizz_synth_t* synth);
|
|||
*/
|
||||
SFIZZ_EXPORTED_API bool sfizz_load_file(sfizz_synth_t* synth, const char* path);
|
||||
|
||||
/**
|
||||
* @brief Loads an SFZ file from textual data. This accepts a virtual
|
||||
* path name for the imaginary sfz file, which is not required to
|
||||
* exist on disk. The purpose of the virtual path is to locate
|
||||
* samples with relative paths.
|
||||
*
|
||||
* @param synth The sfizz synth.
|
||||
* @param path The virtual path of the SFZ file.
|
||||
* @param text The contents of the virtual SFZ file.
|
||||
*
|
||||
* @return @true when file loading went OK,
|
||||
* @false if some error occured while loading.
|
||||
*/
|
||||
SFIZZ_EXPORTED_API bool sfizz_load_string(sfizz_synth_t* synth, const char* path, const char* text);
|
||||
|
||||
/**
|
||||
* @brief Return the number of regions in the currently loaded SFZ file.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -57,6 +57,22 @@ public:
|
|||
*/
|
||||
bool loadSfzFile(const std::string& path);
|
||||
|
||||
/**
|
||||
* @brief Empties the current regions and load a new SFZ document from memory.
|
||||
*
|
||||
* This is similar to loadSfzFile() in functionality.
|
||||
* This accepts a virtual path name for the imaginary sfz file, which is not
|
||||
* required to exist on disk. The purpose of the virtual path is to locate
|
||||
* samples with relative paths.
|
||||
*
|
||||
* @param path The virtual path of the SFZ file, as string.
|
||||
* @param text The contents of the virtual SFZ file.
|
||||
*
|
||||
* @return @false if no regions were loaded,
|
||||
* @true otherwise.
|
||||
*/
|
||||
bool loadSfzString(const std::string& path, const std::string& text);
|
||||
|
||||
/**
|
||||
* @brief Return the current number of regions loaded.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -336,6 +336,30 @@ bool sfz::Synth::loadSfzFile(const fs::path& file)
|
|||
if (regions.empty())
|
||||
return false;
|
||||
|
||||
finalizeSfzLoad();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sfz::Synth::loadSfzString(const fs::path& path, absl::string_view text)
|
||||
{
|
||||
clear();
|
||||
|
||||
const std::lock_guard<std::mutex> disableCallback { callbackGuard };
|
||||
parser.parseString(path, text);
|
||||
if (parser.getErrorCount() > 0)
|
||||
return false;
|
||||
|
||||
if (regions.empty())
|
||||
return false;
|
||||
|
||||
finalizeSfzLoad();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void sfz::Synth::finalizeSfzLoad()
|
||||
{
|
||||
resources.filePool.setRootDirectory(parser.originalDirectory());
|
||||
|
||||
auto currentRegion = regions.begin();
|
||||
|
|
@ -469,8 +493,6 @@ bool sfz::Synth::loadSfzFile(const fs::path& file)
|
|||
voice->setMaxFiltersPerVoice(maxFilters);
|
||||
voice->setMaxEQsPerVoice(maxEQs);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sfz::Voice* sfz::Synth::findFreeVoice() noexcept
|
||||
|
|
|
|||
|
|
@ -90,6 +90,26 @@ public:
|
|||
* @return false if the file was not found or no regions were loaded.
|
||||
*/
|
||||
bool loadSfzFile(const fs::path& file);
|
||||
/**
|
||||
* @brief Empties the current regions and load a new SFZ document from memory.
|
||||
*
|
||||
* This is similar to loadSfzFile() in functionality.
|
||||
* This accepts a virtual path name for the imaginary sfz file, which is not
|
||||
* required to exist on disk. The purpose of the virtual path is to locate
|
||||
* samples with relative paths.
|
||||
*
|
||||
* @param path The virtual path of the SFZ file, as string.
|
||||
* @param text The contents of the virtual SFZ file.
|
||||
*
|
||||
* @return @false if no regions were loaded,
|
||||
* @true otherwise.
|
||||
*/
|
||||
bool loadSfzString(const fs::path& path, absl::string_view text);
|
||||
/**
|
||||
* @brief Finalize SFZ loading, following a successful execution of the
|
||||
* parsing step.
|
||||
*/
|
||||
void finalizeSfzLoad();
|
||||
/**
|
||||
* @brief Get the current number of regions loaded
|
||||
*
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ bool sfz::Sfizz::loadSfzFile(const std::string& path)
|
|||
return synth->loadSfzFile(path);
|
||||
}
|
||||
|
||||
bool sfz::Sfizz::loadSfzString(const std::string& path, const std::string& text)
|
||||
{
|
||||
return synth->loadSfzString(path, text);
|
||||
}
|
||||
|
||||
int sfz::Sfizz::getNumRegions() const noexcept
|
||||
{
|
||||
return synth->getNumRegions();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@ bool sfizz_load_file(sfizz_synth_t* synth, const char* path)
|
|||
return self->loadSfzFile(path);
|
||||
}
|
||||
|
||||
bool sfizz_load_string(sfizz_synth_t* synth, const char* path, const char* text)
|
||||
{
|
||||
auto self = reinterpret_cast<sfz::Synth*>(synth);
|
||||
return self->loadSfzString(path, text);
|
||||
}
|
||||
|
||||
void sfizz_free(sfizz_synth_t* synth)
|
||||
{
|
||||
delete reinterpret_cast<sfz::Synth*>(synth);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue