class RBMusic::NoteSet

Attributes

notes[RW]

Public Class Methods

from_scale(scale, octave=0, octaves=1) click to toggle source
# 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
new(notes = []) click to toggle source
# File lib/rb-music/note_set.rb, line 8
def initialize(notes = [])
  @notes = notes
end

Public Instance Methods

<<(other) click to toggle source
# File lib/rb-music/note_set.rb, line 38
def <<(other)
  @notes << other
end
Also aliased as: push
==(other) click to toggle source
# File lib/rb-music/note_set.rb, line 47
def ==(other)
  @notes == other.notes
end
Also aliased as: eql?
[](index) click to toggle source
# File lib/rb-music/note_set.rb, line 34
def [](index)
  @notes[index]
end
add(that) click to toggle source
# File lib/rb-music/note_set.rb, line 56
def add(that)
  NoteSet.new(@notes.map { |note| note.add(that) })
end
each(&block) click to toggle source
# File lib/rb-music/note_set.rb, line 30
def each(&block)
  @notes.each(&block)
end
eql?(other)
Alias for: ==
map(&block) click to toggle source
# File lib/rb-music/note_set.rb, line 43
def map(&block)
  @notes.map(&block)
end
push(other)
Alias for: <<
size() click to toggle source
# File lib/rb-music/note_set.rb, line 52
def size
  @notes.size
end
subtract(that) click to toggle source
# File lib/rb-music/note_set.rb, line 60
def subtract(that)
  NoteSet.new(@notes.map { |note| note.subtract(that) })
end