FMCREATE.C
资源名称:泡泡龙源代码.zip [点击查看]
上传用户:junwei_58
上传日期:2007-05-15
资源大小:79k
文件大小:5k
源码类别:
其他智力游戏
开发平台:
Visual C++
- #define FMCREATE_C
- #include "fmmusic.h"
- #include "fmcreate.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <dos.h>
- //#include "vbe.h"
- char *FMfilename="fmmus001.dat";
- ///////////////////////////
- // FMload () load a fm music file from disk
- // and set a FMMusicNote pointer
- // On success return the music pointer
- // On failure return NULL
- //
- FMMusicNote *FMload(char *filename,int *len){
- FILE *fp;
- FMMusicNote tmp,*head;
- if((fp=fopen(filename,"rb"))==NULL)return 0;
- fread(&tmp,sizeof(FMMusicNote),1,fp);//read the file head
- *len=tmp.time;
- head=(FMMusicNote *)malloc(sizeof(FMMusicNote)**len);
- if(fread(head,sizeof(FMMusicNote)**len,1,fp) != 1){
- free(head);
- head=NULL;
- *len=0;
- }
- fclose(fp);
- return head;
- }
- ///////////////////////////
- // FMsave () save a fm music to file
- // with a FMMusicNote pointer
- // On success return the music length
- // On failure return 0
- //
- int FMsave(char *filename,FMMusicNote *head,int length){
- FILE* fp;
- FMMusicNote tmp;
- if((fp=fopen(filename,"wb"))==NULL)return 0;
- tmp.time=length;
- fwrite(&tmp,sizeof(FMMusicNote),1,fp);//write the file head
- if(fwrite(head,sizeof(FMMusicNote),length,fp)!=length)length=0;
- fclose(fp);
- return length;
- }
- /*
- int FMcreate(){
- char a,octave=3,k=4,str[4];
- FMMusicNote music[2000];
- int n=0,max=0;
- char notename[13]={' ','c','C','d','D','e',
- 'f','F','g','G','a','A','b',};
- directvideo=0;
- window(1,1,80,25);
- while(1){
- a=getch();
- FMSoundOFF(music[n].note,music[n].octave);
- if(a==27)break;
- if(a==','&&n>0){
- lineH((n%20)*32,(n/20)*40+120,15,0);
- n--;
- lineH((n%20)*32,(n/20)*40+120,15,15);
- continue;
- }
- if(a=='.'&&n<max){
- lineH((n%20)*32,(n/20)*40+120,15,0);
- n++;
- lineH((n%20)*32,(n/20)*40+120,15,15);
- continue;
- }
- if(a=='-'&&max>0){
- lineH((n%20)*32,(n/20)*40+120,15,0);
- max--;
- n=max;
- lineH((n%20)*32,(n/20)*40+120,15,15);
- continue;
- }
- switch(a){
- case '1':music[max].note=0;n=max++;music[n].octave=octave;music[n].time=k;break;
- case 'q':music[max].note=1;n=max++;music[n].octave=octave;music[n].time=k;break;
- case '2':music[max].note=2;n=max++;music[n].octave=octave;music[n].time=k;break;
- case 'w':music[max].note=3;n=max++;music[n].octave=octave;music[n].time=k;break;
- case '3':music[max].note=4;n=max++;music[n].octave=octave;music[n].time=k;break;
- case 'e':music[max].note=5;n=max++;music[n].octave=octave;music[n].time=k;break;
- case 'r':music[max].note=6;n=max++;music[n].octave=octave;music[n].time=k;break;
- case '5':music[max].note=7;n=max++;music[n].octave=octave;music[n].time=k;break;
- case 't':music[max].note=8;n=max++;music[n].octave=octave;music[n].time=k;break;
- case '6':music[max].note=9;n=max++;music[n].octave=octave;music[n].time=k;break;
- case 'y':music[max].note=10;n=max++;music[n].octave=octave;music[n].time=k;break;
- case '7':music[max].note=11;n=max++;music[n].octave=octave;music[n].time=k;break;
- case 'u':music[max].note=12;n=max++;music[n].octave=octave;music[n].time=k;break;
- case '8':if(music[n].note<12)music[n].note++;
- else music[n].note=0;break;
- case 'i':if(music[n].note>0)music[n].note--;
- else music[n].note=12;break;
- case '9':if(music[n].octave<7)music[n].octave++;break;
- case '0':if(music[n].octave>0)music[n].octave--;break;
- case ']':if(music[n].time<7)k=++music[n].time;break;
- case '[':if(music[n].time>0)k=--music[n].time;break;
- default:break;
- }
- sprintf(str,"%c%1d%1d",notename[music[n].note],music[n].octave,music[n].time);
- textxy((n%20)*32,(n/20)*40+100,str);
- FMSound(notetable[music[n].note],music[n].octave);
- delayFM(5);
- }
- for(n=0;n<max;n++){
- music[n].time=timetable[music[n].time];
- music[n].note=notetable[music[n].note];
- }
- return (FMsave(FMfilename,music,max)==max);
- }
- void main(){
- // FMMusicNote *head;
- int n;
- initVBEMode(0x113);
- setcolor(15);
- textxy(10,20,"1 2 3 5 6 7 8 9 0 -");
- textxy(10,40," q w e r t y u i [ ]");
- textxy(250,20,"1:wait q-u,2,3,5,6,7:tones 8,i:adjust tone 9,0:octave -:back");
- textxy(250,40,"[,]:pace(0:4 1:2 2:full 3:1/2 4:1/4 5:1/8 6:1/16 7:1/32)");
- textxy(250,60,"e.g. c34 is doe with octave 3 and 1/4 pace");
- initPiano();
- FMfilename[5]+=0;
- FMfilename[6]+=0;
- FMfilename[7]+=1;
- // FMcreate();
- music=FMload(FMfilename,&length);
- for(n=0;n<length;){
- FMSoundOFF(notetable[music[n].note],music[n].octave);
- n++;
- printf("%c %c %dt",music[n].note+'0',music[n].octave+'0',music[n].time);
- FMSound(music[n].note,music[n].octave);
- delayFM(5);
- delay(music[n].time*10);
- }
- // printf("%d",length);
- free(music);
- // returnMode();
- }*/