/// <summary> /// Called when a mouse button is pressed onto the piano keyboard /// </summary> protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button == MouseButtons.Left) { Stopwatch stopwatch = Stopwatch.StartNew(); lastCursorLocation = e.Location; leftMouseDown = true; lastMouseNote = GetNoteAtPoint(e.Location); if (lastMouseNote != NoteEnum.None) { MidiPlayer.PlayNote(lastMouseNote); int silenceLength = (int)SilenceStopwatch.ElapsedMilliseconds; NoteLength restLength = Staff.ToNoteLength(silenceLength); if (restLength >= NoteLength.DemiSemiQuaver) { Staff.AddNote(NoteEnum.None, restLength); } else { MusicNote lastNote = Staff.LastNote; if (lastNote != null) { lastNote.LengthInMilliseconds += silenceLength; } } SilenceStopwatch.Restart(); currentMouseNote = Staff.AddNote(lastMouseNote, NoteLength.HemiDemiSemiQuaver); if (!pressedNotes.ContainsKey(lastMouseNote)) { pressedNotes.Add(lastMouseNote, currentMouseNote); } Staff.StartAdjustingNote(currentMouseNote, stopwatch); Invalidate(GetNoteArea(lastMouseNote), false); } } }
/// <summary> /// Called when a mouse button is pressed on the music note /// </summary> public void MarkMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { oldCursorY = Cursor.Position.Y; leftButtonDown = true; oldPitch = pitch; Keyboard.MarkKeyPressed(pitch, false); } else if (e.Button == MouseButtons.Right) { Staff.StartAdjustingNote(this, Stopwatch.StartNew()); } Highlighted = true; }