반응형

지금까지는 악기변경 따로 연주 따로 식으로 소스코드를 구현했다.

 

이번에는 연주가 될때 악기가 변할 수도 있게, 화음을 on / off 할 수있게, 음량조절 및 박자 조절

 

모두를 동시에 할 수있는 소스코드를 구현 하고자 한다.

 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
#include <stdio.h>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <mmsystem.h>
#include <process.h> // 쓰레드 이용
 
#pragma comment(lib, "winmm.lib")
#pragma pack(push,1)
 
#define CHANGE_INST 0xC0 // 악기 변주 정의
 
#define black            0
#define dark_green        2    //     BLACK,            0 : 까망                  DARK_BLUE,      1 : 어두운 파랑 
#define dark_red        4
#define dark_yellow        6    //     DARK_GREEN,    2 : 어두운 초록          DARK_SKY_BLUE,  3 : 어두운 하늘
#define dark_gray        8 
#define dark_blue        1    //     DARK_RED,      4 : 어두운 빨강          DARK_VIOLET,    5 : 어두운 보라
#define dark_sky_blue    3
#define dark_violet        5    //     DARK_YELLOW,   6 : 어두운 노랑             GRAY,             7 : 회색 
#define green            10
#define red                12     //     DARK_GRAY,     8 : 어두운 회색          BLUE,             9 : 파랑 
#define yellow            14     
#define gray            7    //     GREEN,            10 : 초록                  SKY_BLUE,         11 : 하늘 
#define blue            9
#define sky_blue        11    //     RED,            12 : 빨강                 VIOLET,         13 : 보라
#define violet            13
#define white            15    //     YELLOW,        14 : 노랑                  WHITE,             15 : 하양
 
typedef struct
{
 
    BYTE byteState;
    BYTE byteNote;
    BYTE byteVelocity;
    BYTE byteNULL;
 
}MJGRShortMidiMSG_ST;
 
typedef union  
{
    DWORD                dwMidi_Data;
    MJGRShortMidiMSG_ST  stMidi_Data;
    
}MJGRShortMidiMSG;
 
#pragma pack(pop)
 
HMIDIOUT     m_DevHandle;
MMRESULT     m_MMErrCode;
MIDIOUTCAPS  m_NowMidiOutCaps;
 
void CALLBACK MidiOutProc(HMIDIOUT MidiOut, UINT Msg, DWORD Instance, DWORD Param1, DWORD Param2)
{
}
 
void Midi_OutputError(MMRESULT mmrErrCode)
{
 
    char m_szErrMsg[128];
    midiInGetErrorText(mmrErrCode, (char *)m_szErrMsg, sizeof(m_szErrMsg));
    MessageBox(0, m_szErrMsg, "Midi Error!!!", MB_OK);
 
}
 
long Midi_GetDevID(HMIDIOUT m_DevOutHandle)
{
 
    UINT     uDeviceID;
    MMRESULT Result = midiOutGetID(m_DevOutHandle, &uDeviceID);
    
    if(Result != MMSYSERR_NOERROR)
    {
        Midi_OutputError(Result);
        return -1;
    }
 
    return (long)uDeviceID;
 
}
 
void Midi_GetDevCaps(HMIDIOUT m_DevOutHandle, MIDIOUTCAPS *Caps)
 
