Click here to Skip to main content
13,663,349 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 19 Sep 2012
Licenced CPOL

Chord Shape Generator

, 20 Sep 2012
Rate this:
Please Sign up or sign in to vote.
Using number systems in statistics


You may find this project useful if you're planning to create a chord chart or a complete database of chord voicings for the guitar.

The code enumerates all possible lowest position moveable chord shape combinations within the first 5 frets. The resulting shapes may then be easily slid or transposed to other frets like barre chords.

Approximately 31,000 distinct shapes are produced for a 6 string guitar while 201,811 shapes are produced for a 7 string guitar. Processing time may take about 1 to 3 minutes depending on the number of strings selected.

For now, the app still generates awkward chord shapes or wide stretches which may be impossible to press on a real instrument. Exceptional open string possibilities have been excluded from the calculation.

After all combinations have been found, the shapes are then sorted according to their intervallic structure. I've used binary numbers and decimal numbers to represent and abbreviate the intervals of conventional chord formulas. Here are a few examples:


4095 1111111111111-b2-2-b3-3-4-b5-5-#5-6-b7-7Chromatic scale
27731010110101011-x-2-x-3-4-x-5-x-6-x-7Major scale
21921000100100001-x-x-x-3-x-x-5-x-x-x-xmajor chord
2320 1001000100001-x-x-b3-x-x-x-5-x-x-x-xminor chord

Table of Upper Ranges

Fretspan5 Fretspan4 Fretspan3 Fretspan2 Fretspan1
Base6 Base5 Base4 Base3 Base2
4 string 1295 624 255 80 15
5 string 7775 3124 1023 242 31
6 string 46655 15624 4095 728 63
7 string 279935 78124 16383 2186 127

Code Excerpts

I would suggest that you download the entire .zip file which contains the supporting procedures. Here is one function I've used:

Function NumberSystemEquivalent(ByVal DecimalInput As Long, BaseNumber As Integer) As String
   Dim Exponent As Integer
   Dim Num As Long
   Num = DecimalInput
   Exponent = 0
   If Num < BaseNumber ^ Exponent Then
      Exit Do
   End If
   Exponent = Exponent + 1

   Exponent = Exponent - 1

   If Exponent < 0 Then
      Exponent = 0
   End If
   Dim y As Integer, PositionalValue As Long

   For y = Exponent To 0 Step -1
      PositionalValue = BaseNumber ^ y
      If (Num \ PositionalValue) >= 1 Then
         NumberSystemEquivalent = NumberSystemEquivalent & (Num \ PositionalValue)
         Num = Num Mod PositionalValue
      ElseIf (Num \ PositionalValue) < 1 Then
         NumberSystemEquivalent = NumberSystemEquivalent & "0"
      End If
   Next y

End Function
// The base number used by the function above varies
// depending on the fret span selected by the user:
Select Case lstFretSpan.ListIndex
   Case 0
   BaseN = 5
   Case 1
   BaseN = 6
End Select

// ... and the way the shapes are extracted can be quickly summarized in this way:

Sub ExtractChordShapes()
   Dim x As Long
   Dim ReturnValue As String
   Dim FormatResult As String
   Dim TABFormat As String, ChordNumber As Integer
   Dim ctr As Long
   Erase mChordNumber_Shape
   ctr = -1
   For x = 1 To Range 
        ReturnValue = NumberSystemEquivalent(x, BaseN)
        FormatResult = Format(ReturnValue, String(NumberofStrings, "0"))
        If InStr(FormatResult, "1") <> 0 Then // << This statement ensures that no duplicate shapes
                                              // occur and that the shapes are in the 
                                              // lowest position
           TABFormat = Replace(FormatResult, "0", "x")
           ctr = ctr + 1

           ReDim Preserve mChordNumber_Shape(ctr)

           ChordNumber = DecimalEquivalent(BinaryFormula(TABFormat))
           mChordNumber_Shape(ctr) = ChordNumber & " = " & TABFormat
        End If
   Next x
   Call Alphabetize(mChordNumber_Shape)
   txtCount.Text = ctr + 1
End Sub

Points of Interest

For the guitar tuning arrays found in the other supporting procedures not shown above: C4 would correspond to Middle C or MIDI Note Number 60.

The code contained in the zip file is already quite self-documenting in itself and a very detailed explanation of the code would make this introduction very lengthy. I've used descriptive variable declarations and labels to make it easier to visualize how the code works. This may become more apparent once you've gone through the code and if you're quite familiar with the basic VB syntax.

Feel free to make use of or alter the code in case you might have similar applications.


  • Revised: 9-20-2012


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Philippines Philippines
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionTheory Pin
ProcopioPi30-Jul-17 8:28
memberProcopioPi30-Jul-17 8:28 
QuestionWhere is the solution of this project? Pin
Menelaos Vergis19-Sep-12 22:49
memberMenelaos Vergis19-Sep-12 22:49 
AnswerRe: Where is the solution of this project? Pin
ha_asgag19-Sep-12 22:54
memberha_asgag19-Sep-12 22:54 
AnswerRe: Where is the solution of this project? Pin
ha_asgag22-Sep-12 20:22
memberha_asgag22-Sep-12 20:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06-2016 | 2.8.180810.1 | Last Updated 21 Sep 2012
Article Copyright 2012 by ha_asgag
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid