Skip to content

Commit

Permalink
Merge pull request #3861 from rism-digital/develop-beethovens-werkstatt
Browse files Browse the repository at this point in the history
Improvement to the facsimile support and ledger line connection to notes
  • Loading branch information
lpugin authored Nov 14, 2024
2 parents 605bb38 + 73f28d6 commit acc6d64
Show file tree
Hide file tree
Showing 23 changed files with 546 additions and 78 deletions.
5 changes: 5 additions & 0 deletions include/vrv/devicecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ class DeviceContext {
*/
virtual void SetCustomGraphicColor(const std::string &color) {}

/**
* Method for adding custom graphic data-* attributes
*/
virtual void SetCustomGraphicAttributes(const std::string &data, const std::string &value) {}

/**
* @name Methods for re-starting and ending a graphic for objects drawn in separate steps
* The methods can be used to the output together, for example for a Beam
Expand Down
19 changes: 19 additions & 0 deletions include/vrv/facsimile.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ class Facsimile : public Object, public AttTyped {
const Zone *FindZoneByID(const std::string &zoneId) const;
int GetMaxX() const;
int GetMaxY() const;

//----------//
// 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:
//
};

} // namespace vrv
Expand Down
14 changes: 12 additions & 2 deletions include/vrv/facsimilefunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class SyncFromFacsimileFunctor : public Functor {
Measure *m_currentNeumeLine;
/** map to store the zone corresponding to a staff */
std::map<Staff *, Zone *> m_staffZones;
//
int m_pageMarginTop;
int m_pageMarginLeft;
//
double m_ppuFactor;
};

