Coder Social home page Coder Social logo

chordy's Introduction

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 notes.

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.

$ irb -r chordy
irb(main):001:0> play C
 E [--3-]
 A [--3-]
 D [--2-]
 G [--0-]
 B [--1-]
 E [--0-]

=> #<C:0x4d896f8 @flags=0, @strings=[3, 3, 2, 0, 1, 0], @type=:major>

irb(main):002:0> play EFlat
 E [--3-----]
 A [--3---1-]
 D [--2---1-]
 G [--0---3-]
 B [--1---4-]
 E [--0---3-]

=> #<DSharp:0x4d7afc8 @flags=0, @strings=[-1, 1, 1, 3, 4, 3], @type=:major>

irb(main):003:0>

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.

irb(main):001:0> play C, :minor
 E [----]
 A [--3-]
 D [--1-]
 G [--0-]
 B [--4-]
 E [--3-]

=> #<C:0xb72e1924 @flags=0, @strings=[-1, 3, 1, 0, 4, 3], @type=:minor>

irb(main):002:0> play E, :sus4
 E [------0-]
 A [--3---2-]
 D [--1---2-]
 G [--0---2-]
 B [--4---0-]
 E [--3---0-]

=> #<E:0xb72df138 @flags=0, @strings=[0, 2, 2, 2, 0, 0], @type=:suspended_4>

irb(main):003:0>

A chord can also be described in terms of it’s strings, by just passing an array of integers to the play function.

irb(main):001:0> play [5]
 E [--5-]
 A [----]
 D [----]
 G [----]
 B [----]
 E [----]

=> #<Chord:0xb726e2e4 @strings=[5, -1, -1, -1, -1, -1], @flags=0>

irb(main):002:0> play [2, 4, 4]
 E [--5---2-]
 A [------4-]
 D [------4-]
 G [--------]
 B [--------]
 E [--------]

=> #<Chord:0xb726b01c @strings=[2, 4, 4, -1, -1, -1], @flags=0>

irb(main):003:0>

You can also play variations in notes, such as a muted chord or a harmonic. To play a variation, you can either use the play function suffixed with 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.

irb(main):001:0> play_mute A
 E [--0-]
 A [--0-]
 D [--2-]
 G [--2-]
 B [--2-]
 E [--0-]
      M

=> #<A:0x4d85018 @flags=1, @strings=[0, 0, 2, 2, 2, 0], @type=:major>

irb(main):002:0> slide_down {
irb(main):003:1*   play [2, 2, 4]
irb(main):004:1>   play [4, 4, 6]
irb(main):005:1> }
 E [--0---2\--4\]
 A [--0---2\--4\]
 D [--2---4\--6\]
 G [--2---------]
 B [--2---------]
 E [--0---------]
      M

=> #<Chord:0x4d4a1a0 @flags=32, @strings=[4, 4, 6, -1, -1, -1]>

irb(main):006:0>

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 a variable prefixed with tuning_, followed by the number of strings in the tuning and the name of the tuning. For example, tuning_7_a represents A-tuning on a 7-string instrument. This wiki page contains a complete listing of all supported tunings.

irb(main):001:0> tuning_7_a
=> ["a", "d", "g", "c", "f", "a", "d"]

irb(main):002:0> tune tuning_7_a
=> nil

irb(main):003:0> play C
 A [----]
 D [--3-]
 G [--3-]
 C [--2-]
 F [--0-]
 A [--1-]
 D [--0-]

=> #<C:0x4d67018 @flags=0, @strings=[-1, 3, 3, 2, 0, 1, 0], @type=:major>

irb(main):004:0>

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 [--3---0-------0--|--3-----]
 A [--3---2---3---2--|--3---0-]
 D [--2---2---1---2--|--2---2-]
 G [--0---1---0---0--|--0---2-]
 B [--1---0---4---0--|--1-----]
 E [--0---0---3---0--|--------]

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 [--3---0-]
 A [--3---2-]
 D [--2---2-]
 G [--0---1-]
 B [--1---0-]
 E [--0---0-]

--Phrase 1------------------------------

 E [------0-]
 A [--3---2-]
 D [--1---2-]
 G [--0---0-]
 B [--4---0-]
 E [--3---0-]

--Phrase 2------------------------------

 E [--3-----]
 A [--3---0-]
 D [--2---2-]
 G [--0---2-]
 B [--1-----]
 E [--------]

Documentation

Visit the wiki for more information. To generate the API documentation, use rake rdoc.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.