Class: HeadMusic::Rudiment::Spelling::EnharmonicEquivalence

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

Overview

Enharmonic equivalence occurs when two spellings refer to the same pitch class, such as D# and Eb.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spelling) ⇒ EnharmonicEquivalence

Returns a new instance of EnharmonicEquivalence.



108
109
110
# File 'lib/head_music/rudiment/spelling.rb', line 108

def initialize(spelling)
  @spelling = HeadMusic::Rudiment::Spelling.get(spelling)
end

Instance Attribute Details

#spellingObject (readonly)

Returns the value of attribute spelling.



106
107
108
# File 'lib/head_music/rudiment/spelling.rb', line 106

def spelling
  @spelling
end

Class Method Details

.get(spelling) ⇒ Object



100
101
102
103
104
# File 'lib/head_music/rudiment/spelling.rb', line 100

def self.get(spelling)
  spelling = HeadMusic::Rudiment::Spelling.get(spelling)
  @enharmonic_equivalences ||= {}
  @enharmonic_equivalences[spelling.to_s] ||= new(spelling)
end

Instance Method Details

#enharmonic_equivalent?(other) ⇒ Boolean Also known as: enharmonic?, equivalent?

Returns:

  • (Boolean)


112
113
114
115
# File 'lib/head_music/rudiment/spelling.rb', line 112

def enharmonic_equivalent?(other)
  other = HeadMusic::Rudiment::Spelling.get(other)
  spelling != other && spelling.pitch_class_number == other.pitch_class_number
end