1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
#include <iostream>
#include <cmath>
#include <windows.h>
#include <cctype>
#include <conio.h>
using namespace std;
void major_scale (void);
int scale_selection (void);
int start_note_selection (void);
int chromatic_scale(void);
int main()
{
int scale_selected;
int note_selected;
cout<<".......................Scale player.........................\n";
cout<<"Press enter to continue\n";
cin.get();
int option = 1;
char choice;
do
{
cout<<"Hello do you want to play a scale? Press [Y]es to to play or press [N]o to exit the program\n";
cin>>choice;
switch(choice)
{
case 'Y':
case 'y':
if(option!=0)
{
note_selected=start_note_selection();
}
if(option!=0)
{
scale_selected=scale_selection();
}
case 'N':
case 'n':
cout<<"Ok see ya\n";
option=0;
break;
_getch();
default: cout<<"\nSorry wrong choice\n";
option=1;
}// end switch
}//end do while
while(option!=0);
cin.get();
return 0;
}
int start_note_selection (void)
{
int key;
int test=0;
int choice;
int octave;
double start_freq = 0;
double key_ref = 0;
double base_ref = 261.14;
do
{
test=0;
cout<<"Select the note you would like your scale to start with;\n\t1-C\n\t2-D\n\t3-E\n\t4-F\n\t5-G\n\t6-A\n\t7-B\n";
cin>>key;
key_ref = base_ref * pow(1.059463094359,key);
start_freq = key_ref * pow(1.059463094359,octave);
cout<<" Enter starting octave \n";
cout<<" 0 to 7 only! \n";
cin>> choice;
switch(octave)
{
case 0: octave = -48;
break;
case 1: octave = -36;
break;
case 2: octave = -24;
break;
case 3: octave = -12;
break;
case 4: octave = 0;
break;
case 5: octave = 12;
break;
case 6: octave = 24;
break;
case 7: octave = 36;
break;
default: cout<<"Error\n";
break;
if(key_ref!=1 && key_ref!=2 && key_ref!=3 && key_ref!=4 && key_ref!=5 && key_ref!=6 && key_ref!=7 && key_ref!=0)
{
cout<<"Invalid selection, try again\n";
test=1;
}
}
}
while (test==1);
}
int scale_selection(void)
{
int i;
int test=0;
int scale;
double freq;
double start_freq = 0;
int chrom_scale[12]={0,1,2,3,4,5,6,7,8,9,10,11};
int major_scale[8]={0,2,4,5,7,9,11,12};
int duration = 100;
do
{
test=0;
cout<<"Select the number corresponding to your chosen scale;\n\t1-Chromatic scale\n\t2-Major scale\n";
cin>>scale;
for (i=0, i<12, i++)
{
freq=start_freq *pow(1.059463094359,chrom_scale[i]);
cout<<"freq\n";
Beep(freq,duration);
}
for (i=0, i<8, i++)
{
freq=start_freq *pow(1.059463094359,major_scale[i]);
cout<<"freq\n";
Beep(freq,duration);
}
if(scale!=1 && scale!=2 && scale!=3 && scale!=0)
//if((scale < 1) || (scale >3)
{
cout<<"Invalid selection, try again\n";
test=1;
}
}
while (test==1);
return scale;
}
|