From: Jean Lazarou on
Here is a partial solution, it does not support all type of chord
symbols (see
comments in the main script).

The main script is chord_translator.rb, it contains the 'chord' API and
also
translates chords when run from the command line.
Usage: ruby chord_translator.rb {chord-symbols}

Example:
>ruby chord_translator.rb C Cdim7 Am F#+7
C => C E G
Cdim7 => C Eb Gb A
Am => A C E
F#+7 => F# A# D E

The chord_translator_test.rb file contain tests validating the currently
supported chord symbols and also presents the APIs implemented by
chord_translator.rb.

The other scripts are files for the GUI version of the tool, they use
the
current trunk version of Swiby (a layer on top of Java/Swing) and need
jRuby.
(the first two scripts can run with any Ruby interpreter)
The startup command is: jruby -I<swiby-trunk>/core/lib
chord_translator_ui.rb
(chord_translator_ui.rb contains the GUI definition and the GUI logic -
pretty
basic -, score_painter.rb paints the musical notation - staff - and
styles.rb
defines the CSS-like styles of the GUI). It uses a font to draw the
musical symbols, downloaded from
http://simplythebest.net/fonts/fonts/musical_symbols.html

The attached ZIP-file contains all the scripts and an image file
presenting a run of the GUI version.

Regards to all...

Attachments:
http://www.ruby-forum.com/attachment/4551/chord.zip

--
Posted via http://www.ruby-forum.com/.

From: Daniel Moore on
Introduction

*This summary was written by Jean Lazarou.*

This quiz has some tricky aspects; translating a chord symbol to the notes
that it comprise may be ambiguous. The rule to follow when interpreting a
chord symbol may be different from one person to another and still be
correct.

As an example take the C major chord, one may expect three notes (C, E and
G). On a guitar you can produce 6 notes, on a piano you can produce 10
notes. Would you only play three notes? Another example: Cb on the piano
results in hitting the B key. Should a chord like Ab-Cb be rendered as Ab-B?
Have a look at the thread of discussion…

Therefore, I am not considering all interpretation differences. I am not an
expert and I would probably be wrong.
Terminology

In the hope to make the summary clear, let’s first present the terminology
we use.

The ‘thing’ the solution program expects as input is a chord symbol.

The chord symbol has a specific syntax. It starts with a note name, a letter
from A to G, that we name the chord root. We can assign a pitch to the note,
a flat or a sharp. We write a flatted note by adding the lower case letter
‘b’ and a sharped by adding the ‘#’ symbol.

After the root note follows the quality and the extension, they are a
limited set of strings defining what notes to include in the produced chord
First  |  Prev  | 
Pages: 1 2 3 4 5 6
Prev: Random integer within a range?
Next: Please help!