Ejemplo n.º 1
0
 public void paintByString(string strLine)
 {
     string[] theMeasures = strLine.Split(new char[] { '/' });
     for (int i = 0; i < theMeasures.Length; i++)
     {
         Measure aMeasure = TheNoteReader.CalculateMeasure(theMeasures[i]);
         if (CurrentStaffIndex == ((Page)Pages[CurrentPageIndex]).Staffs.Count)
         {
             int count = ((Page)Pages[CurrentPageIndex]).Staffs.Count;
             for (int j = 0; j < count; j++)
             {
                 ((Page)Pages[CurrentPageIndex]).AddStaff(new Staff());
             }
         }
         ((Staff)(((Page)Pages[CurrentPageIndex]).Staffs[CurrentStaffIndex])).AddMeasure(aMeasure);
         CurrentMeasureIndex++;
         aMeasure.CalcPosition();
         MusicMakerSheet.CurrentStaffPosition += Note.kNoteSpacing; // add an extra space for the measure
         //if (CurrentStaffPosition > Staff.kStaffInPixels - Note.kNoteSpacing * 7)
         //{
         CurrentStaffIndex++;
         CurrentStaffPosition = 0;
         //}
     }
 }
Ejemplo n.º 2
0
        private void OpenMenu_Click(object sender, System.EventArgs e)
        {
            try
            {
                //				openFileDialog1 = new OpenFileDialog();
//				openFileDialog1.Reset();
                //				openFileDialog1.InitialDirectory = "c:\\" ;
                //				openFileDialog1.Filter = "song files (*.song)|*.song|All files (*.*)|*.*" ;
                //				openFileDialog1.FilterIndex = 2 ;
                //				openFileDialog1.RestoreDirectory = true ;
                openFileDialog1.FileName = "*.notes";                 // do this here because it won't let me do it at design time
                if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
                {
                    FileStream   fs             = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                    StreamReader m_streamReader = new StreamReader(fs);
                    // Read to the file using StreamReader  class

                    m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);


                    // Read  each line of the stream and parse until last line is reached
                    InitializeMusic();
                    string strLine = m_streamReader.ReadLine();
                    while (strLine != null)
                    {
                        // process the next line
                        int keyIndex = strLine.IndexOf(":");
                        if (keyIndex != -1)                         // contains non-note information
                        {
                            string strKey = strLine.Substring(0, keyIndex);
                            strKey = strKey.ToLower();
                            switch (strKey)
                            {
                            case "title":
                                SongTitleString = strLine.Substring(keyIndex + 1);
                                break;

                            case "signature1":
                                TopSignature = Convert.ToInt32(strLine.Substring(keyIndex + 1), 10);
                                break;

                            case "signature2":
                                BottomSignature = Convert.ToInt32(strLine.Substring(keyIndex + 1), 10);
                                break;

                            default:
                                break;
                            }
                        }
                        else                          // read in notes
                        {
                            string[] theMeasures = strLine.Split(new char[] { '/' });
                            for (int i = 0; i < theMeasures.Length; i++)
                            {
                                Measure aMeasure = TheNoteReader.CalculateMeasure(theMeasures[i]);
                                ((Staff)(((Page)Pages[CurrentPageIndex]).Staffs[CurrentStaffIndex])).AddMeasure(aMeasure);
                                CurrentMeasureIndex++;
                                aMeasure.CalcPosition();
                                MusicMakerSheet.CurrentStaffPosition += Note.kNoteSpacing;                                 // add an extra space for the measure
                                if (CurrentStaffPosition > Staff.kStaffInPixels - Note.kNoteSpacing * 7)
                                {
                                    CurrentStaffIndex++;
                                    CurrentStaffPosition = 0;
                                }
                            }
                        }
                        strLine = m_streamReader.ReadLine();
                    }
                    // Close the stream

                    m_streamReader.Close();
                    Invalidate();
                }
            }
            catch (Exception em)
            {
                System.Windows.Forms.MessageBox.Show(em.Message.ToString());
                Invalidate();
            }
        }