chordy <img src=“https://secure.travis-ci.org/darth10/chordy.png?branch=master” />
chordy is a DSL written in Ruby for printing guitar chord diagrams. A chordy script produces output that looks like a song with various chords, sections and arbitrary text.
It supports all chord families and most chord types. Variations in a note, such as a palm-mute or a trill, are also supported.
Formatting options are also provided.
Installation
Ruby Gems is required. Run gem install chordy
to install the gem.
Usage
After installing the chordy gem, you can start chordy in an interactive mode through irb
. You can declare chords to play using the play
function.
Basic chords
The play
function takes one required arugment, which can be a chord family like C or F#. There are a handful of notations to specify a chord family. For example, the C chord family can be represented as C
, :C
or "C"
. Similarly, F sharp is FSharp
, :F!
or "F!"
. A !
suffix denotes a sharp, and _
denotes a flat.
$ irb -r chordy
1.9.3p327 :001 > play C
e [--0-]
b [--1-]
G [--0-]
D [--2-]
A [--3-]
E [--3-]
=> #<Chordy::C:0x9288e54 @strings=[3, 3, 2, 0, 1, 0], @type=:major, @flags=0>
1.9.3p327 :002 > play :F!
e [--0---2-]
b [--1---2-]
G [--0---3-]
D [--2---4-]
A [--3---4-]
E [--3---2-]
=> #<Chordy::FSharp:0x92673f8 @strings=[2, 4, 4, 3, 2, 2], @type=:major, @flags=0>
1.9.3p327 :003 > play :E_
e [--0---2---3-]
b [--1---2---4-]
G [--0---3---3-]
D [--2---4---1-]
A [--3---4---1-]
E [--3---2-----]
=> #<Chordy::DSharp:0x9258e70 @strings=[-1, 1, 1, 3, 4, 3], @type=:major, @flags=0>
1.9.3p327 :004 >
To specify a chord type such a minor or a suspended chord, specify a second parameter such as :minor
or :suspended_4
. The chord type can also specified in a shorter way like :m
or :sus4
. Note that the default for this parameter is :major
, which is shortened to :M
. This wiki page contains a complete listing of all chord families and types.
1.9.3p327 :001 > play C, :minor
e [--3-]
b [--4-]
G [--0-]
D [--1-]
A [--3-]
E [----]
=> #<Chordy::C:0xa1d0650 @strings=[-1, 3, 1, 0, 4, 3], @type=:minor, @flags=0>
1.9.3p327 :002 > play :E_, :sus4
e [--3---4-]
b [--4---4-]
G [--0---1-]
D [--1---1-]
A [--3---1-]
E [--------]
=> #<Chordy::DSharp:0xa1ae668 @strings=[-1, 1, 1, 1, 4, 4], @type=:suspended_4, @flags=0>
1.9.3p327 :003 >
Chords are printed in high-to-low string order by default. To switch to low-to-high and high-to-string orders for printing, use the do_low_to_high
and do_high_to_low
functions respectively. Note that chords are always internally represented in low-to-high string order.
1.9.3p327 :001 > play C
e [--0-]
b [--1-]
G [--0-]
D [--2-]
A [--3-]
E [--3-]
=> #<Chordy::C:0x940be84 @strings=[3, 3, 2, 0, 1, 0], @type=:major, @flags=0>
1.9.3p327 :002 > play D
e [--0---2-]
b [--1---3-]
G [--0---2-]
D [--2---0-]
A [--3---0-]
E [--3-----]
=> #<Chordy::D:0x93ea658 @strings=[-1, 0, 0, 2, 3, 2], @type=:major, @flags=0>
1.9.3p327 :003 > do_low_to_high
E [--3-----]
A [--3---0-]
D [--2---0-]
G [--0---2-]
b [--1---3-]
e [--0---2-]
=> nil
1.9.3p327 :004 > do_high_to_low
e [--0---2-]
b [--1---3-]
G [--0---2-]
D [--2---0-]
A [--3---0-]
E [--3-----]
=> nil
1.9.3p327 :005 >
A chord can also be described in terms of it’s strings, by just passing an array of integers to the play
function. The array represents the individual strings of chord in high-to-low string order. You can specify low-to-high string order for playing a chord by adding a :low_to_high
argument.
1.9.3-p327 :001 > play [5]
e [--5-]
b [----]
G [----]
D [----]
A [----]
E [----]
=> #<Chordy::Chord:0x9602440 @strings=[-1, -1, -1, -1, -1, 5], @flags=0>
1.9.3-p327 :002 > play [5], :low_to_high
e [--5-----]
b [--------]
G [--------]
D [--------]
A [--------]
E [------5-]
=> #<Chordy::Chord:0x95f8af8 @strings=[5, -1, -1, -1, -1, -1], @flags=0>
1.9.3-p327 :003 > play [2, 4, 4]
e [--5-------2-]
b [----------4-]
G [----------4-]
D [------------]
A [------------]
E [------5-----]
=> #<Chordy::Chord:0x95a9bd8 @strings=[-1, -1, -1, 4, 4, 2], @flags=0>
1.9.3-p327 :004 > play [2, 4, 4], :low_to_high
e [--5-------2-----]
b [----------4-----]
G [----------4-----]
D [--------------4-]
A [--------------4-]
E [------5-------2-]
=> #<Chordy::Chord:0x958d99c @strings=[2, 4, 4, -1, -1, -1], @flags=0>
1.9.3-p327 :005 >
Variations
You can also play variations in chords, such as a muted chord or a harmonic. To play a variation, use the play_var function, where var is the variation name to play. Alternatively, you could use the name of the variation itself as a function, which takes a block of chords to be played. For example, the play_mute
function plays a muted chord, and the slide_down
function plays multiple chords with a slide down. This wiki page contains a complete listing of all supported varations.
An interesting consequence is that variations can overlap. It’s possible that a chord can have a mute
as well as a slide_down
variation. Of course, all such combinations are not possible. You won’t get an error, but the printing will appear unaffected. For example, it’s not possible to print both variations in a chord with both mute
and harmonic
variations.
1.9.3-p327 :001 > play_mute A
e [--0-]
b [--2-]
G [--2-]
D [--2-]
A [--0-]
E [--0-]
M
=> #<Chordy::A:0x9f95fac @strings=[0, 0, 2, 2, 2, 0], @type=:major, @flags=1>
1.9.3-p327 :002 > slide_down {
1.9.3-p327 :003 > play [2, 4, 4], :low_to_high
1.9.3-p327 :004?> play [4, 6, 6], :low_to_high
1.9.3-p327 :005?> }
e [--0---------]
b [--2---------]
G [--2---------]
D [--2---4\--6\]
A [--0---4\--6\]
E [--0---2\--4\]
M
=> #<Chordy::Chord:0x9d36914 @strings=[4, 6, 6, -1, -1, -1], @flags=32>
1.9.3-p327 :006 > mute { slide_down { play [6] } }
e [--0-----------6\]
b [--2-------------]
G [--2-------------]
D [--2---4\--6\----]
A [--0---4\--6\----]
E [--0---2\--4\----]
M M
=> #<Chordy::Chord:0x9fbbf7c @strings=[-1, -1, -1, -1, -1, 6], @flags=33>
1.9.3-p327 :007 > harmonic { mute { play [6] } }
e [--0-----------6\-|--6-]
b [--2--------------|----]
G [--2--------------|----]
D [--2---4\--6\-----|----]
A [--0---4\--6\-----|----]
E [--0---2\--4\-----|----]
M M M
=> #<Chordy::Chord:0x9faed40 @strings=[-1, -1, -1, -1, -1, 6], @flags=3>
1.9.3-p327 :008 >
Tuning
Chordy also supports different tunings. The tune
function can be used to change the tuning, and has to be supplied with a tuning parameter. A tuning is represented as tuning_x_y, where x is the number of strings in the tuning and y is the name of the tuning. You must also prefix the Chordy
module name. For example, Chordy.tuning_7_a
represents A-tuning on a 7-string instrument. This wiki page contains a complete listing of all supported tunings.
1.9.3-p327 :001 > play :C
e [--0-]
b [--1-]
G [--0-]
D [--2-]
A [--3-]
E [--3-]
=> #<Chordy::C:0x98f60e8 @strings=[3, 3, 2, 0, 1, 0], @type=:major, @flags=0>
1.9.3-p327 :002 > Chordy.tuning_7_a
=> ["a", "d", "g", "c", "f", "a", "d"]
1.9.3-p327 :003 > tune Chordy.tuning_7_a
d [--0-]
a [--1-]
f [--0-]
C [--2-]
G [--3-]
D [--3-]
A [----]
=> nil
1.9.3-p327 :004 > play D
d [--0---2-]
a [--1---3-]
f [--0---2-]
C [--2---0-]
G [--3---0-]
D [--3-----]
A [--------]
=> #<Chordy::D:0x989dc04 @strings=[-1, -1, 0, 0, 2, 3, 2], @type=:major, @flags=0>
1.9.3-p327 :005 >
Scripting
You could also script the chords to play by using require 'chordy_script'
. Just be sure to call print_chords
. Here’s a sample chordy script.
# 'sample.rb'
require 'chordy_script'
play :C
play "E"
play :C, :m
play "E", "minor"
play [-1, 3, 3, 2, 0, 1, -1]
play [-1, 0, 2, 2]
print_chords
Here’s what the output of the script looks like.
$ ruby -r rubygems sample.rb
e [--0---0---3---0--|--3-----]
b [--1---0---4---0--|--3---0-]
G [--0---1---0---0--|--2---2-]
D [--2---2---1---2--|--0---2-]
A [--3---2---3---2--|--1-----]
E [--3---0-------0--|--------]
Text and Sections
Text can be added by using text
. To provide structure to your output, use section
to separate chords. Here’s the previous script with some text and sections.
# sample.rb
require 'chordy_script'
text "Some tune"
section "Intro"
play :C
play "E"
section "Phrase 1"
play :C, :m
play "E", "minor"
section "Phrase 2"
play [-1, 3, 3, 2, 0, 1, -1]
play [-1, 0, 2, 2]
print_chords
Here’s the output of the modified script.
$ ruby -r rubygems sample.rb
Some tune
--Intro---------------------------------
e [--0---0-]
b [--1---0-]
G [--0---1-]
D [--2---2-]
A [--3---2-]
E [--3---0-]
--Phrase 1------------------------------
e [--3---0-]
b [--4---0-]
G [--0---0-]
D [--1---2-]
A [--3---2-]
E [------0-]
--Phrase 2------------------------------
e [--3-----]
b [--3---0-]
G [--2---2-]
D [--0---2-]
A [--1-----]
E [--------]
Documentation
The API documentation is available on RDoc.info. You could also generate the RDoc yourself by using rake rdoc
.
Visit the wiki for more information.
Contributing
-
Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.
-
Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.
-
Fork the project.
-
Start a feature/bugfix branch.
-
Commit and push until you are happy with your contribution.
-
Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Make sure your code is formatted as described in the Github Ruby style-guide.
-
Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.