Programming Guitar Tabs

Play ASCII tab in Sonic PI

Simple little sonic-pi program to read ASCII tab format, and play it.

I should probably update it to output midi, so I can have ableton render the sound since they have much better guitar sounds.

guitar_strings = {
  'E': [:E3, :F3, :Fs3, :G3, :Gs3, :A3, :As3, :B3, :C4, :Cs4, :D4, :Ds4, :E4, :F4, :Fs4, :G4, :Gs4, :A4],
  'A': [:A4, :As4, :B4, :C5, :Cs5, :D5, :Ds5, :E5, :F5, :Fs5, :G5, :Gs5, :A5, :As5, :B5, :C6, :Cs6, :D6],
  'D': [:D5, :Ds5, :E5, :F5, :Fs5, :G5, :Gs5, :A5, :As5, :B5, :C6, :Cs6, :D6, :Ds6, :E6, :F6, :Fs6, :G6],
  'G': [:G5, :Gs5, :A5, :As5, :B5, :C6, :Cs6, :D6, :Ds6, :E6, :F6, :Fs6, :G6, :Gs6, :A6, :As6, :B6, :C7],
  'B': [:B5, :C6, :Cs6, :D6, :Ds6, :E6, :F6, :Fs6, :G6, :Gs6, :A6, :As6, :B6, :C7, :Cs7, :D7, :Ds7, :E7],
  'e': [:E6, :F6, :Fs6, :G6, :Gs6, :A6, :As6, :B6, :C7, :Cs7, :D7, :Ds7, :E7, :F7, :Fs7, :G7, :Gs7, :A7]
}

notes = {}

File.open("/Users/mattpoepping/s/cli/licks/2022-11-10.tab","r") do |f|
  while strline = f.gets
    strline = strline.strip()
    notes[ strline[0] ] = strline.split("").drop(2)
  end
end

use_synth_defaults release: 0.4
use_synth :fm
use_bpm 120

with_fx :hpf, cutoff: 80, res: 0.9, amp: 1.5  do
  with_fx :distortion, distort: 0.8, amp: 0.5, mix: 0.4  do
    for i in 0..notes['e'].length() do
      notes.each do |k,v|
      if ['1','2','3','4','5','6','7','8','9','0'].include? notes[k][i] then
        #puts k.to_sym , notes[k][i].to_i, guitar_strings[ k.to_sym ]
        play_note = guitar_strings[ k.to_sym ][ notes[k][i].to_i ]
        puts play_note
        play play_note
        sleep 0.2
      end
    end
  end
end
end

Better Tab 2 Note

I figured I could do a little better and use math:

class Tab2note
  def self.getNote (s, fret)
    slist = { :E => ['E', 3],
              :A => ['A', 4],
              :D => ['D', 5],
              :G => ['G', 5],
              :B => ['B', 5],
              :e => ['E', 6]
    }

    notes = ['C','CS','D','DS','E','F','FS','G','GS','A','AS','B']

    start_tone = slist[s][1] 
    inc_key = (notes.index( slist[s][0] ) + fret) / 12
    note = (notes.index( slist[s][0] ) + fret) % 12

    "#{notes[note]}#{(start_tone + inc_key)}"

  end
end

Editing Guitar Tabs in Vim

I was using Guitar Pro to create licks, but the workflow requires you to really have a separate file for each lick, or just export them all out. I'll probably keep using Guitar Pro for some stuff since it is usefull, but for small daily lick stuff I'm going to just use vim, because it's easy and can export a single lick.

If i'm really on top of things, I should really write a simple program to play text tabs from the cli.

Add this to your .vimrc:

:autocmd BufNewFile  *.tab      0r ~/.vim/skeleton/tabs
:autocmd BufNew,BufEnter *.tab set virtualedit=all 
" use R (replace mode) to edit the tabs

and then create the file ~/.vim/skeleton/tabs with this content:

e|-----------------|-----------------|-----------------|-----------------|
B|-----------------|-----------------|-----------------|-----------------|
G|-----------------|-----------------|-----------------|-----------------|
D|-----------------|-----------------|-----------------|-----------------|
A|-----------------|-----------------|-----------------|-----------------|
E|-----------------|-----------------|-----------------|-----------------|

Now instead of going into insert mode with i go into replace mode with R and make your edits


Home