/** Guitar Scales Program
* I have been writing this program and as it has grown I wanted to
* make it more organized thus I learned about structured programming
* but I am having some trouble.I think that I have found a way that
* works. I can get the first two menus to load (select_scale &
* select_key) however as soon as they pass the int values to
* "open_scale" there is an error it must be in the way I send the
* variable data but I am not sure why or how to fix it I get no specific
* errors such as " missing ';' " there is a memory error instead I don't
* wish to post all of it (using visual studio by the way).
*
* This program presents two different menus to select a musical scale
* and then key
* (select_scale, select_key).
*
* *The rest of the code is located in open_scale.* *
* After which it searches the appropriate .txt file
* (ifstream open and seek).
* and inputs the values to an array.
* ( x[11] ).
* Then a simple 'cout' and a little display structure is all that is needed to
* output a mock-up of a guitar fretboard.
*
* Thank you in advanced for any help!
*/
#include <iostream>
#include <windows.h> //console design ex:SetConsoleTitle
#include <fstream> //if and ofstream gets txt content
#include <string> //duh
using namespace std;
int select_key_menu(void);
int select_scale_menu(void);
void open_scale(int, int);
int main()
{
SetConsoleTitle ("Guitar Scales");
int k;
int s;
//do{
s = select_scale_menu();
k = select_key_menu();
open_scale(s, k);
return 0;
//while(input_key value != 'Q' or 'q'...maybe 0 instead int not char)
}
int select_scale_menu()
{
int scale = 0;
cout << endl << "Featured Scales: \n\n"
<< "\t1. Major Scale \n"
<< "\t2. Minor Scale \n"
<< endl << "Select scale number: ";
cin >> scale;
cout << endl;
return scale;
}
int select_key_menu()
{
int key = 0;
cout << endl << "Keys: \n\n"
<< "\t 1. All"<<endl
<< "\t 2. Ab" << endl
<< "\t 3. A" << endl
<< "\t 4. Bb" << endl
<< "\t 5. B" << endl
<< "\t 6. C" << endl
<< "\t 7. Db" << endl
<< "\t 8. D" << endl
<< "\t 9. Eb" << endl
<< "\t10. E" << endl
<< "\t11. F" << endl
<< "\t12. Gb" << endl
<< "\t13. G" << endl
<< endl << "Select key number: ";
cin >> key;
return key;
}
void open_scale(int scale, int key)
{
ifstream inFile;
char notout;
string x[11];
string gs(" |--");
string gm("-|--");
string ge("-|\n");
switch(scale) {
case 1:
inFile.open("T:\\projects\\code\\major.txt");
break;
case 2:
inFile.open("T:\\projects\\code\\minor.txt");
break;
default: cout << "Error incorrect selection type\n";
}
switch(key) {
case 1:
inFile.seekg(0, ios::beg);
break;
case 2:
inFile.seekg(36, ios::beg);
break;
case 3:
inFile.seekg(72, ios::beg);
break;
case 4:
inFile.seekg(110, ios::beg);
break;
case 5:
inFile.seekg(146, ios::beg);
break;
case 6:
inFile.seekg(185, ios::beg);
break;
case 7:
inFile.seekg(221, ios::beg);
break;
case 8:
inFile.seekg(261, ios::beg);
break;
case 9:
inFile.seekg(296, ios::beg);
break;
case 10:
inFile.seekg(333, ios::beg);
break;
case 11:
inFile.seekg(369, ios::beg);
break;
case 12:
inFile.seekg(405, ios::beg);
break;
case 13:
inFile.seekg(443, ios::beg);
break;
default: cout << "Error incorrect selection type\n";
}
if (!inFile) {
cout << "Unable to open file\n";
cin >> notout;
exit(1); // terminate with error
}
else {
inFile >> x[0] // Ab
>> x[1] // A
>> x[2] // Bb
>> x[3] // B
>> x[4] // C
>> x[5] // Db
>> x[6] // D
>> x[7] // Eb
>> x[8] // E
>> x[9] // F
>> x[10]; // Gb
//>> x[11]; // G < IF I COMMENT THIS OUT EVERYTHING IS FINE??
inFile.close();
}
cout
<< endl << endl
/* E */ << x[8]
<< gs << x[9] << gm << x[10] << gm << x[11] << gm << x[0]
<< gm << x[1] << gm << x[2] << gm << x[3] << gm << x[4]
<< gm << x[5] << gm << x[6] << gm << x[7] << gm << x[8]
<< ge
/* A */ << x[3]
<< gs << x[4] << gm << x[5] << gm << x[6] << gm << x[7]
<< gm << x[8] << gm << x[9] << gm << x[10] << gm << x[11]
<< gm << x[0] << gm << x[1] << gm << x[2] << gm << x[3]
<< ge
/* D */ << x[11]
<< gs << x[0] << gm << x[1] << gm << x[2] << gm << x[3]
<< gm << x[4] << gm << x[5] << gm << x[6] << gm << x[7]
<< gm << x[8] << gm << x[9] << gm << x[10] << gm << x[11]
<< ge
/* G */ << x[6]
<< gs << x[7] << gm << x[8] << gm << x[9] << gm << x[10]
<< gm << x[11] << gm << x[0] << gm << x[1] << gm << x[2]
<< gm << x[3] << gm << x[4] << gm << x[5] << gm << x[6]
<< ge
/* B */ << x[1]
<< gs << x[2] << gm << x[3] << gm << x[4] << gm << x[5]
<< gm << x[6] << gm << x[7] << gm << x[8] << gm << x[9]
<< gm << x[10] << gm << x[11] << gm << x[0] << gm << x[1]
<< ge
/* E */ << x[8]
<< gs << x[9] << gm << x[10] << gm << x[11] << gm << x[0]
<< gm << x[1] << gm << x[2] << gm << x[3] << gm << x[4]
<< gm << x[5] << gm << x[6] << gm << x[7] << gm << x[8]
<< ge
<< endl << endl;
cout << "EXIT: ";
cin >> notout;
}