Sha256: 8197480dd56f35bfa3e5686914237874216639803e0d552701cfbb1fde626600

Contents?: true

Size: 1.42 KB

Versions: 9

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

# A PitchClassSet represents a pitch-class set or pitch collection.
# See also: PitchSet, PitchClass
class HeadMusic::PitchClassSet
  attr_reader :pitch_classes

  delegate :empty?, to: :pitch_classes
  alias_method :empty_set?, :empty?

  def initialize(identifiers)
    @pitch_classes = identifiers.map { |identifier| HeadMusic::PitchClass.get(identifier) }.uniq.sort
  end

  def inspect
    pitch_classes.map(&:to_s).join(" ")
  end

  def to_s
    pitch_classes.map(&:to_s).join(" ")
  end

  def ==(other)
    pitch_classes == other.pitch_classes
  end

  def equivalent?(other)
    pitch_classes.sort == other.pitch_classes.sort
  end

  def size
    @size ||= pitch_classes.length
  end

  def monochord?
    pitch_classes.length == 1
  end
  alias_method :monad?, :monochord?

  def dichord?
    pitch_classes.length == 2
  end
  alias_method :dyad?, :dichord?

  def trichord?
    pitch_classes.length == 3
  end

  def tetrachord?
    pitch_classes.length == 4
  end

  def pentachord?
    pitch_classes.length == 5
  end

  def hexachord?
    pitch_classes.length == 6
  end

  def heptachord?
    pitch_classes.length == 7
  end

  def octachord?
    pitch_classes.length == 8
  end

  def nonachord?
    pitch_classes.length == 9
  end

  def decachord?
    pitch_classes.length == 10
  end

  def undecachord?
    pitch_classes.length == 11
  end

  def dodecachord?
    pitch_classes.length == 12
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
head_music-4.0.1 lib/head_music/pitch_class_set.rb
head_music-4.0.0 lib/head_music/pitch_class_set.rb
head_music-3.0.1 lib/head_music/pitch_class_set.rb
head_music-3.0.0 lib/head_music/pitch_class_set.rb
head_music-2.0.1 lib/head_music/pitch_class_set.rb
head_music-2.0.0 lib/head_music/pitch_class_set.rb
head_music-1.0.0 lib/head_music/pitch_class_set.rb
head_music-0.29.0 lib/head_music/pitch_class_set.rb
head_music-0.28.0 lib/head_music/pitch_class_set.rb