Sha256: 6d774aaf89577d3325820e86d1e0221111d10716fd926e64d750f17b788c3f24

Contents?: true

Size: 1.36 KB

Versions: 7

Compression:

Stored size: 1.36 KB

Contents

# 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 to_s
    pitch_classes.map(&:to_i).inspect
  end
  alias_method :inspect, :to_s

  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

7 entries across 7 versions & 1 rubygems

Version Path
head_music-7.0.5 lib/head_music/pitch_class_set.rb
head_music-7.0.4 lib/head_music/pitch_class_set.rb
head_music-7.0.3 lib/head_music/pitch_class_set.rb
head_music-7.0.2 lib/head_music/pitch_class_set.rb
head_music-7.0.1 lib/head_music/pitch_class_set.rb
head_music-7.0.0 lib/head_music/pitch_class_set.rb
head_music-6.0.1 lib/head_music/pitch_class_set.rb