Class: Coltrane::NoteSet
- Inherits:
-
Object
- Object
- Coltrane::NoteSet
- Extended by:
- Forwardable
- Defined in:
- lib/coltrane/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
- #accidentals ⇒ Object
- #alter(alteration) ⇒ Object
- #alter_accidentals(alteration) ⇒ Object
- #degree(note) ⇒ Object
- #flats ⇒ 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.
21 22 23 24 25 26 27 28 |
# File 'lib/coltrane/note_set.rb', line 21 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.
12 13 14 |
# File 'lib/coltrane/note_set.rb', line 12 def notes @notes end |
Class Method Details
.[](*notes) ⇒ Object
17 18 19 |
# File 'lib/coltrane/note_set.rb', line 17 def self.[](*notes) new(notes) end |
Instance Method Details
#&(other) ⇒ Object
30 31 32 |
# File 'lib/coltrane/note_set.rb', line 30 def &(other) NoteSet[*(notes & other.notes)] end |
#+(other) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/coltrane/note_set.rb', line 38 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
46 47 48 49 50 51 |
# File 'lib/coltrane/note_set.rb', line 46 def -(other) case other when NoteSet then NoteSet[*(notes - other.notes)] when Interval then NoteSet[*notes.map { |n| n - other }] end end |
#accidentals ⇒ Object
65 66 67 |
# File 'lib/coltrane/note_set.rb', line 65 def accidentals count(&:accidental?) end |
#alter(alteration) ⇒ Object
77 78 79 |
# File 'lib/coltrane/note_set.rb', line 77 def alter(alteration) NoteSet[*map {|n| n.alter(alteration)}] end |
#alter_accidentals(alteration) ⇒ Object
81 82 83 |
# File 'lib/coltrane/note_set.rb', line 81 def alter_accidentals(alteration) NoteSet[*map {|n| n.alter(alteration) if n.accidental?}] end |
#degree(note) ⇒ Object
34 35 36 |
# File 'lib/coltrane/note_set.rb', line 34 def degree(note) index(note) + 1 end |
#flats ⇒ Object
73 74 75 |
# File 'lib/coltrane/note_set.rb', line 73 def flats count(&:flat?) end |
#integers ⇒ Object
61 62 63 |
# File 'lib/coltrane/note_set.rb', line 61 def integers map(&:integer) end |
#interval_sequence ⇒ Object
85 86 87 |
# File 'lib/coltrane/note_set.rb', line 85 def interval_sequence IntervalSequence.new(notes: self) end |
#names ⇒ Object
57 58 59 |
# File 'lib/coltrane/note_set.rb', line 57 def names map(&:name) end |
#pretty_names ⇒ Object
53 54 55 |
# File 'lib/coltrane/note_set.rb', line 53 def pretty_names map(&:pretty_name) end |
#sharps ⇒ Object
69 70 71 |
# File 'lib/coltrane/note_set.rb', line 69 def sharps count(&:sharp?) end |