Class: RBMusic::NoteSet
- Inherits:
-
Object
- Object
- RBMusic::NoteSet
- Includes:
- Enumerable
- Defined in:
- lib/rb-music/note_set.rb
Instance Attribute Summary collapse
-
#notes ⇒ Object
Returns the value of attribute notes.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(other) ⇒ Object (also: #push)
- #==(other) ⇒ Object (also: #eql?)
- #[](index) ⇒ Object
- #add(that) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(notes = []) ⇒ NoteSet
constructor
A new instance of NoteSet.
- #map(&block) ⇒ Object
- #size ⇒ Object
- #subtract(that) ⇒ Object
Constructor Details
#initialize(notes = []) ⇒ NoteSet
Returns a new instance of NoteSet.
8 9 10 |
# File 'lib/rb-music/note_set.rb', line 8 def initialize(notes = []) @notes = notes end |
Instance Attribute Details
#notes ⇒ Object
Returns the value of attribute notes.
6 7 8 |
# File 'lib/rb-music/note_set.rb', line 6 def notes @notes end |
Class Method Details
.from_scale(scale, octave = 0, octaves = 1) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rb-music/note_set.rb', line 12 def self.from_scale(scale, octave=0, octaves=1) raise ArgumentError unless scale.is_a?(Scale) && octaves > 0 root_note = Note.from_latin("#{scale.key}#{octave}") notes = [] octaves.times do |i| notes += scale.degrees.map do |interval_name| note = root_note.add(interval_name) i.times do |octave_offset| note = note.add(:octave) end note end end self.new(notes) end |
Instance Method Details
#<<(other) ⇒ Object Also known as: push
38 39 40 |
# File 'lib/rb-music/note_set.rb', line 38 def <<(other) @notes << other end |
#==(other) ⇒ Object Also known as: eql?
47 48 49 |
# File 'lib/rb-music/note_set.rb', line 47 def ==(other) @notes == other.notes end |
#[](index) ⇒ Object
34 35 36 |
# File 'lib/rb-music/note_set.rb', line 34 def [](index) @notes[index] end |
#add(that) ⇒ Object
56 57 58 |
# File 'lib/rb-music/note_set.rb', line 56 def add(that) NoteSet.new(@notes.map { |note| note.add(that) }) end |
#each(&block) ⇒ Object
30 31 32 |
# File 'lib/rb-music/note_set.rb', line 30 def each(&block) @notes.each(&block) end |
#map(&block) ⇒ Object
43 44 45 |
# File 'lib/rb-music/note_set.rb', line 43 def map(&block) @notes.map(&block) end |
#size ⇒ Object
52 53 54 |
# File 'lib/rb-music/note_set.rb', line 52 def size @notes.size end |