Sha256: c8562953e145be93a56ff7974df14fd1c78b4ad7fa03124a9db3189587b362e1

Contents?: true

Size: 744 Bytes

Versions: 9

Compression:

Stored size: 744 Bytes

Contents

# An enharmonic equivalent pitch is the same frequency spelled differently, such as D# and Eb.
class HeadMusic::Pitch::EnharmonicEquivalence
  def self.get(pitch)
    pitch = HeadMusic::Pitch.get(pitch)
    @enharmonic_equivalences ||= {}
    @enharmonic_equivalences[pitch.to_s] ||= new(pitch)
  end

  attr_reader :pitch

  delegate :pitch_class, to: :pitch

  def initialize(pitch)
    @pitch = HeadMusic::Pitch.get(pitch)
  end

  def enharmonic_equivalent?(other)
    other = HeadMusic::Pitch.get(other)
    pitch.midi_note_number == other.midi_note_number && pitch.spelling != other.spelling
  end

  alias_method :enharmonic?, :enharmonic_equivalent?
  alias_method :equivalent?, :enharmonic_equivalent?

  private_class_method :new
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
head_music-7.0.5 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-7.0.4 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-7.0.3 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-7.0.2 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-7.0.1 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-7.0.0 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-6.0.1 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-6.0.0 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-5.0.0 lib/head_music/pitch/enharmonic_equivalence.rb