Skip to content

Commit

Permalink
Merge pull request #129 from rism-digital/develop-facsimile-neume-line
Browse files Browse the repository at this point in the history
Update: Develop facsimile neume line
  • Loading branch information
yinanazhou authored Jan 9, 2024
2 parents 928688f + 3d18b64 commit ebe94a8
Show file tree
Hide file tree
Showing 22 changed files with 189 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [unreleased]
* Support for `fTrem@unitdur` (@eNote-GmbH)

## [4.1.0] - 2023-12-15
* Support for staves ordered by `scoreDef`
Expand Down
7 changes: 7 additions & 0 deletions include/vrv/devicecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class DeviceContext {
m_baseWidth = 0;
m_baseHeight = 0;
m_pushBack = false;
m_viewBoxFactor = (double)DEFINITION_FACTOR;
}
DeviceContext(ClassId classId)
{
Expand All @@ -89,6 +90,7 @@ class DeviceContext {
m_baseWidth = 0;
m_baseHeight = 0;
m_pushBack = false;
m_viewBoxFactor = (double)DEFINITION_FACTOR;
}
virtual ~DeviceContext(){};
ClassId GetClassId() const { return m_classId; }
Expand Down Expand Up @@ -124,12 +126,14 @@ class DeviceContext {
m_baseWidth = width;
m_baseHeight = height;
}
void SetViewBoxFactor(double ppuFactor);
int GetWidth() const { return m_width; }
int GetHeight() const { return m_height; }
int GetContentHeight() const { return m_contentHeight; }
double GetUserScaleX() { return m_userScaleX; }
double GetUserScaleY() { return m_userScaleY; }
std::pair<int, int> GetBaseSize() const { return std::make_pair(m_baseWidth, m_baseHeight); }
double GetViewBoxFactor() const { return m_viewBoxFactor; }
///@}

/**
Expand Down Expand Up @@ -365,6 +369,9 @@ class DeviceContext {
/** stores the scale as requested by the used */
double m_userScaleX;
double m_userScaleY;

/** stores the viewbox factor taking into account the DEFINTION_FACTOR and the PPU */
double m_viewBoxFactor;
};

} // namespace vrv
Expand Down
3 changes: 3 additions & 0 deletions include/vrv/doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ class Doc : public Object {
///@{
Score *GetCorrespondingScore(const Object *object);
const Score *GetCorrespondingScore(const Object *object) const;
// Generic version that does not necessarily rely on precalculated visible scores
Score *GetCorrespondingScore(const Object *object, const std::list<Score *> &scores);
const Score *GetCorrespondingScore(const Object *object, const std::list<Score *> &scores) const;
///@}

/**
Expand Down
6 changes: 5 additions & 1 deletion include/vrv/facsimilefunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SyncFromFacsimileFunctor : public Functor {
/*
* Abstract base implementation
*/
bool ImplementsEndInterface() const override { return false; }
bool ImplementsEndInterface() const override { return true; }

/*
* Functor interface
Expand All @@ -51,6 +51,7 @@ class SyncFromFacsimileFunctor : 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 All @@ -71,6 +72,9 @@ class SyncFromFacsimileFunctor : public Functor {
//
Page *m_currentPage;
System *m_currentSystem;
Measure *m_currentNeumeLine;
/** map to store the zone corresponding to a staff */
std::map<Staff *, Zone *> m_staffZones;
};

//----------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions include/vrv/facsimileinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ class FacsimileInterface : public Interface, public AttFacsimile {
Zone *GetZone() { return m_zone; }
const Zone *GetZone() const { return m_zone; }
///@}
///

/** Get the surface */
///@{
Surface *GetSurface() { return m_surface; }
const Surface *GetSurface() const { return m_surface; }
///@}

//-----------------//
// Pseudo functors //
Expand Down
4 changes: 3 additions & 1 deletion include/vrv/setscoredeffunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ScoreDefSetCurrentPageFunctor : public DocFunctor {
*/
///@{
FunctorCode VisitPageEnd(Page *page) override;
FunctorCode VisitScore(Score *score) override;
///@}

protected:
Expand All @@ -97,7 +98,8 @@ class ScoreDefSetCurrentPageFunctor : public DocFunctor {
public:
//
private:
//
// The list of all scores
std::list<Score *> m_scores;
};

//----------------------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions include/vrv/staff.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ class Staff : public Object,
}
///@}

/**
* @name Getters and setters for the rotation.
* Used only with facsimile rendering.
*/
///@{
void SetDrawingRotation(double drawingRotation) { m_drawingRotation = drawingRotation; }
double GetDrawingRotation() const { return m_drawingRotation; }
bool HasDrawingRotation() const { return (m_drawingRotation != 0.0); }
int GetDrawingRotationOffsetFor(int x);
///@}

/**
* Delete all the legder line arrays.
*/
Expand Down Expand Up @@ -247,6 +258,12 @@ class Staff : public Object,
ArrayOfLedgerLines m_ledgerLinesAboveCue;
ArrayOfLedgerLines m_ledgerLinesBelowCue;
///@}

