A Ruby library to generate images of guitar, ukulele, mandolin or banjo chords
gem install chord_generator
or if you are using Bundler, add this line to your Gemfile:
gem 'chord_generator'
File.open("/tmp/A_major.png", 'w') do |f|
chord = ChordGenerator::Chord.new("x-0-2-2-2-0")
f.write chord.to_png(:label => "A")
end
This will write a basic open string A chord with no frills to /tmp/A_major_.png:
You can also add fingerings, tone intervals, root notes and bars with the following options
The chord code passed into the generator, at a minimum, specifies the string and fret. So "x-0-2-2-2-0" means, muted 6th string, open 5th string, 2nd fret 4th string, etc.
If you want to add fingerings to each fretted note you need to enhance the chord code by adding a pipe to each played string followed by the finger number (open strings can be left blank)
File.open("/tmp/A_major.png", 'w') do |f|
chord = ChordGenerator::Chord.new("x-0|-2|1-2|2-2|3-0|")
f.write chord.to_png(:label => "A with fingering")
end
If you want to add interval tones to each fretted note you need to enhance the chord code by adding a pipe to each played string followed by the finger number (open strings can be left blank) followed by the interval
File.open("/tmp/A_major.png", 'w') do |f|
chord = ChordGenerator::Chord.new("x-0||1-2|1|5-2|2|1-2|3|3-0||5")
f.write chord.to_png(:label => "A with intervals")
end
If you want to add bars and root notes to your diagrams simply enhance the code with more pipes. For each fret/string position in the code you have the following options (fret number|fingering|interval|B|R) where B and R stand for Bar and Root note. For Barred notes to work correctly there must be a matching bar notation on the same fret but different string.
File.open("/tmp/A_major_bar.png", 'w') do |f|
chord = ChordGenerator::Chord.new("5|1|1|B|R-7|3|5-7|4|1-6|2|3-5|1|5-5|1|1|B")
f.write chord.to_png(:label => "A bar with root")
end
To specify a different instrument or tuning, pass in a supported tuning from the Dictionary.
chord = ChordGenerator::Chord.new("0||1-0||5-2|2|3-3|3|1")
chord.to_png({:label => "G Mandolin", :tuning => ChordGenerator::Dictionary::MANDOLIN_TUNINGS[:standard]})
Lot's of code based on andmej/jamming, thanks!
Copyright (c) 2012 Dan Bunker ((http://totalguitarandbass.com)). See LICENSE.txt for further details.