Skip to content

Commit

Permalink
Adds arpeggio
Browse files Browse the repository at this point in the history
  • Loading branch information
beneggett committed Mar 10, 2015
1 parent f21a8fd commit 47f0a3c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/music_theory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require "music_theory/modes"
require "music_theory/third"
require "music_theory/chord"
require "music_theory/arpeggio"
require "music_theory/harmonize"
require "music_theory/output"
require "music_theory/play"
Expand Down
25 changes: 25 additions & 0 deletions lib/music_theory/arpeggio.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'music_theory/output'

module MusicTheory
class Arpeggio
include MusicTheory::Output

attr_accessor :third, :duration, :all_notes, :output_file_name

def initialize(third, options = {})
@duration = options[:duration] || 0.25
@third = third
@output_file_name = options[:output_file_name] || 'chord' # File name to write (without extension)
end

def arpeggionate
third.all_notes.each {|note| note.duration = duration}
third.all_notes + [third.all_notes[2], third.all_notes[1], third.all_notes[0], third.all_notes[1]]
end

def samples
arpeggionate.map(&:samples).flatten
end

end
end
4 changes: 4 additions & 0 deletions lib/music_theory/scale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def third
third ||= MusicTheory::Third.new self
end

def arpeggio
arpeggio ||= third.arpeggio
end

def chord
third.chord
end
Expand Down
5 changes: 5 additions & 0 deletions lib/music_theory/third.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ def chord
chord ||= MusicTheory::Chord.new self
end

def arpeggio
arpeggio ||= MusicTheory::Arpeggio.new self
end

def output_file_name
scale.output_file_name || 'thirds'
end


end
end
2 changes: 1 addition & 1 deletion lib/music_theory/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MusicTheory
VERSION = "0.1.1"
VERSION = "0.2.0"
end

0 comments on commit 47f0a3c

Please sign in to comment.