Class: HeadMusic::Rudiment::Pitch::OctaveEquivalence

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/rudiment/pitch/octave_equivalence.rb

Overview

Octave equivalence is the functional equivalence of pitches with the same spelling separated by one or more octaves.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pitch) ⇒ OctaveEquivalence

Returns a new instance of OctaveEquivalence.



10
11
12
# File 'lib/head_music/rudiment/pitch/octave_equivalence.rb', line 10

def initialize(pitch)
  @pitch = pitch
end

Instance Attribute Details

#pitchObject (readonly)

Returns the value of attribute pitch.



8
9
10
# File 'lib/head_music/rudiment/pitch/octave_equivalence.rb', line 8

def pitch
  @pitch
end

Class Method Details

.get(pitch) ⇒ Object



3
4
5
6
# File 'lib/head_music/rudiment/pitch/octave_equivalence.rb', line 3

def self.get(pitch)
  @octave_equivalences ||= {}
  @octave_equivalences[pitch.to_s] ||= new(pitch)
end

Instance Method Details

#octave_equivalent?(other) ⇒ Boolean Also known as: equivalent?

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/head_music/rudiment/pitch/octave_equivalence.rb', line 14

def octave_equivalent?(other)
  other = HeadMusic::Rudiment::Pitch.get(other)
  pitch.spelling == other.spelling && pitch.register != other.register
end