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.
292
293
294
295
296
|
# File 'lib/head_music/diatonic_interval.rb', line 292
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.
43
44
45
|
# File 'lib/head_music/diatonic_interval.rb', line 43
def higher_pitch
@higher_pitch
end
|
#lower_pitch ⇒ Object
Returns the value of attribute lower_pitch.
43
44
45
|
# File 'lib/head_music/diatonic_interval.rb', line 43
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
356
357
358
359
|
# File 'lib/head_music/diatonic_interval.rb', line 356
def <=>(other)
other = self.class.get(other) unless other.is_a?(HeadMusic::DiatonicInterval)
semitones <=> other.semitones
end
|
#consonance(style = :standard_practice) ⇒ Object
311
312
313
314
315
|
# File 'lib/head_music/diatonic_interval.rb', line 311
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?
317
318
319
|
# File 'lib/head_music/diatonic_interval.rb', line 317
def consonance?(style = :standard_practice)
consonance(style).perfect? || consonance(style).imperfect?
end
|
#dissonance?(style = :standard_practice) ⇒ Boolean
330
331
332
|
# File 'lib/head_music/diatonic_interval.rb', line 330
def dissonance?(style = :standard_practice)
consonance(style).dissonant?
end
|
#imperfect_consonance?(style = :standard_practice) ⇒ Boolean
326
327
328
|
# File 'lib/head_music/diatonic_interval.rb', line 326
def imperfect_consonance?(style = :standard_practice)
consonance(style).imperfect?
end
|
#interval_class ⇒ Object
344
345
346
|
# File 'lib/head_music/diatonic_interval.rb', line 344
def interval_class
[simple_semitones, 12 - simple_semitones].min
end
|
#interval_class_name ⇒ Object
348
349
350
|
# File 'lib/head_music/diatonic_interval.rb', line 348
def interval_class_name
"ic #{interval_class}"
end
|
#inversion ⇒ Object
Also known as:
invert
302
303
304
305
306
307
308
|
# File 'lib/head_music/diatonic_interval.rb', line 302
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
322
323
324
|
# File 'lib/head_music/diatonic_interval.rb', line 322
def perfect_consonance?(style = :standard_practice)
consonance(style).perfect?
end
|
#quality ⇒ Object
298
299
300
|
# File 'lib/head_music/diatonic_interval.rb', line 298
def quality
HeadMusic::Quality.get(quality_name)
end
|