Class: HeadMusic::PitchClassSet

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/pitch_class_set.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifiers) ⇒ PitchClassSet

Returns a new instance of PitchClassSet.



9
10
11
# File 'lib/head_music/pitch_class_set.rb', line 9

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

Instance Attribute Details

#pitch_classesObject (readonly)

Returns the value of attribute pitch_classes.



4
5
6
# File 'lib/head_music/pitch_class_set.rb', line 4

def pitch_classes
  @pitch_classes
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
# File 'lib/head_music/pitch_class_set.rb', line 18

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

#decachord?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/head_music/pitch_class_set.rb', line 68

def decachord?
  pitch_classes.length == 10
end

#dichord?Boolean Also known as: dyad?

Returns:

  • (Boolean)


35
36
37
# File 'lib/head_music/pitch_class_set.rb', line 35

def dichord?
  pitch_classes.length == 2
end

#dodecachord?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/head_music/pitch_class_set.rb', line 76

def dodecachord?
  pitch_classes.length == 12
end

#equivalent?(other) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/head_music/pitch_class_set.rb', line 22

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

#heptachord?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/head_music/pitch_class_set.rb', line 56

def heptachord?
  pitch_classes.length == 7
end

#hexachord?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/head_music/pitch_class_set.rb', line 52

def hexachord?
  pitch_classes.length == 6
end

#monochord?Boolean Also known as: monad?

Returns:

  • (Boolean)


30
31
32
# File 'lib/head_music/pitch_class_set.rb', line 30

def monochord?
  pitch_classes.length == 1
end

#nonachord?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/head_music/pitch_class_set.rb', line 64

def nonachord?
  pitch_classes.length == 9
end

#octachord?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/head_music/pitch_class_set.rb', line 60

def octachord?
  pitch_classes.length == 8
end

#pentachord?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/head_music/pitch_class_set.rb', line 48

def pentachord?
  pitch_classes.length == 5
end

#sizeObject



26
27
28
# File 'lib/head_music/pitch_class_set.rb', line 26

def size
  @size ||= pitch_classes.length
end

#tetrachord?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/head_music/pitch_class_set.rb', line 44

def tetrachord?
  pitch_classes.length == 4
end

#to_sObject Also known as: inspect



13
14
15
# File 'lib/head_music/pitch_class_set.rb', line 13

def to_s
  pitch_classes.map(&:to_i).inspect
end

#trichord?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/head_music/pitch_class_set.rb', line 40

def trichord?
  pitch_classes.length == 3
end

#undecachord?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/head_music/pitch_class_set.rb', line 72

def undecachord?
  pitch_classes.length == 11
end