{
 
    long     lDeviceID;
    MMRESULT Result;
    lDeviceID=Midi_GetDevID(m_DevOutHandle);
 
    if (lDeviceID < 0return;
 
    Result = midiOutGetDevCaps((UINT)lDeviceID, Caps, sizeof(MIDIOUTCAPS));
 
    if(Result != MMSYSERR_NOERROR)
    {
 
        Midi_OutputError(Result);
 
    }
 
}
 
HMIDIOUT Midi_Open(WORD wDevsNum)
{
 
    WORD      wMaxDevNum=0;
    MMRESULT  uiMidiOpen=0;
    HMIDIOUT  m_DevHandle=NULL;
    wMaxDevNum=midiInGetNumDevs();
 
 
 
    if (wDevsNum >= wMaxDevNum)
 
    {
        wDevsNum=0;
    }
 
    
 
    uiMidiOpen = midiOutOpen(&m_DevHandle, wDevsNum,
                              (DWORD)(MidiOutProc),
                              (DWORD)NULL, CALLBACK_FUNCTION);
 
    
    if(uiMidiOpen!=MMSYSERR_NOERROR)
    {
        Midi_OutputError(uiMidiOpen);
        return NULL;
    }
 
    return m_DevHandle;
 
}
 
LRESULT Midi_Close(HMIDIOUT m_DevOutHandle)
 
{
 
    MMRESULT Result;
    Result = midiOutClose(m_DevOutHandle);
    
    if(Result!=MMSYSERR_NOERROR)
    {
 
        Midi_OutputError(Result);
        return FALSE;
 
    }
    else
    {
       m_DevOutHandle=NULL;
    }
 
    return TRUE;
 
}
 
void Midi_SendShortMsg(HMIDIOUT m_DevOutHandle, BYTE byteState, BYTE byteNote, BYTE byteValo)
{
 
    MJGRShortMidiMSG  sMsg;
    sMsg.stMidi_Data.byteVelocity = byteValo;
    sMsg.stMidi_Data.byteNote     = byteNote;
    sMsg.stMidi_Data.byteState    = byteState;
    sMsg.stMidi_Data.byteNULL     = 0;
    midiOutShortMsg(m_DevOutHandle, sMsg.dwMidi_Data);
 
}
 
void Midi_SendLongMsg(HMIDIOUT m_DevOutHandle, BYTE *lpMsg, DWORD dwMsgLength)
{
 
    MIDIHDR  m_MIDIHdr;
    MMRESULT Result;
    ZeroMemory(&m_MIDIHdr, sizeof(MIDIHDR));    
 
    m_MIDIHdr.lpData         = (char *)lpMsg;
    m_MIDIHdr.dwBufferLength = dwMsgLength;
    m_MIDIHdr.dwFlags        = 0;
 
    Result = midiOutPrepareHeader(m_DevOutHandle, &m_MIDIHdr, sizeof(MIDIHDR));
 
    if(Result != MMSYSERR_NOERROR)
    {
 
        Midi_OutputError(Result);
        return ;
 
    }
 
    Result = midiOutLongMsg(m_DevOutHandle, &m_MIDIHdr, sizeof(MIDIHDR));
 
    if(Result != MMSYSERR_NOERROR)
    {
 
        Midi_OutputError(Result);
        return ;
 
    }
 
    midiOutUnprepareHeader(m_DevOutHandle, &m_MIDIHdr, sizeof(MIDIHDR));
 
}
 
void Midi_AllChannelSoundOff(HMIDIOUT m_DevOutHandle)
{
 
    BYTE channel;
 
    for(channel=0; channel < 16; channel++)
    {
 
        Midi_SendShortMsg(m_DevOutHandle, (BYTE)(0xB0+channel), 0x780);
 
    }
 
}
void gotoxy(int x, int y)      // 좌표 보내기 gotoxy 
{
    
 
     COORD Cur;
     Cur.X=x;
     Cur.Y=y;
     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Cur);
}
void setcolor(int bgcolor, int color) // 배경,글자색
{
 
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), ((bgcolor & 0xf<<4| color);
 
}
void intro()
{
    int i;
 
        setcolor(white,black);
    for(i = 0; i < 24 ; i++)
    {
 
        printf("                                                                                                                                               ");
 
    }
    system("mode con: cols=80 lines=24"); // 화면 고정
   setcolor(white,green); printf("                                                           #####################");
   setcolor(white,green); printf("                                                          ######################");
   setcolor(white,green); printf("                                                          ####################");setcolor(dark_red,dark_red);printf("□");setcolor(white,black);
   setcolor(white,green); printf("                                                           #################");setcolor(dark_red,dark_red);printf("□□");setcolor(white,black);
   setcolor(white,green); printf("                                                              ############");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);;
   setcolor(white,green); printf("                                                                 #######");setcolor(dark_red,dark_red);printf("□□□□");setcolor(white,black);
   setcolor(white,green); printf("                                                                   #######");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
   setcolor(white,green); printf("                                                                     #####");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(white,black);
    printf("                                                                          ");setcolor(dark_red,dark_red);printf("□□□");setcolor(green,black);
    printf("                                                                          ");setcolor(green,green);printf("      ");setcolor(white,black);
    setcolor(white,black);
    gotoxy(25,6); puts("센과 치히로의 행방불명 OST");
    gotoxy(35,8); puts(" - 언제나 몇번이라도 -");
 
 
}
 
 
void print_sub(int x,int y) // 피아노 검은건반 만들어주기
{
    int i;
    for( i = 0 ; i < 6 ; i ++)
    {
        gotoxy(x,y+i);setcolor(black,black);printf("┃");
 
    }
    setcolor(white,black);
}
void print_map()
{
    int i;   
     system("cls");
    setcolor(white,black);//흰배경으로 만들어주기
    for(i = 0; i < 24 ; i++)
    {
 
        printf("                                                                                                                                               ");
 
    }
    gotoxy(0,0);
     puts("┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃");
     puts("┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃");  
     puts("┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃");  
     puts("┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃");
     puts("┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃ ┃┃┃┃ ┃ ┃┃┃┃┃┃ ┃"); 
     puts("┃ ┗┛┗┛ ┃ ┗┛┗┛┗┛ ┃ ┗┛┗┛ ┃ ┗┛┗┛┗┛ ┃ ┗┛┗┛ ┃ ┗┛┗┛┗┛ ┃ ┗┛┗┛ ┃ ┗┛┗┛┗┛ ┃ ┗┛┗┛ ┃ ┗┛┗┛┗┛ ┃");
     puts("┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃");
     puts("┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃");
     puts("┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃  ┃"); 
     puts("┗━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┻━┛");  
 
     print_sub(4,0);print_sub(8,0);print_sub(16,0);print_sub(20,0);print_sub(24,0);
     print_sub(32,0);print_sub(36,0);print_sub(44,0);print_sub(48,0);print_sub(52,0);
     print_sub(60,0);print_sub(64,0);print_sub(72,0);print_sub(76,0);print_sub(80,0);
     print_sub(88,0);print_sub(92,0);print_sub(100,0);print_sub(104,0);print_sub(108,0);
     print_sub(116,0);print_sub(120,0);print_sub(128,0);print_sub(132,0);print_sub(136,0);
gotoxy(57,11);printf("현재 악기 : 1. Acoustic Grand ");
gotoxy(57,13);printf("    화 음 : 켜짐 ");
gotoxy(57,15);printf("    음 량 : 127   ( 최소 : 0  최대 : 127 )");
gotoxy(0,20);printf("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓");
gotoxy(0,21);printf("┃악기 변경 : ←키 →키 : 1칸씩 이동 / Page Up, Page Down키 : 3칸씩 이동┃ 화음 ON / OFF : F1키           http://programbasic.tistory.com   ┃");
gotoxy(0,22);printf("┃연주 도중 종료 : Esc키                                                ┃ 음량 조절 : ↑키 ↓키                             제작자 : 가누  ┃");
gotoxy(0,23);printf("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛");
gotoxy(2,21);setcolor(white,blue);printf("악기 변경");setcolor(white,black);
gotoxy(2,22);setcolor(white,blue);printf("연주 도중 종료");setcolor(white,black);
gotoxy(75,21);setcolor(white,blue);printf("화음 ON / OFF");setcolor(white,black);
gotoxy(75,22);setcolor(white,blue);printf("음량 조절");gotoxy(10,21);setcolor(white,black);
gotoxy(106,21);setcolor(white,red);printf("http://programbasic.tistory.com");setcolor(white,black);
 
gotoxy(0,0);
}
 
