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

Add initial support for <annot type="score"> (classes and round trip read/write) #3896

Merged
merged 9 commits into from
Dec 17, 2024
88 changes: 88 additions & 0 deletions include/vrv/annotscore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/////////////////////////////////////////////////////////////////////////////
// Name: annotscore.h
// Author: David Lewis
// Created: 2024
// Copyright (c) Authors and others. All rights reserved.
/////////////////////////////////////////////////////////////////////////////

#ifndef __VRV_ANNOTSCORE_H__
#define __VRV_ANNOTSCORE_H__

#include "atts_cmn.h"
#include "atts_shared.h"
#include "controlelement.h"
#include "editorial.h"
#include "timeinterface.h"

namespace vrv {

//----------------------------------------------------------------------------
// AnnotScore
//----------------------------------------------------------------------------

/**
* This class models the MEI <annot> element where @type is score.
*/
class AnnotScore : public ControlElement, public TimeSpanningInterface, public AttPlist {
public:
/**
* @name Constructors, destructors, and other standard methods
* Reset method reset all attribute classes
*/
///@{
AnnotScore();
virtual ~AnnotScore();
// Object *Clone() const override { return new AnnotScore(*this); }
void Reset() override;
std::string GetClassName() const override { return "AnnotScore"; }
///@}

/**
* @name Getter to interfaces
*/
///@{
TimePointInterface *GetTimePointInterface() override { return vrv_cast<TimePointInterface *>(this); }
const TimePointInterface *GetTimePointInterface() const override
{
return vrv_cast<const TimePointInterface *>(this);
}
TimeSpanningInterface *GetTimeSpanningInterface() override { return vrv_cast<TimeSpanningInterface *>(this); }
const TimeSpanningInterface *GetTimeSpanningInterface() const override
{
return vrv_cast<const TimeSpanningInterface *>(this);
}

/**
* Add a text element to an annotation.
* Only supported elements will be actually added to the child list.
*/
bool IsSupportedChild(Object *object) override;

///@}

//----------//
// Functors //
//----------//

/**
* Interface for class functor visitation
*/
///@{
FunctorCode Accept(Functor &functor) override;
FunctorCode Accept(ConstFunctor &functor) const override;
FunctorCode AcceptEnd(Functor &functor) override;
FunctorCode AcceptEnd(ConstFunctor &functor) const override;
///@}

protected:
//
private:
//
public:
//
private:
};

} // namespace vrv

