class MusicTheory::Scale
Attributes
all_notes[RW]
distort[RW]
duration[RW]
frequency[RW]
output_file_name[RW]
scale_notes[RW]
scale_type[RW]
starting_note[RW]
Public Class Methods
new(scale_type = :major, options = {})
click to toggle source
# File lib/music_theory/scale.rb, line 10 def initialize(scale_type = :major, options = {}) @scale_type = scale_type @distort = options[:distort] || false @duration = options[:duration] || 0.5 @frequency = options[:frequency] || 220.0 @starting_note = create_new_note(frequency) # Note to start on @output_file_name = options[:output_file_name] || 'scale' # File name to write (without extension) set_all_notes set_scale_notes end
Public Instance Methods
arpeggio()
click to toggle source
# File lib/music_theory/scale.rb, line 58 def arpeggio arpeggio ||= third.arpeggio end
chord()
click to toggle source
# File lib/music_theory/scale.rb, line 62 def chord chord ||= third.chord end
create_new_note(note_frequency)
click to toggle source
# File lib/music_theory/scale.rb, line 38 def create_new_note(note_frequency) MusicTheory::Note.new( frequency: note_frequency, duration: duration, distort: distort) end
mode()
click to toggle source
# File lib/music_theory/scale.rb, line 25 def mode MusicTheory::Modes.send(scale_type) end
samples()
click to toggle source
# File lib/music_theory/scale.rb, line 50 def samples scale_notes.map(&:samples).flatten end
set_all_notes()
click to toggle source
# File lib/music_theory/scale.rb, line 42 def set_all_notes @all_notes = [@starting_note] 12.times do new_note = create_new_note(all_notes.last.frequency * twelfth_root_of_two) all_notes << new_note end end
set_scale_notes()
click to toggle source
# File lib/music_theory/scale.rb, line 29 def set_scale_notes @scale_notes = [all_notes.first] note_index = 0 mode.each do |interval| note_index += interval scale_notes << all_notes[note_index] end end
third()
click to toggle source
# File lib/music_theory/scale.rb, line 54 def third third ||= MusicTheory::Third.new self.dup end
twelfth_root_of_two()
click to toggle source
# File lib/music_theory/scale.rb, line 21 def twelfth_root_of_two 2 ** (1.0/12) end