/**
* The drawing rotation.
* Used only with facsimile rendering
*/
double m_drawingRotation;
};

//----------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/devicecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ const Resources *DeviceContext::GetResources(bool showWarning) const
return m_resources;
}

void DeviceContext::SetViewBoxFactor(double ppuFactor)
{
m_viewBoxFactor = double(DEFINITION_FACTOR) / ppuFactor;
}

void DeviceContext::SetPen(int color, int width, int style, int dashLength, int gapLength, int lineCap, int lineJoin)
{
float opacityValue;
Expand Down
29 changes: 21 additions & 8 deletions src/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1294,9 +1294,6 @@ void Doc::ConvertToCastOffMensuralDoc(bool castOff)
m_isMensuralMusicOnly = false;
}

// Calling Doc::PrepareData is expected to collect visible scores
assert(m_dataPreparationDone);

// Make sure the document is not cast-off
this->UnCastOffDoc();

Expand Down Expand Up @@ -1413,6 +1410,8 @@ void Doc::SyncToFacsimileDoc()
if (!m_facsimile->FindDescendantByType(SURFACE)) {
m_facsimile->AddChild(new Surface());
}
this->ScoreDefSetCurrentDoc();

m_facsimile->SetType("transcription");
m_facsimile->ClearChildren();

Expand Down Expand Up @@ -1555,10 +1554,20 @@ Score *Doc::GetCorrespondingScore(const Object *object)

const Score *Doc::GetCorrespondingScore(const Object *object) const
{
assert(!m_visibleScores.empty());
return this->GetCorrespondingScore(object, m_visibleScores);
}

