public MusicKeyboard() : base() { timer1 = new Timer(); MusKey mk; BlackMusKey bmk; KeyBoardEntries ke; int[] whitePitch = { 1, 3, 5, 6, 8, 10, 12, 13, 15, 17, 18, 20, 22, 24 }; for (int k = 0; k < whitePitch.Length; k++) { int pitch = whitePitch[k]; int xPos = k * 20; mk = new MusKey(pitch, xPos, 20); ke = new KeyBoardEntries(timer1, count, xLoc, yLoc); mk.MouseDown += new MouseEventHandler(this.button1_MouseDown); mk.MouseUp += new MouseEventHandler(this.button1_MouseUp); mk.KeyDown += new KeyEventHandler(ke.button1_KeyDown); mk.KeyUp += new KeyEventHandler(ke.button1_KeyUp); this.Controls.Add(mk); } int[] blackPitch = { 2, 4, 7, 9, 11, 14, 16, 19, 21, 23 }; int[] xPosArray = { 10, 30, 70, 90, 110, 150, 170, 210, 230, 250 }; for (int k = 0; k < blackPitch.Length; k++) { int pitch = blackPitch[k]; int xPos = xPosArray[k]; bmk = new BlackMusKey(pitch, xPos, 20); bmk.MouseDown += new MouseEventHandler(this.button1_MouseDown); bmk.MouseUp += new MouseEventHandler(this.button1_MouseUp); this.Controls.Add(bmk); this.Controls[this.Controls.Count - 1].BringToFront(); } }
private void button1_MouseUp(object sender, MouseEventArgs e) { BlackMusKey bmk = new BlackMusKey(2, 1, 1); foreach (MusKey mk in this.Controls) { if (sender == mk) { if (e.Button == MouseButtons.Left) { timer1.Enabled = false; sp.Stop(); string bNoteShape = null; int duration = 0; if (count >= 11) { bNoteShape = "SemiBreve"; duration = 11; } else if (count >= 9 && count <= 10) { bNoteShape = "DotMinim"; duration = (9 + 10) / 2; } else if (count >= 7 && count <= 8) { bNoteShape = "minim"; duration = (7 + 8) / 2; } else if (count >= 4 && count <= 6) { bNoteShape = "Crotchet"; duration = (4 + 6) / 2; } else if (count >= 2 && count <= 3) { bNoteShape = "Quaver"; duration = (2 + 3) / 2; } else { bNoteShape = "SemiQuaver"; duration = 1; } if (mk.GetType() == bmk.GetType()) { bNoteShape += "Sharp"; } MusicNote mn = new MusicNote(mk.MusicNote, duration, bNoteShape); mn.Location = new Point(xLoc, yLoc); AddNote(mn); xLoc = xLoc + 40; } } } }
//enum Try { Q,W,E, R, T, Y, U, I, O, P, A, S, D, F, G, H, J, K, L, Z, X, C, V, B }; public void button1_KeyUp(object sender, KeyEventArgs e) { BlackMusKey bmk = new BlackMusKey(2, 1, 1); foreach (MusKey mk in this.Controls) { if (sender == mk) { for (int i = 1; i < 24; i++) { if (e.KeyCode == Keys.Q || e.KeyCode == Keys.W || e.KeyCode == Keys.E || e.KeyCode == Keys.R || e.KeyCode == Keys.T || e.KeyCode == Keys.Y || e.KeyCode == Keys.U || e.KeyCode == Keys.I || e.KeyCode == Keys.O || e.KeyCode == Keys.P || e.KeyCode == Keys.A || e.KeyCode == Keys.S || e.KeyCode == Keys.D || e.KeyCode == Keys.F || e.KeyCode == Keys.G || e.KeyCode == Keys.H || e.KeyCode == Keys.J || e.KeyCode == Keys.K || e.KeyCode == Keys.L || e.KeyCode == Keys.Z || e.KeyCode == Keys.X || e.KeyCode == Keys.C || e.KeyCode == Keys.V || e.KeyCode == Keys.B) { timer.Enabled = false; sp.Stop(); string bNoteShape = null; int duration = 0; if (count >= 11) { bNoteShape = "SemiBreve"; duration = 11; } else if (count >= 9 && count <= 10) { bNoteShape = "DotMinim"; duration = (9 + 10) / 2; } else if (count >= 7 && count <= 8) { bNoteShape = "minim"; duration = (7 + 8) / 2; } else if (count >= 4 && count <= 6) { bNoteShape = "Crotchet"; duration = (4 + 6) / 2; } else if (count >= 2 && count <= 3) { bNoteShape = "Quaver"; duration = (2 + 3) / 2; } else { bNoteShape = "SemiQuaver"; duration = 1; } if (mk.GetType() == bmk.GetType()) { bNoteShape += "Sharp"; } MusicNote mn = new MusicNote(mk.MusicNote, duration, bNoteShape); mn.Location = new Point(xLoc, yLoc); xLoc = xLoc + 40; } } } } }