From: Adam Shelly Date: 2006-05-18T01:50:10+09:00 Subject: Re: [QUIZ] Tab Player (#79) ------=_Part_2992_17423903.1147884607507 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Here's my short solution. It just assumes any set of 6 equal-length lines starting with ('A'..'G') are a tab, and ignores the rest of the file. It passes everything it finds on the tab lines to the guitar, since I was hoping to improve guitar.rb to handle hammers and slides and such.. Unfortunately, real life just takes too much time... ---begin player.rb ------ require 'guitar.rb' tuningMap =3D { 'EADGBE' =3D> Guitar::EADGBE, 'DADGBE' =3D> Guitar::DADGBE, 'DGCFAD'=3D> Guitar::DGCFAD } puts "usage: Player.rb tabfile" or exit if ARGV.size < 1 lines,lastlength=3D[],nil until ARGF.eof do lines << ARGF.gets.chomp.split(''); #read until we find 6 lines of same length if lastlength and lastlength !=3D lines[-1].length #throw away nonmatching lines lines.shift while lines.size > 1 end lastlength =3D lines[-1].length if lines.size =3D=3D 6 sig =3D lines.inject([]){|a,l| a < wrote: > > 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 =3D /(([eADGBE]\|? > [\-0-9~xhpbrBend\(\)\[\]\{\}=3D*|#]+ > [.\r\n]*){6})/x > tabs =3D [] > > ARGF.read.scan(tabre) { > tab =3D $1.split > tabs << tab if tab.all? { |line| line.length =3D=3D tab[0].length } > } > > axe =3D Guitar.new(Guitar::CLEAN_ELECTRIC) > tabs.inject([[]]) do |bars,t| > (t[0].length - 2).times do |i| > notes =3D t.inject("") { |s,line| s << line[i+2] }.reverse > if notes =3D~ /[|*]{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 > > > ------=_Part_2992_17423903.1147884607507--