From: Ross Bamford Date: 2006-05-18T00:21:43+09:00 Subject: Re: [QUIZ] Tab Player (#79) This is the 'proof of concept' solution I wrote for this quiz. It just uses a regexp approach to extract whatever tab it can find from the input, and it has the limitations mentioned in the quiz (9 frets, etc). #!/usr/local/bin/ruby # # This is a very simple solution to this quiz, using # the simple software guitar supplied. Run e.g: # # ./playtab.rb sometab.tab | timidity -Os - # # Using the correct -O (s is ALSA - see --help for more). # Alternatively, file the output and load it in your # midi player. # require 'guitar' tabre = /(([eADGBE]\|? [\-0-9~xhpbrBend\(\)\[\]\{\}=*|#]+ [.\r\n]*){6})/x tabs = [] ARGF.read.scan(tabre) { tab = $1.split tabs << tab if tab.all? { |line| line.length == tab[0].length } } axe = Guitar.new(Guitar::CLEAN_ELECTRIC) tabs.inject([[]]) do |bars,t| (t[0].length - 2).times do |i| notes = t.inject("") { |s,line| s << line[i+2] }.reverse if notes =~ /[|*]{6}/ bars << [] else bars.last << notes end end bars end.reject { |a| a.empty? }.each do |bar| bar.each do |notes| axe.play(notes) end end $stdout.write(axe.dump) -- Ross Bamford - rosco@roscopeco.REMOVE.co.uk