#!/usr/bin/awk -f # # Copyright: GNU GPL 2 or 3 # Author: Martin Fick # Version: 1.1 1008/03/06 # Use: ascii2abctab [<] [asciitab] > [abctab] # # Note: On solaris try setting awk to nawk or gawk # BEGIN { FS=":"; FRETS[0] = "a"; FRETS[1] = "b"; FRETS[2] = "c"; FRETS[3] = "d"; FRETS[4] = "e"; FRETS[5] = "f"; FRETS[6] = "g"; FRETS[7] = "h"; FRETS[8] = "i"; FRETS[9] = "k"; FRETS[10] = "l"; FRETS[11] = "m"; FRETS[12] = "n"; FRETS[13] = "o"; FRETS[14] = "p"; FRETS[15] = "q"; FRETS[16] = "r"; FRETS[17] = "s"; FRETS[18] = "t"; FRETS[19] = "u"; FRETS[20] = "v"; FRETS[21] = "w"; FRETS["-"] = ","; FRETS[" "] = ","; FRETS[""] = ","; OTH["|"] = "|"; OTH["["] = "["; OTH["]"] = "]"; OTH[":"] = ":"; DEFHEAD[1] = "X" DEFHEAD[2] = "%%tabaddflags" DEFHEAD[3] = "%%tabrhstyle" DEFHEAD[4] = "%%systemsep" DEFHEAD[5] = "%%tabfontscale" DEFHEAD[6] = "%%tabfontsize" DEFHEAD[7] = "%%tabfontitalian" DEFHEAD[8] = "%%titleleft" DEFHEAD[9] = "T" DEFHEAD[10] = "M" DEFHEAD[11] = "L" DEFHEAD[12] = "K" DEFHEADER["X"] = "1"; DEFHEADER["%%tabaddflags"] = "0"; DEFHEADER["%%tabrhstyle"] = "none"; DEFHEADER["%%systemsep"] = "40.0pt"; DEFHEADER["%%tabfontscale"] = "1.0"; DEFHEADER["%%tabfontsize"] = "11"; DEFHEADER["%%tabfontitalian"] = "Borrono"; DEFHEADER["%%titleleft"] = "yes"; DEFHEADER["T"] = ""; DEFHEADER["M"] = "C|"; DEFHEADER["L"] = "1/8"; DEFHEADER["K"] = "guitartab"; } { tab = 0 } /^[ ]*e-*/ { if (TAB == 0 || TAB == 5) tab = 1; } /^[ ]*b-*/ { if (TAB == 1) tab = 1; } /^[ ]*g-*/ { if (TAB == 2) tab = 1; } /^[ ]*d-*/ { if (TAB == 3) tab = 1; } /^[ ]*a-*/ { if (TAB == 4) tab = 1; } tab { sub(/^[eadgb]/,"|-") ; } /^[ ]*\|*--*/ { tab = 1; } tab { TAB++; TABLINES[TAB] = $0 } !tab { TAB=0; if(top != "") { if (song) { print "%%text "top } else { if(ptext) ptext = ptext "\n" ptext = ptext "%%text "top } } top = ""; if (NF > 1 && length($1) == 1) { if ($1 == "X") song = 0; if (song) { print } else { NHEAD++; HEAD[$1] = NHEAD; HEADER[NHEAD] = $0; } } else if(substr($0, 1, 2) == "%%") { if (song) { print } else if (split($0, hfmt, /[ ] */) > 1) { NHEAD++; HEAD[hfmt[1]] = NHEAD; HEADER[NHEAD] = $0; } } else if ($0 ~ /^[ 0-9\/]*$/) { top = $0; } else if ($0 !~ /^[ ]*$/) { #if(ptab) { if (song) { print "%%text "$0 } else { if(ptext) ptext = ptext "\n" ptext = ptext "%%text "$0 } } } { ptab =0; } TAB==6 { ptab=1; nstaves++; if (song==0) { song=1; for (def in DEFHEAD) { ndefs++; } for (i=1; i <= ndefs; i++) { def= DEFHEAD[i]; head = HEAD[def]; if (head > 0) { print HEADER[head]; HEAD[def]=0; } else { ab = substr(def, 1, 2); if(ab == "%%") print def " " DEFHEADER[def]; else print def ":" DEFHEADER[def]; } } for (head in HEAD) if (HEAD[head]) print HEADER[HEAD[head]] ; if(ptext) print ptext } TAB = 0; len = 0; TABLINES[0]=top; for(l = 0; l < 7; l++) { llen[l] = length(TABLINES[l]); len = len > llen[l] ? len : llen[l]; } bar = ""; for(i = 1; i <= len; i++) { notes= 0; chord = ""; blank = ""; nchars = 0; for(l = 0; l < 7; l++) { for (nc = 0; 1;) { c = ""; if (llen[l] >= i + nc) c = substr(TABLINES[l], i + nc, 1); if (l==0) { if("" == c || c !~ /[0-9\/]/ ) break; } else { fret = FRETS[c]; if("" == fret || "," == fret) break; } nc++; if (nchars < nc) nchars = nc; } } duration =""; if (llen[0] >= i) duration = substr(TABLINES[0], i, nchars); for(l = 1; l < 7; l++) { frets[l] = ""; for (nc = 0; nc < nchars; nc++) { c = ""; if (llen[l] >= i + nc) c = substr(TABLINES[l], i + nc, 1); if("" != c && c * 1 == c ) frets[l] = frets[l] c; } frets[l] = FRETS[frets[l]]; } for(l = 1; l < 7; l++) { oth = OTH[substr(TABLINES[l], i, 1)]; if ("" != oth) break; fret = frets[l]; if (fret == "") fret = ","; if ("," == fret) { blank = blank ","; } else { notes++; chord = chord blank fret; blank = ""; } } if (nchars > 1) i = i + nchars -1; if ("" != oth) { notes=0; chord = oth; } else { if (1 < notes) chord = "[" chord "]"; if ("" != duration) chord = chord duration; } if (1 == notes && "" != bar) bar = bar " "; bar = bar chord; } print bar top = ""; }