Sha256: 8ea63b45f2f39a66db59373e41583585346d93dd6af14af41dd34bc2383870d1

Contents?: true

Size: 775 Bytes

Versions: 9

Compression:

Stored size: 775 Bytes

Contents

# frozen_string_literal: true

# 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-4.0.1 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-4.0.0 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-3.0.1 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-3.0.0 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-2.0.1 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-2.0.0 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-1.0.0 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-0.29.0 lib/head_music/pitch/enharmonic_equivalence.rb
head_music-0.28.0 lib/head_music/pitch/enharmonic_equivalence.rb