#endif
5 changes: 5 additions & 0 deletions include/vrv/functorinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Accid;
class Alignment;
class AlignmentReference;
class AnchoredText;
class AnnotScore;
class Arpeg;
class Artic;
class BarLine;
Expand Down Expand Up @@ -280,6 +281,8 @@ class FunctorInterface {
///@{
virtual FunctorCode VisitAnchoredText(AnchoredText *anchoredText);
virtual FunctorCode VisitAnchoredTextEnd(AnchoredText *anchoredText);
virtual FunctorCode VisitAnnotScore(AnnotScore *annotScore);
virtual FunctorCode VisitAnnotScoreEnd(AnnotScore *annotScore);
virtual FunctorCode VisitArpeg(Arpeg *arpeg);
virtual FunctorCode VisitArpegEnd(Arpeg *arpeg);
virtual FunctorCode VisitBeamSpan(BeamSpan *beamSpan);
Expand Down Expand Up @@ -653,6 +656,8 @@ class ConstFunctorInterface {
///@{
virtual FunctorCode VisitAnchoredText(const AnchoredText *anchoredText);
virtual FunctorCode VisitAnchoredTextEnd(const AnchoredText *anchoredText);
virtual FunctorCode VisitAnnotScore(const AnnotScore *annotScore);
virtual FunctorCode VisitAnnotScoreEnd(const AnnotScore *annotScore);
virtual FunctorCode VisitArpeg(const Arpeg *arpeg);
virtual FunctorCode VisitArpegEnd(const Arpeg *arpeg);
virtual FunctorCode VisitBeamSpan(const BeamSpan *beamSpan);
Expand Down
8 changes: 8 additions & 0 deletions include/vrv/iomei.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Add;
class AltSymInterface;
class AnchoredText;
class Annot;
class AnnotScore;
class App;
class AreaPosInterface;
class Arpeg;
Expand Down Expand Up @@ -432,6 +433,7 @@ class MEIOutput : public Output {
*/
///@{
void WriteAnchoredText(pugi::xml_node currentNode, AnchoredText *anchoredText);
void WriteAnnotScore(pugi::xml_node currentNode, AnnotScore *annotScore);
void WriteArpeg(pugi::xml_node currentNode, Arpeg *arpeg);
void WriteBeamSpan(pugi::xml_node currentNode, BeamSpan *beamSpan);
void WriteBracketSpan(pugi::xml_node currentNode, BracketSpan *bracketSpan);
Expand Down Expand Up @@ -800,6 +802,7 @@ class MEIInput : public Input {
bool ReadAbbr(Object *parent, pugi::xml_node abbr, EditorialLevel level, Object *filter = NULL);
bool ReadAdd(Object *parent, pugi::xml_node add, EditorialLevel level, Object *filter = NULL);
bool ReadAnnot(Object *parent, pugi::xml_node annot);
bool ReadAnnotScore(Object *parent, pugi::xml_node annot);
bool ReadApp(Object *parent, pugi::xml_node app, EditorialLevel level, Object *filter = NULL);
bool ReadAppChildren(Object *parent, pugi::xml_node parentNode, EditorialLevel level, Object *filter = NULL);
bool ReadChoice(Object *parent, pugi::xml_node choice, EditorialLevel level, Object *filter = NULL);
Expand Down Expand Up @@ -865,6 +868,11 @@ class MEIInput : public Input {
*/
void ReadUnsupportedAttr(pugi::xml_node element, Object *object);

/**
* Returns true if the element is a 'score' annotation. Currently based on @type
*/
bool IsAnnotScore(pugi::xml_node element);

/**
* Returns true if the element is name is an editorial element (e.g., "app", "supplied", etc.)
*/
Expand Down
1 change: 1 addition & 0 deletions include/vrv/vrvdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ enum ClassId : uint16_t {
// Ids for ControlElement child classes
CONTROL_ELEMENT,
ANCHOREDTEXT,
ANNOTSCORE,
ARPEG,
BEAMSPAN,
BRACKETSPAN,
Expand Down
86 changes: 86 additions & 0 deletions src/annotscore.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/////////////////////////////////////////////////////////////////////////////
// Name: annotscore.cpp
// Author: David Lewis
// Created: 2024
// Copyright (c) Authors and others. All rights reserved.
/////////////////////////////////////////////////////////////////////////////

#include "annotscore.h"

//----------------------------------------------------------------------------

#include <cassert>

//----------------------------------------------------------------------------

#include "devicecontext.h"
#include "doc.h"
#include "functor.h"
#include "text.h"
#include "verticalaligner.h"
#include "vrv.h"

namespace vrv {

//----------------------------------------------------------------------------
// AnnotScore
//----------------------------------------------------------------------------

static const ClassRegistrar<AnnotScore> s_factory("annotScore", ANNOTSCORE);

AnnotScore::AnnotScore() : ControlElement(ANNOTSCORE, "annotscore-"), AttPlist()
{
this->RegisterInterface(TimeSpanningInterface::GetAttClasses(), TimeSpanningInterface::IsInterface());
this->RegisterAttClass(ATT_PLIST);

this->Reset();
}

AnnotScore::~AnnotScore() {}

void AnnotScore::Reset()
{
ControlElement::Reset();
this->ResetPlist();
TimeSpanningInterface::Reset();
}

bool AnnotScore::IsSupportedChild(Object *child)
{
if (child->IsTextElement()) {
assert(dynamic_cast<TextElement *>(child));
}
else if (child->Is(ANNOT)) {
assert(dynamic_cast<AnnotScore *>(child));
}
else {
return false;
}
return true;
}

//----------------------------------------------------------------------------
// AnnotScore functor methods
//----------------------------------------------------------------------------

FunctorCode AnnotScore::Accept(Functor &functor)
{
return functor.VisitAnnotScore(this);
}

FunctorCode AnnotScore::Accept(ConstFunctor &functor) const
{
return functor.VisitAnnotScore(this);
}

FunctorCode AnnotScore::AcceptEnd(Functor &functor)
{
return functor.VisitAnnotScoreEnd(this);
}

FunctorCode AnnotScore::AcceptEnd(ConstFunctor &functor) const
{
return functor.VisitAnnotScoreEnd(this);
}

} // namespace vrv
21 changes: 21 additions & 0 deletions src/functorinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "accid.h"
#include "anchoredtext.h"
#include "annotscore.h"
#include "arpeg.h"
#include "artic.h"
#include "barline.h"
Expand Down Expand Up @@ -490,6 +491,16 @@ FunctorCode FunctorInterface::VisitAnchoredTextEnd(AnchoredText *anchoredText)
return this->VisitControlElementEnd(anchoredText);
}

FunctorCode FunctorInterface::VisitAnnotScore(AnnotScore *annotScore)
{
return this->VisitControlElement(annotScore);
}

FunctorCode FunctorInterface::VisitAnnotScoreEnd(AnnotScore *annotScore)
{
return this->VisitControlElementEnd(annotScore);
}

FunctorCode FunctorInterface::VisitArpeg(Arpeg *arpeg)
{
return this->VisitControlElement(arpeg);
Expand Down Expand Up @@ -1824,6 +1835,16 @@ FunctorCode ConstFunctorInterface::VisitAnchoredTextEnd(const AnchoredText *anch
return this->VisitControlElementEnd(anchoredText);
}

FunctorCode ConstFunctorInterface::VisitAnnotScore(const AnnotScore *annotScore)
{
return this->VisitControlElement(annotScore);
}

FunctorCode ConstFunctorInterface::VisitAnnotScoreEnd(const AnnotScore *annotScore)
{
return this->VisitControlElementEnd(annotScore);
}

FunctorCode ConstFunctorInterface::VisitArpeg(const Arpeg *arpeg)
{
return this->VisitControlElement(arpeg);
Expand Down
4 changes: 2 additions & 2 deletions src/iohumdrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2939,7 +2939,7 @@ void HumdrumInput::createDigitalSource(pugi::xml_node sourceDesc)
pugi::xml_node bibl = source.append_child("bibl");
bibl.append_copy(m_simpleTitle);
for (pugi::xml_node_iterator childIt = m_simpleComposersDoc.begin(); childIt != m_simpleComposersDoc.end();
++childIt) {
++childIt) {
bibl.append_copy(*childIt);
}

Expand Down Expand Up @@ -3691,7 +3691,7 @@ void HumdrumInput::createPrintedSource(pugi::xml_node sourceDesc)

bibl.append_copy(m_simpleTitle);
for (pugi::xml_node_iterator childIt = m_simpleComposersDoc.begin(); childIt != m_simpleComposersDoc.end();
++childIt) {
++childIt) {
bibl.append_copy(*childIt);
}

Expand Down
Loading
Loading