Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make typedef for data_DEGREES and default to MEI_UNSET #3890

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libmei/addons/att.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions libmei/addons/att.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions libmei/addons/attdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ enum data_BEATRPT_REND {
*/
typedef std::vector<std::pair<double, double>> data_BULGE;

/**
* MEI data.DEGREES
*/
typedef double data_DEGREES;

/**
* MEI data.DURATION
*/
Expand Down
4 changes: 2 additions & 2 deletions libmei/datatypes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ mapped:
std::string
data.CONFIDENCE:
double
data.DEGREES:
double
data.CLEFLINE:
char
data.COURSENUMBER:
Expand Down Expand Up @@ -135,6 +133,8 @@ defaults:
std::vector<std::pair<double, double>>()
data_COMPASSDIRECTION:
data_COMPASSDIRECTION()
data_DEGREES:
MEI_UNSET
data_EVENTREL:
data_EVENTREL()
data_HEXNUM:
Expand Down
12 changes: 6 additions & 6 deletions libmei/dist/attmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1756,11 +1756,11 @@ bool AttModule::SetGestural(Object *element, const std::string &attrType, const
AttSoundLocation *att = dynamic_cast<AttSoundLocation *>(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;
}
}
Expand Down Expand Up @@ -1878,10 +1878,10 @@ void AttModule::GetGestural(const Object *element, ArrayOfStrAttr *attributes)
const AttSoundLocation *att = dynamic_cast<const AttSoundLocation *>(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)) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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)) {
Expand Down
16 changes: 8 additions & 8 deletions libmei/dist/atts_gestural.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -497,24 +497,24 @@ 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;
}

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);
}

//----------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions libmei/dist/atts_gestural.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

//----------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions libmei/dist/atts_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -1059,7 +1059,7 @@ bool AttCoordinated::HasLry() const

bool AttCoordinated::HasRotate() const
{
return (m_rotate != 0.0);
return (m_rotate != MEI_UNSET);
}

//----------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions libmei/dist/atts_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
///@}

Expand All @@ -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;
};

//----------------------------------------------------------------------------
Expand Down
Loading