Skip to content

Commit

Permalink
Merge pull request #22927 from RomanPudashkin/musesampler_init_refact…
Browse files Browse the repository at this point in the history
…_431

musesampler_init_refact_431
  • Loading branch information
RomanPudashkin committed May 21, 2024
2 parents ea73092 + 78d9ef3 commit 2544ca1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
33 changes: 23 additions & 10 deletions src/framework/musesampler/internal/libhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
namespace mu::musesampler {
struct MuseSamplerLibHandler
{
ms_init initLib = nullptr;
ms_disable_reverb disableReverb = nullptr;
ms_get_version_major getVersionMajor = nullptr;
ms_get_version_minor getVersionMinor = nullptr;
ms_get_version_revision getVersionRevision = nullptr;
Expand Down Expand Up @@ -103,6 +101,8 @@ struct MuseSamplerLibHandler
ms_MuseSampler_all_notes_off allNotesOff = nullptr;

private:
ms_init initLib = nullptr;
ms_disable_reverb disableReverb = nullptr;
ms_MuseSampler_add_track_dynamics_event addDynamicsEventInternal = nullptr;
ms_MuseSampler_add_track_dynamics_event_2 addDynamicsEventInternal2 = nullptr;
ms_MuseSampler_add_track_pedal_event addPedalEventInternal = nullptr;
Expand Down Expand Up @@ -380,14 +380,6 @@ struct MuseSamplerLibHandler
setPlaying = (ms_MuseSampler_set_playing)getLibFunc(m_lib, "ms_MuseSampler_set_playing");
process = (ms_MuseSampler_process)getLibFunc(m_lib, "ms_MuseSampler_process");
allNotesOff = (ms_MuseSampler_all_notes_off)getLibFunc(m_lib, "ms_MuseSampler_all_notes_off");

if (initLib) {
initLib();

if (disableReverb) {
disableReverb();
}
}
}

~MuseSamplerLibHandler()
Expand All @@ -399,6 +391,27 @@ struct MuseSamplerLibHandler
closeLib(m_lib);
}

bool init()
{
if (!initLib) {
LOGE() << "Could not find ms_init";
return false;
}

if (initLib() != ms_Result_OK) {
LOGE() << "Could not init lib";
return false;
}

if (disableReverb) {
if (disableReverb() != ms_Result_OK) {
LOGW() << "Could not disable reverb";
}
}

return true;
}

bool isValid() const
{
return m_lib
Expand Down
34 changes: 17 additions & 17 deletions src/framework/musesampler/internal/musesamplerresolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,28 @@ InstrumentInfo findInstrument(MuseSamplerLibHandlerPtr libHandler, const AudioRe

void MuseSamplerResolver::init()
{
io::path_t path = configuration()->userLibraryPath();
m_libHandler = std::make_shared<MuseSamplerLibHandler>(path);
if (checkLibrary()) {
if (doInit(configuration()->userLibraryPath())) {
return;
}

// Use fallback
path = configuration()->fallbackLibraryPath();
m_libHandler = std::make_shared<MuseSamplerLibHandler>(path);
if (!checkLibrary()) {
doInit(configuration()->fallbackLibraryPath());
}

bool MuseSamplerResolver::doInit(const io::path_t& libPath)
{
m_libHandler = std::make_shared<MuseSamplerLibHandler>(libPath);

bool ok = m_libHandler->isValid();
if (ok) {
ok = m_libHandler->init();
}

if (!ok) {
LOGE() << "Incompatible MuseSampler library; ignoring";
m_libHandler.reset();
}

return ok;
}

ISynthesizerPtr MuseSamplerResolver::resolveSynth(const audio::TrackId /*trackId*/, const audio::AudioInputParams& params) const
Expand Down Expand Up @@ -304,16 +314,6 @@ std::vector<Instrument> MuseSamplerResolver::instruments() const
return result;
}

bool MuseSamplerResolver::checkLibrary() const
{
if (!m_libHandler->isValid()) {
LOGE() << "Incompatible MuseSampler library; ignoring";
return false;
}

return true;
}

void MuseSamplerResolver::loadSoundPresetAttributes(SoundPresetAttributes& attributes, int instrumentId, const char* presetCode) const
{
const char* articulations_cstr = m_libHandler->getTextArticulations(instrumentId, presetCode);
Expand Down
3 changes: 1 addition & 2 deletions src/framework/musesampler/internal/musesamplerresolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class MuseSamplerResolver : public audio::synth::ISynthResolver::IResolver, publ
std::vector<Instrument> instruments() const override;

private:
bool checkLibrary() const;
bool isVersionSupported() const;
bool doInit(const io::path_t& libPath);

void loadSoundPresetAttributes(audio::SoundPresetAttributes& attributes, int instrumentId, const char* presetCode) const;

Expand Down
2 changes: 0 additions & 2 deletions src/framework/musesampler/internal/musesamplerwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ MuseSamplerWrapper::MuseSamplerWrapper(MuseSamplerLibHandlerPtr samplerLib, cons
return;
}

m_samplerLib->initLib();

m_sequencer.setOnOffStreamFlushed([this]() {
revokePlayingNotes();
});
Expand Down

0 comments on commit 2544ca1

Please sign in to comment.