class Coltrane::Theory::NoteSet
It describes a set of notes
Attributes
all[R]
notes[R]
Public Class Methods
[](*notes)
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 18 def self.[](*notes) new(notes) end
new(arg)
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 22 def initialize(arg) @notes = case arg when NoteSet then arg.notes when Array then arg.compact.map { |n| n.is_a?(PitchClass) ? n : Note[n] }.uniq else raise InvalidNotesError, arg end end
Public Instance Methods
&(other)
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 37 def &(other) NoteSet[*(notes & other.notes)] end
+(other)
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 45 def +(other) case other when Note then NoteSet[*(notes + [other])] when NoteSet then NoteSet[*notes, *other.notes] when Interval then NoteSet[*notes.map { |n| n + other }] end end
-(other)
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 53 def -(other) case other when NoteSet then NoteSet[*(notes - other.notes)] when Interval then NoteSet[*notes.map { |n| n - other }] end end
==(other)
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 31 def ==(other) (self & other).size == self.size end
Also aliased as: eql?
accidentals()
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 76 def accidentals count(&:accidental?) end
alter(alteration)
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 88 def alter(alteration) NoteSet[*map { |n| n.alter(alteration) }] end
alter_accidentals(alteration)
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 92 def alter_accidentals(alteration) NoteSet[*map { |n| n.alter(alteration) if n.accidental? }] end
degree(note)
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 41 def degree(note) index(note) + 1 end
flats()
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 84 def flats count(&:flat?) end
hash()
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 68 def hash integers.join.to_i end
integers()
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 72 def integers map(&:integer) end
interval_sequence()
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 96 def interval_sequence IntervalSequence.new(notes: self) end
names()
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 64 def names map(&:name) end
pretty_names()
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 60 def pretty_names map(&:pretty_name) end
sharps()
click to toggle source
# File lib/coltrane/theory/note_set.rb, line 80 def sharps count(&:sharp?) end