#include <stdio.h>

void Delay(int num)

{
	int a, b, c;
	for(a = 0;a < num;a++)
    for(b = 0;b <1000;b++)
	for(c = 0;c < 400;c++);
}
void mainmenu()
{
	clrscr();
	printf("Welcome you to come here!\n");
	printf("This is a music program!\n");
	printf("Please select!\n");
	printf("|***********************|\n");
	printf("|Simple Electronic Organ|\n");
	printf("|***********************|\n");
	printf("| 1      MUSIC1         |\n");
	printf("| 2      MUSIC2         |\n");
	printf("| 3      MUSIC3         |\n");
	printf("| 4      MUSIC4         |\n");
	printf("| 5      MUSIC5         |\n");
	printf("| 6      SCALE PLAY     |\n");
	printf("| 7      EXIT           |\n");
	printf("|***********************|\n");
	printf("| BY Shopping 2014/4/23 |\n");
	printf("|***********************|\n");
	
}
void scaleplay()
{
    char c;
	int i;
	int h;
	int m;
	int l;
	int time;
	long int tone[21][7]={
		{221,248,278,294,330,371,416},
		{441,495,556,589,661,742,833},
		{882,990,1112,1178,1322,1484,1665},
		{248,278,312,330,371,416,467},
		{495,556,624,661,742,833,935},
		{990,1112,1248,1322,1484,1665,1869},
		{131,147,165,175,196,221,248},
		{262,294,330,350,393,441,495},
		{525,589,661,700,786,882,990},
		{147,165,185,196,221,248,278},
		{294,330,371,393,441,495,556},
		{589,661,742,786,882,990,1112},
		{165,185,208,221,248,278,312},
		{330,371,416,441,495,556,624},
		{661,742,833,882,990,1112,1248},
		{175,196,221,234,262,294,330},
		{350,393,441,467,525,589,661},
		{700,786,882,935,1049,1178,1322},
		{196,221,248,262,294,330,371},
		{393,441,495,525,589,661,742},
		{786,882,990,1049,1178,1322,1484}
	};
	mainmenu();
	printf("please select tone:\n");
seltone:
	printf("1->A;2->B;3->C;4->D;5->E;6->F;7->G;\n");
	printf("or press'0'to cancle.\n");
	c=bioskey(0);
	switch(c)
	{
		case'1':l=0;m=1;h=2;
		break;
		case'2':l=3;m=4;h=5;
		break;
		case'3':l=6;m=7;h=8;
		break;
		case'4':l=9;m=10;h=11;
		break;
		case'5':l=12;m=13;h=14;
		break;
		case'6':l=15;m=16;h=17;
		break;
		case'7':l=18;m=19;h=20;
		break;
		case '0':
		mainmenu();
		printf(" What do you want to do?\n");
		printf(" Please select.\n");
		goto exit;
	default:
		printf(" Error Input!\n");
		printf(" Please select again!\n");
		goto seltone;
	}
	printf(" Please select time.\n");
seltime:
	printf(" 1->slow,2->middle,3->fast\n");
	printf(" or press '0' to cancle.\n");
	c=bioskey(0);
	if(c=='1')
		time=350;
	else if(c=='2')
		time=250;
	else if(c=='3')
		time=150;
	else if(c=='0')
	{
		mainmenu();
		printf(" What do you want to do?\n");
		goto exit;
	}
	else
	{
		printf(" Error Input.Please select again!\n");
		goto seltime;
	}
	printf(" Start to play!(Prees '0' to exit)\n");
	c=bioskey(0);
	while(1)
	{
		c=bioskey(0);
		switch(c)
		{
			case '1':
		sound(tone[m][0]);
		Delay(time);
		nosound();
		break;
		case '2':
		sound(tone[m][1]);
		Delay(time);
		nosound();
		break;
		case '3':
		sound(tone[m][2]);
		Delay(time);
		nosound();
		break;
		case '4':sound(tone[m][3]);
		Delay(time);
		nosound();
		break;
		case '5':
		sound(tone[m][4]);
		Delay(time);
		nosound();
		break;
		case '6':
		sound(tone[m][5]);
		Delay(time);
		nosound();
		break;
		case '7':
		sound(tone[m][6]);
		Delay(time);
		nosound();
		break;
		case 'q':
		sound(tone[h][0]);
		Delay(time);
		nosound();
		break;
		case 'w':
		sound(tone[h][1]);
		Delay(time);
		break;
		case 'e':
		sound(tone[h][2]);
		Delay(time);
		nosound();
		break;
		case 'r':
		sound(tone[h][3]);
		Delay(time);
		nosound();
		break;
		case 't':
		sound(tone[h][4]);
		Delay(time);
		nosound();
		break;
		case 'y':
			sound(tone[h][5]);
			Delay(time);
			nosound();
			break;
		case 'u':
			sound(tone[h][6]);
			Delay(time);
			nosound();
			break;
		case 'a':
			sound(tone[l][0]);
			Delay(time);
			nosound();
			break;
		case 's':
			sound(tone[l][1]);
			Delay(time);
			nosound();
			break;
		case 'd':
			sound(tone[l][2]);
			Delay(time);
			nosound();
			break;
		case 'f':
			sound(tone[l][3]);
			Delay(time);
			nosound();
			break;
		case 'g':
			sound(tone[l][4]);
			Delay(time);
			nosound();
			break;
		case 'h':
			sound(tone[l][5]);
			Delay(time);
			nosound();
			break;
		case 'j':
			sound(tone[l][6]);
			Delay(time);
			nosound();
			break;
		case '0':
			mainmenu();
			printf(" What do you want to do?\n");
			printf(" Please select\n");
			goto exit;
		default:
			sound(0);
			break;
			
}
}
exit:return;
}
main()
{
	int i;
	char c;
	int
		freq1[]={393,393,441,294,262,262,221,294,393,393,441,525,441,393,262,262,221,294,393,294,262,248,221,196,393,294,330,294,262,262,221,294,330,294,262,294,262,248,221,196,1};
	int
		dely1[]={200,100,100,400,200,100,100,400,200,200,150,50,100,100,200,100,100,400,200,200,200,100,100,200,200,200,100,100,200,100,100,15,50,100,100,100,100,100,100,200,100,50,50,75,25,50,50,50,50,50,50,200};
	int
		freq2[]={330,294,330,330,294,330,330,294,330,441,393,330,294,262,294,330,330,294,330,330,294,330,525,441,393,330,330,393,441,441,525,441,393,330,294,262,294,330,330,393,330,330,262,294,330,294,330,330,294,330,330,294,330,441,393,330,294,330,393,441,525,441,525,393,441,525,390,441,393,330,393,441,330,393,441,330,393,441,525,441,441,393,330,393,441,525,393,330,294,393,294,330,441,393,294,330,294,330,294,262,294,262,221,262,294,330,393,441,330,262,294,330,393,441,525,393,330,294,393,294,330,441,393,330,393,441,525,589,441,393,441,525,661,589,525,393,441,1};
	int
		dely2[]={200,200,400,200,200,400,200,200,200,200,200,200,400,200,200,400,200,200,400,200,200,200,200,200,200,400,200,200,400,200,200,400,200,200,800,200,200,400,200,200,400,200,200,800,200,200,400,200,200,400,200,200,200,200,200,200,400,200,200,300,100,300,100,200,200,200,200,200,200,200,200,800,200,200,800,200,200,200,200,200,800,800,400,400,600,200,400,400,800,400,400,600,200,400,400,800,400,200,200,800,200,200,400,400,400,400,400,400,600,200,800,400,400,600,200,400,400,800,400,400,600,200,400,400,800,400,400,400,400,400,400,800,400,400,1200,1200,1200,400,400,400,400,400,400,2400};
	int
		freq3[]={262,262,294,262,394,330,262,262,294,262,392,349,262,262,523,440,349,262,262,466,466,440,262,392,349,1};
	int
		dely3[]={100,100,200,200,200,200,200,100,100,200,200,200,200,200,100,100,200,200,200,200,200,200,100,100,200,200,200,200,200};
	int
		freq4[]={990,882,990,990,661,882,786,742,661,742,661,589,495,495,589,786,495,589,742,661,589,661,990,882,990,882,990,990,661,882,786,742,661,742,661,589,495,495,589,786,495,489,882,990,882,589,661,742,661,786,882,990,990,1178,990,786,882,661,786,990,882,786,661,589,589,661,786,882,990,1178,1322,1178,990,786,882,661,786,990,882,786,661,661,990,882,786,661,589,661,661,589,661,786,882,661,786,882,990,0,990,882,990,990,661,882,786,742,661,742,661,589,495,495,589,786,495,589,742,661,589,661,990,882,990,882,990,990,661,882,786,742,661,742,661,589,495,495,589,786,495,589,882,990,882,589,661,742,589,495,661,661,1};
	int
		dely4[]={200,200,400,200,200,600,100,100,300,100,200,200,400,200,200,400,200,200,400,200,200,600,200,400,200,200,400,200