diff --git a/lib/blues/guitar.rb b/lib/blues/guitar.rb index 2493ced..a48d1bc 100644 --- a/lib/blues/guitar.rb +++ b/lib/blues/guitar.rb @@ -2,20 +2,9 @@ module Blues class Guitar - VALID_TUNINGS = [ - :all_fifths, - :all_fourths, - :down_half_step, - :drop_d, - :modal_c, - :open_a, - :standard, - ].freeze - attr_reader :strings def initialize(amplifier: nil) - @tuning = nil @strings = Array.new(6) { |i| GuitarString.new(number: i + 1) } @amplifier = amplifier end @@ -34,11 +23,7 @@ def pick(string:, fret:) end def tune(tuning = :standard) - raise "unknown tuning" unless VALID_TUNINGS.include?(tuning) - - send("#{tuning}_tuning") - - @tuning = tuning + Tuner.new(self).tune(tuning) end def restring(gauge_set:) @@ -49,31 +34,5 @@ def restring(gauge_set:) ) end end - - private - - def standard_tuning - @strings[5].tune(note: :e, octave: 2) - @strings[4].tune(note: :a, octave: 2) - @strings[3].tune(note: :d, octave: 3) - @strings[2].tune(note: :g, octave: 3) - @strings[1].tune(note: :b, octave: 3) - @strings[0].tune(note: :e, octave: 4) - end - - def down_half_step_tuning - @strings[5].tune(note: :e_flat, octave: 2) - @strings[4].tune(note: :a_flat, octave: 2) - @strings[3].tune(note: :d_flat, octave: 3) - @strings[2].tune(note: :g_flat, octave: 3) - @strings[1].tune(note: :b_flat, octave: 3) - @strings[0].tune(note: :e_flat, octave: 4) - end - - def drop_d_tuning = nil - def open_a_tuning = nil - def modal_c_tuning = nil - def all_fourths_tuning = nil - def all_fifths_tuning = nil end end diff --git a/lib/blues/tuner.rb b/lib/blues/tuner.rb new file mode 100644 index 0000000..175cb07 --- /dev/null +++ b/lib/blues/tuner.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module Blues + class Tuner + VALID_TUNINGS = [ + :all_fifths, + :all_fourths, + :down_half_step, + :drop_d, + :modal_c, + :open_a, + :standard, + ].freeze + + def initialize(guitar) + @guitar = guitar + end + + def tune(tuning = :standard) + raise "unknown tuning" unless VALID_TUNINGS.include?(tuning) + + send("#{tuning}_tuning") + end + + private + + def standard_tuning + @guitar.strings[5].tune(note: :e, octave: 2) + @guitar.strings[4].tune(note: :a, octave: 2) + @guitar.strings[3].tune(note: :d, octave: 3) + @guitar.strings[2].tune(note: :g, octave: 3) + @guitar.strings[1].tune(note: :b, octave: 3) + @guitar.strings[0].tune(note: :e, octave: 4) + end + + def down_half_step_tuning + @guitar.strings[5].tune(note: :e_flat, octave: 2) + @guitar.strings[4].tune(note: :a_flat, octave: 2) + @guitar.strings[3].tune(note: :d_flat, octave: 3) + @guitar.strings[2].tune(note: :g_flat, octave: 3) + @guitar.strings[1].tune(note: :b_flat, octave: 3) + @guitar.strings[0].tune(note: :e_flat, octave: 4) + end + + def drop_d_tuning = nil + def open_a_tuning = nil + def modal_c_tuning = nil + def all_fourths_tuning = nil + def all_fifths_tuning = nil + end +end