Skip to content

Commit

Permalink
Merge pull request #3822 from rism-digital/develop-fraction
Browse files Browse the repository at this point in the history
Add file for Fraction class
  • Loading branch information
lpugin authored Oct 11, 2024
2 parents 329d6db + b275678 commit 0d36ed9
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 182 deletions.
16 changes: 16 additions & 0 deletions Verovio.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@
4D16945A1E3A44F300569BF4 /* dot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC34BA719BC4A83006175CD /* dot.cpp */; };
4D16946A1E3A455100569BF4 /* humlib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 40CA06581E351161009CFDD7 /* humlib.cpp */; };
4D1694741E3A455200569BF4 /* humlib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 40CA06581E351161009CFDD7 /* humlib.cpp */; };
4D1788C22CB8FD0100FE9043 /* fraction.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D1788C12CB8FD0100FE9043 /* fraction.h */; };
4D1788C32CB8FD0100FE9043 /* fraction.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D1788C12CB8FD0100FE9043 /* fraction.h */; settings = {ATTRIBUTES = (Public, ); }; };
4D1788C52CB8FD7300FE9043 /* fraction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D1788C42CB8FD7300FE9043 /* fraction.cpp */; };
4D1788C62CB8FD7300FE9043 /* fraction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D1788C42CB8FD7300FE9043 /* fraction.cpp */; };
4D1788C72CB8FD7300FE9043 /* fraction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D1788C42CB8FD7300FE9043 /* fraction.cpp */; };
4D1788C82CB8FD7300FE9043 /* fraction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D1788C42CB8FD7300FE9043 /* fraction.cpp */; };
4D1AC9772B6A9BB200434023 /* filereader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D1AC9762B6A9BB200434023 /* filereader.cpp */; };
4D1AC9782B6A9BB200434023 /* filereader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D1AC9762B6A9BB200434023 /* filereader.cpp */; };
4D1AC9792B6A9BB200434023 /* filereader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D1AC9762B6A9BB200434023 /* filereader.cpp */; };
Expand Down Expand Up @@ -1805,6 +1811,8 @@
4D09D3EC1EA8AD8500A420E6 /* horizontalaligner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = horizontalaligner.cpp; path = src/horizontalaligner.cpp; sourceTree = "<group>"; };
4D14600F1EA8A913007DB90C /* horizontalaligner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = horizontalaligner.h; path = include/vrv/horizontalaligner.h; sourceTree = "<group>"; };
4D1694601E3A44F300569BF4 /* Verovio-Humdrum */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Verovio-Humdrum"; sourceTree = BUILT_PRODUCTS_DIR; };
4D1788C12CB8FD0100FE9043 /* fraction.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = fraction.h; path = include/vrv/fraction.h; sourceTree = "<group>"; };
4D1788C42CB8FD7300FE9043 /* fraction.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = fraction.cpp; path = src/fraction.cpp; sourceTree = "<group>"; };
4D1AC9762B6A9BB200434023 /* filereader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = filereader.cpp; path = src/filereader.cpp; sourceTree = "<group>"; };
4D1AC97B2B6A9BD000434023 /* filereader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = filereader.h; path = include/vrv/filereader.h; sourceTree = "<group>"; };
4D1BD1B421908D6B000D35B2 /* halfmrpt.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = halfmrpt.cpp; path = src/halfmrpt.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2836,6 +2844,8 @@
4D1AC97B2B6A9BD000434023 /* filereader.h */,
4DF28A041A754DF000BA9F7D /* floatingobject.cpp */,
4D95D4F41D7185DE00B2B856 /* floatingobject.h */,
4D1788C12CB8FD0100FE9043 /* fraction.h */,
4D1788C42CB8FD7300FE9043 /* fraction.cpp */,
4D09D3EC1EA8AD8500A420E6 /* horizontalaligner.cpp */,
4D14600F1EA8A913007DB90C /* horizontalaligner.h */,
4DACC93F2990ED2600B55913 /* libmei.h */,
Expand Down Expand Up @@ -3474,6 +3484,7 @@
4DEBE6E12B36E78900B67DFB /* facsimilefunctor.h in Headers */,
4D94E0E22995411100F49F89 /* meibasic.h in Headers */,
BD2E4D9B2875882200B04350 /* stem.h in Headers */,
4D1788C22CB8FD0100FE9043 /* fraction.h in Headers */,
4DACC9EA2990F29A00B55913 /* attmodule.h in Headers */,
4DACC98E2990F29A00B55913 /* atts_externalsymbols.h in Headers */,
4D6413762035F57800BB630E /* pages.h in Headers */,
Expand Down Expand Up @@ -3750,6 +3761,7 @@
4DC3B9EB239E2B23007F185E /* transposition.h in Headers */,
BB4C4BC122A932FC001F6AF0 /* MidiMessage.h in Headers */,
BB4C4B9222A932DF001F6AF0 /* textelement.h in Headers */,
4D1788C32CB8FD0100FE9043 /* fraction.h in Headers */,
BB4C4B5C22A932D7001F6AF0 /* mensur.h in Headers */,
4D79641E26C152400026288B /* pageelement.h in Headers */,
BB4C4AEC22A932BC001F6AF0 /* editorial.h in Headers */,
Expand Down Expand Up @@ -4003,6 +4015,7 @@
E7F1C36929F03461007E12C1 /* savefunctor.cpp in Sources */,
4DF092A62497711800239195 /* phrase.cpp in Sources */,
4DB3D8D91F83D13C00B5FC2B /* turn.cpp in Sources */,
4D1788C62CB8FD7300FE9043 /* fraction.cpp in Sources */,
4DA0EAC422BB779400A7EBEB /* surface.cpp in Sources */,
4D1694051E3A44F300569BF4 /* iodarms.cpp in Sources */,
4DEC4DAF21C81F0600D1D273 /* sic.cpp in Sources */,
Expand Down Expand Up @@ -4483,6 +4496,7 @@
4DACC9F82990F29A00B55913 /* atts_figtable.cpp in Sources */,
400FEDD3206FA743000D3233 /* gracegrp.cpp in Sources */,
4D4FCD0C1F5455FF0009C455 /* staffgrp.cpp in Sources */,
4D1788C82CB8FD7300FE9043 /* fraction.cpp in Sources */,
4DEC4DBE21C828AC00D1D273 /* corr.cpp in Sources */,
4D1BD1B521908D6B000D35B2 /* halfmrpt.cpp in Sources */,
4D1EB6A12A2A40B400AF2F98 /* textlayoutelement.cpp in Sources */,
Expand Down Expand Up @@ -4582,6 +4596,7 @@
E7F1C36729F0345D007E12C1 /* savefunctor.cpp in Sources */,
4DEC4D8021C804C500D1D273 /* add.cpp in Sources */,
8F3DD36518854B390051330C /* view_tuplet.cpp in Sources */,
4D1788C72CB8FD7300FE9043 /* fraction.cpp in Sources */,
4DF092A72497711800239195 /* phrase.cpp in Sources */,
4D20741422A708C600E0765F /* view_tab.cpp in Sources */,
4D1BE7861C6A40A80086DC0E /* pugixml.cpp in Sources */,
Expand Down Expand Up @@ -4872,6 +4887,7 @@
E7F1C36829F0345D007E12C1 /* savefunctor.cpp in Sources */,
BB4C4AC122A932B6001F6AF0 /* layer.cpp in Sources */,
BB4C4B0522A932C3001F6AF0 /* pgfoot.cpp in Sources */,
4D1788C52CB8FD7300FE9043 /* fraction.cpp in Sources */,
4DF092A82497711800239195 /* phrase.cpp in Sources */,
BB4C4ABF22A932B6001F6AF0 /* labelabbr.cpp in Sources */,
4DA0EAC622BB779400A7EBEB /* surface.cpp in Sources */,
Expand Down
9 changes: 8 additions & 1 deletion bindings/iOS/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import <VerovioFramework/adjustgracexposfunctor.h>
#import <VerovioFramework/adjustharmgrpsspacingfunctor.h>
#import <VerovioFramework/adjustlayersfunctor.h>
#import <VerovioFramework/adjustneumexfunctor.h>
#import <VerovioFramework/adjustslursfunctor.h>
#import <VerovioFramework/adjuststaffoverlapfunctor.h>
#import <VerovioFramework/adjustsylspacingfunctor.h>
Expand All @@ -28,6 +29,7 @@
#import <VerovioFramework/adjustxposfunctor.h>
#import <VerovioFramework/adjustxrelfortranscriptionfunctor.h>
#import <VerovioFramework/adjustyposfunctor.h>
#import <VerovioFramework/adjustyrelfortranscriptionfunctor.h>
#import <VerovioFramework/alignfunctor.h>
#import <VerovioFramework/altsyminterface.h>
#import <VerovioFramework/anchoredtext.h>
Expand Down Expand Up @@ -105,9 +107,11 @@
#import <VerovioFramework/findlayerelementsfunctor.h>
#import <VerovioFramework/fing.h>
#import <VerovioFramework/floatingobject.h>
#import <VerovioFramework/fraction.h>
#import <VerovioFramework/ftrem.h>
#import <VerovioFramework/functor.h>
#import <VerovioFramework/functorinterface.h>
#import <VerovioFramework/genericlayerelement.h>
#import <VerovioFramework/git_commit.h>
#import <VerovioFramework/gliss.h>
#import <VerovioFramework/glyph.h>
Expand All @@ -121,13 +125,14 @@
#import <VerovioFramework/humlib.h>
#import <VerovioFramework/instrdef.h>
#import <VerovioFramework/interface.h>
#import <VerovioFramework/iobase.h>
#import <VerovioFramework/ioabc.h>
#import <VerovioFramework/iobase.h>
#import <VerovioFramework/iodarms.h>
#import <VerovioFramework/iohumdrum.h>
#import <VerovioFramework/iomei.h>
#import <VerovioFramework/iomusxml.h>
#import <VerovioFramework/iopae.h>
#import <VerovioFramework/iovolpiano.h>
#import <VerovioFramework/jsonxx.h>
#import <VerovioFramework/justifyfunctor.h>
#import <VerovioFramework/keyaccid.h>
Expand Down Expand Up @@ -167,6 +172,7 @@
#import <VerovioFramework/octave.h>
#import <VerovioFramework/options.h>
#import <VerovioFramework/orig.h>
#import <VerovioFramework/oriscus.h>
#import <VerovioFramework/ornam.h>
#import <VerovioFramework/page.h>
#import <VerovioFramework/pageelement.h>
Expand All @@ -184,6 +190,7 @@
#import <VerovioFramework/positioninterface.h>
#import <VerovioFramework/preparedatafunctor.h>
#import <VerovioFramework/proport.h>
#import <VerovioFramework/quilisma.h>
#import <VerovioFramework/rdg.h>
#import <VerovioFramework/ref.h>
#import <VerovioFramework/reg.h>
Expand Down
2 changes: 1 addition & 1 deletion include/vrv/durationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "atts_gestural.h"
#include "atts_mensural.h"
#include "atts_shared.h"
#include "horizontalaligner.h"
#include "fraction.h"
#include "interface.h"

