Class: MusicTheory::Octave
- Inherits:
-
Object
- Object
- MusicTheory::Octave
- Includes:
- Output
- Defined in:
- lib/music_theory/octave.rb
Instance Attribute Summary collapse
-
#all_notes ⇒ Object
Returns the value of attribute all_notes.
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#output_file_name ⇒ Object
Returns the value of attribute output_file_name.
-
#starting_note ⇒ Object
Returns the value of attribute starting_note.
Instance Method Summary collapse
- #build_octave ⇒ Object
-
#initialize(options = {}) ⇒ Octave
constructor
A new instance of Octave.
- #samples ⇒ Object
Methods included from Output
#buffer_format, #format, #output_track, #play, #sample_rate
Constructor Details
#initialize(options = {}) ⇒ Octave
Returns a new instance of Octave.
8 9 10 11 12 13 14 |
# File 'lib/music_theory/octave.rb', line 8 def initialize( = {}) @starting_note = [:starting_note] || MusicTheory::Note.new # Note to start on @amount = [:amount] || 2 # Number of octaves to repeat @direction = [:direction] || 'asc' # Number of seconds per note @output_file_name = [:output_file_name] || 'octave' # File name to write (without extension) build_octave end |
Instance Attribute Details
#all_notes ⇒ Object
Returns the value of attribute all_notes.
6 7 8 |
# File 'lib/music_theory/octave.rb', line 6 def all_notes @all_notes end |
#amount ⇒ Object
Returns the value of attribute amount.
6 7 8 |
# File 'lib/music_theory/octave.rb', line 6 def amount @amount end |
#direction ⇒ Object
Returns the value of attribute direction.
6 7 8 |
# File 'lib/music_theory/octave.rb', line 6 def direction @direction end |
#output_file_name ⇒ Object
Returns the value of attribute output_file_name.
6 7 8 |
# File 'lib/music_theory/octave.rb', line 6 def output_file_name @output_file_name end |
#starting_note ⇒ Object
Returns the value of attribute starting_note.
6 7 8 |
# File 'lib/music_theory/octave.rb', line 6 def starting_note @starting_note end |
Instance Method Details
#build_octave ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/music_theory/octave.rb', line 16 def build_octave @all_notes = [ starting_note ] amount.to_i.times do new_note = all_notes.last.dup if direction == 'asc' new_note.frequency = all_notes.last.frequency * 2 elsif direction == 'desc' new_note.frequency = all_notes.last.frequency / 2 end all_notes << new_note unless new_note.frequency > 20000 end end |
#samples ⇒ Object
29 30 31 |
# File 'lib/music_theory/octave.rb', line 29 def samples all_notes.map(&:samples).flatten end |