Пример #1
0
 private void playAll()
 {
     foreach (string s in listBox1.Items)
     {
         Note.NoteCode noteName = (Note.NoteCode)Enum.Parse(typeof(Note.NoteCode), s.Split('-')[0]);
         Note.NoteType noteType = (Note.NoteType)Enum.Parse(typeof(Note.NoteType), s.Split('-')[1]);
         Note.Play(noteName, noteType);
     }
 }
Пример #2
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (!worker.CancellationPending)
            {
                int nonnotelines = 0;
                NoNoteLines = 0;

                foreach (string s in textBox1.Lines)
                {
                    if (s.StartsWith("#") || s == "")
                    {
                        nonnotelines++;
                        NoNoteLines++;
                    }
                }

                if (nonnotelines == textBox1.Lines.Count())
                {
                    worker.CancelAsync();
                    break;
                }

                for (int i = 0; i < textBox1.Lines.Count(); i++)
                {
                    if (worker.CancellationPending)
                    {
                        break;
                    }

                    worker.ReportProgress(i - nonnotelines);

                    if (textBox1.Lines[i] == "#STOP")
                    {
                        worker.CancelAsync();
                        break;
                    }
                    else if (textBox1.Lines[i].StartsWith("#"))
                    {
                        continue;
                    }
                    else if (textBox1.Lines[i] == "")
                    {
                        continue;
                    }

                    try
                    {
                        Note.NoteCode noteName = (Note.NoteCode)Enum.Parse(typeof(Note.NoteCode), textBox1.Lines[i].Split('-')[0]);
                        Note.NoteType noteType = (Note.NoteType)Enum.Parse(typeof(Note.NoteType), textBox1.Lines[i].Split('-')[1]);
                        Note.Play(noteName, noteType);
                    }
                    catch (ArgumentException ex)
                    {
                        string badNote = ex.ToString().Split('\'')[1];
                        MessageBox.Show("Note " + ((i + 1) - nonnotelines) + "/" + (textBox1.Lines.Count() - nonnotelines) + " '" + badNote + "' was not valid.\nMusic will stop once OK is pressed.");
                        worker.CancelAsync();
                        return;
                        //textBox1.Lines[i] += " (INVALID)";
                    }
                }
            }

            e.Cancel = true;
            return;
        }