Class: HeadMusic::DiatonicInterval
- Inherits:
-
Object
- Object
- HeadMusic::DiatonicInterval
show all
- Includes:
- Comparable
- Defined in:
- lib/head_music/diatonic_interval.rb
Overview
A diatonic interval is the distance between two spelled pitches.
Defined Under Namespace
Classes: Category, Naming, Parser, Semitones, Size
Constant Summary
collapse
- NUMBER_NAMES =
TODO: include Named module
%w[
unison second third fourth fifth sixth seventh octave
ninth tenth eleventh twelfth thirteenth fourteenth fifteenth
sixteenth seventeenth
].freeze
- NAME_SUFFIXES =
Hash.new("th").merge(1 => "st", 2 => "nd", 3 => "rd").freeze
- QUALITY_SEMITONES =
{
unison: {perfect: 0},
second: {major: 2},
third: {major: 4},
fourth: {perfect: 5},
fifth: {perfect: 7},
sixth: {major: 9},
seventh: {major: 11},
octave: {perfect: 12},
ninth: {major: 14},
tenth: {major: 16},
eleventh: {perfect: 17},
twelfth: {perfect: 19},
thirteenth: {major: 21},
fourteenth: {major: 23},
fifteenth: {perfect: 24},
sixteenth: {major: 26},
seventeenth: {major: 28}
}.freeze
- QUALITY_ABBREVIATIONS =
{
P: "perfect",
M: "major",
m: "minor",
d: "diminished",
A: "augmented"
}.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of DiatonicInterval.
66
67
68
69
70
|
# File 'lib/head_music/diatonic_interval.rb', line 66
def initialize(pitch1, pitch2)
pitch1 = HeadMusic::Pitch.get(pitch1)
pitch2 = HeadMusic::Pitch.get(pitch2)
@lower_pitch, @higher_pitch = [pitch1, pitch2].sort
end
|
Instance Attribute Details
#higher_pitch ⇒ Object
Returns the value of attribute higher_pitch.
41
42
43
|
# File 'lib/head_music/diatonic_interval.rb', line 41
def higher_pitch
@higher_pitch
end
|
#lower_pitch ⇒ Object
Returns the value of attribute lower_pitch.
41
42
43
|
# File 'lib/head_music/diatonic_interval.rb', line 41
def lower_pitch
@lower_pitch
end
|
Class Method Details
.get(identifier) ⇒ Object
Accepts a name and returns the interval with middle c on the bottom
Instance Method Details
#<=>(other) ⇒ Object
130
131
132
133
|
# File 'lib/head_music/diatonic_interval.rb', line 130
def <=>(other)
other = self.class.get(other) unless other.is_a?(HeadMusic::DiatonicInterval)
semitones <=> other.semitones
end
|
#consonance(style = :standard_practice) ⇒ Object
85
86
87
88
89
|
# File 'lib/head_music/diatonic_interval.rb', line 85
def consonance(style = :standard_practice)
consonance_for_perfect(style) ||
consonance_for_major_and_minor ||
HeadMusic::Consonance.get(:dissonant)
end
|
#consonance?(style = :standard_practice) ⇒ Boolean
Also known as:
consonant?
91
92
93
|
# File 'lib/head_music/diatonic_interval.rb', line 91
def consonance?(style = :standard_practice)
consonance(style).perfect? || consonance(style).imperfect?
end
|
#dissonance?(style = :standard_practice) ⇒ Boolean
104
105
106
|
# File 'lib/head_music/diatonic_interval.rb', line 104
def dissonance?(style = :standard_practice)
consonance(style).dissonant?
end
|
#imperfect_consonance?(style = :standard_practice) ⇒ Boolean
100
101
102
|
# File 'lib/head_music/diatonic_interval.rb', line 100
def imperfect_consonance?(style = :standard_practice)
consonance(style).imperfect?
end
|
#interval_class ⇒ Object
118
119
120
|
# File 'lib/head_music/diatonic_interval.rb', line 118
def interval_class
[simple_semitones, 12 - simple_semitones].min
end
|
#interval_class_name ⇒ Object
122
123
124
|
# File 'lib/head_music/diatonic_interval.rb', line 122
def interval_class_name
"ic #{interval_class}"
end
|
#inversion ⇒ Object
Also known as:
invert
76
77
78
79
80
81
82
|
# File 'lib/head_music/diatonic_interval.rb', line 76
def inversion
inverted_low_pitch = lower_pitch
while inverted_low_pitch < higher_pitch
inverted_low_pitch = HeadMusic::Pitch.fetch_or_create(lower_pitch.spelling, inverted_low_pitch.register + 1)
end
HeadMusic::DiatonicInterval.new(higher_pitch, inverted_low_pitch)
end
|
#perfect_consonance?(style = :standard_practice) ⇒ Boolean
96
97
98
|
# File 'lib/head_music/diatonic_interval.rb', line 96
def perfect_consonance?(style = :standard_practice)
consonance(style).perfect?
end
|
#quality ⇒ Object
72
73
74
|
# File 'lib/head_music/diatonic_interval.rb', line 72
def quality
HeadMusic::Quality.get(quality_name)
end
|