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.



11
12
13
# File 'lib/head_music/pitch_class_set.rb', line 11

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.



6
7
8
# File 'lib/head_music/pitch_class_set.rb', line 6

def pitch_classes
  @pitch_classes
end

Instance Method Details

#==(other) ⇒ Object



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

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

#decachord?Boolean

Returns:

  • (Boolean)


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

def decachord?
  pitch_classes.length == 10
end

#dichord?Boolean Also known as: dyad?

Returns:

  • (Boolean)


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

def dichord?
  pitch_classes.length == 2
end

#dodecachord?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/head_music/pitch_class_set.rb', line 81

def dodecachord?
  pitch_classes.length == 12
end

#equivalent?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#heptachord?Boolean

Returns:

  • (Boolean)


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

def heptachord?
  pitch_classes.length == 7
end

#hexachord?Boolean

Returns:

  • (Boolean)


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

def hexachord?
  pitch_classes.length == 6
end

#inspectObject



15
16
17
# File 'lib/head_music/pitch_class_set.rb', line 15

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

#monochord?Boolean Also known as: monad?

Returns:

  • (Boolean)


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

def monochord?
  pitch_classes.length == 1
end

#nonachord?Boolean

Returns:

  • (Boolean)


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

def nonachord?
  pitch_classes.length == 9
end

#octachord?Boolean

Returns:

  • (Boolean)


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

def octachord?
  pitch_classes.length == 8
end

#pentachord?Boolean

Returns:

  • (Boolean)


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

def pentachord?
  pitch_classes.length == 5
end

#sizeObject



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

def size
  @size ||= pitch_classes.length
end

#tetrachord?Boolean

Returns:

  • (Boolean)


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

def tetrachord?
  pitch_classes.length == 4
end

#to_sObject



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

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

#trichord?Boolean

Returns:

  • (Boolean)


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

def trichord?
  pitch_classes.length == 3
end

#undecachord?Boolean

Returns:

  • (Boolean)


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

def undecachord?
  pitch_classes.length == 11
end