Skip to content

Commit

Permalink
Merge pull request #26320 from rettinghaus/mei/libmei
Browse files Browse the repository at this point in the history
fine tune LibMEI
  • Loading branch information
cbjeukendrup authored Feb 4, 2025
2 parents b3217a1 + 8441360 commit 5f03b85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
18 changes: 4 additions & 14 deletions src/importexport/mei/thirdparty/libmei/att.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::string Att::IntToStr(int data) const

std::string Att::VUToStr(data_VU data) const
{
return StringFormat("%fvu", data);
return DblToStr(data) + "vu";
}

// Basic converters for reading
Expand Down Expand Up @@ -416,7 +416,7 @@ std::string Att::MeasurementsignedToStr(data_MEASUREMENTSIGNED data) const
value = StringFormat("%dpx", data.GetPx() / DEFINITION_FACTOR);
}
else if (data.GetType() == MEASUREMENTTYPE_vu) {
value = StringFormat("%.4fvu", data.GetVu());
value = VUToStr(data.GetVu());
}

return value;
Expand Down Expand Up @@ -631,7 +631,7 @@ data_ORIENTATION Att::StrToOrientation(const std::string &value, bool logWarning

std::string Att::PercentToStr(data_PERCENT data) const
{
return StringFormat("%.2f%%", data);
return DblToStr(data) + "%";
}

data_PERCENT Att::StrToPercent(const std::string &value, bool logWarning) const
Expand All @@ -644,11 +644,6 @@ data_PERCENT Att::StrToPercent(const std::string &value, bool logWarning) const
return atof(value.substr(0, value.find("%")).c_str());
}

std::string Att::PercentLimitedToStr(data_PERCENT_LIMITED data) const
{
return StringFormat("%.2f%%", data);
}

data_PERCENT_LIMITED Att::StrToPercentLimited(const std::string &value, bool logWarning) const
{
static const std::regex test("[0-9]+(\\.?[0-9]*)?%");
Expand All @@ -659,16 +654,11 @@ data_PERCENT_LIMITED Att::StrToPercentLimited(const std::string &value, bool log
return atof(value.substr(0, value.find("%")).c_str());
}

std::string Att::PercentLimitedSignedToStr(data_PERCENT_LIMITED_SIGNED data) const
{
return StringFormat("%.2f%%", data);
}

data_PERCENT_LIMITED_SIGNED Att::StrToPercentLimitedSigned(const std::string &value, bool logWarning) const
{
static const std::regex test("(+|-)?[0-9]+(\\.?[0-9]*)?%");
if (!std::regex_match(value, test)) {
if (logWarning) LogWarning("Unsupported data.PERCENT.LIMITED.SIGNEd '%s'", value.c_str());
if (logWarning) LogWarning("Unsupported data.PERCENT.LIMITED.SIGNED '%s'", value.c_str());
return 0;
}
return atof(value.substr(0, value.find("%")).c_str());
Expand Down
9 changes: 6 additions & 3 deletions src/importexport/mei/thirdparty/libmei/att.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ class Att : public AttConverterBase {
std::string MeasurementsignedToStr(data_MEASUREMENTSIGNED data) const;
data_MEASUREMENTSIGNED StrToMeasurementsigned(const std::string &value, bool logWarning = true) const;

std::string MeasurementunsignedToStr(data_MEASUREMENTUNSIGNED data) const { return MeasurementsignedToStr(data); }
std::string MeasurementunsignedToStr(data_MEASUREMENTUNSIGNED data) const
{
return MeasurementsignedToStr(data);
}
data_MEASUREMENTUNSIGNED StrToMeasurementunsigned(const std::string &value, bool logWarning = true) const
{
return StrToMeasurementsigned(value, logWarning);
Expand Down Expand Up @@ -132,10 +135,10 @@ class Att : public AttConverterBase {
std::string PercentToStr(data_PERCENT data) const;
data_PERCENT StrToPercent(const std::string &value, bool logWarning = true) const;

std::string PercentLimitedToStr(data_PERCENT_LIMITED_SIGNED data) const;
std::string PercentLimitedToStr(data_PERCENT_LIMITED_SIGNED data) const { return PercentToStr(data); }
data_PERCENT_LIMITED StrToPercentLimited(const std::string &value, bool logWarning = true) const;

std::string PercentLimitedSignedToStr(data_PERCENT_LIMITED data) const;
std::string PercentLimitedSignedToStr(data_PERCENT_LIMITED data) const { return PercentToStr(data); }
data_PERCENT_LIMITED_SIGNED StrToPercentLimitedSigned(const std::string &value, bool logWarning = true) const;

std::string PitchnameToStr(data_PITCHNAME data) const;
Expand Down

0 comments on commit 5f03b85

Please sign in to comment.