Class: HeadMusic::Rudiment::RhythmicUnit
- Inherits:
-
Object
- Object
- HeadMusic::Rudiment::RhythmicUnit
show all
- 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
Attributes included from Named
#alias_name_keys, #name_key
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Named
#ensure_localized_name, included, #localized_name, #localized_names, #name, #name=
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
#denominator ⇒ Object
Returns the value of attribute denominator.
24
25
26
|
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 24
def denominator
@denominator
end
|
#numerator ⇒ Object
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
#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
|
#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
|
#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
|
#ticks ⇒ Object
40
41
42
|
# File 'lib/head_music/rudiment/rhythmic_unit.rb', line 40
def ticks
HeadMusic::Rudiment::Rhythm::PPQN * 4 * relative_value
end
|