Class: HeadMusic::Rudiment::RhythmicUnit
- Inherits:
-
Object
- Object
- HeadMusic::Rudiment::RhythmicUnit
- Includes:
- Named
- Defined in:
- lib/head_music/rudiment/rhythmic_unit.rb
Overview
A rhythmic unit is a rudiment of duration consisting of doublings and divisions of a whole note.
Constant Summary collapse
- MULTIPLES =
["whole", "double whole", "longa", "maxima"].freeze
- FRACTIONS =
[ "whole", "half", "quarter", "eighth", "sixteenth", "thirty-second", "sixty-fourth", "hundred twenty-eighth", "two hundred fifty-sixth" ].freeze
- BRITISH_MULTIPLE_NAMES =
%w[semibreve breve longa maxima].freeze
- BRITISH_DIVISION_NAMES =
%w[ semibreve minim crotchet quaver semiquaver demisemiquaver hemidemisemiquaver semihemidemisemiquaver demisemihemidemisemiquaver ].freeze
Instance Attribute Summary collapse
-
#alias_name_keys ⇒ Object
included
from Named
readonly
Returns the value of attribute alias_name_keys.
-
#denominator ⇒ Object
readonly
Returns the value of attribute denominator.
-
#name_key ⇒ Object
included
from Named
readonly
Returns the value of attribute name_key.
-
#numerator ⇒ Object
readonly
Returns the value of attribute numerator.
Class Method Summary collapse
Instance Method Summary collapse
-
#british_fractions_keys ⇒ Object
private
-
#british_multiples_keys ⇒ Object
private
-
#british_name ⇒ Object
-
#denominator_exponent ⇒ Object
private
-
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object
included
from Named
-
#flags ⇒ Object
-
#fraction? ⇒ Boolean
private
-
#fractions_keys ⇒ Object
private
-
#initialize(canonical_name) ⇒ RhythmicUnit
constructor
A new instance of RhythmicUnit.
-
#localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object
included
from Named
-
#localized_name_in_default_locale ⇒ Object
included
from Named
private
-
#localized_name_in_locale_matching_language(locale) ⇒ Object
included
from Named
private
-
#localized_name_in_matching_locale(locale) ⇒ Object
included
from Named
private
-
#localized_names ⇒ Object
included
from Named
Returns an array of LocalizedName instances that are synonymous with the name.
-
#multiple? ⇒ Boolean
private
-
#multiples_keys ⇒ Object
private
-
#name(locale_code: Locale::DEFAULT_CODE) ⇒ Object
included
from Named
-
#name=(name) ⇒ Object
included
from Named
-
#notehead ⇒ Object
-
#numerator_exponent ⇒ Object
private
-
#relative_value ⇒ Object
-
#stemmed? ⇒ Boolean
-
#ticks ⇒ Object
Constructor Details
#initialize(canonical_name) ⇒ RhythmicUnit
Returns a new instance of RhythmicUnit.
30 31 32 33 34 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 30 def initialize(canonical_name) self.name = canonical_name @numerator = 2**numerator_exponent @denominator = 2**denominator_exponent end |
Instance Attribute Details
#alias_name_keys ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute alias_name_keys.
#denominator ⇒ Object (readonly)
Returns the value of attribute denominator.
24 25 26 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 24 def denominator @denominator end |
#name_key ⇒ Object (readonly) Originally defined in module Named
Returns the value of attribute name_key.
#numerator ⇒ Object (readonly)
Returns the value of attribute numerator.
24 25 26 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 24 def numerator @numerator end |
Class Method Details
.for_denominator_value(denominator) ⇒ Object
20 21 22 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 20 def self.for_denominator_value(denominator) get(FRACTIONS[Math.log2(denominator).to_i]) end |
.get(name) ⇒ Object
26 27 28 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 26 def self.get(name) get_by_name(name) end |
Instance Method Details
#british_fractions_keys ⇒ Object (private)
103 104 105 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 103 def british_fractions_keys BRITISH_DIVISION_NAMES.map { |fraction| fraction.gsub(/\W+/, "_") } end |
#british_multiples_keys ⇒ Object (private)
91 92 93 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 91 def british_multiples_keys BRITISH_MULTIPLE_NAMES.map { |multiple| multiple.gsub(/\W+/, "_") } end |
#british_name ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 61 def british_name if multiple? BRITISH_MULTIPLE_NAMES[MULTIPLES.index(name)] elsif fraction? BRITISH_DIVISION_NAMES[FRACTIONS.index(name)] elsif BRITISH_MULTIPLE_NAMES.include?(name) || BRITISH_DIVISION_NAMES.include?(name) name end end |
#denominator_exponent ⇒ Object (private)
95 96 97 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 95 def denominator_exponent fractions_keys.index(name.gsub(/\W+/, "_")) || british_fractions_keys.index(name.gsub(/\W+/, "_")) || 0 end |
#ensure_localized_name(name:, locale_code: Locale::DEFAULT_CODE, abbreviation: nil) ⇒ Object Originally defined in module Named
#flags ⇒ Object
53 54 55 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 53 def flags FRACTIONS.include?(name) ? [FRACTIONS.index(name) - 2, 0].max : 0 end |
#fraction? ⇒ Boolean (private)
79 80 81 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 79 def fraction? FRACTIONS.include?(name) end |
#fractions_keys ⇒ Object (private)
99 100 101 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 99 def fractions_keys FRACTIONS.map { |fraction| fraction.gsub(/\W+/, "_") } end |
#localized_name(locale_code: Locale::DEFAULT_CODE) ⇒ Object Originally defined in module Named
#localized_name_in_default_locale ⇒ Object (private) Originally defined in module Named
#localized_name_in_locale_matching_language(locale) ⇒ Object (private) Originally defined in module Named
#localized_name_in_matching_locale(locale) ⇒ Object (private) Originally defined in module Named
#localized_names ⇒ Object Originally defined in module Named
Returns an array of LocalizedName instances that are synonymous with the name.
#multiple? ⇒ Boolean (private)
75 76 77 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 75 def multiple? MULTIPLES.include?(name) end |
#multiples_keys ⇒ Object (private)
87 88 89 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 87 def multiples_keys MULTIPLES.map { |multiple| multiple.gsub(/\W+/, "_") } end |
#name(locale_code: Locale::DEFAULT_CODE) ⇒ Object Originally defined in module Named
#name=(name) ⇒ Object Originally defined in module Named
#notehead ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 44 def notehead return :maxima if relative_value == 8 return :longa if relative_value == 4 return :breve if relative_value == 2 return :open if [0.5, 1].include? relative_value :closed end |
#numerator_exponent ⇒ Object (private)
83 84 85 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 83 def numerator_exponent multiples_keys.index(name.gsub(/\W+/, "_")) || british_multiples_keys.index(name.gsub(/\W+/, "_")) || 0 end |
#relative_value ⇒ Object
36 37 38 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 36 def relative_value @numerator.to_f / @denominator end |
#stemmed? ⇒ Boolean
57 58 59 |
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 57 def stemmed? relative_value < 1 end |