#include #include #include #include #include #include #define N 5 //³ìÀ½Çϱⰹ¼ö typedef struct sound SOUND; typedef struct note NOTE; int MainMenu(); int RecordMenu(NOTE* nhead[]); int PlayMenu(NOTE* nhead[]); void Init(SOUND* head); //±¸Á¶Ã¼ ÃʱâÈ­ÇÏ´Â ÇÔ¼ö void Piano(SOUND* head, char name[10], char key,double frq, int id); //ÇǾƳëÀÇ À½µéÀ» Linked List·Î ¸¸µé¾îÁÖ´Â ÇÔ¼ö void Show(); //ÇÇ¾Æ³ë º¸¿©ÁÖ´Â ÇÔ¼ö SOUND* PlaythePiano(SOUND* head,int num); //¼Ò¸®³»ÁÖ´ÂÇÔ¼ö void Practice(SOUND* head); //¿¬½À¸ðµå void Recording(SOUND* head,NOTE* nhead); //³ìÀ½¸ðµå void RecordNote(NOTE* nhead, double frq, int length); void PlaytheRecord(NOTE* nhead); //³ìÀ½µè±â int TotalLength(NOTE* nhead); int InputKey (SOUND* head); //Å°ÀÔ·Â void Save(NOTE* nhead[]); //ÀúÀåÇϱâ void Load(NOTE* nhead); //ºÒ·¯¿À±â void gotoxy(int x,int y); void Effect(int id); struct sound{ char name[10]; char key; //ÇØ´ç Å°º¸µåÅ° double frq; //frequency int id; SOUND* next; }; struct note{ double frq; int push_time; //Å°´­·¶À» ½Ã clockÇÔ¼ö°ª int length; //À½ÀDZæÀÌ NOTE* next; }; int main() { int menu; int num; int i; SOUND* head; //head±¸Á¶Ã¼ Æ÷ÀÎÅÍ·Î ¼±¾ð NOTE* nhead[N]; head = (SOUND*)malloc(sizeof(SOUND)); //µ¿ÀûÇÒ´ç head->next = NULL; // equals (*head).next = NULL for(i=0; inext = NULL; } //ÇÔ¼öÈ£Ãâ -ÃʱâÈ­ÇÏ°í º¸¿©ÁÜ Init(head); while(1) { system("cls"); menu = MainMenu(); switch(menu) { case 1: Show(); Practice(head); break; case 2: num = RecordMenu(nhead); if(num==N+1) break; Show(); Recording(head,nhead[num-1]); break; case 3: num = PlayMenu(nhead); if(num==N+1) break; Show(); PlaytheRecord(nhead[num-1]); break; case 4: //for(i=0; inext = NULL; //PianoÇÔ¼ö ÀÎÀÚ·Î ¹ÞÀº °ªµéÀ» »õ·Î ¸¸µé ±¸Á¶Ã¼(newsound)¿¡ ³Ö¾îÁÜ strcpy(newsound->name,name); newsound->key = key; newsound->frq = frq; newsound->id = id; if(head->next == NULL) //Çìµå¸¸ ÀÖ´Â °æ¿ì { head->next = newsound; } else //Çìµå¿¡ ´Ù¸¥ ±¸Á¶Ã¼°¡ linkµÇ¾îÀÖ´Â °æ¿ì { while(cursor->next!=NULL) { cursor = cursor->next; } cursor->next = newsound;// } } void Show() { printf(" µµ# ·¹# ÆÄ# ¼Ö# ¶ó# \n"); printf(" (w) (e) (t) (y) (u) \n"); printf(" ¦®¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦³¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦¬¦³¦¬¦¬¦¬¦¯\n"); printf(" ¦­ ***** ***** ¦­ ***** ***** ***** ¦­ ¦­\n"); printf(" ¦­ ***** ***** ¦­ ***** ***** ***** ¦­ ¦­\n"); printf(" ¦­ ***** ***** ¦­ ***** ***** ***** ¦­ ¦­\n"); printf(" ¦­ ***** ***** ¦­ ***** ***** ***** ¦­ ¦­\n"); printf(" ¦­ ***** ***** ¦­ ***** ***** ***** ¦­ ¦­\n"); printf(" ¦­ ***** ***** ¦­ ***** ***** ***** ¦­ ¦­\n"); printf(" ¦­ ¦­ ¦­ ¦­ ¦­ ¦­ ¦­ ¦­ ¦­\n"); printf(" ¦­ ¦­ ¦­ ¦­ ¦­ ¦­ ¦­ ¦­ ¦­\n"); printf(" ¦­ ¦­ ¦­ ¦­ ¦­ ¦­ ¦­ ¦­ ¦­\n"); printf(" ¦­ µµ ¦­ ·¹ ¦­ ¹Ì ¦­ ÆÄ ¦­ ¼Ö ¦­ ¶ó ¦­ ½Ã ¦­ µµ ¦­\n"); printf(" ¦­ (a) ¦­ (s) ¦­ (d) ¦­ (f) ¦­ (g)¦­ (h) ¦­ (j) ¦­ (k) ¦­\n"); printf(" ¦±¦¬¦¬¦¬¦µ¦¬¦¬¦¬¦µ¦¬¦¬¦¬¦µ¦¬¦¬¦¬¦µ¦¬¦¬¦¬¦µ¦¬¦¬¦¬¦µ¦¬¦¬¦¬¦µ¦¬¦¬¦¬¦°\n"); /*SOUND* cursor = head; while(cursor->next != NULL) { cursor = cursor->next; printf("id : %d °èÀ̸§ : %s ÁÖÆļö : %.1lf\n",cursor->id,cursor->name,cursor->frq); } */ } SOUND* PlaythePiano(SOUND* head,int num) { SOUND* cursor = head; while(cursor->next != NULL) { cursor = cursor->next; if(cursor->id == num) // Ä¿¼­·Î id°¡ numÀÎ ±¸Á¶Ã¼¸¦ ãÀ½ break; } Beep(cursor->frq,100);// ex)Beep(523.3,1000) ->1ÃÊ°£ µµÀç»ý. return cursor; } void Practice(SOUND* head) { int num; printf("\n³¡³ª¸é ¾Æ¹« Å°³ª ÀÔ·ÂÇϼ¼¿ä"); while(1) { num = InputKey(head); if(num == -1) break; else PlaythePiano(head,num); //¼Ò¸®³»´Â ÇÔ¼ö È£Ãâ } } int RecordMenu(NOTE* nhead[]) { int i,num; int total; while(1) { for(i=0; inext = NULL; printf("\n³¡³ª¸é ¾Æ¹« Å°³ª ÀÔ·ÂÇϼ¼¿ä"); while(1) { num = InputKey(head); push_time = clock(); if(num == -1) { printf("\n³ìÀ½À̳¡³µ½À´Ï´Ù\n"); RecordNote(nhead,0, push_time); break; } else { target = PlaythePiano(head,num); RecordNote(nhead, target->frq, push_time); } } } void RecordNote(NOTE* nhead, double frq, int push_time) //»õ·Î¿î ±¸Á¶Ã¼ »ý¼º { NOTE* newnote; NOTE* cursor = nhead; newnote = (NOTE*)malloc(sizeof(NOTE)); newnote->next = NULL; newnote->frq = frq; newnote->push_time = push_time; if(nhead->next == NULL) //Çìµå¸¸ ÀÖ´Â °æ¿ì { nhead->next = newnote; } else //Çìµå¿¡ ´Ù¸¥ ±¸Á¶Ã¼°¡ linkµÇ¾îÀÖ´Â °æ¿ì { while(cursor->next!=NULL) { cursor = cursor->next; } cursor->length = push_time - cursor->push_time; cursor->next = newnote; if(newnote->frq == 0) //³ìÀ½³¡³ÂÀ»¶§ newnote->length = 0; } } int PlayMenu(NOTE* nhead[]) //³ìÀ½ ¾ÈµÇ¾îÀÖ´Â °Í ´­·¶À» ½Ã °æ°íÃß°¡! { int i,num; int total; while(1) { for(i=0; inext != NULL) { cursor = cursor->next; Effect(cursor->frq); Beep(cursor->frq,cursor->length); } */ while(cursor->next != NULL) { system("cls"); printf("\nÀç »ý Áß . . ."); if(i%3==0)printf("¢Û\n"); else if(i%3==1)printf("¢Ü\n"); else printf("¢Ý\n"); cursor = cursor->next; Beep(cursor->frq,cursor->length); i++; } } int TotalLength(NOTE* nhead) { NOTE* cursor = nhead; int total_length = 0; if(nhead->next == NULL) { total_length = 0; } else { while(cursor->next != NULL) { cursor = cursor->next; total_length += cursor->length; } } return total_length; } int InputKey (SOUND* head) { SOUND* cursor = head; char input = getch(); fflush(stdin); while(cursor->next != NULL) { cursor = cursor->next; if(input == cursor->key) { Effect(cursor->id); return cursor->id; } } return -1; } void Save(NOTE* nhead[]) { FILE* fp; NOTE* cursor; int i; cursor = nhead[0]; fp = fopen("³ìÀ½.txt","w+"); while(cursor->next != NULL) { cursor = cursor->next; fprintf(fp,"%.1lf %d ", cursor->frq, cursor->push_time); } fprintf(fp,"0 %d",cursor->push_time); //³ìÀ½ÀÌ Á¾·áµÇ¾úÀ½À» ¶æÇÔ fclose(fp); } void Load(NOTE* nhead) { FILE* fp; //NOTE* cursor = nhead; double frq; int push_time; fp = fopen("³ìÀ½.txt","r"); while(!feof(fp)) { fscanf(fp,"%lf %d",&frq,&push_time); RecordNote(nhead,frq,push_time); } fclose(fp); } void gotoxy(int x, int y) { COORD Cur; Cur.X=x; Cur.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Cur); } void Effect(int id) { switch(id){ case 1: //µµ gotoxy(4,3);printf("¡á"); gotoxy(4,4);printf("¡á"); gotoxy(4,5);printf("¡á"); gotoxy(4,6);printf("¡á"); gotoxy(4,7);printf("¡á"); gotoxy(4,8);printf("¡á"); gotoxy(4,9);printf("¡á¡á"); gotoxy(4,10);printf("¡á¡á"); gotoxy(4,11);printf("¡á¡á"); Sleep(100); gotoxy(4,3);printf(" "); gotoxy(4,4);printf(" "); gotoxy(4,5);printf(" "); gotoxy(4,6);printf(" "); gotoxy(4,7);printf(" "); gotoxy(4,8);printf(" "); gotoxy(4,9);printf(" "); gotoxy(4,10);printf(" "); gotoxy(4,11);printf(" "); gotoxy(28,16); break; case 6: //ÆÄ gotoxy(28,3);printf("¡á"); gotoxy(28,4);printf("¡á"); gotoxy(28,5);printf("¡á"); gotoxy(28,6);printf("¡á"); gotoxy(28,7);printf("¡á"); gotoxy(28,8);printf("¡á"); gotoxy(28,9);printf("¡á¡á"); gotoxy(28,10);printf("¡á¡á"); gotoxy(28,11);printf("¡á¡á"); Sleep(100); gotoxy(28,3);printf(" "); gotoxy(28,4);printf(" "); gotoxy(28,5);printf(" "); gotoxy(28,6);printf(" "); gotoxy(28,7);printf(" "); gotoxy(28,8);printf(" "); gotoxy(28,9);printf(" "); gotoxy(28,10);printf(" "); gotoxy(28,11);printf(" "); gotoxy(28,16); break; } }