public void PreviewSong()
        {
            if (songlines != null)
            {
                Previewing = true;
                SetPreviewText("Stop Preview");
                Console.WriteLine("Scheduling notes");

                for (int i = 0; i < songlines.Length - 1; i++)
                {
                    string[] songinfo  = songlines[i].Split(' '); //[0] = Pitch, [1] = TimeStartStamp [2] = LengthOfNote
                    string[] songinfo2 = songlines[i + 1].Split(' ');
                    KeyToPlay = Convert.ToInt32(songinfo[0]) - 48;
                    Pitch pitch = (Pitch)Convert.ToInt32(songinfo[0]) + 5; //THE BROTHER JAKOB FILE IS IN THE WRONG KEY!!!!

                    //Start note and visualize
                    keyBoard[KeyToPlay].SetKeyFill(mainKeyColor);
                    canvas.Invalidate(new Rectangle(keyBoard[KeyToPlay].X, keyBoard[KeyToPlay].Y, 12 * multiplier, 42 * multiplier));
                    noteScheduler.NoteOn(pitch);
                    Thread.Sleep(Convert.ToInt32(songinfo[2]) * 3); //*3 for breathing room

                    //Stop note and visualize
                    noteScheduler.NoteOff(pitch);
                    keyBoard[KeyToPlay].Clear();
                    canvas.Invalidate(new Rectangle(keyBoard[KeyToPlay].X, keyBoard[KeyToPlay].Y, 12 * multiplier, 42 * multiplier));
                    //Let some time between notes
                    Thread.Sleep(((Convert.ToInt32(songinfo2[1]) - Convert.ToInt32(songinfo[1])) - Convert.ToInt32(songinfo[2])) * 3);
                    if (i == songlines.Length - 2)
                    {
                        KeyToPlay = Convert.ToInt32(songinfo2[0]) - 48;
                        pitch     = (Pitch)Convert.ToInt32(songinfo2[0]) + 5;

                        keyBoard[KeyToPlay].SetKeyFill(mainKeyColor);
                        canvas.Invalidate(new Rectangle(keyBoard[KeyToPlay].X, keyBoard[KeyToPlay].Y, 12 * multiplier, 42 * multiplier));
                        noteScheduler.NoteOn(pitch);
                        Thread.Sleep(Convert.ToInt32(songinfo2[2]) * 3);
                        noteScheduler.NoteOff(pitch);
                        keyBoard[KeyToPlay].Clear();
                        canvas.Invalidate(new Rectangle(keyBoard[KeyToPlay].X, keyBoard[KeyToPlay].Y, 12 * multiplier, 42 * multiplier));
                    }
                }
                SetPreviewText("Preview Song");
                Previewing = false;
            }
            else
            {
                Console.WriteLine("No songlines found");
            }

            Console.WriteLine("previewthread ended");
        }
 private void ActivateKey(int key)
 {
     if (learnHandler.Learning == true)
     {
         if (key != learnHandler.KeyToPlay)
         {
             keyBoard[key].SetKeyFill(KeyColor.RED);
         }
         else
         {
             keyBoard[key].SetKeyFill(KeyColor.GREEN);
         }
     }
     else
     {
         keyBoard[key].SetKeyFill(mainKeyColor);
     }
     noteScheduler.NoteOn(pianoKeys[key]);
     canvas.Invalidate(new Rectangle(keyBoard[key].X, keyBoard[key].Y, 12 * multiplier, 42 * multiplier));
     learnHandler.LastKeyPlayed = key;
 }