#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,200,600,100,100,300,100,200,200,400,200,200,400,200,200,300,100,200,200,800,1600,400,200,200,800,200,200,200,200,800,400,200,200,400,400,600,200,800,400,200,200,600,200,200,200,200,200,800,400,200,200,400,400,800,200,200,200,200,200,200,200,200,400,200,200,400,200,200,400,200,200,300,100,200,200,400,200,200,400,200,200,400,200,200,600,200,400,200,200,400,200,200,400,200,200,300,100,200,200,400,200,200,400,200,200,300,100,200,200,800,800,200,200,800,800};
int
freq5[]={416,416,416,371,416,371,416,371,371,278,278,312,330,371,330,312,248,278,416,416,416,371,416,556,495,556,495,495,371,371,416,441,495,441,416,371,416,416,556,624,556,495,416,495,416,495,371,556,495,416,371,416,371,495,556,330,556,556,556,556,624,661,624,556,624,495,416,416,556,624,556,495,416,495,441,495,556,624,556,624,495,556,416,371,495,556,330,556,556,556,556,624,661,624,556,624,495,1112,1};
int
dely5[]={200,200,200,200,400,200,200,200,400,200,200,400,200,200,300,100,800,200,200,200,200,300,100,200,200,200,200,400,200,200,400,200,200,300,100,800,200,400,200,200,300,100,800,200,200,400,200,200,300,100,800,400,200,600,400,200,200,200,200,200,400,200,200,300,100,800,200,400,200,200,300,100,800,200,200,400,200,200,400,150,50,800,400,200,600,400,200,200,200,200,200,400,200,200,300,100,800};
mainmenu();
while(1)
{
c=bioskey(0);
switch(c)
{
case'1':
printf(" Start playing!(Prees '0' to stop.)\n");
for(i=0;freq1[i]!=1;i++)
{
sound(freq1[i]);
Delay(dely1[i]);
nosound();
c=bioskey(1);
if(c=='0')
break;
}
mainmenu();
break;
case '2':
printf(" Start playing!(Prees '0' to stop.)\n");
for(i=0;freq2[i]!=1;i++)
{
sound(freq2[i]);
Delay(dely2[i]);
nosound();c=bioskey(1);
if(c=='0')
break;
}
mainmenu();
break;
case '3':
printf(" Start playing!(Prees '0' to stop.)\n");
for(i=0;freq3[i]!=1;i++)
{
sound(freq3[i]);
Delay(dely3[i]);
nosound();
c=bioskey(1);
if(c=='0')
break;
}
mainmenu();
break;
case '4':
printf(" Start playing!(Prees '0' to stop.)\n");
for(i=0;freq4[i]!=1;i++)
{
sound(freq4[i]);
Delay(dely4[i]);
nosound();
c=bioskey(1);
if(c=='0')
break;
}
mainmenu();
break;
case '5':
printf(" Start playing!(Prees '0' to stop.)\n");
for(i=0;freq5[i]!=1;i++)
{
sound(freq5[i]);
Delay(dely5[i]/1.2);
nosound();
c=bioskey(1);
if(c=='0')
break;
}
mainmenu();
break;
case '6':
scaleplay();
break;
case '0':
mainmenu();
printf(" What do you want to do?\n");
printf(" Please select.\n");
break;
case '7':
printf(" Thanks for using!");
Delay(2000);
goto exit;
default:
mainmenu();
printf(" Input Error!\n");
printf(" Please input again.\n");
break;
}
}
exit:return;
}
/*
1>d:\学习内容\vs2012\v-1\mymusice\mymusice\源.c(99): warning C4013: “kbhit”未定义;假设外部返回 int
1>d:\学习内容\vs2012\v-1\mymusice\mymusice\源.c(125): warning C4013: “sound”未定义;假设外部返回 int
1>d:\学习内容\vs2012\v-1\mymusice\mymusice\源.c(127): warning C4013: “nosound”未定义;假设外部返回 int
1>d:\学习内容\vs2012\v-1\mymusice\mymusice\源.c(35): warning C4101: “i”: 未引用的局部变量
1>d:\学习内容\vs2012\v-1\mymusice\mymusice\源.c(326): warning C4244: “函数”: 从“double”转换到“int”,可能丢失数据
1>源.obj : error LNK2019: 无法解析的外部符号 _clrscr,该符号在函数 _mainmenu 中被引用
1>源.obj : error LNK2019: 无法解析的外部符号 _bioskey,该符号在函数 _main 中被引用
1>源.obj : error LNK2019: 无法解析的外部符号 _sound,该符号在函数 _main 中被引用
1>源.obj : error LNK2019: 无法解析的外部符号 _nosound,该符号在函数 _main 中被引用
1>D:\学习内容\VS2012\V-1\mymusice\Debug\mymusice.exe : fatal error LNK1120: 4 个无法解析的外部命令
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
*/