diff --git a/libmei/addons/att.cpp b/libmei/addons/att.cpp index 8d7e6a47b0..c76024f407 100644 --- a/libmei/addons/att.cpp +++ b/libmei/addons/att.cpp @@ -158,6 +158,21 @@ data_BULGE Att::StrToBulge(const std::string &value, bool logWarning) const return bulge; } +std::string Att::DegreesToStr(data_DEGREES data) const +{ + return StringFormat("%f", data); +} + +data_DEGREES Att::StrToDegrees(const std::string &value, bool logWarning) const +{ + double degrees = atof(value.c_str()); + if ((degrees > 360.0) || (degrees < -360.0)) { + if (logWarning) LogWarning("Unsupported data.DEGREES '%s'", value.c_str()); + return 0; + } + return degrees; +} + std::string Att::DurationToStr(data_DURATION data) const { std::string value; diff --git a/libmei/addons/att.h b/libmei/addons/att.h index 5b4c696080..bcf7a75ca4 100644 --- a/libmei/addons/att.h +++ b/libmei/addons/att.h @@ -69,6 +69,9 @@ class Att : public AttConverterBase { std::string BulgeToStr(const data_BULGE &data) const; data_BULGE StrToBulge(const std::string &value, bool logWarning = true) const; + std::string DegreesToStr(data_DEGREES data) const; + data_DEGREES StrToDegrees(const std::string &value, bool logWarning = true) const; + std::string DurationToStr(data_DURATION data) const; data_DURATION StrToDuration(const std::string &value, bool = true) const; diff --git a/libmei/addons/attdef.h b/libmei/addons/attdef.h index 04ee0b3c3e..01494ea2bc 100644 --- a/libmei/addons/attdef.h +++ b/libmei/addons/attdef.h @@ -73,6 +73,11 @@ enum data_BEATRPT_REND { */ typedef std::vector> data_BULGE; +/** + * MEI data.DEGREES + */ +typedef double data_DEGREES; + /** * MEI data.DURATION */ diff --git a/libmei/datatypes.yml b/libmei/datatypes.yml index 165866c920..796033cb75 100644 --- a/libmei/datatypes.yml +++ b/libmei/datatypes.yml @@ -44,8 +44,6 @@ mapped: std::string data.CONFIDENCE: double - data.DEGREES: - double data.CLEFLINE: char data.COURSENUMBER: @@ -135,6 +133,8 @@ defaults: std::vector>() data_COMPASSDIRECTION: data_COMPASSDIRECTION() + data_DEGREES: + MEI_UNSET data_EVENTREL: data_EVENTREL() data_HEXNUM: diff --git a/libmei/dist/attmodule.cpp b/libmei/dist/attmodule.cpp index e0c35c7635..b4dd982efb 100644 --- a/libmei/dist/attmodule.cpp +++ b/libmei/dist/attmodule.cpp @@ -1756,11 +1756,11 @@ bool AttModule::SetGestural(Object *element, const std::string &attrType, const AttSoundLocation *att = dynamic_cast(element); assert(att); if (attrType == "azimuth") { - att->SetAzimuth(att->StrToDbl(attrValue)); + att->SetAzimuth(att->StrToDegrees(attrValue)); return true; } if (attrType == "elevation") { - att->SetElevation(att->StrToDbl(attrValue)); + att->SetElevation(att->StrToDegrees(attrValue)); return true; } } @@ -1878,10 +1878,10 @@ void AttModule::GetGestural(const Object *element, ArrayOfStrAttr *attributes) const AttSoundLocation *att = dynamic_cast(element); assert(att); if (att->HasAzimuth()) { - attributes->push_back({ "azimuth", att->DblToStr(att->GetAzimuth()) }); + attributes->push_back({ "azimuth", att->DegreesToStr(att->GetAzimuth()) }); } if (att->HasElevation()) { - attributes->push_back({ "elevation", att->DblToStr(att->GetElevation()) }); + attributes->push_back({ "elevation", att->DegreesToStr(att->GetElevation()) }); } } if (element->HasAttClass(ATT_TIMESTAMPGES)) { @@ -3252,7 +3252,7 @@ bool AttModule::SetShared(Object *element, const std::string &attrType, const st return true; } if (attrType == "rotate") { - att->SetRotate(att->StrToDbl(attrValue)); + att->SetRotate(att->StrToDegrees(attrValue)); return true; } } @@ -4856,7 +4856,7 @@ void AttModule::GetShared(const Object *element, ArrayOfStrAttr *attributes) attributes->push_back({ "lry", att->IntToStr(att->GetLry()) }); } if (att->HasRotate()) { - attributes->push_back({ "rotate", att->DblToStr(att->GetRotate()) }); + attributes->push_back({ "rotate", att->DegreesToStr(att->GetRotate()) }); } } if (element->HasAttClass(ATT_COORDINATEDUL)) { diff --git a/libmei/dist/atts_gestural.cpp b/libmei/dist/atts_gestural.cpp index 28917cfcbf..b45d22c563 100644 --- a/libmei/dist/atts_gestural.cpp +++ b/libmei/dist/atts_gestural.cpp @@ -473,20 +473,20 @@ AttSoundLocation::AttSoundLocation() : Att() void AttSoundLocation::ResetSoundLocation() { - m_azimuth = 0.0; - m_elevation = 0.0; + m_azimuth = MEI_UNSET; + m_elevation = MEI_UNSET; } bool AttSoundLocation::ReadSoundLocation(pugi::xml_node element, bool removeAttr) { bool hasAttribute = false; if (element.attribute("azimuth")) { - this->SetAzimuth(StrToDbl(element.attribute("azimuth").value())); + this->SetAzimuth(StrToDegrees(element.attribute("azimuth").value())); if (removeAttr) element.remove_attribute("azimuth"); hasAttribute = true; } if (element.attribute("elevation")) { - this->SetElevation(StrToDbl(element.attribute("elevation").value())); + this->SetElevation(StrToDegrees(element.attribute("elevation").value())); if (removeAttr) element.remove_attribute("elevation"); hasAttribute = true; } @@ -497,11 +497,11 @@ bool AttSoundLocation::WriteSoundLocation(pugi::xml_node element) { bool wroteAttribute = false; if (this->HasAzimuth()) { - element.append_attribute("azimuth") = DblToStr(this->GetAzimuth()).c_str(); + element.append_attribute("azimuth") = DegreesToStr(this->GetAzimuth()).c_str(); wroteAttribute = true; } if (this->HasElevation()) { - element.append_attribute("elevation") = DblToStr(this->GetElevation()).c_str(); + element.append_attribute("elevation") = DegreesToStr(this->GetElevation()).c_str(); wroteAttribute = true; } return wroteAttribute; @@ -509,12 +509,12 @@ bool AttSoundLocation::WriteSoundLocation(pugi::xml_node element) bool AttSoundLocation::HasAzimuth() const { - return (m_azimuth != 0.0); + return (m_azimuth != MEI_UNSET); } bool AttSoundLocation::HasElevation() const { - return (m_elevation != 0.0); + return (m_elevation != MEI_UNSET); } //---------------------------------------------------------------------------- diff --git a/libmei/dist/atts_gestural.h b/libmei/dist/atts_gestural.h index 9400a9d9bf..ebd750a372 100644 --- a/libmei/dist/atts_gestural.h +++ b/libmei/dist/atts_gestural.h @@ -503,20 +503,20 @@ class AttSoundLocation : public Att { * to the default value) **/ ///@{ - void SetAzimuth(double azimuth_) { m_azimuth = azimuth_; } - double GetAzimuth() const { return m_azimuth; } + void SetAzimuth(data_DEGREES azimuth_) { m_azimuth = azimuth_; } + data_DEGREES GetAzimuth() const { return m_azimuth; } bool HasAzimuth() const; // - void SetElevation(double elevation_) { m_elevation = elevation_; } - double GetElevation() const { return m_elevation; } + void SetElevation(data_DEGREES elevation_) { m_elevation = elevation_; } + data_DEGREES GetElevation() const { return m_elevation; } bool HasElevation() const; ///@} private: /** The lateral or left-to-right plane. **/ - double m_azimuth; + data_DEGREES m_azimuth; /** The above-to-below axis. **/ - double m_elevation; + data_DEGREES m_elevation; }; //---------------------------------------------------------------------------- diff --git a/libmei/dist/atts_shared.cpp b/libmei/dist/atts_shared.cpp index d65dd28bf2..3636cd2dfc 100644 --- a/libmei/dist/atts_shared.cpp +++ b/libmei/dist/atts_shared.cpp @@ -1005,7 +1005,7 @@ void AttCoordinated::ResetCoordinated() { m_lrx = MEI_UNSET; m_lry = MEI_UNSET; - m_rotate = 0.0; + m_rotate = MEI_UNSET; } bool AttCoordinated::ReadCoordinated(pugi::xml_node element, bool removeAttr) @@ -1022,7 +1022,7 @@ bool AttCoordinated::ReadCoordinated(pugi::xml_node element, bool removeAttr) hasAttribute = true; } if (element.attribute("rotate")) { - this->SetRotate(StrToDbl(element.attribute("rotate").value())); + this->SetRotate(StrToDegrees(element.attribute("rotate").value())); if (removeAttr) element.remove_attribute("rotate"); hasAttribute = true; } @@ -1041,7 +1041,7 @@ bool AttCoordinated::WriteCoordinated(pugi::xml_node element) wroteAttribute = true; } if (this->HasRotate()) { - element.append_attribute("rotate") = DblToStr(this->GetRotate()).c_str(); + element.append_attribute("rotate") = DegreesToStr(this->GetRotate()).c_str(); wroteAttribute = true; } return wroteAttribute; @@ -1059,7 +1059,7 @@ bool AttCoordinated::HasLry() const bool AttCoordinated::HasRotate() const { - return (m_rotate != 0.0); + return (m_rotate != MEI_UNSET); } //---------------------------------------------------------------------------- diff --git a/libmei/dist/atts_shared.h b/libmei/dist/atts_shared.h index b86e2877ba..69f913a1ed 100644 --- a/libmei/dist/atts_shared.h +++ b/libmei/dist/atts_shared.h @@ -1223,8 +1223,8 @@ class AttCoordinated : public Att { int GetLry() const { return m_lry; } bool HasLry() const; // - void SetRotate(double rotate_) { m_rotate = rotate_; } - double GetRotate() const { return m_rotate; } + void SetRotate(data_DEGREES rotate_) { m_rotate = rotate_; } + data_DEGREES GetRotate() const { return m_rotate; } bool HasRotate() const; ///@} @@ -1239,7 +1239,7 @@ class AttCoordinated : public Att { * interpreted, with respect to the normal orientation of the parent surface. * The orientation is expressed in arc degrees. **/ - double m_rotate; + data_DEGREES m_rotate; }; //----------------------------------------------------------------------------