Class: MusicTheory::Scale
- Inherits:
-
Object
- Object
- MusicTheory::Scale
- Includes:
- Output, ScaleSteps
- Defined in:
- lib/music_theory/scale.rb
Instance Attribute Summary collapse
-
#all_notes ⇒ Object
Returns the value of attribute all_notes.
-
#distort ⇒ Object
Returns the value of attribute distort.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#output_file_name ⇒ Object
Returns the value of attribute output_file_name.
-
#scale_notes ⇒ Object
Returns the value of attribute scale_notes.
-
#scale_type ⇒ Object
Returns the value of attribute scale_type.
-
#starting_note ⇒ Object
Returns the value of attribute starting_note.
Instance Method Summary collapse
- #arpeggio ⇒ Object
- #chord ⇒ Object
- #create_new_note(note_frequency) ⇒ Object
-
#initialize(scale_type = :major, options = {}) ⇒ Scale
constructor
A new instance of Scale.
- #mode ⇒ Object
- #samples ⇒ Object
- #set_all_notes ⇒ Object
- #set_scale_notes ⇒ Object
- #third ⇒ Object
- #twelfth_root_of_two ⇒ Object
Methods included from ScaleSteps
#i, #ii, #iii, #iv, #v, #vi, #vii, #viii
Methods included from Output
#buffer_format, #format, #output_track, #play, #sample_rate
Constructor Details
#initialize(scale_type = :major, options = {}) ⇒ Scale
Returns a new instance of Scale.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/music_theory/scale.rb', line 10 def initialize(scale_type = :major, = {}) @scale_type = scale_type @distort = [:distort] || false @duration = [:duration] || 0.5 @frequency = [:frequency] || 220.0 @starting_note = create_new_note(frequency) # Note to start on @output_file_name = [:output_file_name] || 'scale' # File name to write (without extension) set_all_notes set_scale_notes end |
Instance Attribute Details
#all_notes ⇒ Object
Returns the value of attribute all_notes.
8 9 10 |
# File 'lib/music_theory/scale.rb', line 8 def all_notes @all_notes end |
#distort ⇒ Object
Returns the value of attribute distort.
8 9 10 |
# File 'lib/music_theory/scale.rb', line 8 def distort @distort end |
#duration ⇒ Object
Returns the value of attribute duration.
8 9 10 |
# File 'lib/music_theory/scale.rb', line 8 def duration @duration end |
#frequency ⇒ Object
Returns the value of attribute frequency.
8 9 10 |
# File 'lib/music_theory/scale.rb', line 8 def frequency @frequency end |
#output_file_name ⇒ Object
Returns the value of attribute output_file_name.
8 9 10 |
# File 'lib/music_theory/scale.rb', line 8 def output_file_name @output_file_name end |
#scale_notes ⇒ Object
Returns the value of attribute scale_notes.
8 9 10 |
# File 'lib/music_theory/scale.rb', line 8 def scale_notes @scale_notes end |
#scale_type ⇒ Object
Returns the value of attribute scale_type.
8 9 10 |
# File 'lib/music_theory/scale.rb', line 8 def scale_type @scale_type end |
#starting_note ⇒ Object
Returns the value of attribute starting_note.
8 9 10 |
# File 'lib/music_theory/scale.rb', line 8 def starting_note @starting_note end |
Instance Method Details
#arpeggio ⇒ Object
58 59 60 |
# File 'lib/music_theory/scale.rb', line 58 def arpeggio arpeggio ||= third.arpeggio end |
#chord ⇒ Object
62 63 64 |
# File 'lib/music_theory/scale.rb', line 62 def chord chord ||= third.chord end |
#create_new_note(note_frequency) ⇒ Object
38 39 40 |
# 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 ⇒ Object
25 26 27 |
# File 'lib/music_theory/scale.rb', line 25 def mode MusicTheory::Modes.send(scale_type) end |
#samples ⇒ Object
50 51 52 |
# File 'lib/music_theory/scale.rb', line 50 def samples scale_notes.map(&:samples).flatten end |
#set_all_notes ⇒ Object
42 43 44 45 46 47 48 |
# 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 ⇒ Object
29 30 31 32 33 34 35 36 |
# 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 ⇒ Object
54 55 56 |
# File 'lib/music_theory/scale.rb', line 54 def third third ||= MusicTheory::Third.new self.dup end |
#twelfth_root_of_two ⇒ Object
21 22 23 |
# File 'lib/music_theory/scale.rb', line 21 def twelfth_root_of_two 2 ** (1.0/12) end |