Skip to content

Commit

Permalink
Merge pull request #3806 from rism-digital/develop-align-fraction
Browse files Browse the repository at this point in the history
Refactoring for using fraction in alignment calculation
  • Loading branch information
ahankinson authored Oct 7, 2024
2 parents 0528c93 + 775021d commit 8a846f2
Show file tree
Hide file tree
Showing 54 changed files with 860 additions and 608 deletions.
2 changes: 1 addition & 1 deletion include/vrv/alignfunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AlignHorizontallyFunctor : public DocFunctor {
// The measureAligner
MeasureAligner *m_measureAligner;
// The time
double m_time;
Fraction m_time;
// The current MeterSig, Mensur and Proport
AlignMeterParams m_currentParams;
// The current notation type
Expand Down
7 changes: 4 additions & 3 deletions include/vrv/beam.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class BeamSegment {
int CalcMixedBeamCenterY(int step, int unit) const;

// Helper to calculate location and duration of the note that would be setting highest/lowest point for the beam
std::tuple<int, int, int> CalcStemDefiningNote(const Staff *staff, data_BEAMPLACE place) const;
std::tuple<int, int, data_DURATION> CalcStemDefiningNote(const Staff *staff, data_BEAMPLACE place) const;

// Calculate positioning for the horizontal beams
void CalcHorizontalBeam(const Doc *doc, const Staff *staff, const BeamDrawingInterface *beamInterface);
Expand Down Expand Up @@ -429,7 +429,8 @@ class BeamElementCoord {
void SetClosestNoteOrTabDurSym(data_STEMDIRECTION stemDir, bool outsideStaff);

/** Helper for calculating the stem length for staff notation and tablature beams within the staff */
int CalculateStemLength(const Staff *staff, data_STEMDIRECTION stemDir, bool isHorizontal, int preferredDur) const;
int CalculateStemLength(
const Staff *staff, data_STEMDIRECTION stemDir, bool isHorizontal, data_DURATION preferredDur) const;

/** Helper for calculating the stem length for tablature beam placed outside the staff */
int CalculateStemLengthTab(const Staff *staff, data_STEMDIRECTION stemDir) const;
Expand All @@ -454,7 +455,7 @@ class BeamElementCoord {

int m_x;
int m_yBeam; // y value of stem top position
int m_dur; // drawing duration
data_DURATION m_dur; // drawing duration
int m_breaksec;
int m_overlapMargin;
int m_maxShortening; // maximum allowed shortening in half units
Expand Down
10 changes: 5 additions & 5 deletions include/vrv/beatrpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ class BeatRpt : public LayerElement, public AttColor, public AttBeatRptLog, publ
bool HasToBeAligned() const override { return true; }

/**
* Returns the duration (in double) for the BeatRpt.
* Returns the duration (in Fraction) for the BeatRpt.
*/

double GetBeatRptAlignmentDuration(int meterUnit) const;
Fraction GetBeatRptAlignmentDuration(data_DURATION meterUnit) const;

/**
* MIDI timing information
*/
///@{
void SetScoreTimeOnset(double scoreTime);
double GetScoreTimeOnset() const;
void SetScoreTimeOnset(Fraction scoreTime);
Fraction GetScoreTimeOnset() const;

//----------//
// Functors //
Expand All @@ -75,7 +75,7 @@ class BeatRpt : public LayerElement, public AttColor, public AttBeatRptLog, publ
* The score-time onset of the note in the measure (duration from the start of measure in
* quarter notes).
*/
double m_scoreTimeOnset;
Fraction m_scoreTimeOnset;
};

} // namespace vrv
Expand Down
6 changes: 3 additions & 3 deletions include/vrv/calcalignmentxposfunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CalcAlignmentXPosFunctor : public DocFunctor {
*/
///@{
int GetLongestActualDur() const { return m_longestActualDur; }
void SetLongestActualDur(int dur) { m_longestActualDur = dur; }
void SetLongestActualDur(data_DURATION dur) { m_longestActualDur = dur; }
///@}

/*
Expand All @@ -61,11 +61,11 @@ class CalcAlignmentXPosFunctor : public DocFunctor {
//
private:
// The previous time position
double m_previousTime;
Fraction m_previousTime;
// The previous x rel position
int m_previousXRel;
// Duration of the longest note
int m_longestActualDur;
data_DURATION m_longestActualDur;
// The estimated justification ratio of the system
double m_estimatedJustificationRatio;
// The last alignment that was not timestamp-only
Expand Down
4 changes: 2 additions & 2 deletions include/vrv/calcstemfunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CalcStemFunctor : public DocFunctor {
* Adjusts the flag placement and stem length if they are crossing notehead or ledger lines
*/
void AdjustFlagPlacement(
const Doc *doc, Stem *stem, Flag *flag, int staffSize, int verticalCenter, int duration) const;
const Doc *doc, Stem *stem, Flag *flag, int staffSize, int verticalCenter, data_DURATION duration) const;

public:
//
Expand All @@ -72,7 +72,7 @@ class CalcStemFunctor : public DocFunctor {
// The vertical center of the staff
int m_verticalCenter;
// The actual duration of the chord / note
int m_dur;
data_DURATION m_dur;
// The flag for grace notes (stem is not extended)
bool m_isGraceNote;
// The flag for stem.sameas notes
Expand Down
2 changes: 1 addition & 1 deletion include/vrv/drawinginterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class BeamDrawingInterface : public ObjectListInterface {
Staff *m_crossStaffContent;
data_STAFFREL_basic m_crossStaffRel;
bool m_isSpanningElement;
int m_shortestDur;
data_DURATION m_shortestDur;
data_STEMDIRECTION m_notesStemDir;
data_BEAMPLACE m_drawingPlace;
Staff *m_beamStaff;
Expand Down
44 changes: 22 additions & 22 deletions include/vrv/durationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "atts_gestural.h"
#include "atts_mensural.h"
#include "atts_shared.h"
#include "horizontalaligner.h"
#include "interface.h"

namespace vrv {
Expand Down Expand Up @@ -57,19 +58,19 @@ class DurationInterface : public Interface,
///@}

/**
* Returns the duration (in double) for the element.
* It returns 0.0 for grace notes.
* Returns the duration (in Fraction) for the element.
* It returns 0/1 for grace notes.
* Careful: this method is not overriding LayerElement::GetAlignmentDuration since
* LayerElement and DurationInterface have no inheritance link.
*/
double GetInterfaceAlignmentDuration(int num, int numBase) const;
Fraction GetInterfaceAlignmentDuration(int num, int numBase) const;

/**
* Returns the duration (in double) for the element for mensural notation
* Currently this assume brevis equality (through DUR_MENSURAL_REF) and would
* Returns the duration (in Fraction) for the element for mensural notation
* Currently this assume brevis equality and would
* need to be modified for shorter equality in later repertoire.
*/
double GetInterfaceAlignmentMensuralDuration(int num, int numBase, const Mensur *currentMensur) const;
Fraction GetInterfaceAlignmentMensuralDuration(int num, int numBase, const Mensur *currentMensur) const;

/**
* Return true if the note or rest is the first of a beam.
Expand All @@ -84,19 +85,18 @@ class DurationInterface : public Interface,
/**
* @name Return the actual (gestural) duration of the note, for both CMN and mensural durations
* See data_DURATION
* For CMN, it is the same (DURATION_1 == DUR_1)
* For mensural, we need to apply the DUR_MENSURAL_MASK
* For Mensural, it is the same (DURATION_2 == DURATION_minima)
*/
///@{
int GetActualDur() const;
int GetActualDurGes() const;
data_DURATION GetActualDur() const;
data_DURATION GetActualDurGes() const;
///@}

/**
* If the element is part of a chord, return the chord actual duration, otherwise the note actual duration.
* Since we need to check what the element is, we need to pass it as parameter.
*/
int GetNoteOrChordDur(const LayerElement *element) const;
data_DURATION GetNoteOrChordDur(const LayerElement *element) const;

/**
* Return true if the value is a mensural (DURATION_longa, brevis, etc.)
Expand All @@ -113,17 +113,17 @@ class DurationInterface : public Interface,
* MIDI timing information
*/
///@{
void SetScoreTimeOnset(double scoreTime);
void SetScoreTimeOnset(Fraction scoreTime);
void SetRealTimeOnsetSeconds(double timeInSeconds);
void SetScoreTimeOffset(double scoreTime);
void SetScoreTimeOffset(Fraction scoreTime);
void SetRealTimeOffsetSeconds(double timeInSeconds);
void SetScoreTimeTiedDuration(double timeInSeconds);
double GetScoreTimeOnset() const;
void SetScoreTimeTiedDuration(Fraction timeInSeconds);
Fraction GetScoreTimeOnset() const;
double GetRealTimeOnsetMilliseconds() const;
double GetScoreTimeOffset() const;
double GetScoreTimeTiedDuration() const;
Fraction GetScoreTimeOffset() const;
Fraction GetScoreTimeTiedDuration() const;
double GetRealTimeOffsetMilliseconds() const;
double GetScoreTimeDuration() const;
Fraction GetScoreTimeDuration() const;
///@}

//-----------------//
Expand All @@ -140,7 +140,7 @@ class DurationInterface : public Interface,
/**
* Calculate the actual duration => translate mensural values
*/
int CalcActualDur(data_DURATION dur) const;
data_DURATION CalcActualDur(data_DURATION dur) const;

public:
//
Expand All @@ -149,7 +149,7 @@ class DurationInterface : public Interface,
* The score-time onset of the note in the measure (duration from the start of measure in
* quarter notes).
*/
double m_scoreTimeOnset;
Fraction m_scoreTimeOnset;

/**
* The score-time off-time of the note in the measure (duration from the start of the measure
Expand All @@ -159,7 +159,7 @@ class DurationInterface : public Interface,
* of the printed note, and the m_scoreTimeTiedDuration is -1.0 to indicate that it should not
* be exported when creating a MIDI file.
*/
double m_scoreTimeOffset;
Fraction m_scoreTimeOffset;

/**
* The time in milliseconds since the start of the measure element that contains the note.
Expand All @@ -179,7 +179,7 @@ class DurationInterface : public Interface,
* If the note is a secondary note in a tied group, then this variable is set to -1.0 to
* indicate that it should not be written to MIDI output.
*/
double m_scoreTimeTiedDuration;
Fraction m_scoreTimeTiedDuration;

/**
* The default duration: extracted from scoreDef/staffDef and used when no duration attribute is given
Expand Down
12 changes: 6 additions & 6 deletions include/vrv/findlayerelementsfunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class LayersInTimeSpanFunctor : public ConstFunctor {
/*
* Set the time and duration of the event
*/
void SetEvent(double time, double duration);
void SetEvent(const Fraction &time, const Fraction &duration);

/*
* Retrieve the search result
Expand All @@ -65,9 +65,9 @@ class LayersInTimeSpanFunctor : public ConstFunctor {
//
private:
// The time of the event
double m_time;
Fraction m_time;
// The duration of the event
double m_duration;
Fraction m_duration;
// The layers (layerN) found
std::set<int> m_layers;
// The current time alignment parameters
Expand Down Expand Up @@ -99,7 +99,7 @@ class LayerElementsInTimeSpanFunctor : public ConstFunctor {
/*
* Set the time and duration of the event
*/
void SetEvent(double time, double duration);
void SetEvent(const Fraction &time, const Fraction &duration);

/*
* Consider all layers except the current one
Expand All @@ -126,9 +126,9 @@ class LayerElementsInTimeSpanFunctor : public ConstFunctor {
//
private:
// The time of the event
double m_time;
Fraction m_time;
// The duration of the event
double m_duration;
Fraction m_duration;
// The list of layer elements found
ListOfConstObjects m_elements;
// The current time alignment parameters
Expand Down
Loading

0 comments on commit 8a846f2

Please sign in to comment.