void cursor(int n) // 커서 보이기 & 숨기기
{
    HANDLE hConsole;
    CONSOLE_CURSOR_INFO ConsoleCursor;
 
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 
    ConsoleCursor.bVisible = n;
    ConsoleCursor.dwSize = 1;
 
    SetConsoleCursorInfo(hConsole , &ConsoleCursor);
}
 
void find_inst(int check)
//    int inst[12] = {0, 1, 4, 5, 6, 7, 8, 14, 12, 108,0}; 
 
    if(check == 0printf("Acoustic Grand                ");
    else if(check == 1printf("Electric Piano 1         ");
    else if(check == 2printf("Electric Piano 2         ");
    else if(check == 3printf("Music Box                ");
    else if(check == 4printf("Harpsichord              ");
    else if(check == 5printf("Clav                     ");
    else if(check == 6printf("Celesta                  ");
    else if(check == 7printf("Tubular Bells            ");
    else if(check == 8printf("Marimba                  ");
    else if(check == 9printf("Kalimba                  ");
              
 
}
int note1[10000= 
{
 
6,18,22,6,18,22,    6,18,22,6,18,22,    6,18,22,17,220,25,0,    15,218,22,0,10,217,22,0,
11,218,23,0,10,218,22,0,    8,215,20,0,213,17,20,0,    6,18,22,17,220,25,0,
15,218,22,0,10,217,22,0,    11,218,23,0,10,218,22,0,    8,215,20,13,     6,18,22,6,18,22,
6,18,22,17,220,25,0,    15,18,22,10,217,22,0,    15,222,27,18,11,218,23,0,
 
8,15,23,213,17,20,25,    6,18,22,17,220,25,17,    15,18,22,10,217,22,0,
11,15,18,10,218,22,0,    11,215,20,13,6,213,18,0,    6,18,22,6,18,22,
6,18,22,17,220,25,0,    15,218,22,0,10,217,22,0,    11,218,23,0,10,218,22,0,
8,15,23,213,20,25,0,    6,18,22,17,220,25,0,    15,218,22,0,10,217,22,0,
11,218,23,0,10,218,22,0,    8,215,20,13,6,213,18,0,    6,18,22,6,18,22,    6,18,22,17,220,25,0,
 
15,18,22,10,217,22,0,    15,222,27,18,11,218,23,0,    8,15,23,213,17,20,25,
8,18,22,17,220,25,17,    15,18,22,10,217,22,0,    11,218,23,0,10,218,22,0,
11,215,20,13,    6,13,22,6,13,22,    6,18,22,6,18,22,    11,218,23,0,10,218,22,0,
11,18,27,10,218,22,0,    11,18,27,10,218,22,0,    8,215,20,13,    6,18,22,6,18,22,
 
6,213,18,218,22,222,25,225,30,30,  //  6,213,18,22,6,213,18,22,    6,213,18,218,22,222,25,225,30,230,34,    225,230,34,0,0,0,0,0,
 
};
 
            // 1  2  3  4  5  6  7   8  9 10  11 12  13  14 15 16 17    
            //도    레     미 파     솔    라    시  도     레    미
int note2[10000= 
{
    
0,0,0,0,0,0,0,0,0,0,0,406,408,    410,406,13,500,410,8,13,8,    406,403,10,500,406,5,0,5,   
3,5,406,408,1,6,408,410,    11,411,410,408,406,8,0,406,408,    410,406,13,500,410,8,13,8,
406,403,3,405,406,1,0,500,401,    3,5,406,408,1,6,408,410,    11,411,410,408,406,    6,0,0,0,0,410,411,
13,13,13,13,413,415,413,411,    10,10,10,10,410,411,410,408,    6,6,406,405,3,5,405,406,
 
8,408,410,408,410,8,0,410,411,    13,13,13,13,413,415,413,411,    10,10,10,410,411,410,408,406,405,
3,403,405,406,408,1,6,408,410,    8,500,408,408,406,6,0,0,    0,0,0,0,0,406,408,
410,406,13,500,410,8,13,8,    406,403,10,500,406,5,0,406,405,    3,5,406,408,1,6,408,410,
11,411,410,408,406,8,0,406,408,    410,406,13,500,410,8,13,8,    406,403,3,405,406,1,0,1,
3,5,406,408,1,6,408,410,    11,500,410,408,406,6,0,0,    0,0,0,0,0,410,411,    13,13,13,13,413,415,413,411,
                    
10,10,10,10,410,411,410,408,    6,6,406,405,3,5,405,406,    8,408,410,408,410,8,0,410,411,
13,13,13,13,413,415,413,411,    10,10,10,410,411,410,408,406,405,    0,403,405,406,408,1,6,408,410,
8,0,408,406,    6,0,0,0,0,0,    0,0,0,0,0,406,408,    3,5,406,408,1,6,500,405,
3,5,406,408,1,0,406,405,    3,5,406,408,1,6,408,410,    11,411,410,408,406,    6,0,0,0,0,0,
 
0,0,0,0,0,0,0,//410,411,    6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                
100
};
 
            // 1  2  3  4  5  6  7   8  9 10  11 12 13 14 15 16 17    
            //도    레     미 파     솔    라    시  도     레    미
//////////////    전역변수 저장소    /////////////////////////
    int j_1 = 0;  // 악보1 전역변수
    int j_2 = 0;  // 악보2 전역변수
    int inst[12= {0,  45,106781412108,0};
    int check = 0;
    int hwaum = 1;
    int volume = 127;
    int thread_on = 1;
//////////////////////////////////////////////////////////////
unsigned __stdcall Thread_inst(void *arg)//스레드 악기 및 키조작
{
    
        while(note2[j_2] != 100)
        {
            if(kbhit() == 1)if (getch() == 27 ) exit(0); // esc 눌렀을때 종료
 
            else if(GetKeyState(VK_PRIOR) < 0 )
            { // 악기 바꾸기, 3++
                check = check + 3;
                inst[10= inst[check];
                if(9 < check) check = 0, inst[10= 0;
                gotoxy(57,11);printf("현재 악기 : %d. ",check+1); find_inst(check);
                Midi_SendShortMsg(m_DevHandle,CHANGE_INST,inst[10],0);
               Sleep(200);
            }
            else if(GetKeyState(VK_NEXT) < 0 )
            { // 악기 바꾸기, 3--
                check = check - 3;
                inst[10= inst[check];
                if(check < 0) check = 9, inst[10= 9;
                gotoxy(57,11);printf("현재 악기 : %d. ",check+1); find_inst(check);
                Midi_SendShortMsg(m_DevHandle,CHANGE_INST,inst[10],0);
               Sleep(200);
            }
            
            else if(GetKeyState(VK_RIGHT) < 0 )
            { // 악기 바꾸기, 1++
                check = check + 1;
                inst[10= inst[check];
                if(9 < check) check = 0, inst[10= 0;
                gotoxy(57,11);printf("현재 악기 : %d. ",check+1); find_inst(check);
                Midi_SendShortMsg(m_DevHandle,CHANGE_INST,inst[10],0);
               Sleep(200);
 
               
            }
            else if(GetKeyState(VK_LEFT) < 0
            { // 악기 바꾸기, 1--
                check = check - 1;
                inst[10= inst[check];
                if(check < 0) check = 9, inst[10= 9;
                gotoxy(57,11);printf("현재 악기 : %d. ",check+1); find_inst(check);
                Midi_SendShortMsg(m_DevHandle,CHANGE_INST,inst[10],0);
               Sleep(200);
            }
            else if(GetKeyState(VK_F1) < 0 )
            { 
 
                hwaum ++;
               Sleep(200);
            }
            else if(GetKeyState(VK_DOWN) < 0 )
            {
                volume --;
                if(volume < 0)
                {
                    volume = 0;
                }
                gotoxy(61,15);printf("음 량 : %d  ",volume);
                Sleep(60);
                
            }
            else if(GetKeyState(VK_UP) < 0)
            {
                volume ++;
                if(volume > 127)
                {
                    volume = 127;
                }
                gotoxy(61,15);printf("음 량 : %d  ",volume);
                Sleep(60);
            }
            
          if(hwaum % 2 == 1 )
          {                
 
                gotoxy(61,13);printf("화 음 : 켜짐 ");
                Sleep(100);
 
 
          }
 
          else if(hwaum % 2 == 0 )
          {
 
                  gotoxy(61,13);printf("화 음 : 꺼짐 ");
                  Sleep(100);
              
          }            
 
 
        } // while(note2[j_2] != 100) 끝나는 부분
        
                 return 0// 스레드 종료
}
 
unsigned __stdcall Thread_note1(void *arg)//스레드 화음
{
        while( note2[j_2] != 100 )
        {
        
          if(hwaum % 2 == 1)
          {                
 
            if(note1[j_1] == 0)
            {
                 Midi_SendShortMsg(m_DevHandle, 0x90, (BYTE)(0x30+note1[j_1]+100+11), volume);//30+i
                Sleep(600);
                j_1++;
            }
            else if(note1[j_1] >= 200 && note1[j_1] <= 300// 동시에 같이 칠때
            {
                  Midi_SendShortMsg(m_DevHandle, 0x90, (BYTE)(0x30+note1[j_1]-200-1+11), volume);//30+i
                j_1++;
            }
            
 
            else
            {
                 Midi_SendShortMsg(m_DevHandle, 0x90, (BYTE)(0x30+note1[j_1]-1+11), volume);//30+i
                Sleep(600);
                j_1++;
            }
 
 
          }
         
          // 화음 껏을때 계속 작업
          if(hwaum % 2 == 0)
          {
 
              if(note1[j_1] == 0) { Sleep(600); j_1 ++; }
              else if(note1[j_1] >= 200 && note1[j_1] <= 300) { j_1 ++; }
              else { Sleep(600); j_1 ++; }
          
 
          }
 
        }
     return 0// 스레드 종료
                 
}
 
 
void main()
{
 
 
    int n = 0, t = 0;
 
     m_DevHandle=Midi_Open(0);
 
    if (m_DevHandle==NULL)
    {
 
        return ;
 
    }
    cursor(0); // 커서 숨김
 
 
    intro(); // 첫화면
    while(kbhit() == 0)
{
 
    if(n < 100// 깜빡이게 만든것
        {
            if(t == 0)
            {gotoxy(5,19);printf("                     << 음악 재생을 원하시면 >>\n                           << 아무키나 누르시오 >>"); t = 1;}
            n++;
            Sleep(10);
        }
        else if(n >= 100 && n <= 200)
        {
            if(t == 1)
            {gotoxy(5,19);printf("                                                \n                                                     "); t = 0;}
            
            n++;
            Sleep(10);
        }
        else 
        {
        n = 0;
        }
 
}
 
    system("mode con: cols=143 lines=24"); // 피아노 건반위해 화면 크기 조절
 
 
    print_map(); // 건반표시
    gotoxy(0,0);
 
    Midi_AllChannelSoundOff(m_DevHandle);
    Midi_SendShortMsg(m_DevHandle, 0xB07127);
 
 
 
    while(1)
    {                        
        if(thread_on == 1)
        {
           _beginthreadex(NULL, 0, Thread_inst, 00,NULL);////////////////////////스레드 시작
            _beginthreadex(NULL, 0, Thread_note1, 00,NULL);////////////////////////스레드 시작  
            thread_on = 0// 노래끝난후 또 스레드 발동될수도 있어서(발동시 잡음발생)
        }
                            
 
        while(note2[j_2] != 100)
        {
    
            if(note2[j_2] == 0// 쉼표 표현
            {
                Midi_SendShortMsg(m_DevHandle, 0x90, (BYTE)(0x30+note2[j_2]+100), volume);//30+i
                Sleep(600);
                j_2++;
            }
            else if(note2[j_2] >= 200 && note2[j_2] <= 300// 동시에 쳐야될때
            {
                Midi_SendShortMsg(m_DevHandle, 0x90, (BYTE)(0x30+note2[j_2]-200+22), volume);
                j_2++;
            }
            else if(note2[j_2] > 300 && note2[j_2] <= 400// 이어서 바로 쳐야될때1 (박자무관)
            { 
                Midi_SendShortMsg(m_DevHandle, 0x90, (BYTE)(0x30+note2[j_2]-300+22), volume);
                Sleep(30);
                j_2++;
                            
            }
            else if(note2[j_2] > 3300 && note2[j_2] <= 3400// 이어서 바로 쳐야될때2 (박자무관)
            { 
                Midi_SendShortMsg(m_DevHandle, 0x90, (BYTE)(0x30+note2[j_2]-3300+22), volume);
                Sleep(570);
                j_2++;
                
            }
            else if(note2[j_2] > 400 && note2[j_2] <= 500// 1/2박자 짜리 나올때 
            { //500은 반박 쉼표
                Midi_SendShortMsg(m_DevHandle, 0x90, (BYTE)(0x30+note2[j_2]-400+22), volume);
                Sleep(300);
                j_2++;
                                
            }
            else
            {
                Midi_SendShortMsg(m_DevHandle, 0x90, (BYTE)(0x30+note2[j_2]+22), volume); // 연주
                Sleep(600);
                j_2++;
            }
                            
        }
                            
    Sleep(600);                        
     Midi_AllChannelSoundOff(m_DevHandle); // 잔류하던 음을 모두 종료
 
    gotoxy(51,19); printf("다시 들으시겠습니까? (y / n)");
    
    if(getch() == 'y' || getch() == 'Y')
    {
        j_1 = 0;
        j_2 = 0;
        thread_on = 1;
 
    gotoxy(51,19); printf("                            "); // 다시 들으시겠습니까 지우기
            
        
    }
    else if(getch() == 'n' || getch() == 'N')
    {
        break;
    }
    
    } // while(1) 닫히는 곳
 
     Midi_Close(m_DevHandle); // 소리나던 음 및 잡음 종료     
}
 
 
 
 
 
Crocus

 

 

 

앞의 소스코드에서 첨가 되는 부분이라면,

 

Midi_SendShortMsg(m_DevHandle, 0x90, (BYTE)(0x30+note2[j_2]+22), volume); // 연주 << 이 부분의

 

volume가 첨가 되었다고 보면 된다.

 

소스코드의 핵심들은 (4)번과 비교하면 달라진 것 하나 없지만,

 

어떻게 응용하여 적용 시키느냐가 중요함을 알 수 있다.

 

또한 그래픽의 구현을 더욱 많이 해보고 싶었지만, 도트의 한계 및 필자의 그림실력 미숙으로 인해

 

그래픽 구현에서는 한없이 초라할 뿐이다...

 

=============================================

 

박자(tempo) 구현을 원한다면 Sleep( ?? );의 ??를 변수 tempo 따위로 지정

 

후 특정 키 입력시 tempo가 오르거나 내리도록 해주면 된다. (단 모든 Sleep속의 숫자 비율들이 같게 해주어야 된다.)

 

608번줄에  system("mode con: cols=143 lines=24"); // 피아노 건반위해 화면 크기 조절 << 라는 것이 있는데

 

이것은 Console의 화면을 조절 할 수 있는 것이다. (cols = 가로 lines = 세로)

 

227번줄에 void setcolor(int bgcolor, int color) // 배경,글자색 << 의 함수는

 

12번줄부터 #define를 적용시켜 다양한 곳에 배경 및 글자색을 응용 시킬 수 있다.

 

=============================================

 

반응형