Class: Coltrane::Theory::NoteSet
- Inherits:
-
Object
- Object
- Coltrane::Theory::NoteSet
- Extended by:
- Forwardable
- Defined in:
- lib/coltrane/theory/note_set.rb
Overview
It describes a set of notes
Instance Attribute Summary collapse
-
#notes ⇒ Object
(also: #all)
readonly
Returns the value of attribute notes.
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #accidentals ⇒ Object
- #alter(alteration) ⇒ Object
- #alter_accidentals(alteration) ⇒ Object
- #degree(note) ⇒ Object
- #flats ⇒ Object
- #hash ⇒ Object
-
#initialize(arg) ⇒ NoteSet
constructor
A new instance of NoteSet.
- #integers ⇒ Object
- #interval_sequence ⇒ Object
- #names ⇒ Object
- #pretty_names ⇒ Object
- #sharps ⇒ Object
Constructor Details
#initialize(arg) ⇒ NoteSet
Returns a new instance of NoteSet.
22 23 24 25 26 27 28 29 |
# 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 |
Instance Attribute Details
#notes ⇒ Object (readonly) Also known as: all
Returns the value of attribute notes.
13 14 15 |
# File 'lib/coltrane/theory/note_set.rb', line 13 def notes @notes end |
Class Method Details
.[](*notes) ⇒ Object
18 19 20 |
# File 'lib/coltrane/theory/note_set.rb', line 18 def self.[](*notes) new(notes) end |
Instance Method Details
#&(other) ⇒ Object
37 38 39 |
# File 'lib/coltrane/theory/note_set.rb', line 37 def &(other) NoteSet[*(notes & other.notes)] end |
#+(other) ⇒ Object
45 46 47 48 49 50 51 |
# 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) ⇒ Object
53 54 55 56 57 58 |
# 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) ⇒ Object Also known as: eql?
31 32 33 |
# File 'lib/coltrane/theory/note_set.rb', line 31 def ==(other) (self & other).size == self.size end |
#accidentals ⇒ Object
76 77 78 |
# File 'lib/coltrane/theory/note_set.rb', line 76 def accidentals count(&:accidental?) end |
#alter(alteration) ⇒ Object
88 89 90 |
# File 'lib/coltrane/theory/note_set.rb', line 88 def alter(alteration) NoteSet[*map { |n| n.alter(alteration) }] end |
#alter_accidentals(alteration) ⇒ Object
92 93 94 |
# 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) ⇒ Object
41 42 43 |
# File 'lib/coltrane/theory/note_set.rb', line 41 def degree(note) index(note) + 1 end |
#flats ⇒ Object
84 85 86 |
# File 'lib/coltrane/theory/note_set.rb', line 84 def flats count(&:flat?) end |
#hash ⇒ Object
68 69 70 |
# File 'lib/coltrane/theory/note_set.rb', line 68 def hash integers.join.to_i end |
#integers ⇒ Object
72 73 74 |
# File 'lib/coltrane/theory/note_set.rb', line 72 def integers map(&:integer) end |
#interval_sequence ⇒ Object
96 97 98 |
# File 'lib/coltrane/theory/note_set.rb', line 96 def interval_sequence IntervalSequence.new(notes: self) end |
#names ⇒ Object
64 65 66 |
# File 'lib/coltrane/theory/note_set.rb', line 64 def names map(&:name) end |
#pretty_names ⇒ Object
60 61 62 |
# File 'lib/coltrane/theory/note_set.rb', line 60 def pretty_names map(&:pretty_name) end |
#sharps ⇒ Object
80 81 82 |
# File 'lib/coltrane/theory/note_set.rb', line 80 def sharps count(&:sharp?) end |