Skip to content

Commit

Permalink
Added upper bound check for MuseSampler's version
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereverzev committed Dec 13, 2022
1 parent 9dcd131 commit e9869aa
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/framework/musesampler/imusesamplerconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class IMuseSamplerConfiguration : MODULE_EXPORT_INTERFACE
virtual mu::io::path_t libraryPath() const = 0;

virtual std::string minimumSupportedVersion() const = 0;
virtual std::string maximumSupportedVersion() const = 0;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static const io::path_t DEFAULT_PATH("MuseSamplerCoreLib.dll");
#endif

static const std::string MINIMUM_SUPPORTED_VERSION = "0.2.2";
static const std::string MAXIMUM_SUPPORTED_VERSION = "0.4.0";

io::path_t MuseSamplerConfiguration::libraryPath() const
{
Expand All @@ -50,3 +51,8 @@ std::string MuseSamplerConfiguration::minimumSupportedVersion() const
{
return MINIMUM_SUPPORTED_VERSION;
}

std::string MuseSamplerConfiguration::maximumSupportedVersion() const
{
return MAXIMUM_SUPPORTED_VERSION;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MuseSamplerConfiguration : public IMuseSamplerConfiguration
io::path_t libraryPath() const override;

std::string minimumSupportedVersion() const override;
std::string maximumSupportedVersion() const override;
};
}

Expand Down
34 changes: 34 additions & 0 deletions src/framework/musesampler/internal/musesamplerresolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ bool MuseSamplerResolver::isVersionSupported() const
return false;
}

return isVersionAboveMinSupported() && isVersionBelowMaxSupported();
}

bool MuseSamplerResolver::isVersionAboveMinSupported() const
{
bool ok = true;
std::array<int, 3> minimumSupported = parseVersion(configuration()->minimumSupportedVersion(), ok);
if (!ok) {
Expand Down Expand Up @@ -217,6 +222,35 @@ bool MuseSamplerResolver::isVersionSupported() const
return false;
}

bool MuseSamplerResolver::isVersionBelowMaxSupported() const
{
bool ok = true;
std::array<int, 3> maxSupported = parseVersion(configuration()->maximumSupportedVersion(), ok);
if (!ok) {
return false;
}

int currentMajorNum = m_libHandler->getVersionMajor();
int currentMinorNum = m_libHandler->getVersionMinor();
int currentRevisionNum = m_libHandler->getVersionRevision();

if (currentMajorNum < maxSupported.at(0)) {
return true;
} else if (currentMajorNum == maxSupported.at(0)) {
if (currentMinorNum < maxSupported.at(1)) {
return true;
} else if (currentMinorNum == maxSupported.at(1)) {
if (currentRevisionNum < maxSupported.at(2)) {
return true;
} else if (currentRevisionNum == maxSupported.at(2)) {

This comment has been minimized.

Copy link
@cbjeukendrup

cbjeukendrup Dec 13, 2022

Contributor

This means that MuseSampler 0.4.0 will also be considered compatible. Is that desired? Shouldn't this method do a "strictly smaller" comparison (i.e. without the last } else if (currentRevisionNum == maxSupported.at(2)) {)?

This comment has been minimized.

Copy link
@vpereverzev

vpereverzev Dec 13, 2022

Author Member

yes, it's desirable

return true;
}
}
}

return false;
}

String MuseSamplerResolver::buildMuseInstrumentId(const String& category, const String& name, int uniqueId) const
{
StringList list;
Expand Down
2 changes: 2 additions & 0 deletions src/framework/musesampler/internal/musesamplerresolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class MuseSamplerResolver : public audio::synth::ISynthResolver::IResolver, publ
private:
bool checkLibrary() const;
bool isVersionSupported() const;
bool isVersionAboveMinSupported() const;
bool isVersionBelowMaxSupported() const;

String buildMuseInstrumentId(const String& category, const String& name, int uniqueId) const;

Expand Down

0 comments on commit e9869aa

Please sign in to comment.