Sha256: 373daf4af47e7495bd17ebe14d9f42e5e7e131d76ec4ecd7afa2860156642317

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 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 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 monad? monochord?

  def dichord?
    pitch_classes.length == 2
  end
  alias 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

17 entries across 17 versions & 1 rubygems

Version Path
head_music-0.27.0 lib/head_music/pitch_class_set.rb
head_music-0.26.3 lib/head_music/pitch_class_set.rb
head_music-0.26.2 lib/head_music/pitch_class_set.rb
head_music-0.26.1 lib/head_music/pitch_class_set.rb
head_music-0.26.0 lib/head_music/pitch_class_set.rb
head_music-0.25.0 lib/head_music/pitch_class_set.rb
head_music-0.24.5 lib/head_music/pitch_class_set.rb
head_music-0.24.4 lib/head_music/pitch_class_set.rb
head_music-0.24.3 lib/head_music/pitch_class_set.rb
head_music-0.24.2 lib/head_music/pitch_class_set.rb
head_music-0.24.1 lib/head_music/pitch_class_set.rb
head_music-0.24.0 lib/head_music/pitch_class_set.rb
head_music-0.23.4 lib/head_music/pitch_class_set.rb
head_music-0.23.3 lib/head_music/pitch_class_set.rb
head_music-0.23.2 lib/head_music/pitch_class_set.rb
head_music-0.23.1 lib/head_music/pitch_class_set.rb
head_music-0.23.0 lib/head_music/pitch_class_set.rb