Script Library: 1247 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Archive version of: guitar-chords.r ... version: 1 ... notchent 3-Dec-2009

Amendment note: new script || Publicly available? Yes

REBOL [
    title: "Guitar Chords"
    date: 4-Dec-2009
    file: %guitar-chords.r
    author:  Nick Antonaccio
    purpose: {
       Create and print instant guitar chord diagram charts for songs.
       Taken from the tutorial at http://re-bol.com
    }
]

help: {
   This program creates guitar chord diagram charts for songs.  It was
   written to help students in highschool jazz band quickly play all of
   the common extended, altered, and complex chord types.  It can also
   be used to create chord charts for any other type of music (with
   simpler chords):  folk, rock, blues, pop, etc.

   To select chords for your song, click the root note (letter name:  A,
   Bb, C#, etc.), and then the sonority (major, minor, 7(#5,b9), etc.) of
   each chord.  The list of chords you've selected will be shown in the 
   text area below.  When you've added all the chords needed to play your
   song, click the "Create Chart" button.  Your browser will open, with a
   complete graphic rendering of all chords in your song.

   Two versions of each chord will be presented:  1 with the root note
   on the 6th string, and another with the root note on the 5th string.
   Chord lists can be saved and reloaded with the "Save" and "Load"
   buttons.  The rendered images and the HTML that displays them are all
   saved to the "./chords" folder (a subfolder of wherever this script is
   run).  You can rename/copy that folder to play your song later, upload
   it to a web server to share with the world, zip it up to store, etc. 

   NOTE:  When playing complex chords (jazz chords) in a band setting,
   guitarists typically SHOULD NOT PLAY THE ROOT NOTE of the chord
   (the bassist or keyboardist will play it).  In diagrams created by 
   this program, unnecessary notes are indicated by light circles, and
   required notes are indicated by dark circles.  Here are the formulas
   and fingering patters used to create chords in this program:

    6th string notes:               5th string notes:
    
    0  1  3  5  7  8  10  12        0  2  3  5  7  8  10  12
    E  F  G  A  B  C  D   E         A  B  C  D  E  F  G   A
    
    
    Root 6 interval shapes:         Root 5 interval shapes:     
    ___________                     ___________
    | | | | 4 |                     | | | | | |
    | 3 6 9 | 7                     | | | | | |
    1 | | | 5 1                     | | | | 1 4
    | | 7 3 | |                     | | 3 6 | |
    | 5 1 4 6 9                     5 1 4 | 9 5
    | | | | | |                     | | | 7 | |
    | | 9 | 7 |                     | | 5 1 3 6
    
    
    CHORD TYPE:         INTERVALS:          SYMBOLS:
    
    Major            =  1    3   (5)   7    (maj, M, triangle)
    Dominant         =  1    3   (5)  b7    ()
    Minor            =  1   b3   (5)  b7    (m, min, mi, -)
    Half Diminished  =  1   b3   b5   b7    (m7b5, circle/line)
    Diminished       =  1   b3   b5  bb7    (dim, circle)    
    Augmented        =  1    3   #5   b7    (aug, #5, +5)
    
    
    Add these intervals to the above 7th chords to create extended chords:
    
    9 (same as 2)   11 (same as 4)   13 (same as 6)   
    
    examples:   min9  =  1  b3  5  b7  9     9(+5)  =  1  3  #5  b7  9
    
    
    Here are some more common chord types:
    
    "sus"       =  change 3 to 4
    "sus2"      =  change 3 to 2
    "add9"      =  1 3 5 9  (same as "add2")
    "6"         =  1 3 5 6
    "min6, m6"  =  1 b3 5 6
    11          =  1 b7 9 11
    "/"         =  Bassist plays the note after the slash
    triad       =  1  3 5  (G,  C,  D...)
    minor triad =  1 b3 5  (Em, Am, Dm...)
    power chord =  1  5    (A5, G5, E5...)  
}

root6-shapes: [
    "." "major triad (major, no symbol)" [1 3 5 11 55 111]
    "m" "minor triad (minor, min, mi, m)" [1 b3 5 11 55 111]
    "aug" "augmented triad (aug, #5, +5)" [1 3 b6 11 111]
    "5" "power chord (5)" [1 55]
    "sus4" "sus4 (sus)" [1 4 5 11 55 111]
    "sus2" "sus2, 2" [1 99 5 11]
    "7sus4" "dominant 7 sus4 (7sus4)" [1 4 5 b7 55 11]
    "7sus2" "dominant 7 sus2 (7sus2)" [1 b7 99 5 11]
    "add9" "add9 (add2)" [1 3 5 999 55 11]
    "madd9" "minor add9 (min add9, m add9, m add2)" [1 b3 5 999 55 11]
    "6" "major 6 (maj6, ma6, 6)" [1 3 5 6 11]
    "m6" "minor 6 (min6, mi6, m6)" [1 b3 5 6 11]
    "69" "major 6/9 (6/9, add6/9)" [1 111 3 13 9]
    "maj7" "major 7 (maj7, ma7, M7, (triangle 7))" [1 3 5 7 11 55]
    "7" "dominant 7 (7)" [1 3 5 b7 11 55]
    "7(b5)" "dominant 7 flat 5, 7(b5), 7(-5)" [1 3 b5 b7 11]
    "7(+5)" "augmented, 7(#5), 7(+5)" [1 3 b6 b7 11]
    "7(b9)" "dominant 7 flat 9, 7(b9), 7(-9)" [1 3 5 b7 b9]
    "7(+9)" "dominant 7 sharp 9, 7(#9), 7(+9)" [1 111 3 b77 b33]
    "m7" "minor 7 (min7, mi7, m7, -7)" [1 b3 5 b7 11 55]
    "m7(b5)" "half diminished, min7(b5), (circle w/ line), m7(-5), -7(b5)"
        [1 b3 b5 b7 11]
    "dim7" "diminished 7, dim7, (circle) 7" [1 b3 b5 6 11]
    "maj9" "major 9 (maj9, ma9, M9, (triangle 9))" [1 3 5 7 9]
    "maj9(+11)" "major 9 sharp 11 (maj9(#11), M9(+11))" [1 3 7 9 b5]
    "9" "dominant 9 (9)" [1 3 5 b7 9 55]
    "9(+11)" "dominant 9 sharp 11 (9(#11), 9(+11))" [1 3 b7 9 b5]
    "m9" "minor 9 (min9, mi9, m9, -9)" [1 b3 5 b7 9 55]
    "11" "dominant 11 (11)" [1 b7 99 44 11]
    "maj13" "major 13 (maj13, ma13, M13, (triangle 13))" [1 3 55 7 11 13]
    "13" "dominant 13 (13)" [1 3 55 b7 11 13]
    "m13" "minor 13 (min13, mi13, m13, -13)" [1 b3 55 b7 11 13]
]
root6-map:  [
    1 20x70 11 120x70 111 60x110 3 80x90 33 40x50 b3 80x70 5 100x70
    55 40x110 b5 100x50 7 60x90 b7 60x70 9 120x110 99 80x50 6 60x50
    13 100x110 4 80x110 44 100x30 999 60x150 b77 100x130 b33 120x130
    b9 120x90 b6 100x90 b55 40x90
]
root5-shapes: [
    "." "major triad (major, no symbol)" [1 3 5 11 55]
    "m" "minor triad (minor, min, mi, m)" [1 b3 5 11 55]
    "aug" "augmented triad (aug, #5, +5)" [1 3 b6 11 b66]
    "5" "power chord (5)" [1 55]
    "sus4" "sus4 (sus)" [1 4 5 11 55]
    "sus2" "sus2, 2" [1 9 5 11 55]
    "7sus4" "dominant 7 sus4 (7sus4)" [1 4 5 b7 55]
    "7sus2" "dominant 7 sus2 (7sus2)" [1 9 5 b7 55]
    "add9" "major add9, (add9, add2)" [1 3 5 99 55]
    "madd9" "minor add9 (min add9, m add9, m add2)" [1 b3 5 99 55]
    "6" "major 6 (maj6, ma6, 6)" [1 3 55 13 11]
    "m6" "minor 6 (min6, mi6, m6)" [1 b3 55 13 11]
    "69" "major 6/9 (6/9, add6/9)" [1 33 6 9 5]
    "maj7" "major 7 (maj7, ma7, M7, (triangle 7))" [1 3 5 7 55]
    "7" "dominant 7 (7)" [1 3 5 b7 55]
    "7(b5)" "dominant 7 flat 5, 7(b5), 7(-5)" [1 33 b5 b7 111]
    "7(+5)" "augmented 7, 7(#5), 7(+5)" [1 33 b6 b7 111]
    "7(b9)" "dominant 7 flat 9, 7(b9), 7(-9)" [1 33 5 b7 b9]
    "7(+9)" "dominant 7 sharp 9, 7(#9), 7(+9)" [1 33 b7 b3]
    "m7" "minor 7 (min7, mi7, m7, -7)" [1 b3 5 b7 55]
    "m7(b5)" "half diminished, min7(b5), (circle w/ line), m7(-5), -7(b5)"
        [1 b3 b5 b7 b55]
    "dim7" "diminished 7, dim7, (circle) 7" [1 b33 b5 6 111]
    "maj9" "major 7 (maj9, ma9, M9, (triangle 9))" [1 33 5 7 9]
    "maj9(+11)" "major 9 sharp 11 (maj9(#11), M9(+11))" [1 33 b5 7 9]
    "9" "dominant 9 (9)" [1 33 5 b7 9]
    "9(+11)" "dominant 9 sharp 11 (9(#11), 9(+11))" [1 33 b5 b7 9]
    "m9" "minor 9 (min9, mi9, m9, -9)" [1 b33 5 b7 9]
    "11" "dominant 11 (11)" [1 b7 9 44 444]
    "maj13" "major 13 (maj13, ma13, M13, (triangle 13))" [1 3 55 7 13]
    "13" "dominant 13 (13)" [1 3 55 b7 13]
    "m13" "minor 13 (min13, mi13, m13, -13)" [1 b3 55 b7 13]
]
root5-map:  [
    1 40x70 11 80x110 111 100x30 3 100x110 33 60x50 b33 60x30 5 120x70
    55 60x110 b5 120x50 7 80x90 b7 80x70 9 100x70 6 80x50 13 120x110
    4 100x130 44 60x70 444 120x30 99 80x150 b3 100x90 b9 100x50 b6 120x90
    b66 60x130 b55 60x90
]
root6-notes:  [
    "e" {12} "f" {1} "f#" {2} "gb" {2} "g" {3} "g#" {4} "ab" {4}
    "a" {5} "a#" {6} "bb" {6} "b" {7} "c" {8} "c#" {9} "db" {9} "d" {10}
    "d#" {11} "eb" {11}
]
root5-notes: [
    "a" {12} "a#" {1} "bb" {1} "b" {2} "c" {3} "c#" {4} "db" {4}
    "d" {5} "d#" {6} "eb" {6} "e" {7} "f" {8} "f#" {9} "gb" {9} "g" {10}
    "g#" {11} "ab" {11}
]

f: copy []
for n 20 160 20 [append f reduce ['line (as-pair 20 n) (as-pair 120 n)]]
for n 20 120 20 [append f reduce ['line (as-pair n 20) (as-pair n 160)]]
fretboard: to-image layout/tight [box white 150x180 effect [draw f]]
spacer: to-image layout/tight [box white 20x20]

view center-face layout [
    across
    t1: text-list 60x270 data [
        "E" "F" "F#" "Gb" "G" "G#" "Ab" "A" "A#" "Bb" "B" "C" "C#" "Db"
        "D" "D#" "Eb"
    ]
    t2: text-list 330x270 data extract/index root6-shapes 3 2 [
        either empty? a/text [
            a/text: rejoin [
                copy t1/picked " "
                pick root6-shapes ((index? find root6-shapes value) - 1)
            ]
        ] [
            a/text: rejoin [
                a/text newline copy t1/picked " " 
                pick root6-shapes ((index? find root6-shapes value) - 1)
            ]
        ]
        show a
    ]
    return
    a: area
    return
    btn "Create Chart" [
        make-dir %chords
        save/bmp %./chords/spacer.bmp spacer
        html: copy "<html><body bgcolor=#ffffffff>"
        foreach [root spacer1 spacer2 type] (parse/all form a/text " ") [
            diagram: copy [image fretboard]
            diagram2: copy [image fretboard]
            root1: copy root
            foreach itvl (third find root6-shapes type) [
                either find [1 55] itvl [
                    append diagram reduce [
                        'fill-pen white 'circle (select root6-map itvl) 5
                    ]
                ] [
                    append diagram reduce [
                        'fill-pen black 'circle (select root6-map itvl) 5
                    ]
                ]
            ]
            append diagram reduce ['text (trim/all join root1 type) 20x0]
            append diagram reduce [
                'text 
                trim/all to-string (
                    select root6-notes trim/all to-string root1
                )
                130x65
            ]
            save/bmp 
                to-file trim/all rejoin [
                    %./chords/ (replace/all root1 {#} {sharp}) type ".bmp"
                ]
                to-image layout/tight [
                box white 150x180 effect [draw diagram]
            ]
            append html rejoin [
                {<img src="./} 
                trim/all rejoin [
                    replace/all copy root1 {#} {sharp} type ".bmp"
                ]
                {">}
            ]

            foreach itvl (third find root5-shapes type) [
                either find [1] itvl [
                    append diagram2 reduce [
                        'fill-pen white 'circle (select root5-map itvl) 5
                    ]
                ] [
                    append diagram2 reduce [
                        'fill-pen black 'circle (select root5-map itvl) 5
                    ]
                ]
            ]
            append diagram2 reduce ['text (trim/all join root type) 20x0]
            append diagram2 reduce [
                'text 
                trim/all to-string (
                    select root5-notes trim/all to-string root
                )
                130x65
            ]
            save/bmp 
                to-file trim/all rejoin [
                    %./chords/ (replace/all root {#} {sharp}) 
                    type "5th.bmp"
                ]
                to-image layout/tight [
                box white 150x180 effect [draw diagram2]
            ]
            append html rejoin [
                {<img src="./} (trim/all rejoin [
                    replace/all root {#} {sharp} type "5th.bmp"
                ]) {">}
                ; {<img src="./spacer.bmp">}
            ]
        ]
        append html [</body></html>]
        write %./chords/chords.html trim/auto html
        browse %./chords/chords.html 
    ]
    btn "Save" [save to-file request-file a/text]
    btn "Load" [a/text: load to-file request-file show a]
    btn "Help" [editor help]
]

quit