This site is being phased out.

Guitar Chord Calculator

From Mathematics Is A Science
Jump to navigationJump to search

Clyde Meador
Honors 396
Sarra, Saveliev
Abstract


I have grown up playing guitar. Like most people who play guitar for fun, however, I have little to no knowledge of music theory, something that is essential to truly advance. One area of music theory especially applicable to the field of guitar is chord theory. Chords are combinations of three or more notes which produce a harmonious sound. This project will build major and minor triads. As the name ‘triad’ suggests, these chords are combinations of three notes. Notes range in value by half steps between the values A and G, with the intermediate values noted as (the preceding value)# [read “sharp”] or (the succeeding value) “flat.” For example, the note between A and B may be called A# or B-flat. A major triad is formed by a root note, the major third (the note 4 semitones higher than the root note,) and the perfect fifth (the note 7 semitones higher than the root note). A minor triad is formed by a root note, the minor third (the note 3 semitones higher than the root note,) and the perfect fifth. Carrying on the previous example, an A major chord is created by using A as the root note, C (4 semitones higher), and D# (7 semitones higher.) An A minor chord is created by using A as the root note, B# (3 semitones higher), and D# (7 semitones higher). A person who knows the note values of every position on the guitar may easily create chords using this method. However, like me, many guitarists lack this knowledge, and so I propose to create a program which will perform these operations for the user. The fret board of the guitar will be mapped out into a series of combinations of two integers, like so: 6, 1. The first digit will represent the string number, a familiar concept to most guitarists as tablature, an inefficient but popular alternative to musical notation, numbers the strings in the same fashion, from one to six (one being the string highest in pitch.) The latter two digits represent the fret. Using the 6, 1 example above, we see that the selected fret is the 1st fret of the 6th string. This numerical notation is an imperceptibly slight shift from tablature and so will be familiar and easy to learn for the target audience for this program: guitarists with no knowledge of music theory. This program can then be used to create chords that are consonant with the notes the user desires. The program will work as follows: the user will input integers for his desired note. The program will then use that value to retrieve the musical value (stored in the program as a number or value in a table). Afterward, the program will prompt the user to select “major” or “minor” chord as their preferred chord type. Next, the program will use whichever chord type was selected to determine which operations to perform. It will calculate the major/minor third and perfect fifth for the selected root note and then convert these values to the same notation used for input

