/// <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; }
/// <summary> /// Called when a key is pressed /// </summary> /// <param name="e">The key that was pressed</param> protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (e.KeyCode == Keys.ControlKey) { musicKeyboard.Text = "Click on a note to delete it"; musicKeyboard.ShowHint = true; } musicKeyboard.MarkKeyPressed(e.KeyCode); }
/// <summary> /// Called when the timer has elapsed /// </summary> private void Timer_Tick(object sender, EventArgs e) { if (noteLengthCandidates.Count != 0) //if has notes whose lengths are being adjusted live { foreach (KeyValuePair <MusicNote, Stopwatch> pair in noteLengthCandidates) { pair.Key.Length = ToNoteLength(pair.Value.ElapsedMilliseconds); } } if (isPlaying) //if sequential note playback is running { if (playerNoteIndex < Notes.Count) { MusicNote currentNote = Notes[playerNoteIndex]; if (currentNoteLength.ElapsedMilliseconds >= currentNote.LengthInMilliseconds) //if current note is finished { if (playerNoteIndex < Notes.Count) //stop old note { Keyboard.MarkKeyReleased(currentNote.Pitch); currentNote.Highlighted = false; } playerNoteIndex++; if (playerNoteIndex < Notes.Count) { //play new note currentNote = Notes[playerNoteIndex]; Timer.Interval = Math.Max((int)currentNote.LengthInMilliseconds, MinimumTimerInterval); Keyboard.MarkKeyPressed(currentNote.Pitch, false); currentNoteLength.Restart(); currentNote.Highlighted = true; } else { StopPlayingNotes(); //arrived to the end of the notes } } } else { StopPlayingNotes(); } } if (!isPlaying && noteLengthCandidates.Count == 0) { Timer.Enabled = false; //nothing left to do } }