Coder Social home page Coder Social logo

chordy's Introduction

chordy

<img src=“https://badge.fury.io/rb/chordy.png” alt=“Gem Version” /> <img src=“https://secure.travis-ci.org/darth10/chordy.png?branch=master” /> <img src=“https://app.fossa.io/api/projects/git%2Bgithub.com%2Fdarth10%2Fchordy.svg?type=shield”/>

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.

chordy's People

Contributors

darth10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chordy's Issues

Add more effects

Several more effects can be implemented, such as:

  • Release/bend using r and b. Should look like this on printing:
    --5b7--------5b7r5--------5b--------5br
    
  • Tap using t
  • Natural Harmonic using *
  • Strum up/down using and

Remove Jekyll dependency

Chordy doesn't depend on jekyll at all.
It must have been added for Github pages at the time, but should be removed.

Code Organization

Someone got downvoted pretty hard on reddit for saying that your code organization needs work - that guy was right but he wasn't helpful so here's some practical tips on how you can improve your code:

  • Don't pollute the lib directory. When you call require 'fancy_gem' Ruby puts all of the gem's lib directory directly on the load path. This means that you need to respect it and not put more in there than is absolutely necessary. In your case, you need to move everything out of lib and into a new 'chordy' directory inside lib (lib/chordy/). The only thing that should stay is the file that people need in order to require your gem, e.g. chordy.rb
  • Don't pollute the global namespace. Right now when your gem is required, you include two modules in the global namespace - don't do this! Instead, use a private namespace named after your gem.
module Chordy
  class Chord
    ...
  end
end

This helps keep your class names specific to your namespace so anyone using a similar name in their app won't have issues with conflicts. This also means you have to go through all of your chord classes and update them to be nested inside a module.

  • Good grief man, 12 classes with 19 constant-returning methods each? None of those classes deserve to be classes. You never even instantiate any objects from them! All of that data is just configuration information and should be in a yml file that is read at runtime.
c_sharp: 1,2,3,4,5,6
require 'yaml'
chord_data = YAML.load(File.open('chords.yml'))

def chord_lookup(desired_chord)
  chord_data[desired_chord].split(',')
end
  • Eval is not evil but your use of it is. Eval will get you into trouble, especially the way you're using it to dynamically dispatch methods. Try Object#send instead.
  • Globals, so many globals. For things that don't change, use constants that are in your namespace. For things that can change, use instance variables. This is just another instance of polluting the global namespace - be polite to people using your code.

Cannot make ukulele chords

When I try to add a new tuning for a ukulele, I receive the error Invalid tuning; only 6,7,8 strings are allowed.

I haven't looked at the code yet to see why this is: I just tried it this morning and noticed. If I have time later, I'll dig into the code and try to add this ability myself.

Complete wiki pages

Add documentation on all the wiki pages, and add more information if available.

String Order

Why have you decided to order the guitar strings from high -> low by default? Guitar tab is conventionally low -> high.

Option for printing high E on top

An option to print high E on top and low E on the bottom of a phrase.

Edit:

The functions where direction matter are tune and play. Both should have an option to reverse to low-to-high printing.

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.