c++钢琴
代码:
#include<bits/stdc++.h>
#include <windows.h>
#define L1 261.626
#define L2 293.665
#define L3 329.629
#define L4 349.228
#define L5 391.995
#define L6 440.000
#define L7 493.883
#define M1 523.251
#define M2 587.330
#define M3 659.255
#define M4 698.456
#define M5 783.991
#define M6 880.000
#define M7 987.767
#define H1 1046.502
#define H2 1174.659
#define H3 1318.520
#define H4 1479.978
#define H5 1567.982
#define H6 1760.000
#define H7 1975.533
#define SL1 277.183
#define SL2 311.127
#define SL3 349.228
#define SL4 369.994
#define SL5 415.305
#define SL6 466.164
#define SL7 523.251
#define SM1 554.365
#define SM2 622.254
#define SM3 698.456
#define SM4 739.989
#define SM5 830.609
#define SM6 932.328
#define SM7 1046.502
#define stopspeed 100 //停留速度,越小越连贯,但可能会失音。
#define zjspeed 1000 //自检速度
#define iszj 0 //是否自检
using namespace std;
map<string,int>mu;
string zijian[35]={"L1","SL1","L2","SL2","L3","SL3","L4","SL4","L5","SL5","L6","SL6","L7","SL7","M1","SM1","M2","SM2","M3","SM3","M4","SM4","M5","SM5","M6","SM6","M7","SM7","H1","H2","H3","H4","H5","H6","H7"};
string yin;
int speed;
void setmu();
int main(){
setmu();
#if iszj == 1
printf("自检中...\n");
yin="";
speed;
for(int i=0;i<35;i++){
yin=zijian[i];
speed=zjspeed;
cout<<yin<<" "<<speed<<endl;
Beep(mu[yin],speed);
Sleep(stopspeed);
}
printf("-----自检完成-----\n");
#endif
char address[100001];
printf("曲谱规范:\n");
printf("每个音:((((可不加,如果音区是高音,那么不能加)S:升音,一个音的降音 = 这个音-1的升音,升3 = 4,升7 = 下一个音区1) + (L:低音 M:中音 H:高音) + 数字(1~7),如果以上为0,则表示休止) + (空格) + (时间,单位:毫秒)),音内没有换行、空格(除了标注的),音和音由换行、空格隔开\n曲谱最后最好要加上 (空格)end\n");
printf("请输入曲谱地址:");
cin>>address;
cout<<"-----开始播放:"<<address<<"-----"<<endl;
freopen(address,"r",stdin);
yin="";
int num=0;
while(cin>>yin&&yin!="end"){
num++;
if(!(cin>>speed)){
printf("曲谱中第%d个音没有播放时间!");
return 0;
}
else if(speed<=0){
printf("曲谱中第%d个音的播放时间太短!");
return 0;
}
cout<<yin<<" "<<speed<<endl;
if(speed<=0)continue;
if(yin=="0"){
Sleep(speed);
}
else{
Beep(mu[yin],speed);
}
Sleep(stopspeed);
}
if(num==0){
printf("-----曲谱不存在或为空!-----");
}
else{
printf("-----播放完毕-----");
}
fclose(stdin);
Sleep(3000);
return 0;
}
void setmu(){
mu["M1"]=M1;
mu["M2"]=M2;
mu["M3"]=M3;
mu["M4"]=M4;
mu["M5"]=M5;
mu["M6"]=M6;
mu["M7"]=M7;
mu["L1"]=L1;
mu["L2"]=L2;
mu["L3"]=L3;
mu["L4"]=L4;
mu["L5"]=L5;
mu["L6"]=L6;
mu["L7"]=L7;
mu["H1"]=H1;
mu["H2"]=H2;
mu["H3"]=H3;
mu["H4"]=H4;
mu["H5"]=H5;
mu["H6"]=H6;
mu["H7"]=H7;
mu["SM1"]=SM1;
mu["SM2"]=SM2;
mu["SM3"]=SM3;
mu["SM4"]=SM4;
mu["SM5"]=SM5;
mu["SM6"]=SM6;
mu["SM7"]=SM7;
mu["SL1"]=SL1;
mu["SL2"]=SL2;
mu["SL3"]=SL3;
mu["SL4"]=SL4;
mu["SL5"]=SL5;
mu["SL6"]=SL6;
mu["SL7"]=SL7;
}
测试数据(需要保存下来,输入地址):
M1 500 M1 500
M5 500 M5 500
M6 500 M6 500
M5 1000
M4 500 M4 500
M3 500 M3 500
M2 500 M2 500
M1 1000
M5 500 M5 500
M4 500 M4 500
M3 500 M3 500
M2 1000
M5 500 M5 500
M4 500 M4 500
M3 500 M3 500
M2 1000
M1 500 M1 500
M5 500 M5 500
M6 500 M6 500
M5 1000
M4 500 M4 500
M3 500 M3 500
M2 500 M2 500
M1 1000
end
示范:
© \ \LARGE\color{red}{本}^{\huge\color{#ff9900}{文}\large\color{black}\text{zto}}_{\ \ \color{#ffe000}{由}}\color{#50e000}{\Huge{汪}}\color{#00d0f0}{\Huge{嘉}}\color{#00a0ff}{\Huge{乐}}^{\color{blue}{巨}^{\color{blue}{巨}^{\color{blue}{巨}^{\color{blue}{佬}}}}}_{\large\color{black}\text{orz}\Huge\color{#a000ff}{原}\color{#ff00ff}{创}}\\