MNX Document Model
Loading...
Searching...
No Matches
CommonClasses.h
1/*
2 * Copyright (C) 2025, Robert Patterson
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22#pragma once
23
24#include <utility>
25#include <numeric>
26#include <stdexcept>
27#include <limits>
28#include <type_traits>
29
30#include "BaseTypes.h"
31#include "Enumerations.h"
32
33namespace mnx {
34
49
73struct [[nodiscard]] FractionValue
74{
76 using NumType = unsigned;
77 static_assert(std::is_integral<NumType>::value, "FractionValue::NumType must be an integral type");
78
79private:
80 NumType m_num = 0;
81 NumType m_den = 1;
82
83 template<typename T = NumType,
84 typename std::enable_if_t<std::is_signed<T>::value, int> = 0>
85 constexpr void normalizeSign()
86 {
87 if (m_den < 0) {
88 m_den = -m_den;
89 m_num = -m_num;
90 }
91 }
92
93 // Unsigned case: no-op, never even sees m_den < 0
94 template<typename T = NumType,
95 typename std::enable_if_t<!std::is_signed<T>::value, int> = 0>
96 constexpr void normalizeSign() {}
97
98public:
102 constexpr FractionValue() = default;
103
116 constexpr FractionValue(NumType num, NumType den)
117 : m_num(num), m_den(den)
118 {
119 if (m_den == 0) {
120 throw std::invalid_argument("FractionValue: denominator must not be zero.");
121 }
122 normalizeSign();
123 }
124
130 constexpr FractionValue(NumType value) : m_num(value), m_den(1) {}
131
133 [[nodiscard]] constexpr NumType numerator() const noexcept { return m_num; }
134
136 [[nodiscard]] constexpr NumType denominator() const noexcept { return m_den; }
137
142 [[nodiscard]] constexpr NumType quotient() const
143 {
144 return m_num / m_den;
145 }
146
151 constexpr FractionValue remainder() const
152 {
153 FractionValue result;
154 result.m_num = m_num % m_den;
155 result.m_den = m_den;
156 return result;
157 }
158
160 static constexpr FractionValue max() noexcept
161 {
162 return FractionValue((std::numeric_limits<NumType>::max)());
163 }
164
166 [[nodiscard]] constexpr double toDouble() const {
167 return double(m_num) / double(m_den);
168 }
169
179 {
180 // a/b + c/d = (ad + bc)/bd
181 m_num = m_num * rhs.m_den + rhs.m_num * m_den;
182 m_den = m_den * rhs.m_den;
183 reduce();
184 return *this;
185 }
186
196 {
197 // a/b - c/d = (ad - bc)/bd
198 m_num = m_num * rhs.m_den - rhs.m_num * m_den;
199 m_den = m_den * rhs.m_den;
200 reduce();
201 return *this;
202 }
203
213 {
214 m_num = m_num * rhs.m_num;
215 m_den = m_den * rhs.m_den;
216 reduce();
217 return *this;
218 }
219
231 {
232 if (rhs.m_num == 0) {
233 throw std::invalid_argument("Division by zero FractionValue.");
234 }
235 m_num = m_num * rhs.m_den;
236 m_den = m_den * rhs.m_num;
237 reduce();
238 return *this;
239 }
240
244 constexpr void reduce()
245 {
246 const NumType g = std::gcd(m_num, m_den);
247 if (g > 1) {
248 m_num /= g;
249 m_den /= g;
250 }
251 normalizeSign();
252 }
253
257 constexpr FractionValue reduced() const
258 {
259 auto result = *this;
260 result.reduce();
261 return result;
262 }
263
294 constexpr bool expressWithDenominator(NumType targetDenominator)
295 {
296 if (targetDenominator == 0) {
297 // Cannot express anything with denominator 0.
298 return false;
299 }
300
301 // Zero fraction: 0/d is expressible as 0/targetDenominator.
302 if (m_num == 0) {
303 m_den = targetDenominator;
304 return true;
305 }
306
307 // Reduce the fraction logically: m_num/m_den -> (numRed/denRed).
308 // We don't actually have to store the reduced form; just use it to
309 // check compatibility and compute the new numerator.
310 const NumType g = std::gcd(m_num, m_den);
311 const NumType denRed = m_den / g;
312 const NumType numRed = m_num / g; // sign preserved
313
314 // For an integer representation with the requested denominator to exist
315 // (while preserving the value), the reduced denominator must divide
316 // targetDenominator exactly.
317 if (targetDenominator % denRed != 0) {
318 return false; // No integer scaling factor exists.
319 }
320
321 const NumType factor = targetDenominator / denRed;
322
323 // Apply the scaling to the reduced numerator and store the new form.
324 m_num = numRed * factor;
325 m_den = targetDenominator;
326
327 normalizeSign();
328
329 return true;
330 }
331};
332#ifndef DOXYGEN_SHOULD_IGNORE_THIS
333
334// ------------------------------------------------------------
335// Non-member arithmetic operators
336// ------------------------------------------------------------
337
338[[nodiscard]] constexpr FractionValue operator+(FractionValue lhs, const FractionValue& rhs)
339{
340 lhs += rhs;
341 return lhs;
342}
343
344[[nodiscard]] constexpr FractionValue operator-(FractionValue lhs, const FractionValue& rhs)
345{
346 lhs -= rhs;
347 return lhs;
348}
349
350[[nodiscard]] constexpr FractionValue operator*(FractionValue lhs, const FractionValue& rhs)
351{
352 lhs *= rhs;
353 return lhs;
354}
355
356[[nodiscard]] constexpr FractionValue operator/(FractionValue lhs, const FractionValue& rhs)
357{
358 lhs /= rhs;
359 return lhs;
360}
361
362// ------------------------------------------------------------
363// Comparison operators
364// ------------------------------------------------------------
365
366[[nodiscard]] constexpr bool operator==(const FractionValue& a, const FractionValue& b)
367{
368 return a.numerator() * b.denominator() == b.numerator() * a.denominator();
369}
370
371[[nodiscard]] constexpr bool operator!=(const FractionValue& a, const FractionValue& b)
372{
373 return !(a == b);
374}
375
376[[nodiscard]] constexpr bool operator<(const FractionValue& a, const FractionValue& b)
377{
378 return a.numerator() * b.denominator() < b.numerator() * a.denominator();
379}
380
381[[nodiscard]] constexpr bool operator<=(const FractionValue& a, const FractionValue& b)
382{
383 return !(b < a);
384}
385
386[[nodiscard]] constexpr bool operator>(const FractionValue& a, const FractionValue& b)
387{
388 return b < a;
389}
390
391[[nodiscard]] constexpr bool operator>=(const FractionValue& a, const FractionValue& b)
392{
393 return !(a < b);
394}
395
396#endif // DOXYGEN_SHOULD_IGNORE_THIS
397
400class Fraction : private Array<unsigned>
401{
402private:
403 using NumType = FractionValue::NumType;
405
406 static constexpr size_t NUMERATOR_INDEX = 0;
407 static constexpr size_t DENOMINATOR_INDEX = 1;
408
409public:
411 Fraction(const std::shared_ptr<json>& root, json_pointer pointer)
413 {
414 if (size() != 2) {
415 throw std::invalid_argument("mnx::Fraction must have exactly 2 elements.");
416 }
417 }
418
423 Fraction(Base& parent, std::string_view key, const FractionValue& value)
424 : ArrayType(parent, key)
425 {
426 push_back(value.numerator());
427 push_back(value.denominator());
428 }
429
431 [[nodiscard]] operator FractionValue() const
432 {
433 return FractionValue(numerator(), denominator());
434 }
435
436 MNX_ARRAY_ELEMENT_PROPERTY(NumType, numerator, NUMERATOR_INDEX);
437 MNX_ARRAY_ELEMENT_PROPERTY(NumType, denominator, DENOMINATOR_INDEX);
438
439 friend class Base;
440};
441
446class IdPair : public Object
447{
448public:
450 struct Required
451 {
452 std::string startId;
453 std::string endId;
454 };
455
457 IdPair(const std::shared_ptr<json>& root, json_pointer pointer)
459 {
460 }
461
467 IdPair(Base& parent, std::string_view key, const std::string& startId, const std::string& endId)
468 : Object(parent, key)
469 {
470 set_start(startId);
471 set_end(endId);
472 }
473
475 operator Required() const { return { start(), end() }; }
476
478 static Required make(const std::string& startId, const std::string& endId) { return { startId, endId }; }
479
480 MNX_REQUIRED_PROPERTY(std::string, start);
481 MNX_REQUIRED_PROPERTY(std::string, end);
482};
483
489{
490public:
492 struct Required
493 {
495 };
496
498 RhythmicPosition(const std::shared_ptr<json>& root, json_pointer pointer)
500 {
501 }
502
507 RhythmicPosition(Base& parent, std::string_view key, const FractionValue& position)
508 : Object(parent, key)
509 {
510 create_fraction(position);
511 }
512
516 : Object()
517 {
518 create_fraction(position);
519 }
520
522 operator Required() const { return { fraction() }; }
523
525 static Required make(const FractionValue& position) { return { position }; }
526
534 [[nodiscard]] static int compare(const RhythmicPosition& lhs,
535 const RhythmicPosition& rhs,
536 bool rhsIncludesTrailingGrace = false);
537
539 Fraction, fraction,
540 (const FractionValue&, value));
541 MNX_OPTIONAL_PROPERTY(unsigned, graceIndex);
543};
544
550{
551public:
553 struct Required
554 {
555 std::string measureId;
557 };
558
560 MeasureRhythmicPosition(const std::shared_ptr<json>& root, json_pointer pointer)
562 {
563 }
564
570 MeasureRhythmicPosition(Base& parent, std::string_view key, const std::string& measureId, const FractionValue& position)
571 : Object(parent, key)
572 {
573 set_measure(measureId);
574 create_position(position);
575 }
576
580 MeasureRhythmicPosition(const std::string& measureId, const FractionValue& position)
581 : Object()
582 {
583 set_measure(measureId);
584 create_position(position);
585 }
586
588 operator Required() const { return { measure(), position().fraction() }; }
589
591 static Required make(const std::string& measureId, const FractionValue& position) { return { measureId, position }; }
592
593 MNX_REQUIRED_PROPERTY(std::string, measure);
595 RhythmicPosition, position,
596 (const FractionValue&, position));
597};
598
603class Interval : public Object
604{
605public:
607 struct Required
608 {
610 int halfSteps{};
611 };
612
614 Interval(const std::shared_ptr<json>& root, json_pointer pointer)
616 {
617 }
618
624 Interval(Base& parent, std::string_view key, int staffDistance, int halfSteps)
625 : Object(parent, key)
626 {
627 set_halfSteps(halfSteps);
628 set_staffDistance(staffDistance);
629 }
630
632 operator Required() const { return { staffDistance(), halfSteps() }; }
633
635 static Required make(int staffDistance, int halfSteps) { return { staffDistance, halfSteps }; }
636
637 MNX_REQUIRED_PROPERTY(int, halfSteps);
638 MNX_REQUIRED_PROPERTY(int, staffDistance);
639};
640
645class KeySignature : public Object
646{
647public:
649 struct Required
650 {
651 int fifths{};
652 };
653
655 KeySignature(const std::shared_ptr<json>& root, json_pointer pointer)
657 {
658 }
659
661 operator Required() const { return { fifths() }; }
662
664 static Required make(int fifths) { return { fifths }; }
665
670 KeySignature(Base& parent, std::string_view key, int fifths)
671 : Object(parent, key)
672 {
673 set_fifths(fifths);
674 }
675
676 MNX_OPTIONAL_PROPERTY(std::string, color);
678};
679
684class NoteValue : public Object
685{
686public:
688 struct Required
689 {
691 unsigned dots{};
692 };
693
695 NoteValue(const std::shared_ptr<json>& root, json_pointer pointer)
697 {
698 }
699
705 NoteValue(Base& parent, std::string_view key, NoteValueBase base, unsigned dots = 0)
706 : Object(parent, key)
707 {
708 set_base(base);
709 if (dots) {
710 set_dots(dots);
711 }
712 }
713
715 operator Required() const { return { base(), dots() }; }
716
718 static Required make(NoteValueBase base, unsigned dots = 0) { return { base, dots }; }
719
721 [[nodiscard]] operator FractionValue() const;
722
725
727 [[nodiscard]] unsigned calcNumberOfFlags() const;
728};
729
735{
736public:
738 struct Required
739 {
740 unsigned count{};
742 };
743
745 NoteValueQuantity(const std::shared_ptr<json>& root, json_pointer pointer)
747 {
748 }
749
755 NoteValueQuantity(Base& parent, std::string_view key, unsigned count, const NoteValue::Required& noteValue)
756 : Object(parent, key)
757 {
758 set_multiple(count);
759 create_duration(noteValue.base, noteValue.dots);
760 }
761
763 operator Required() const { return { multiple(), duration() }; }
764
766 static Required make(unsigned count, const NoteValue::Required& noteValue) { return { count, noteValue }; }
767
769 [[nodiscard]] operator FractionValue() const
770 { return multiple() * duration(); }
771
773 (NoteValueBase, base), (unsigned, dots));
774 MNX_REQUIRED_PROPERTY(unsigned, multiple);
775};
776
781class TimeSignature : public Object
782{
783public:
785 struct Required
786 {
787 int count{};
789 };
790
792 TimeSignature(const std::shared_ptr<json>& root, json_pointer pointer)
794 {
795 }
796
802 TimeSignature(Base& parent, std::string_view key, int count, TimeSignatureUnit unit)
803 : Object(parent, key)
804 {
805 set_count(count);
806 set_unit(unit);
807 }
808
810 operator Required() const { return { count(), unit() }; }
811
813 static Required make(int count, TimeSignatureUnit unit) { return { count, unit }; }
814
817 [[nodiscard]] operator FractionValue() const
818 { return FractionValue(static_cast<FractionValue::NumType>(count()), static_cast<FractionValue::NumType>(unit())); }
819
822};
823
824} // namespace mnx
Represents an MNX array, encapsulating property access.
Definition BaseTypes.h:506
size_t size() const
Get the size of the array.
Definition BaseTypes.h:559
std::enable_if_t<!std::is_base_of_v< Base, U >, void > push_back(const U &value)
Append a new value to the array. (Available only for primitive types)
Definition BaseTypes.h:608
Base class wrapper for all MNX JSON nodes.
Definition BaseTypes.h:198
json_pointer pointer() const
Returns the json_pointer for this node.
Definition BaseTypes.h:260
T parent() const
Returns the parent object for this node.
Definition BaseTypes.h:246
const std::shared_ptr< json > & root() const
Returns the root.
Definition BaseTypes.h:283
Defines a fermata.
Definition CommonClasses.h:40
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(FermataDuration, duration, FermataDuration::Auto)
subjective playback duration of the fermata
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(FermataSymbol, symbol, FermataSymbol::Normal)
the style of symbol for the fermata
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(Orientation, orient, Orientation::Auto)
vertical placement of the fermata
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(MarkingUpDownAuto, pointing, MarkingUpDownAuto::Auto)
direction of the fermata symbol
Represents a fraction of a whole note, for measuring musical time.
Definition CommonClasses.h:401
MNX_ARRAY_ELEMENT_PROPERTY(NumType, denominator, DENOMINATOR_INDEX)
the denominator of the fraction
Fraction(Base &parent, std::string_view key, const FractionValue &value)
Creates a new Array class as a child of a JSON element.
Definition CommonClasses.h:423
MNX_ARRAY_ELEMENT_PROPERTY(NumType, numerator, NUMERATOR_INDEX)
the numerator of the fraction
Fraction(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor to wrap a Fraction instance around existing JSON.
Definition CommonClasses.h:411
Represents a start and end id pair.
Definition CommonClasses.h:447
IdPair(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing id pairs.
Definition CommonClasses.h:457
MNX_REQUIRED_PROPERTY(std::string, end)
the end id of the pair
MNX_REQUIRED_PROPERTY(std::string, start)
the start id of the pair
static Required make(const std::string &startId, const std::string &endId)
Create a Required instance for IdPair.
Definition CommonClasses.h:478
IdPair(Base &parent, std::string_view key, const std::string &startId, const std::string &endId)
Creates a new IdPair class as a child of a JSON element.
Definition CommonClasses.h:467
Represents a musical chromatic interval.
Definition CommonClasses.h:604
static Required make(int staffDistance, int halfSteps)
Create a Required instance for Interval.
Definition CommonClasses.h:635
MNX_REQUIRED_PROPERTY(int, halfSteps)
the number of 12-EDO chromatic halfsteps in the interval (negative is down)
Interval(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing NoteValue instances.
Definition CommonClasses.h:614
MNX_REQUIRED_PROPERTY(int, staffDistance)
the number of diatonic steps in the interval (negative is down)
Interval(Base &parent, std::string_view key, int staffDistance, int halfSteps)
Creates a new Barline class as a child of a JSON element.
Definition CommonClasses.h:624
Represents a key signature.
Definition CommonClasses.h:646
MNX_OPTIONAL_PROPERTY(std::string, color)
color to use when rendering the key signature
KeySignature(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing KeySignature objects.
Definition CommonClasses.h:655
MNX_REQUIRED_PROPERTY(int, fifths)
offset from signature with no accidentals
KeySignature(Base &parent, std::string_view key, int fifths)
Creates a new KeySignature class as a child of a JSON element.
Definition CommonClasses.h:670
static Required make(int fifths)
Create a Required instance for KeySignature.
Definition CommonClasses.h:664
Represents a system on a page in a score.
Definition CommonClasses.h:550
static Required make(const std::string &measureId, const FractionValue &position)
Create a Required instance for MeasureRhythmicPosition.
Definition CommonClasses.h:591
MeasureRhythmicPosition(const std::string &measureId, const FractionValue &position)
Creates a stand-alone MeasureRhythmicPosition class unattached to any json document.
Definition CommonClasses.h:580
MeasureRhythmicPosition(Base &parent, std::string_view key, const std::string &measureId, const FractionValue &position)
Creates a new MeasureRhythmicPosition class as a child of a JSON element.
Definition CommonClasses.h:570
MeasureRhythmicPosition(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing rhythmic position instances.
Definition CommonClasses.h:560
MNX_REQUIRED_PROPERTY(std::string, measure)
The id of the global measure of this MeasureRhythmicPosition.
MNX_REQUIRED_CHILD(RhythmicPosition, position,(const FractionValue &, position))
The metric position, where 1/4 is a quarter note.
Represents a quantity of symbolic note values=.
Definition CommonClasses.h:735
static Required make(unsigned count, const NoteValue::Required &noteValue)
Create a Required instance for NoteValueQuantity.
Definition CommonClasses.h:766
MNX_REQUIRED_PROPERTY(unsigned, multiple)
quantity of duration units
MNX_REQUIRED_CHILD(NoteValue, duration,(NoteValueBase, base),(unsigned, dots))
duration unit
NoteValueQuantity(Base &parent, std::string_view key, unsigned count, const NoteValue::Required &noteValue)
Creates a new Barline class as a child of a JSON element.
Definition CommonClasses.h:755
NoteValueQuantity(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing NoteValue instances.
Definition CommonClasses.h:745
Represents a symbolic note value (not necessarily a duration)
Definition CommonClasses.h:685
NoteValue(Base &parent, std::string_view key, NoteValueBase base, unsigned dots=0)
Creates a new Barline class as a child of a JSON element.
Definition CommonClasses.h:705
MNX_OPTIONAL_PROPERTY_WITH_DEFAULT(unsigned, dots, 0)
the number of dots
unsigned calcNumberOfFlags() const
Calculates the number of flags or beams required by this note value.
Definition Implementations.cpp:451
NoteValue(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing NoteValue instances.
Definition CommonClasses.h:695
MNX_REQUIRED_PROPERTY(NoteValueBase, base)
the type ("base") of note
static Required make(NoteValueBase base, unsigned dots=0)
Create a Required instance for NoteValue.
Definition CommonClasses.h:718
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:415
Object()
Constructor fresh document or detached instance.
Definition BaseTypes.h:418
Represents a system on a page in a score.
Definition CommonClasses.h:489
RhythmicPosition(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing rhythmic position instances.
Definition CommonClasses.h:498
MNX_OPTIONAL_PROPERTY(unsigned, graceIndex)
MNX_REQUIRED_CHILD(Fraction, fraction,(const FractionValue &, value))
The metric position, where 1/4 is a quarter note.
RhythmicPosition(Base &parent, std::string_view key, const FractionValue &position)
Creates a new RhythmicPosition class as a child of a JSON element.
Definition CommonClasses.h:507
static int compare(const RhythmicPosition &lhs, const RhythmicPosition &rhs, bool rhsIncludesTrailingGrace=false)
Compare two rhythmic positions within the same measure.
Definition Implementations.cpp:516
static Required make(const FractionValue &position)
Create a Required instance for RhythmicPosition.
Definition CommonClasses.h:525
RhythmicPosition(const FractionValue &position)
Creates a stand-alone RhythmicPosition instance unattached to any JSON document.
Definition CommonClasses.h:515
Represents the tempo for a global measure.
Definition CommonClasses.h:782
MNX_REQUIRED_PROPERTY(TimeSignatureUnit, unit)
the unit value (bottom number)
TimeSignature(const std::shared_ptr< json > &root, json_pointer pointer)
Constructor for existing NoteValue instances.
Definition CommonClasses.h:792
static Required make(int count, TimeSignatureUnit unit)
Create a Required instance for TimeSignature.
Definition CommonClasses.h:813
TimeSignature(Base &parent, std::string_view key, int count, TimeSignatureUnit unit)
Creates a new Barline class as a child of a JSON element.
Definition CommonClasses.h:802
MNX_REQUIRED_PROPERTY(int, count)
the number of beats (top number)
object model for MNX format
MarkingUpDownAuto
Specifies up or down or auto for a marking symbol.
Definition Enumerations.h:232
@ Auto
determined by consuming property
FermataSymbol
Specifies the symbol style for the fermat.
Definition Enumerations.h:120
@ Normal
standard curved fermata symbol with single dot (the default)
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:68
TimeSignatureUnit
Valid units for the lower numbers of time signatures.
Definition Enumerations.h:390
FermataDuration
Specifies the subjective playback duration of a fermata.
Definition Enumerations.h:105
@ Auto
unspecified (the default)
NoteValueBase
The note values allowed in MNX.
Definition Enumerations.h:260
Orientation
Specifies the vertical visual orientation of a glyph with respect to its corresponding notation.
Definition Enumerations.h:285
@ Auto
the default value determined by implementation
Represents a detached arithmetic fraction with normalization.
Definition CommonClasses.h:74
constexpr NumType denominator() const noexcept
Returns the denominator.
Definition CommonClasses.h:136
constexpr bool expressWithDenominator(NumType targetDenominator)
Attempts to express this fraction with the given denominator.
Definition CommonClasses.h:294
constexpr FractionValue()=default
Default constructor initializes the value to 0/1.
constexpr void reduce()
Reduces the fraction to lowest terms using std::gcd.
Definition CommonClasses.h:244
constexpr FractionValue(NumType num, NumType den)
Constructs a fraction from a numerator and denominator.
Definition CommonClasses.h:116
constexpr NumType quotient() const
Returns the integer (whole number) part of the fraction.
Definition CommonClasses.h:142
constexpr FractionValue(NumType value)
Constructs a Fraction object from an integer.
Definition CommonClasses.h:130
static constexpr FractionValue max() noexcept
Constructs the max fractional value.
Definition CommonClasses.h:160
constexpr FractionValue remainder() const
Returns the fractional part of the fraction.
Definition CommonClasses.h:151
constexpr FractionValue & operator+=(const FractionValue &rhs)
Adds another FractionValue to this one.
Definition CommonClasses.h:178
constexpr FractionValue & operator-=(const FractionValue &rhs)
Subtracts another FractionValue from this one.
Definition CommonClasses.h:195
unsigned NumType
Unsigned integer type used for numerator and denominator.
Definition CommonClasses.h:76
constexpr double toDouble() const
Converts the fraction to floating point double.
Definition CommonClasses.h:166
constexpr FractionValue reduced() const
Returns a copy of the fraction reduced to lowest terms using std::gcd.
Definition CommonClasses.h:257
constexpr FractionValue & operator*=(const FractionValue &rhs)
Multiplies this fraction by another.
Definition CommonClasses.h:212
constexpr NumType numerator() const noexcept
Returns the numerator.
Definition CommonClasses.h:133
constexpr FractionValue & operator/=(const FractionValue &rhs)
Divides this fraction by another.
Definition CommonClasses.h:230
initializer class for IdPair
Definition CommonClasses.h:451
std::string startId
the start id of the pair
Definition CommonClasses.h:452
std::string endId
the end id of the pair
Definition CommonClasses.h:453
initializer class for Interval
Definition CommonClasses.h:608
int halfSteps
the number of 12-EDO chromatic halfsteps in the interval (negative is down)
Definition CommonClasses.h:610
int staffDistance
the number of diatonic steps in the interval (negative is down)
Definition CommonClasses.h:609
initializer class for KeySignature
Definition CommonClasses.h:650
int fifths
offset from signature with no accidentals
Definition CommonClasses.h:651
initializer class for MeasureRhythmicPosition
Definition CommonClasses.h:554
std::string measureId
the global measure id of the position
Definition CommonClasses.h:555
FractionValue position
the position within the measure
Definition CommonClasses.h:556
initializer class for NoteValueQuantity
Definition CommonClasses.h:739
unsigned count
The quantity of note values.
Definition CommonClasses.h:740
NoteValue::Required noteValue
the note value base to initialize
Definition CommonClasses.h:741
initializer class for NoteValue
Definition CommonClasses.h:689
NoteValueBase base
the note value base to initialize
Definition CommonClasses.h:690
unsigned dots
the number of dots to initialize
Definition CommonClasses.h:691
initializer class for RhythmicPosition
Definition CommonClasses.h:493
FractionValue position
position within a measure
Definition CommonClasses.h:494
initializer class for TimeSignature
Definition CommonClasses.h:786
int count
the number of beats (top number)
Definition CommonClasses.h:787
TimeSignatureUnit unit
the unit value (bottom number)
Definition CommonClasses.h:788