Module: HeadMusic::Notation::DottedDuration

Defined in:
lib/head_music/notation/dotted_duration.rb

Overview

The exact fractional length of a (possibly dotted) rhythmic value in terms of its own unit. RhythmicValue’s own value methods return Floats, so the fraction is rebuilt here from the unit’s integer numerator and denominator to keep downstream arithmetic (ABC multipliers, MusicXML divisions) exact.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dotted_unit_fraction(rhythmic_value) ⇒ Object



11
12
13
14
15
16
# File 'lib/head_music/notation/dotted_duration.rb', line 11

def dotted_unit_fraction(rhythmic_value)
  unit = rhythmic_value.unit
  dots = rhythmic_value.dots
  # A value with d dots spans (2^(d+1) - 1) / 2^d of its own unit.
  Rational(unit.numerator, unit.denominator) * Rational((2**(dots + 1)) - 1, 2**dots)
end

Instance Method Details

#dotted_unit_fraction(rhythmic_value) ⇒ Object (private)



11
12
13
14
15
16
# File 'lib/head_music/notation/dotted_duration.rb', line 11

def dotted_unit_fraction(rhythmic_value)
  unit = rhythmic_value.unit
  dots = rhythmic_value.dots
  # A value with d dots spans (2^(d+1) - 1) / 2^d of its own unit.
  Rational(unit.numerator, unit.denominator) * Rational((2**(dots + 1)) - 1, 2**dots)
end