// // --- R E S I Z E & R E L O C A T E --- // // private void ResizeBlackKeys() { //white keys resize automaticaly via control's code int blackKeyWidth, blackKeyHeight; blackKeyWidth = pianoKey1.BlackWidthKey + pianoKey2.BlackWidthLeftSide; blackKeyHeight = pianoKey1.BlackHeight; foreach (Control blackKey in pnlKeyboard.Controls) { if (blackKey is BlackPianoKey) { string blackKeyNumber = null; int i, num; WhitePianoKey leftWhiteKey = new WhitePianoKey(); WhitePianoKey rightWhiteKey = new WhitePianoKey(); //i = blackKey.Name.Length - 8; number of digits in the key number for (i = 8; i < blackKey.Name.Length; i++) { blackKeyNumber += blackKey.Name[i].ToString(); } //blackKeyNumber = blackKey.Name[blackKey.Name.Length - i].ToString(); num = Convert.ToInt32(blackKeyNumber); //detemine left and right white keys of this black key foreach (Control whiteKey in pnlKeyboard.Controls) { if (whiteKey.Name == "pianoKey" + num) { leftWhiteKey = (WhitePianoKey)whiteKey; } if (whiteKey.Name == "pianoKey" + (num + 1)) { rightWhiteKey = (WhitePianoKey)whiteKey; } } blackKey.Height = blackKeyHeight; blackKey.Width = blackKeyWidth; //black key position if (leftWhiteKey.KeyType == WhitePianoKey.PianoKeyType.Left) { blackKey.Location = new Point (rightWhiteKey.BlackPositionLeftEnd + rightWhiteKey.Location.X - blackKey.Width, 0); } else if (rightWhiteKey.KeyType == WhitePianoKey.PianoKeyType.Right) { blackKey.Location = new Point (leftWhiteKey.BlackPositionRightStart + leftWhiteKey.Location.X, 1); } else if ((leftWhiteKey.KeyType == WhitePianoKey.PianoKeyType.Middle) && (rightWhiteKey.KeyType == WhitePianoKey.PianoKeyType.Middle)) { blackKey.Location = new Point (leftWhiteKey.BlackPositionRightStart + leftWhiteKey.Location.X, 0); } } } }
private void WhiteKey_Click(object sender, EventArgs e) { if (ModifierKeys != Keys.Alt) //if alt was held dont register note { WhitePianoKey key = (WhitePianoKey)sender; int noteCode; Color noteColor; noteCode = Convert.ToInt32(key.Tag); if (key.GetColor() == Color.Gainsboro) { frmMaster.GetAllNotes().Add(noteCode, 1, timer.ElapsedMilliseconds); noteColor = frmMaster.GetAllNotes().GetColor(noteCode); key.SetColor(noteColor); frmMaster.AddNote(this, noteCode); } else { if (frmMaster.chkOverrideNotes.Checked) { frmMaster.GetAllNotes().AddAnother(noteCode, timer.ElapsedMilliseconds); } else { key.SetColor(Color.Gainsboro); frmMaster.GetAllNotes().Remove(noteCode); frmMaster.RemoveNote(this, noteCode); } } } }
private void WhiteKey_MouseDown(object sender, EventArgs e) { WhitePianoKey key = (WhitePianoKey)sender; noteValue = Note.ConvertCodeToNotation(Convert.ToInt32(key.Tag)); MidiPlayer.Play(new ProgramChange(0, 1, GeneralMidiInstruments.AcousticGrand)); MidiPlayer.Play(new NoteOn(0, 1, noteValue, 127)); timer.Reset(); timer.Start(); }