This code will determine the musical relationship between different notes based on a tonic. Includes inversions.
Inversions, intervals, music and programming.
Date Created:Sunday March 04th, 2007 09:29 PM
Date Modified:Saturday August 02nd, 2008 02:55 PM
#include <stdio.h>
void modsortarray();
void swap();
int main()
{
int inversion0[3] = {1,3,5};
int inversion1[3] = {3,5,1};
int inversion2[3] = {5,1,3};
int inversion3[3] = {5,3,1};
// 1 3 5
int makeflatIII[6] = { 0, -2, 0, -1, 0, 0};
int makeIV[6] = { 0, 0, 0, 1, 0, 2};
int makesharpV[6] = { 0, 0, 0, -1, 0, 1};
int makeVI[6] = {-1, 0, 0, 0, 0, 0};
int chord[3][2] = { {1,40}, {3,44}, {5,47} };
int i, note;
int note1, note2, note3, c_note1, c_note2, c_note3;
int orignotes[3];
int usernotes[3];
char note_name[12][6] = {
{"A"},
{"A#/Bb"},
{"B"},
{"C"},
{"C#/Db"},
{"D"},
{"D#/Eb"},
{"E"},
{"F"},
{"F#/Gb"},
{"G"},
{"G#/Ab"}
};
char intervals[25][40] = {
{"Perfect Unison"},
{"minor 2nd"},
{"Major 2nd"},
{"Augumented 2nd/minor 3rd"},
{"Major 3rd"},
{"Perfect 4th"},
{"Augumented 4th/Diminished 5th"},
{"Perfect 5th"},
{"Augumented 5th/Diminished 6th"},
{"Diminished 7th/Major 6th"},
{"minor 7th"},
{"Major 7th"},
{"Octave"},
{"minor 9th"},
{"major 9th"},
{"Augmented 9th"},
{"Major 10th"},
{"Perfect 11th"},
{"Augumented 11th"},
{"Perfect 12th"},
{"Augumented 12th"},
{"Major 13th"},
{"minor 14th"},
{"Major 14th"},
{"Perfect 15th"}
};
for (i = 0; i <3; i++)
{
note = (chord[i][1]-1)%12;
printf("%d\t%s\n\n", chord[i][1] , note_name[note] );
}
printf("Enter in 3 numbers between 1-88\n");
scanf("%d %d %d", ¬e1, ¬e2, ¬e3);
c_note1 = (note1)%12-1;
c_note2 = (note2)%12-1;
c_note3 = (note3)%12-1;
if (c_note1 < 0) c_note1 += 12;
if (c_note2 < 0) c_note2 += 12;
if (c_note3 < 0) c_note3 += 12;
printf("%d %d %d\n\n", note1, note2, note3);
usernotes[0] = c_note1+1;
usernotes[1] = c_note2+1;
usernotes[2] = c_note3+1;
orignotes[0] = note1;
orignotes[1] = note2;
orignotes[2] = note3;
modsortarray(usernotes,3);
modsortarray(orignotes,3);
printf("You Entered:\n");
for ( i = 0; i <3; i++)
{
printf("Original:%d New: %d Note:%s\n\n", orignotes[i], usernotes[i], note_name[ usernotes[i]-1 ] );
}
printf("Choose a root note: %s = 1, %s = 2, %s = 3\n",note_name[ usernotes[0]-1 ], note_name[ usernotes[1]-1 ],note_name[ usernotes[2]-1 ] );
scanf("%d", ¬e);
if (note == 1) note = usernotes[0];
if (note == 2) note = usernotes[1];
if (note == 3) note = usernotes[2];
printf("The root note %d\n",note);
note1 = ((13-note)+usernotes[0])%12;
note2 = ((13-note)+usernotes[1])%12;
note3 = ((13-note)+usernotes[2])%12;
note = ((12-note)+note)%12+1;
printf("Which now is %d\n",note);
printf("%d => %d\t%s\n%d => %d\t%s\n%d => %d\t%s\n\n", orignotes[0], note1, intervals[note1-1],orignotes[1], note2,intervals[note2-1], orignotes[2], note3, intervals[note3-1]);
return 0;
}
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
void modsortarray(int *inputarray, int size) {
int i;
int j;
for ( i = 0; i < size - 1; i++ ) {
for ( j = i + 1; j < size; j++ ) {
if ( inputarray[i]%12 > inputarray[j]%12 ) {
swap(&inputarray[i], &inputarray[j]);
}
}
}
}
Downloads:
Download: intervals.c 3 KB
Please login or Click Here to register for downloads
Intervals and inversions by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