const Score *correspondingScore = m_visibleScores.front();
for (Score *score : m_visibleScores) {
Score *Doc::GetCorrespondingScore(const Object *object, const std::list<Score *> &scores)
{
return const_cast<Score *>(std::as_const(*this).GetCorrespondingScore(object, scores));
}

const Score *Doc::GetCorrespondingScore(const Object *object, const std::list<Score *> &scores) const
{
assert(!scores.empty());

const Score *correspondingScore = scores.front();
for (Score *score : scores) {
if ((score == object) || Object::IsPreOrdered(score, object)) {
correspondingScore = score;
}
Expand Down Expand Up @@ -2124,8 +2133,10 @@ int Doc::GetAdjustedDrawingPageHeight() const
{
assert(m_drawingPage);

// Take into account the PPU when getting the page height in facsimile
if (this->IsTranscription() || this->IsFacs()) {
return m_drawingPage->m_pageHeight / DEFINITION_FACTOR;
const int factor = DEFINITION_FACTOR / m_drawingPage->GetPPUFactor();
return m_drawingPage->m_pageHeight / factor;
}

int contentHeight = m_drawingPage->GetContentHeight();
Expand All @@ -2136,8 +2147,10 @@ int Doc::GetAdjustedDrawingPageWidth() const
{
assert(m_drawingPage);

// Take into account the PPU when getting the page width in facsimile
if (this->IsTranscription() || this->IsFacs()) {
return m_drawingPage->m_pageWidth / DEFINITION_FACTOR;
const int factor = DEFINITION_FACTOR / m_drawingPage->GetPPUFactor();
return m_drawingPage->m_pageWidth / factor;
}

int contentWidth = m_drawingPage->GetContentWidth();
Expand Down
67 changes: 59 additions & 8 deletions src/facsimilefunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "doc.h"
#include "layerelement.h"
#include "measure.h"
#include "miscfunctor.h"
#include "page.h"
#include "pb.h"
#include "sb.h"
Expand Down Expand Up @@ -39,7 +40,7 @@ SyncFromFacsimileFunctor::SyncFromFacsimileFunctor(Doc *doc) : Functor()

FunctorCode SyncFromFacsimileFunctor::VisitLayerElement(LayerElement *layerElement)
{
if (!layerElement->Is({ NOTE, REST })) return FUNCTOR_CONTINUE;
if (!layerElement->Is({ CLEF, CUSTOS, NC, NOTE, REST, SYL })) return FUNCTOR_CONTINUE;

Zone *zone = layerElement->GetZone();
assert(zone);
Expand All @@ -50,31 +51,66 @@ FunctorCode SyncFromFacsimileFunctor::VisitLayerElement(LayerElement *layerEleme

FunctorCode SyncFromFacsimileFunctor::VisitMeasure(Measure *measure)
{
Zone *zone = measure->GetZone();
assert(zone);
measure->m_drawingFacsX1 = m_view.ToLogicalX(zone->GetUlx() * DEFINITION_FACTOR);
measure->m_drawingFacsX2 = m_view.ToLogicalX(zone->GetLrx() * DEFINITION_FACTOR);
// neon specific code - measure have no zone, we will use the staff one in VisitStaff
if (measure->IsNeumeLine()) {
m_currentNeumeLine = measure;
}
else {
Zone *zone = measure->GetZone();
assert(zone);
measure->m_drawingFacsX1 = m_view.ToLogicalX(zone->GetUlx() * DEFINITION_FACTOR);
measure->m_drawingFacsX2 = m_view.ToLogicalX(zone->GetLrx() * DEFINITION_FACTOR);
}

return FUNCTOR_CONTINUE;
}

FunctorCode SyncFromFacsimileFunctor::VisitPage(Page *page)
{
m_staffZones.clear();
m_currentPage = page;
m_doc->SetDrawingPage(m_currentPage->GetIdx());

return FUNCTOR_CONTINUE;
}

FunctorCode SyncFromFacsimileFunctor::VisitPageEnd(Page *page)
{
// Used for adjusting staff size in neon - filled in VisitStaff
if (m_staffZones.empty()) return FUNCTOR_CONTINUE;

// The staff size is calculated based on the zone height and takes into acocunt the rotation
for (auto &[staff, zone] : m_staffZones) {
double rotate = (zone->HasRotate()) ? zone->GetRotate() : 0.0;
int yDiff
= zone->GetLry() - zone->GetUly() - (zone->GetLrx() - zone->GetUlx()) * tan(abs(rotate) * M_PI / 180.0);
staff->m_drawingStaffSize
= 100 * yDiff / (m_doc->GetOptions()->m_unit.GetValue() * 2 * (staff->m_drawingLines - 1));
staff->SetDrawingRotation(rotate);
}

// Since we multiply all values by the DEFINITION_FACTOR, set it as PPU
m_currentPage->SetPPUFactor(DEFINITION_FACTOR);
if (m_currentPage->GetPPUFactor() != 1.0) {
ApplyPPUFactorFunctor applyPPUFactor;
m_currentPage->Process(applyPPUFactor);
m_doc->UpdatePageDrawingSizes();
}

return FUNCTOR_CONTINUE;
}

FunctorCode SyncFromFacsimileFunctor::VisitPb(Pb *pb)
{
// This would happen if we run the functor on data not converted to page-based
assert(m_currentPage);

Zone *zone = pb->GetZone();
assert(zone && zone->GetParent());
Surface *surface = (zone->GetParent()->Is(SURFACE)) ? vrv_cast<Surface *>(zone->GetParent()) : NULL;
// Use the parent surface attributes if given
Surface *surface = pb->GetSurface();
if (!surface && zone && zone->GetParent())
surface = (zone->GetParent()->Is(SURFACE)) ? vrv_cast<Surface *>(zone->GetParent()) : NULL;
assert(zone || surface);
// Use the (parent) surface attributes if given
if (surface && surface->HasLrx() && surface->HasLry()) {
m_currentPage->m_pageHeight = surface->GetLry() * DEFINITION_FACTOR;
m_currentPage->m_pageWidth = surface->GetLrx() * DEFINITION_FACTOR;
Expand Down Expand Up @@ -109,12 +145,27 @@ FunctorCode SyncFromFacsimileFunctor::VisitStaff(Staff *staff)
assert(zone);
staff->m_drawingFacsY = m_view.ToLogicalY(zone->GetUly() * DEFINITION_FACTOR);

// neon specific code - set the position of the pseudo measure (neume line)
if (m_currentNeumeLine) {
m_currentNeumeLine->m_drawingFacsX1 = m_view.ToLogicalX(zone->GetUlx() * DEFINITION_FACTOR);
m_currentNeumeLine->m_drawingFacsX2 = m_view.ToLogicalX(zone->GetLrx() * DEFINITION_FACTOR);
m_staffZones[staff] = zone;

// The staff slope is going up. The y left position needs to be adjusted accordingly
if (zone->GetRotate() < 0) {
staff->m_drawingFacsY = staff->m_drawingFacsY
+ (m_currentNeumeLine->m_drawingFacsX2 - m_currentNeumeLine->m_drawingFacsX1)
* tan(zone->GetRotate() * M_PI / 180.0);
}
}

return FUNCTOR_CONTINUE;
}

FunctorCode SyncFromFacsimileFunctor::VisitSystem(System *system)
{
m_currentSystem = system;
m_currentNeumeLine = NULL;

return FUNCTOR_CONTINUE;
}
Expand Down
1 change: 0 additions & 1 deletion src/iohumdrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31612,7 +31612,6 @@ void HumdrumInput::finalizeDocument(Doc *doc)
if (m_mens) {
doc->SetMensuralMusicOnly(true);
doc->m_notationType = NOTATIONTYPE_mensural;
doc->PrepareData();
doc->ConvertToCastOffMensuralDoc(true);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/iomei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8198,12 +8198,14 @@ void MEIInput::UpgradePageTo_5_0(Page *page)

PageMilestoneEnd *scoreEnd = new PageMilestoneEnd(score);
page->AddChild(scoreEnd);
score->SetEnd(scoreEnd);

Mdiv *mdiv = new Mdiv();
page->InsertChild(mdiv, 0);

PageMilestoneEnd *mdivEnd = new PageMilestoneEnd(mdiv);
page->AddChild(mdivEnd);
mdiv->SetEnd(mdivEnd);
}

void MEIInput::UpgradePgHeadFootTo_5_0(pugi::xml_node element)
Expand Down
Loading

0 comments on commit ebe94a8

Please sign in to comment.