|
UI 미디파일 악보에 띄우기 |
조: 2조 |
작성일: 2011-06-02 | |
작성자: 유미영 |
실행화면 |
|
파일 불러오기 버튼을 클릭하여 *.mid 파일을 선택한다.
|
*.mid 파일을 불러오면 해당 파일의 음악의 4분 음표의 템포(길이)가 나오고, 박자도 나온다.
또한 음 길이만큼 악보에 띄워진다.
음을 가지고 있는 enum |
enum Octaves { C0, Csharp0, D0, Dsharp0, E0, F0, Fsharp0, G0, Gsharp0, A0, Asharp0, B0, C1, Csharp1, D1, Dsharp1, E1, F1, Fsharp1, G1, Gsharp1, A1, Asharp1, B1, C2, Csharp2, D2, Dsharp2, E2, F2, Fsharp2, G2, Gsharp2, A2, Asharp2, B2, C3, Csharp3, D3, Dsharp3, E3, F3, Fsharp3, G3, Gsharp3, A3, Asharp3, B3, C4, Csharp4, D4, Dsharp4, E4, F4, Fsharp4, G4, Gsharp4, A4, Asharp4, B4, C5, Csharp5, D5, Dsharp5, E5, F5, Fsharp5, G5, Gsharp5, A5, Asharp5, B5, C6, Csharp6, D6, Dsharp6, E6, F6, Fsharp6, G6, Gsharp6, A6, Asharp6, B6, C7, Csharp7, D7, Dsharp7, E7, F7, Fsharp7, G7, Gsharp7, A7, Asharp7, B7, C8, Csharp8, D8, Dsharp8, E8, F8, Fsharp8, G8, Gsharp8, A8, Asharp8, B8, C9, Csharp9, D9, Dsharp9, E9, F9, Fsharp9, G9, Gsharp9, A9, Asharp9, B9, C10, Csharp10, D10, Dsharp10, E10, F10, Fsharp10, G10, Gsharp10, A10, Asharp10, B10 }; |
악보에 띄울 음을 가지고 있는 enum ( sharp 제외 ) |
enum Seat_Octaves { C0, D0, E0, F0, G0, A0, B0, C1, D1, E1, F1, G1, A1, B1, C2, D2, E2, F2, G2, A2, B2, C3, D3, E3, F3, G3, A3, B3, C4, D4, E4, F4, G4, A4, B4, C5, D5, E5, F5, G5, A5, B5, C6, D6, E6, F6, G6, A6, B6, C7, D7, E7, F7, G7, A7, B7, C8, D8, E8, F8, G8, A8, B8, C9, D9, E9, F9, G9, A9, B9, C10, D10, E10, F10, G10, A10, B10 }; |
음표를 가지고 있는 enum (온음표, 4분음표, 3분음표, 2분음표 …) |
enum All_Clef { WholeNote, Clef2,Clef3, Clef4, Clef8, Clef16,Clef32, WholeRest, Rest2, Rest4, Rest8, Rest16 }; |
dll 참조 |
MidiPrototype.Form1 md = new MidiPrototype.Form1(); |
파일 열기 |
private void File_Open_Click(object sender, RoutedEventArgs e) { md.OpenFile(); MessageBox.Show("파일 열기 성공", "Success"); InitSet(img); LoadMusicScore(); } |
미디 파일을 선택 하여 파일이 열리게 되면 LoadMusicScore()가 호출된다.
악보 띄우기 |
private void LoadMusicScore() { . . . quatercleflength = md.TimeDivistions; Music_Note =md.MusicNote;
for(int b = 0;b<Music_Note.Count;b++) { img = mc.MakeFourNote(); notes[img] = new Note(section, (int)Octaves.C1, rythm, word, i, Canvas_Position, string.Empty); int[] temp = Music_Note[b]; notes[img].Tone = (byte)temp[0]; if (a==mul) { notes[img].Word = word; notes[img].InWord = i; notes[img].Section = section; section++; word++; asd += 120; CreateCanvas(); notes[img].CanvasPosition = Canvas_Position; i = 1; loc = 30; word = 1; a = 0; ob = Compare_Clef(img, i, a, loc,b); a = (double)ob[0]; loc = (double)ob[1]; } else { ob = Compare_Clef(img, i, a, loc,b); a = (double)ob[0]; loc = (double)ob[1];
if (i == quatercleflength) { word++; i = 0; } } } } |
quatercleflength = md.TimeDivistions; // mid파일의 4분음표 연주 길이
Music_Note =md.MusicNote; // mid정보 (int[]타입을 가지고 있는 List로서 int[] 첫번째 값에는 음의 정보(도, 레, 미,...) 두번째 값에는 음의 길이(4분음표, 3분음표,…)를 갖고 있다.
음 비교하기 |
private Object[] Compare_Clef(Image im, int i, double a, double loc,int index) { Object[] obj = new Object[2]; int default_sum = 1; string ac = Find_Clef(index); if (ac ==All_Clefs[1]) { SetWord(i, word, loc,ac); loc += quatercleflength; a += default_sum; } else if (ac ==All_Clefs[2]) { SetWord(i, word, loc, ac); loc += quatercleflength*(1.5); a += (default_sum*1.5); } else if (ac == All_Clefs[0]) { SetWord(i, word, loc, ac); loc += quatercleflength * 4; a += (default_sum*4); } else if (ac == All_Clefs[3]) { SetWord(i, word, loc, ac); loc += quatercleflength * 2; a += (default_sum*2); } . . . obj[0] = a; obj[1] = loc; return obj; } |
미디파일의 index번째에 있는 음과 All_Clefs배열 내에 있는 음과 일치 할 경우, 그 음과 음의 길이를 함께 넘겨준다.
음 띄우기 |
private void SetWord(int inword, int index, double locationX, string ac) { Point pt = TranslatePoint(po, mystave); string tone = notes[img].Tone.ToString(); Octaves oc = (Octaves)(Enum.Parse(typeof(Octaves), tone));
oc = IsSharpClef(oc);
Seat_Octaves sco = (Seat_Octaves)Enum.Parse(typeof(Seat_Octaves),oc.ToString()); int a = ((int)oc)-42;
CompareNote(index, inword, oc); note = oc.ToString(); string path = string.Empty; int quater_length = md.TimeDivistions; if (a == 0) //도 { path = DoSet(ac); SetValueNote(path, pt, locationX, a); } else if (a >= 60) //시,도#,레#,미#,파# { path = HighClefSet(ac); SetValueNote(path, pt, locationX, a - 40); } else //레,미,파,솔,라 { path = DefaultClefSet(ac); SetValueNote(path, pt, locationX, a); } notes[img].Tone = (byte)(int)(Enum.Parse(typeof(Octaves), note)); . . . }
|
비교되어 넘어 온 음을 Octaves 내의 음과 비교하여 해당 음과 음의 길이를 비교하여, 몇 분 음표 인지 알아내고, 악보에
띄워준다.
|
- 악보에 정확하게 음이 띄워지도록 한다. (지금 테스트하는 미디파일이 복잡하여, 간단한 파일로 테스트를 먼저 할 예정이다.) - 위의 작업이 완료 되면 악보 내에서 연주가 가능하도록 구현 - .wav파일 악보에 띄워주기 |