class Fretboard
Constants
- Fret
Attributes
fret_count[R]
open_notes[R]
tuning[R]
Public Class Methods
new(tuning = :EADGBE, fret_count = 20)
click to toggle source
# File lib/chord_finder/fretboard.rb, line 6 def initialize(tuning = :EADGBE, fret_count = 20) @tuning = tuning @fret_count = fret_count note_names = case @tuning when String then tuning.split(/(?![#!b♭_])/) when Array then tuning when Symbol then tuning.to_s.split(/(?![#!b♭_])/) end @open_notes = note_names.map do |name| pretty_name = name.gsub(/[#!b♭_]/, Note::ACCIDENTALS) Note.find(pretty_name) end end
Public Instance Methods
filter_frets(chord, options)
click to toggle source
# File lib/chord_finder/fretboard.rb, line 24 def filter_frets(chord, options) low_fret, high_fret = options[:low_fret], options[:high_fret] frets_for_each_string.map do |string_frets| string_frets.select do |fret| (fret.number > 0 ? fret.number.between?(low_fret, high_fret) : true) && (fret.note.muted? || chord.notes.include?(fret.note)) end end end
Private Instance Methods
create_fret(note, fret_num)
click to toggle source
# File lib/chord_finder/fretboard.rb, line 43 def create_fret(note, fret_num) Fret.new(note, fret_num) end
frets_for_each_string()
click to toggle source
# File lib/chord_finder/fretboard.rb, line 35 def frets_for_each_string @frets_for_each_string ||= open_notes.map do |open_note| (0..fret_count).map { |step| create_fret(open_note + step, step) }.unshift muted_string end end
muted_string()
click to toggle source
# File lib/chord_finder/fretboard.rb, line 47 def muted_string create_fret(Note.new("x"), -1) end