Skip to content

Commit

Permalink
Merge pull request #3919 from brdvd/feat/fraction-constructors
Browse files Browse the repository at this point in the history
Split Fraction constructors
  • Loading branch information
lpugin authored Jan 27, 2025
2 parents 2f6ad06 + 1dda133 commit 4adb291
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion include/vrv/fraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Fraction {

public:
// Constructors - make them explicit to avoid type conversion
explicit Fraction(int num = 0, int denom = 1);
explicit Fraction(int num = 0) : m_numerator(num), m_denominator(1) {}
explicit Fraction(int num, int denom);
explicit Fraction(data_DURATION duration);

// Enable implicit conversion constructor for `int`
Expand Down
4 changes: 2 additions & 2 deletions src/convertfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,8 @@ void ConvertToCmnFunctor::SplitDurationIntoCmn(
const int semiBrevisDots = (prolatioMajor) ? 1 : 0;
const int brevisDots = (tempusPerfectum) ? 1 : 0;

const Fraction semiBrevis = Fraction(1, 1) * abs(mensur->GetProlatio()) / 2;
const Fraction brevis = Fraction(1, 1) * abs(mensur->GetTempus());
const Fraction semiBrevis = Fraction(1) * abs(mensur->GetProlatio()) / 2;
const Fraction brevis = Fraction(1) * abs(mensur->GetTempus());

// First see if we are expecting a breve and if the duration is long enough
if (elementDur == DURATION_breve) {
Expand Down
2 changes: 1 addition & 1 deletion src/durationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Fraction DurationInterface::GetInterfaceAlignmentMensuralDuration(

if (!currentMensur) {
LogWarning("No current mensur for calculating duration");
return Fraction(1, 1);
return Fraction(1);
}

if (this->HasNum() || this->HasNumbase()) {
Expand Down
6 changes: 3 additions & 3 deletions src/fraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Fraction::Fraction(int num, int denom)
denom = 1;
}
m_denominator = denom;
Reduce();
this->Reduce();
}

Fraction::Fraction(data_DURATION duration)
Expand All @@ -39,7 +39,7 @@ Fraction::Fraction(data_DURATION duration)
int den = pow(2, (duration + 1));
m_numerator = 8;
m_denominator = den;
Reduce();
this->Reduce();
}

Fraction Fraction::operator+(const Fraction &other) const
Expand Down Expand Up @@ -122,7 +122,7 @@ void Fraction::Reduce()
m_numerator = -m_numerator;
m_denominator = -m_denominator;
}
int gcdVal = std::gcd(abs(m_numerator), abs(m_denominator));
const int gcdVal = std::gcd(m_numerator, m_denominator);
if (gcdVal != 1) {
m_numerator /= gcdVal;
m_denominator /= gcdVal;
Expand Down
6 changes: 3 additions & 3 deletions src/horizontalaligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,15 @@ void Alignment::Reset()
Object::Reset();

m_xRel = 0;
m_time = Fraction(0, 1);
m_time = Fraction(0);
m_type = ALIGNMENT_DEFAULT;

ClearGraceAligners();
this->ClearGraceAligners();
}

Alignment::~Alignment()
{
ClearGraceAligners();
this->ClearGraceAligners();
}

void Alignment::ClearGraceAligners()
Expand Down
8 changes: 4 additions & 4 deletions src/layerelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ Fraction LayerElement::GetAlignmentDuration(
const AlignMeterParams &params, bool notGraceOnly, data_NOTATIONTYPE notationType) const
{
if (this->IsGraceNote() && notGraceOnly) {
return Fraction(0, 1);
return Fraction(0);
}

// Mensural chords are aligned looking at the duration of the notes
Expand Down Expand Up @@ -777,7 +777,7 @@ Fraction LayerElement::GetAlignmentDuration(
return (syllable->GetLast() == this) ? NEUME_MEDIUM_SPACE : NEUME_SMALL_SPACE;
}
else {
return Fraction(0, 1);
return Fraction(0);
}
}

Expand All @@ -791,7 +791,7 @@ Fraction LayerElement::GetSameAsContentAlignmentDuration(
const AlignMeterParams &params, bool notGraceOnly, data_NOTATIONTYPE notationType) const
{
if (!this->HasSameasLink() || !this->GetSameasLink()->Is({ BEAM, FTREM, TUPLET })) {
return Fraction(0, 1);
return Fraction(0);
}

const LayerElement *sameas = vrv_cast<const LayerElement *>(this->GetSameasLink());
Expand All @@ -804,7 +804,7 @@ Fraction LayerElement::GetContentAlignmentDuration(
const AlignMeterParams &params, bool notGraceOnly, data_NOTATIONTYPE notationType) const
{
if (!this->Is({ BEAM, FTREM, TUPLET })) {
return Fraction(0, 1);
return Fraction(0);
}

Fraction duration;
Expand Down
2 changes: 1 addition & 1 deletion src/view_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ void View::DrawMRest(DeviceContext *dc, LayerElement *element, Layer *layer, Sta

const bool drawingCueSize = mRest->GetDrawingCueSize();
int x = mRest->GetDrawingX();
const bool isDouble = (measure->m_measureAligner.GetMaxTime() >= Fraction(2, 1));
const bool isDouble = (measure->m_measureAligner.GetMaxTime() >= Fraction(2));
int y = isDouble ? element->GetDrawingY() - m_doc->GetDrawingDoubleUnit(staffSize) : element->GetDrawingY();
char32_t rest = isDouble ? SMUFL_E4E2_restDoubleWhole : SMUFL_E4E3_restWhole;

Expand Down

0 comments on commit 4adb291

Please sign in to comment.