示例#1
0
 /// <summary>
 /// Called when the mouse is moved on the control
 /// </summary>
 public void MarkMouseMove()
 {
     if (leftButtonDown)
     {
         NoteEnum newPitch = oldPitch + ((oldCursorY - Cursor.Position.Y) * 2) / MusicStaff.LineSpace;
         if (newPitch >= NoteEnum.None && newPitch <= NoteEnum.CSharp7 && newPitch != pitch)
         {
             Keyboard.MarkKeyReleased(pitch);
             Pitch = newPitch;
             Keyboard.MarkKeyPressed(pitch, false);
         }
     }
 }
示例#2
0
 /// <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
     }
 }
示例#3
0
 /// <summary>
 /// Called when a key is released
 /// </summary>
 /// <param name="e">The key that was released</param>
 protected override void OnKeyUp(KeyEventArgs e)
 {
     base.OnKeyUp(e);
     if (e.KeyCode == Keys.ControlKey)
     {
         musicKeyboard.ShowHint = false;
         musicKeyboard.Text     = "Top of piano can also be resized using mouse";
     }
     musicKeyboard.MarkKeyReleased(e.KeyCode);
 }