Class: Hammelin::NotesRange

Inherits:
Array
  • Object
show all
Defined in:
lib/hammelin/notes_range.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ NotesRange

Returns a new instance of NotesRange.



7
8
9
# File 'lib/hammelin/notes_range.rb', line 7

def initialize(array)
  super(array)
end

Class Method Details

.from_array(array) ⇒ Object



15
16
17
18
# File 'lib/hammelin/notes_range.rb', line 15

def self.from_array(array)
  notes_range = array.inject([]) {|notes,notes_range| notes += notes_range }
  NotesRange.new(notes_range)
end

.from_range(from, to) ⇒ Object



11
12
13
# File 'lib/hammelin/notes_range.rb', line 11

def self.from_range(from,to)
  NotesRange.new(transverse_notes(from,to))
end

Instance Method Details

#decrease_octave(times = 1) ⇒ Object



40
41
42
43
44
# File 'lib/hammelin/notes_range.rb', line 40

def decrease_octave(times=1)
  notes = map {|note| note.decrease_octave(times)}

  NotesRange.new(notes)      
end

#downto(value) ⇒ Object Also known as: upto

downto and upto are just some sintactic sugar for expanding the range to a new value. It will create a new NotesRange object with the last Note and then will figure out how to get to the newest one.



28
29
30
# File 'lib/hammelin/notes_range.rb', line 28

def downto(value)
  NotesRange.from_range(last,value)
end

#increase_octave(times = 1) ⇒ Object



34
35
36
37
38
# File 'lib/hammelin/notes_range.rb', line 34

def increase_octave(times=1)
  notes = map {|note| note.increase_octave(times)}

  NotesRange.new(notes)
end

#music_stringObject



46
47
48
# File 'lib/hammelin/notes_range.rb', line 46

def music_string
  map{|i| i.music_string }.join(" ")
end

#playObject



20
21
22
23
# File 'lib/hammelin/notes_range.rb', line 20

def play
  Hammelin.play_string music_string
  self
end