Class: HeadMusic::Analysis::DiatonicInterval::Inversion

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/analysis/diatonic_interval/inversion.rb

Overview

Inverting an interval puts its lower pitch on top. The lower pitch keeps its spelling and climbs by whole octaves until it is no longer below the pitch it is being inverted over, and the interval is read from there. Climbing by octaves rather than computing the register outright is what keeps the spelling honest at the edges, where C♭5 sits below B♯4.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lower_pitch, higher_pitch) ⇒ Inversion

Returns a new instance of Inversion.



10
11
12
13
# File 'lib/head_music/analysis/diatonic_interval/inversion.rb', line 10

def initialize(lower_pitch, higher_pitch)
  @lower_pitch = lower_pitch
  @higher_pitch = higher_pitch
end

Instance Attribute Details

#higher_pitchObject (readonly)

Returns the value of attribute higher_pitch.



8
9
10
# File 'lib/head_music/analysis/diatonic_interval/inversion.rb', line 8

def higher_pitch
  @higher_pitch
end

#lower_pitchObject (readonly)

Returns the value of attribute lower_pitch.



8
9
10
# File 'lib/head_music/analysis/diatonic_interval/inversion.rb', line 8

def lower_pitch
  @lower_pitch
end

Instance Method Details

#intervalObject



15
16
17
# File 'lib/head_music/analysis/diatonic_interval/inversion.rb', line 15

def interval
  HeadMusic::Analysis::DiatonicInterval.new(higher_pitch, raised_lower_pitch)
end

#octave_above(pitch) ⇒ Object (private)



27
28
29
# File 'lib/head_music/analysis/diatonic_interval/inversion.rb', line 27

def octave_above(pitch)
  HeadMusic::Rudiment::Pitch.fetch_or_create(lower_pitch.spelling, pitch.register + 1)
end

#raised_lower_pitchObject (private)



21
22
23
24
25
# File 'lib/head_music/analysis/diatonic_interval/inversion.rb', line 21

def raised_lower_pitch
  pitch = lower_pitch
  pitch = octave_above(pitch) while pitch < higher_pitch
  pitch
end