//----------------------------------------------------------------------------
Expand All @@ -90,14 +95,14 @@ class SyncToFacsimileFunctor : public Functor {
* @name Constructors, destructors
*/
///@{
SyncToFacsimileFunctor(Doc *doc);
SyncToFacsimileFunctor(Doc *doc, double ppuFactor);
virtual ~SyncToFacsimileFunctor() = default;
///@}

/*
* Abstract base implementation
*/
bool ImplementsEndInterface() const override { return false; }
bool ImplementsEndInterface() const override { return true; }

/*
* Functor interface
Expand All @@ -106,6 +111,7 @@ class SyncToFacsimileFunctor : public Functor {
FunctorCode VisitLayerElement(LayerElement *layerElement) override;
FunctorCode VisitMeasure(Measure *measure) override;
FunctorCode VisitPage(Page *page) override;
FunctorCode VisitPageEnd(Page *page) override;
FunctorCode VisitPb(Pb *pb) override;
FunctorCode VisitSb(Sb *sb) override;
FunctorCode VisitStaff(Staff *staff) override;
Expand Down Expand Up @@ -133,6 +139,10 @@ class SyncToFacsimileFunctor : public Functor {
//
int m_pageMarginTop;
int m_pageMarginLeft;
// A flag indicating we are dealing with a neume line
bool m_currentNeumeLine;
//
double m_ppuFactor;
};

} // namespace vrv
Expand Down
32 changes: 32 additions & 0 deletions include/vrv/functorinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class EditorialElement;
class Ending;
class Expansion;
class F;
class Facsimile;
class Fb;
class Fermata;
class Fing;
Expand All @@ -52,6 +53,7 @@ class GenericLayerElement;
class Gliss;
class GraceAligner;
class GraceGrp;
class Graphic;
class GrpSym;
class Hairpin;
class HalfmRpt;
Expand Down Expand Up @@ -118,6 +120,7 @@ class StaffAlignment;
class StaffDef;
class StaffGrp;
class Stem;
class Surface;
class Svg;
class Syl;
class Syllable;
Expand All @@ -142,6 +145,7 @@ class TupletBracket;
class TupletNum;
class Turn;
class Verse;
class Zone;

//----------------------------------------------------------------------------
// FunctorInterface
Expand Down Expand Up @@ -458,6 +462,20 @@ class FunctorInterface {
virtual FunctorCode VisitTextElementEnd(TextElement *textElement);
///@}

/**
* @name Visit facsimle elements
*/
///@{
virtual FunctorCode VisitFacsimile(Facsimile *facsimile);
virtual FunctorCode VisitFacsimileEnd(Facsimile *facsimile);
virtual FunctorCode VisitGraphic(Graphic *graphic);
virtual FunctorCode VisitGraphicEnd(Graphic *graphic);
virtual FunctorCode VisitSurface(Surface *surface);
virtual FunctorCode VisitSurfaceEnd(Surface *surface);
virtual FunctorCode VisitZone(Zone *zone);
virtual FunctorCode VisitZoneEnd(Zone *zone);
///@}

/**
* @name Visit horizontal aligners
*/
Expand Down Expand Up @@ -817,6 +835,20 @@ class ConstFunctorInterface {
virtual FunctorCode VisitTextElementEnd(const TextElement *textElement);
///@}

/**
* @name Visit facsimle elements
*/
///@{
virtual FunctorCode VisitFacsimile(const Facsimile *facsimile);
virtual FunctorCode VisitFacsimileEnd(const Facsimile *facsimile);
virtual FunctorCode VisitGraphic(const Graphic *graphic);
virtual FunctorCode VisitGraphicEnd(const Graphic *graphic);
virtual FunctorCode VisitSurface(const Surface *surface);
virtual FunctorCode VisitSurfaceEnd(const Surface *surface);
virtual FunctorCode VisitZone(const Zone *zone);
virtual FunctorCode VisitZoneEnd(const Zone *zone);
///@}

/**
* @name Visit horizontal aligners
*/
Expand Down
14 changes: 14 additions & 0 deletions include/vrv/graphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ class Graphic : public Object, public AttPointing, public AttWidth, public AttHe
int GetDrawingHeight(int unit, int staffSize) const;
///@}

//----------//
// 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:
Expand Down
4 changes: 3 additions & 1 deletion include/vrv/miscfunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ApplyPPUFactorFunctor : public Functor {
* @name Constructors, destructors
*/
///@{
ApplyPPUFactorFunctor();
ApplyPPUFactorFunctor(Page *page = NULL);
virtual ~ApplyPPUFactorFunctor() = default;
///@}

Expand All @@ -42,7 +42,9 @@ class ApplyPPUFactorFunctor : public Functor {
FunctorCode VisitMeasure(Measure *measure) override;
FunctorCode VisitPage(Page *page) override;
FunctorCode VisitStaff(Staff *staff) override;
FunctorCode VisitSurface(Surface *surface) override;
FunctorCode VisitSystem(System *system) override;
FunctorCode VisitZone(Zone *zone) override;
///@}

protected:
Expand Down
38 changes: 33 additions & 5 deletions include/vrv/staff.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,34 @@ class LedgerLine {
* Add a dash to the ledger line object.
* If necessary merges overlapping dashes.
*/
void AddDash(int left, int right, int extension);
void AddDash(int left, int right, int extension, const Object *event);

class Dash {
public:
int m_x1;
int m_x2;
ListOfConstObjects m_events;

// Constructor
Dash(int x1, int x2, const Object *object)
{
m_x1 = x1;
m_x2 = x2;
m_events.push_back(object);
}

// Merge function to merge another Dash object into this one
void MergeWith(const Dash &other)
{
// Keep the first int from this Dash object, and the second int from the other
this->m_x1 = std::min(other.m_x1, this->m_x1);
this->m_x2 = std::max(other.m_x2, this->m_x2);
// Append the list from other to this
if (!other.m_events.empty()) {
this->m_events.insert(this->m_events.end(), other.m_events.begin(), other.m_events.end());
}
}
};

protected:
//
Expand All @@ -53,7 +80,8 @@ class LedgerLine {
/**
* A list of dashes relative to the staff position.
*/
std::list<std::pair<int, int>> m_dashes;
// std::list<std::pair<int, int>> m_dashes;
std::list<Dash> m_dashes;

protected:
//
Expand Down Expand Up @@ -207,8 +235,8 @@ class Staff : public Object,
* If necessary creates the ledger line array.
*/
///@{
void AddLedgerLineAbove(int count, int left, int right, int extension, bool cueSize);
void AddLedgerLineBelow(int count, int left, int right, int extension, bool cueSize);
void AddLedgerLineAbove(int count, int left, int right, int extension, bool cueSize, const Object *event);
void AddLedgerLineBelow(int count, int left, int right, int extension, bool cueSize, const Object *event);
///@}

/**
Expand Down Expand Up @@ -248,7 +276,7 @@ class Staff : public Object,
/**
* Add the ledger line dashes to the legderline array.
*/
void AddLedgerLines(ArrayOfLedgerLines &lines, int count, int left, int right, int extension);
void AddLedgerLines(ArrayOfLedgerLines &lines, int count, int left, int right, int extension, const Object *event);

public:
/**
Expand Down
14 changes: 14 additions & 0 deletions include/vrv/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ class Surface : public Object, public AttTyped, public AttCoordinated, public At
int GetMaxX() const;
int GetMaxY() const;

//----------//
// 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:
Expand Down
7 changes: 6 additions & 1 deletion include/vrv/svgdevicecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ class SvgDeviceContext : public DeviceContext {
/**
* Method for changing the color of a custom graphic
*/
virtual void SetCustomGraphicColor(const std::string &color) override;
void SetCustomGraphicColor(const std::string &color) override;

/**
* Method for adding custom graphic data-* attributes
*/
void SetCustomGraphicAttributes(const std::string &data, const std::string &value) override;

/**
* @name Methods for re-starting and ending a graphic for objects drawn in separate steps
Expand Down
14 changes: 14 additions & 0 deletions include/vrv/zone.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ class Zone : public Object, public AttTyped, public AttCoordinated, public AttCo
int GetLogicalUly() const;
int GetLogicalLry() const;

//----------//
// 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:
Expand Down
26 changes: 13 additions & 13 deletions src/calcledgerlinesfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ void CalcLedgerLinesFunctor::CalcForLayerElement(
left -= width / 2;
}

const LayerElement *event = (m_doc->GetOptions()->m_svgHtml5.GetValue()) ? layerElement : NULL;
if (linesAbove > 0) {
staff->AddLedgerLineAbove(linesAbove, left, right, extension, drawingCueSize);
staff->AddLedgerLineAbove(linesAbove, left, right, extension, drawingCueSize, event);
}
else {
staff->AddLedgerLineBelow(linesBelow, left, right, extension, drawingCueSize);
staff->AddLedgerLineBelow(linesBelow, left, right, extension, drawingCueSize, event);
}
}

Expand Down Expand Up @@ -121,15 +122,14 @@ void CalcLedgerLinesFunctor::AdjustLedgerLines(
// For each dash on the inner line (both cue and normal) we construct an adjustment with zero delta
// and sort them
std::vector<Adjustment> adjustments;
using DashType = std::pair<int, int>;
if (!lines.empty()) {
for (const DashType &dash : lines.at(0).m_dashes) {
adjustments.push_back({ dash.first, dash.second, false, 0 });
for (const LedgerLine::Dash &dash : lines.at(0).m_dashes) {
adjustments.push_back({ dash.m_x1, dash.m_x2, false, 0 });
}
}
if (!cueLines.empty()) {
for (const DashType &dash : cueLines.at(0).m_dashes) {
adjustments.push_back({ dash.first, dash.second, true, 0 });
for (const LedgerLine::Dash &dash : cueLines.at(0).m_dashes) {
adjustments.push_back({ dash.m_x1, dash.m_x2, true, 0 });
}
}

Expand Down Expand Up @@ -175,13 +175,13 @@ void CalcLedgerLinesFunctor::AdjustLedgerLines(
if (adjustment.delta > 0) {
ArrayOfLedgerLines &linesToAdjust = adjustment.isCue ? cueLines : lines;
for (LedgerLine &line : linesToAdjust) {
std::list<DashType>::iterator iterDash
= std::find_if(line.m_dashes.begin(), line.m_dashes.end(), [&adjustment](const DashType &dash) {
return ((dash.first >= adjustment.left) && (dash.second <= adjustment.right));
});
std::list<LedgerLine::Dash>::iterator iterDash = std::find_if(
line.m_dashes.begin(), line.m_dashes.end(), [&adjustment](const LedgerLine::Dash &dash) {
return ((dash.m_x1 >= adjustment.left) && (dash.m_x2 <= adjustment.right));
});
if (iterDash != line.m_dashes.end()) {
iterDash->first += adjustment.delta;
iterDash->second -= adjustment.delta;
iterDash->m_x1 += adjustment.delta;
iterDash->m_x2 -= adjustment.delta;
}
}
}
Expand Down
Loading

0 comments on commit acc6d64

Please sign in to comment.