An example: The user selects 2, 3 (D) and selects “major.” The program calculates the major third (F) and the perfect fifth (G#). These values are then returned to the user as 3-digit values: (1,2) , (3,2). One final note: I believe I may encounter a pitfall as I create this program. Music is similar to modular arithmetic, in that after G is reached, the next higher note is an A – it wraps around. You can observe this by noting that 3,2, above, is a G# as required, but is in fact lower in pitch than the root note, D. Also, the strings of the guitar have overlapping values (for example: 3,0 = 4,4=5,9=6,14) and so I believe I may have some trouble returning the proper values. An algorithm will have to be included for selecting the proper notes: those closest in physical position to the root note, so as to be able to be pressed by the human hand.

To sum up: this program will fill an existent need, using mathematics and computer language. While the actual mathematics to be used are not exceptionally challenging, my lack of knowledge in the fields of music theory and computer programming render this task a challenging problem to be solved.

Progress Report: 9.10.07

Most of my work during the past week has been teaching myself C++. I am making much fewer basic syntax mistakes now and I am learning how to code if-then statements, which will be essential in my program. I am going to try to use modular arithmetic in the program, because the A-G system corresponds very well with mod12. However, as of right now I do not know if there is a way to code and operate modular arithmetic using C++.

Sketch of algorithm

Step 1: User inputs note value as a 2 integers, with the first integer corresponding to the string number (1-6 as in tablature) and the latter corresponding to the fret position (i.e. 0 = open string, 1 = first fret, etc.)

Step 2: The user inputs a chord type (major or minor).

Step 3: Program takes three digit integer and creates a modular arithmetic number based off of the note value (see below)

A = 0 mod12

A# = 1 mod 12

B = 2 mod 12

C = 3 mod 12

C# = 4 mod 12

D = 5 mod 12

D# = 6 mod 12

E = 7 mod 12

F = 8 mod 12

F# = 9 mod 12

G = 10 mod 12

G# = 11 mod 12

These values are simpler to perform operations with.

Step 4: Program uses chord type to perform the following operations -

If (Major) - two more components: major third and perfect fifth, 4 and 7 semitones higher, respectively. So, Major third = mod value + 4 Perfect fifth = mod value +7

If (Minor) - two more components: minor third and perfect fifth, 3 and 7 semitones higher, respectively. So, Minor third = mod value + 3 Perfect fifth = mod value + 7.

Step 5 (The tricky part) Program then uses mod values for the third and fifth to return 3 digit integer values such as inputted in the beginning. The exact methodology for this has yet to be determined

Ideally, after this part of the program has been completed a GUI will be implemented at the beginning and end (e.g. the user may click on a fret on a picture of a guitar, which will then input the integer value to the program). The note values will be returned in the same way.

Update 10 - 17 - 07

Code has been written for the following: accepting and checking input for fret and string positions for the user. A switch statement calculating the modular value of the root note. Currently, data is being processed to try and find an algorithm to pinpoint the most efficient (read: closest) notes that construct the chord. I am adding that addendum because the data I have looked at so far has informed me that there are many possible positions and permutations for the chords, so, in order to simplify matters, the closest ones will be selected.

Source Code thus far

// Chord Calculator.cpp : Defines the entry point for the console application.

/*

  • Guitar Chord Calculator Prototype*
  • by Clyde Meador *
  • Latest Update: 10.1.07 *
  • /

/* Variables

stringPos represents string, from 1 to 6 fretPos represents fret, from 0 to 12 modRoot is the root note mod12 the other mod values are self-explanatory chordType is a char value with A for major and B for minor stringP5 stringMinor stringMajor are all int values which correspond to the strings of those notes fretP5 fretMinor fretMajor are the same, but with frets.

  • /
  1. include "stdafx.h"
  2. include <iostream>
  3. include <ctype.h>

using namespace std;

/*This program will accept 2 integer values which determine a unique note position on a guitar fretboard, build a major or minor chord around that note, and return an integer value. Should there be time, a GUI will also be created*/


int _tmain(int argc, _TCHAR* argv[]) { int stringPos; int fretPos; int modRoot; int modPerfectFifth; int modMinorThird; int modMajorThird; char chordType; int stringP5; int stringMinor; int stringMajor; int fretP5; int fretMinor; int fretMajor;


cout<<"Welcome to the Guitar Chord Calculator Prototype\n"; cout<<"Please note the fret and string position you would like to build a chord around.\n"<<endl; cout<<"Enter your string, from 1 to 6 with 6 being the low E string (the thickest string)."; cin>>stringPos; if ( !(stringPos <= 6) || !(stringPos >= 1) ) cout<<"You have not entered a valid string"; else cout<<"Please enter the fret number, from 0 to 12"; cin>>fretPos; if ( !(fretPos <= 12) || !(fretPos >=0) ) cout<<"You have not entered a valid fret"; /*

The two if statements have been checked and they both function.

  • /

else switch(stringPos){ case 1: modRoot = 7 + fretPos; break; case 2: modRoot = 2 + fretPos; break; case 3: modRoot = 10 + fretPos; break; case 4: modRoot = 5 + fretPos; break; case 5: modRoot = fretPos; break; case 6: modRoot = 7 + fretPos; break;} modRoot %= 12; modMajorThird = ( (modRoot + 4) % 12 ); modMinorThird = ( (modRoot + 3) % 12 ); modPerfectFifth = ( (modRoot + 7) % 12 ); /*

The switch statement and equations both work.

*/

/*

The next part of the program must calculate the actual positions of the chord component notes: major third, minor third, and perfect fifth.

*/


cout<<"Please select A for a major chord or B for a minor chord."; cin>>chordType;


return 0; }


Code Checking Programs

Strings // proofreading 1.cpp : Defines the entry point for the console application.

/*Proofreading 2 by Clyde Meador This program verifies the efficacy of the subroutine of the Guitar Chord Calculator Prototype which identifies incorrect string values

  • /
  1. include "stdafx.h"
  2. include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[]) { int stringPos; cout<<"enter a string number, between 1 and 6 "; cin>>stringPos; if ( !(stringPos <= 6) || !(stringPos >= 1) ) cout<<"You have not entered a valid string"; else cout<<"You have entered " <<stringPos; return 0; } /* Results: this subroutine is effective: 1->1 2->2 45->incorrect

  • /

Frets

// proofreading 2.cpp : Defines the entry point for the console application.

/*Proofreading 2 by Clyde Meador This program verifies the efficacy of the subroutine of the Guitar Chord Calculator Prototype which identifies incorrect fret values

  • /
  1. include "stdafx.h"
  2. include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[]) { int fretPos; cout<<"enter a fret number, between 0 and 12 "; cin>>fretPos; if ( !(fretPos <= 12) || !(fretPos >= 0) ) cout<<"You have not entered a valid fret"; else cout<<"You have entered " <<fretPos; return 0; /* Results: 1->1 0->0 7->7 25->incorrect

So this program is effective

  • /

}

Switch Statement

// proofreading 3.cpp : Defines the entry point for the console application. //

  1. include "stdafx.h"
  2. include <iostream>

using namespace std; /* This program will check the switch subroutine of Guitar Chord Calculator prototype, which determines the value of the variable modRoot

  • /

int _tmain(int argc, _TCHAR* argv[]) { int stringPos; int fretPos; int modRoot; cout<<"Please enter string position "; cin>>stringPos; cout<<endl<<endl; cout<<"Please enter fret position "; cin>>fretPos; switch(stringPos){ case 1: modRoot = 7 + fretPos; break; case 2: modRoot = 2 + fretPos; break; case 3: modRoot = 10 + fretPos; break; case 4: modRoot = 5 + fretPos; break; case 5: modRoot = fretPos; break; case 6: modRoot = 7 + fretPos; break;} modRoot %= 12; int modMajorThird = ( (modRoot + 4) % 12 ); int modMinorThird = ( (modRoot + 3) % 12 ); int modPerfectFifth = ( (modRoot + 7) % 12 );

cout<<"Your root note is: "<<modRoot<<endl; cout<<"The perfect fifth is: "<<modPerfectFifth<<endl; cout<<"The major third is: "<<modMajorThird<<endl; cout<<"The minor third is: "<<modMinorThird<<endl;

return 0; }