require 'rubygems'
require 'win32console'
class String
#def red; colorize(self, "\e[1m\e[31m"); end
def green; colorize(self, "\e[1m\e[32m"); end
#def dark_green; colorize(self, "\e[32m"); end
#def yellow; colorize(self, "\e[1m\e[33m"); end
#def blue; colorize(self, "\e[1m\e[34m"); end
#def dark_blue; colorize(self, "\e[34m"); end
#def pur; colorize(self, "\e[1m\e[35m"); end
def colorize(text, color_code) "#{color_code}#{text}\e[0m" end
end
def note_to_n(n) #Converts a note name into a number
val = case n.upcase
when "A"
0
when "A#", "BB"
1
when "B", "CB"
2
when "C", "B#"
3
when "C#", "DB"
4
when "D"
5
when "D#", "EB"
6
when "E", "FB"
7
when "F", "E#"
8
when "F#", "GB"
9
when "G"
10
when "G#", "AB"
11
else
0
end
end
def note_to_s(s) #Converts a number into a readable note name
val = case s
when 0
"A "
when 1
"A#"
when 2
"B "
when 3
"C "
when 4
"C#"
when 5
"D "
when 6
"D#"
when 7
"E "
when 8
"F "
when 9
"F#"
when 10
"G "
when 11
"G#"
else
"x "
end
end
def input_tuning
puts "6: "
s6 = note_to_n(gets.chomp)
puts "5: "
s5 = note_to_n(gets.chomp)
puts "4: "
s4 = note_to_n(gets.chomp)
puts "3: "
s3 = note_to_n(gets.chomp)
puts "2: "
s2 = note_to_n(gets.chomp)
puts "1: "
s1 = note_to_n(gets.chomp)
[s1, s2, s3, s4, s5, s6]
end
def fill_array(base_note, string_array)
for i in 0..23 #From fret 0 to fret 23
if i == 0
r = base_note #Set the note reader to the base note
string_array[i] = r
else
r+=1
if r == 12; r = 0 end #Reset note reader
string_array[i] = r
end
end
end
def print_frets(guitar, search)
print_fretguide
color_fret(guitar[0], search)
color_fret(guitar[1], search)
color_fret(guitar[2], search)
color_fret(guitar[3], search)
color_fret(guitar[4], search)
color_fret(guitar[5], search)
end
def print_fretguide
tape = ""
for i in 0..23
if i == 0
tape << "0 |"
else
if i < 10
tape << "#{i} "
else
tape << "#{i} "
end
end
end
puts tape
end
def color_fret(fret, search)
tape = ""
for i in 0..(fret.length - 1)
if i == 0
if search.include?(fret[i])
tape << note_to_s(fret[i]).green << "|"
else
tape << note_to_s(fret[i]) << "|"
end
else
if search.include?(fret[i])
tape << note_to_s(fret[i]).green << " "
else
tape << note_to_s(fret[i]) << " "
end
end
end
puts tape
end
#MAIN CODE STARTS HERE=----------------------------------------------------
s1, s2, s3, s4, s5, s6 = input_tuning
puts "TUNING: #{note_to_s(s6)}, #{note_to_s(s5)}, #{note_to_s(s4)}, #{note_to_s(s3)}, #{note_to_s(s2)}, #{note_to_s(s1)}"
sa1 = Array.new(24, 0) #Fret 0 to 23 filled with 0
sa2 = Array.new(24, 0)
sa3 = Array.new(24, 0)
sa4 = Array.new(24, 0)
sa5 = Array.new(24, 0)
sa6 = Array.new(24, 0)
fill_array(s1, sa1) #Fill arrays with correct note sequence
fill_array(s2, sa2)
fill_array(s3, sa3)
fill_array(s4, sa4)
fill_array(s5, sa5)
fill_array(s6, sa6)
guitar = Array.new([sa1, sa2, sa3, sa4, sa5, sa6])
puts "1) Major Chord"
puts "2) Minor Chord"
puts "3) No chord"
case gets.chomp
when "1"
puts "Bass note:"
bass = note_to_n(gets.chomp)
case bass
when 0..4
print_frets(guitar, [bass, bass + 4, bass + 7])
when 5..7
print_frets(guitar, [bass, bass + 4, bass - 5])
when 8..11
print_frets(guitar, [bass, bass - 8, bass - 5])
else
print_frets(guitar, [bass, bass + 4, bass + 7])
end
when "2"
puts "Bass note:"
bass = note_to_n(gets.chomp)
case bass
when 0..4
print_frets(guitar, [bass, bass + 3, bass + 7])
when 5..8
print_frets(guitar, [bass, bass + 3, bass - 5])
when 9..11
print_frets(guitar, [bass, bass - 9, bass - 5])
else
print_frets(guitar, [bass, bass + 4, bass + 7])
end
else
print_frets(guitar, [])
end
puts "Done."
gets #If you don't run from cmd