namespace vrv {
Expand Down
79 changes: 79 additions & 0 deletions include/vrv/fraction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/////////////////////////////////////////////////////////////////////////////
// Name: fraction.h
// Author: Laurent Pugin
// Created: 2024
// Copyright (c) Authors and others. All rights reserved.
/////////////////////////////////////////////////////////////////////////////

#ifndef __VRV_FRACTION_H__
#define __VRV_FRACTION_H__

#include "vrv.h"

namespace vrv {

//----------------------------------------------------------------------------
// Fraction
//----------------------------------------------------------------------------

class Fraction {

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

// Enable implicit conversion constructor for `int`
template <typename T, typename = std::enable_if_t<std::is_same_v<T, int>>>
Fraction(T num) : m_numerator(num), m_denominator(1)
{
}

/** Addition operator */
Fraction operator+(const Fraction &other) const;
/** Subtraction operator */
Fraction operator-(const Fraction &other) const;
/** Multiplication operator */
Fraction operator*(const Fraction &other) const;
/** Division operator */
Fraction operator/(const Fraction &other) const;

/** Equality operator */
bool operator==(const Fraction &other) const;
/** Ordering operator */
std::strong_ordering operator<=>(const Fraction &other) const;

/** Getters */
int GetNumerator() const { return m_numerator; }
int GetDenominator() const { return m_denominator; }

/** Convert fraction to a double */
double ToDouble() const;

/** Convert fraction to a string */
std::string ToString() const;

/** Convert to data_DURATION and the remaining Fraction */
std::pair<data_DURATION, Fraction> ToDur() const;

//----------------//
// Static methods //
//----------------//

/** Reduce the fraction represented by the two numbers */
static void Reduce(int &numerator, int &denominator);

private:
/** Reduce the fraction */
void Reduce();

public:
//
private:
int m_numerator;
int m_denominator;
};

} // namespace vrv

#endif
64 changes: 1 addition & 63 deletions include/vrv/horizontalaligner.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define __VRV_HORIZONTAL_ALIGNER_H__

#include "atts_shared.h"
#include "fraction.h"
#include "object.h"
#include "vrv.h"

Expand Down Expand Up @@ -60,69 +61,6 @@ enum AlignmentType {
#define BARLINE_REFERENCES -1
#define TSTAMP_REFERENCES -2

//----------------------------------------------------------------------------
// Fraction
//----------------------------------------------------------------------------

class Fraction {

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

// Enable implicit conversion constructor for `int`
template <typename T, typename = std::enable_if_t<std::is_same_v<T, int>>>
Fraction(T num) : m_numerator(num), m_denominator(1)
{
}

/** Addition operator */
Fraction operator+(const Fraction &other) const;
/** Subtraction operator */
Fraction operator-(const Fraction &other) const;
/** Multiplication operator */
Fraction operator*(const Fraction &other) const;
/** Division operator */
Fraction operator/(const Fraction &other) const;

/** Equality operator */
bool operator==(const Fraction &other) const;
/** Ordering operator */
std::strong_ordering operator<=>(const Fraction &other) const;

/** Getters */
int GetNumerator() const { return m_numerator; }
int GetDenominator() const { return m_denominator; }

/** Convert fraction to a double */
double ToDouble() const;

/** Convert fraction to a string */
std::string ToString() const;

/** Convert to data_DURATION and the remaining Fraction */
std::pair<data_DURATION, Fraction> ToDur() const;

//----------------//
// Static methods //
//----------------//

/** Reduce the fraction represented by the two numbers */
static void Reduce(int &numerator, int &denominator);

private:
/** Reduce the fraction */
void Reduce();

public:
//
private:
int m_numerator;
int m_denominator;
};

//----------------------------------------------------------------------------
// Alignment
//----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion include/vrv/layerelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "atts_shared.h"
#include "facsimileinterface.h"
#include "horizontalaligner.h"
#include "fraction.h"
#include "linkinginterface.h"
#include "object.h"

Expand Down
Loading

0 comments on commit 0d36ed9

Please sign in to comment.