Skip to content

Commit

Permalink
Add AlignMeterParams struct for parameter passing simplification [ski…
Browse files Browse the repository at this point in the history
…p-ci]

* No change expected
* Test suite evaluated locally
  • Loading branch information
lpugin committed Sep 20, 2024
1 parent 28e162a commit fd201a9
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 74 deletions.
20 changes: 16 additions & 4 deletions include/vrv/alignfunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@

namespace vrv {

class Mensur;
class MeterSig;

//----------------------------------------------------------------------------
// AlignmentParams
//----------------------------------------------------------------------------
/**
* Regroup pointers to meterSig, mensur and proport objects
*/
struct AlignMeterParams {
const MeterSig *meterSig;
const Mensur *mensur;
};

//----------------------------------------------------------------------------
// AlignHorizontallyFunctor
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -62,10 +76,8 @@ class AlignHorizontallyFunctor : public DocFunctor {
MeasureAligner *m_measureAligner;
// The time
double m_time;
// The current Mensur
Mensur *m_currentMensur;
// The current MeterSig
MeterSig *m_currentMeterSig;
// The current MeterSig, Mensur and Proport
AlignMeterParams m_currentParams;
// The current notation type
data_NOTATIONTYPE m_notationType;
// Indicates the state in processing the caution scoreDef
Expand Down
16 changes: 8 additions & 8 deletions include/vrv/findlayerelementsfunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include "functor.h"

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

#include "alignfunctor.h"

namespace vrv {

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -66,10 +70,8 @@ class LayersInTimeSpanFunctor : public ConstFunctor {
double m_duration;
// The layers (layerN) found
std::set<int> m_layers;
// The current meter signature
const MeterSig *m_meterSig;
// The current mensur
const Mensur *m_mensur;
// The current time alignment parameters
AlignMeterParams m_meterParams;
};

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -129,10 +131,8 @@ class LayerElementsInTimeSpanFunctor : public ConstFunctor {
double m_duration;
// The list of layer elements found
ListOfConstObjects m_elements;
// The current meter signature
const MeterSig *m_meterSig;
// The current mensur
const Mensur *m_mensur;
// The current time alignment parameters
AlignMeterParams m_meterParams;
// The layer to consider
const Layer *m_layer;
// ... or to ignore
Expand Down
22 changes: 16 additions & 6 deletions include/vrv/layerelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace vrv {

class Alignment;
class AlignMeterParams;
class Beam;
class BeamElementCoord;
class FTrem;
Expand Down Expand Up @@ -258,19 +259,28 @@ class LayerElement : public Object,
///@}

/**
* Returns the duration if the element has a DurationInterface
* Return the duration if the element has a DurationInterface.
*/
double GetAlignmentDuration(const Mensur *mensur = NULL, const MeterSig *meterSig = NULL, bool notGraceOnly = true,
double GetAlignmentDuration(const AlignMeterParams &params, bool notGraceOnly = true,
data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;

/**
* Returns the duration if the content of the layer element with a @sameas attribute.
* Return the duration if the element has a DurationInterface.
* Shortcut assigning default values for AlignParameter.
*/
double GetAlignmentDuration(bool notGraceOnly = true, data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;

/**
* Return the duration if the content of the layer element with a @sameas attribute.
* Used only on beam, tuplet or ftrem have.
*/
double GetSameAsContentAlignmentDuration(const Mensur *mensur = NULL, const MeterSig *meterSig = NULL,
bool notGraceOnly = true, data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;
double GetSameAsContentAlignmentDuration(const AlignMeterParams &params, bool notGraceOnly = true,
data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;

double GetContentAlignmentDuration(const AlignMeterParams &params, bool notGraceOnly = true,
data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;

double GetContentAlignmentDuration(const Mensur *mensur = NULL, const MeterSig *meterSig = NULL,
double GetContentAlignmentDuration(
bool notGraceOnly = true, data_NOTATIONTYPE notationType = NOTATIONTYPE_cmn) const;

/**
Expand Down
10 changes: 6 additions & 4 deletions include/vrv/midifunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include "functor.h"

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

#include "alignfunctor.h"

namespace smf {
class MidiFile;
}
Expand Down Expand Up @@ -64,10 +68,8 @@ class InitOnsetOffsetFunctor : public Functor {
double m_currentScoreTime;
// The current real time in seconds in the measure (incremented by each element)
double m_currentRealTimeSeconds;
// The current Mensur
Mensur *m_currentMensur;
// The current MeterSig
MeterSig *m_currentMeterSig;
// The current time alignment parameters
AlignMeterParams m_meterParams;
// The current notation type
data_NOTATIONTYPE m_notationType;
// The current tempo
Expand Down
26 changes: 12 additions & 14 deletions src/alignfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ AlignHorizontallyFunctor::AlignHorizontallyFunctor(Doc *doc) : DocFunctor(doc)
{
m_measureAligner = NULL;
m_time = 0.0;
m_currentMensur = NULL;
m_currentMeterSig = NULL;
m_currentParams.mensur = NULL;
m_currentParams.meterSig = NULL;
m_notationType = NOTATIONTYPE_cmn;
m_scoreDefRole = SCOREDEF_NONE;
m_isFirstMeasure = false;
Expand All @@ -51,8 +51,8 @@ AlignHorizontallyFunctor::AlignHorizontallyFunctor(Doc *doc) : DocFunctor(doc)

FunctorCode AlignHorizontallyFunctor::VisitLayer(Layer *layer)
{
m_currentMensur = layer->GetCurrentMensur();
m_currentMeterSig = layer->GetCurrentMeterSig();
m_currentParams.mensur = layer->GetCurrentMensur();
m_currentParams.meterSig = layer->GetCurrentMeterSig();

// We are starting a new layer, reset the time;
// We set it to -1.0 for the scoreDef attributes since they have to be aligned before any timestamp event (-1.0)
Expand Down Expand Up @@ -169,16 +169,14 @@ FunctorCode AlignHorizontallyFunctor::VisitLayerElement(LayerElement *layerEleme
Alignment *alignment = firstNote->GetAlignment();
layerElement->SetAlignment(alignment);
alignment->AddLayerElementRef(layerElement);
double duration
= layerElement->GetAlignmentDuration(m_currentMensur, m_currentMeterSig, true, m_notationType);
double duration = layerElement->GetAlignmentDuration(m_currentParams, true, m_notationType);
m_time += duration;
return FUNCTOR_CONTINUE;
}
}
// We do not align these (container). Any other?
else if (layerElement->Is({ BEAM, LIGATURE, FTREM, TUPLET })) {
double duration
= layerElement->GetSameAsContentAlignmentDuration(m_currentMensur, m_currentMeterSig, true, m_notationType);
double duration = layerElement->GetSameAsContentAlignmentDuration(m_currentParams, true, m_notationType);
m_time += duration;
return FUNCTOR_CONTINUE;
}
Expand Down Expand Up @@ -213,8 +211,8 @@ FunctorCode AlignHorizontallyFunctor::VisitLayerElement(LayerElement *layerEleme
type = ALIGNMENT_SCOREDEF_CAUTION_MENSUR;
else {
// replace the current mensur
m_currentMensur = vrv_cast<Mensur *>(layerElement);
assert(m_currentMensur);
m_currentParams.mensur = vrv_cast<Mensur *>(layerElement);
assert(m_currentParams.mensur);
type = ALIGNMENT_MENSUR;
}
}
Expand All @@ -228,8 +226,8 @@ FunctorCode AlignHorizontallyFunctor::VisitLayerElement(LayerElement *layerEleme
type = ALIGNMENT_SCOREDEF_METERSIG;
else {
// replace the current meter signature
m_currentMeterSig = vrv_cast<MeterSig *>(layerElement);
assert(m_currentMeterSig);
m_currentParams.meterSig = vrv_cast<MeterSig *>(layerElement);
assert(m_currentParams.meterSig);
// type = ALIGNMENT_METERSIG
// We force this because they should appear only at the beginning of a measure and should be non-justifiable
// We also need it because the PAE importer creates meterSig (and not staffDef @meter)
Expand Down Expand Up @@ -310,7 +308,7 @@ FunctorCode AlignHorizontallyFunctor::VisitLayerElement(LayerElement *layerEleme
// We have already an alignment with grace note children - skip this
if (!layerElement->GetAlignment()) {
// get the duration of the event
duration = layerElement->GetAlignmentDuration(m_currentMensur, m_currentMeterSig, true, m_notationType);
duration = layerElement->GetAlignmentDuration(m_currentParams, true, m_notationType);

// For timestamp, what we get from GetAlignmentDuration is actually the position of the timestamp
// So use it as current time - we can do this because the timestamp loop is redirected from the measure
Expand Down Expand Up @@ -378,7 +376,7 @@ FunctorCode AlignHorizontallyFunctor::VisitMeasure(Measure *measure)

FunctorCode AlignHorizontallyFunctor::VisitMeasureEnd(Measure *measure)
{
int meterUnit = m_currentMeterSig ? m_currentMeterSig->GetUnit() : 4;
int meterUnit = m_currentParams.meterSig ? m_currentParams.meterSig->GetUnit() : 4;
measure->m_measureAligner.SetInitialTstamp(meterUnit);

// We also need to align the timestamps - we do it at the end since we need the *meterSig to be initialized by a
Expand Down
19 changes: 10 additions & 9 deletions src/findlayerelementsfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

#include "alignfunctor.h"
#include "layer.h"
#include "layerelement.h"
#include "staff.h"
Expand All @@ -23,8 +24,8 @@ LayersInTimeSpanFunctor::LayersInTimeSpanFunctor(const MeterSig *meterSig, const
{
m_time = 0.0;
m_duration = 0.0;
m_meterSig = meterSig;
m_mensur = mensur;
m_meterParams.meterSig = meterSig;
m_meterParams.mensur = mensur;
}

void LayersInTimeSpanFunctor::SetEvent(double time, double duration)
Expand All @@ -50,7 +51,7 @@ FunctorCode LayersInTimeSpanFunctor::VisitLayerElement(const LayerElement *layer
return FUNCTOR_CONTINUE;
if (layerElement->Is(NOTE) && layerElement->GetParent()->Is(CHORD)) return FUNCTOR_CONTINUE;

double duration = layerElement->GetAlignmentDuration(m_mensur, m_meterSig);
double duration = layerElement->GetAlignmentDuration(m_meterParams);
double time = layerElement->GetAlignment()->GetTime();

// The event is starting after the end of the element
Expand All @@ -71,14 +72,14 @@ FunctorCode LayersInTimeSpanFunctor::VisitLayerElement(const LayerElement *layer

FunctorCode LayersInTimeSpanFunctor::VisitMensur(const Mensur *mensur)
{
m_mensur = mensur;
m_meterParams.mensur = mensur;

return FUNCTOR_CONTINUE;
}

FunctorCode LayersInTimeSpanFunctor::VisitMeterSig(const MeterSig *meterSig)
{
m_meterSig = meterSig;
m_meterParams.meterSig = meterSig;

return FUNCTOR_CONTINUE;
}
Expand All @@ -93,8 +94,8 @@ LayerElementsInTimeSpanFunctor::LayerElementsInTimeSpanFunctor(
{
m_time = 0.0;
m_duration = 0.0;
m_meterSig = meterSig;
m_mensur = mensur;
m_meterParams.meterSig = meterSig;
m_meterParams.mensur = mensur;
m_layer = layer;
m_allLayersButCurrent = false;
}
Expand Down Expand Up @@ -124,8 +125,8 @@ FunctorCode LayerElementsInTimeSpanFunctor::VisitLayerElement(const LayerElement
if (!layerElement->GetDurationInterface() || layerElement->Is({ MSPACE, SPACE })) return FUNCTOR_CONTINUE;

const double duration = !layerElement->GetFirstAncestor(CHORD)
? layerElement->GetAlignmentDuration(m_mensur, m_meterSig)
: vrv_cast<const Chord *>(layerElement->GetFirstAncestor(CHORD))->GetAlignmentDuration(m_mensur, m_meterSig);
? layerElement->GetAlignmentDuration(m_meterParams)
: vrv_cast<const Chord *>(layerElement->GetFirstAncestor(CHORD))->GetAlignmentDuration(m_meterParams);

const double time = layerElement->GetAlignment()->GetTime();

Expand Down
2 changes: 1 addition & 1 deletion src/horizontalaligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void GraceAligner::AlignStack()
LayerElement *element = vrv_cast<LayerElement *>(m_graceStack.at(i - 1));
assert(element);
// get the duration of the event
double duration = element->GetAlignmentDuration(NULL, NULL, false);
double duration = element->GetAlignmentDuration(false);
// Time goes backward with grace notes
time -= duration;
Alignment *alignment = this->GetAlignmentAtTime(time, ALIGNMENT_DEFAULT);
Expand Down
2 changes: 1 addition & 1 deletion src/iopae.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void PAEOutput::WriteTuplet(Tuplet *tuplet)

Staff *staff = tuplet->GetAncestorStaff();

double content = tuplet->GetContentAlignmentDuration(NULL, NULL, true, staff->m_drawingNotationType);
double content = tuplet->GetContentAlignmentDuration(true, staff->m_drawingNotationType);
// content = DUR_MAX / 2^(dur - 2)
int tupletDur = (content != 0.0) ? log2(DUR_MAX / content) + 2 : 4;
// We should be looking for dotted values
Expand Down
Loading

0 comments on commit fd201a9

Please sign in to comment.