Class: MusicTheory::Chord
- Inherits:
-
Object
- Object
- MusicTheory::Chord
- Includes:
- Output
- Defined in:
- lib/music_theory/chord.rb
Instance Attribute Summary collapse
-
#all_notes ⇒ Object
Returns the value of attribute all_notes.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#output_file_name ⇒ Object
Returns the value of attribute output_file_name.
-
#third ⇒ Object
Returns the value of attribute third.
Instance Method Summary collapse
- #flatten_third ⇒ Object
-
#initialize(third, options = {}) ⇒ Chord
constructor
A new instance of Chord.
- #normalize_samples(new_samples) ⇒ Object
- #samples ⇒ Object
Methods included from Output
#buffer_format, #format, #output_track, #play, #sample_rate
Constructor Details
#initialize(third, options = {}) ⇒ Chord
Returns a new instance of Chord.
9 10 11 12 13 |
# File 'lib/music_theory/chord.rb', line 9 def initialize(third, = {}) @duration = [:duration] || 2.0 @third = third @output_file_name = [:output_file_name] || 'chord' # File name to write (without extension) end |
Instance Attribute Details
#all_notes ⇒ Object
Returns the value of attribute all_notes.
7 8 9 |
# File 'lib/music_theory/chord.rb', line 7 def all_notes @all_notes end |
#duration ⇒ Object
Returns the value of attribute duration.
7 8 9 |
# File 'lib/music_theory/chord.rb', line 7 def duration @duration end |
#output_file_name ⇒ Object
Returns the value of attribute output_file_name.
7 8 9 |
# File 'lib/music_theory/chord.rb', line 7 def output_file_name @output_file_name end |
#third ⇒ Object
Returns the value of attribute third.
7 8 9 |
# File 'lib/music_theory/chord.rb', line 7 def third @third end |
Instance Method Details
#flatten_third ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/music_theory/chord.rb', line 15 def flatten_third third.all_notes.each {|note| note.duration = duration} new_samples = [] sample_count = third.all_notes.first.samples.count third.samples.in_groups_of(sample_count).each do |group| group.each_with_index do |value, i| new_samples[i] ||= 0 new_samples[i] += value end end normalize_samples(new_samples) end |
#normalize_samples(new_samples) ⇒ Object
28 29 30 31 32 |
# File 'lib/music_theory/chord.rb', line 28 def normalize_samples(new_samples) max = new_samples.map {|s| s.abs }.max multiplier = 1.0 / max new_samples.map!{ |s| multiplier * s } end |
#samples ⇒ Object
34 35 36 |
# File 'lib/music_theory/chord.rb', line 34 def samples flatten_third end |