Exemple #1
0
        /// <summary>
        /// Saves the current Score as a MusicXML file.
        /// </summary>
        public void save()
        {
            // Create a save dialog to get the output file path
            Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();
            if (fileName == "" || !File.Exists(fileName))
            {
                dialog.DefaultExt      = "mml";
                dialog.CheckPathExists = true;
                dialog.ValidateNames   = true;
                dialog.Filter          = "Music XML|*.mml";
                Nullable <bool> result = dialog.ShowDialog();
                if (result == false)
                {
                    throw new FileNotFoundException();
                }
                fileName = dialog.FileName;
            }

            try
            {
                // Put the staff in a part to meet MusicXML schema requirements
                Part p1 = new Part(data.FirstStaff);
                p1.Name   = "FirstPart";
                p1.PartId = "01";
                PartGroup pg1 = new PartGroup();
                p1.Group = pg1;
                data.PartGroups.Add(pg1);
                data.Parts.Add(p1);

                // Convert to MusicXML and save
                var parser    = new MusicXmlParser();
                var outputXml = parser.ParseBack(data);
                outputXml.Save(fileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not save to " + fileName + ".\n" + ex.Message);
                fileName = "";
                save();
            }
        }
Exemple #2
0
        /// <summary>
        /// Saves the current Score as a MusicXML file.
        /// PENDING PARSER IMPLEMENTATION FROM MANUFACTURA
        /// </summary>
        /// <returns></returns>
        public bool save()
        {
            var setting = data.FirstStaff.MeasureAddingRule;

            Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();
            if (fileName == "" || !File.Exists(fileName))
            {
                dialog.DefaultExt      = "mml";
                dialog.CheckPathExists = true;
                dialog.ValidateNames   = true;

                dialog.Filter = "Music Maker Score|*.mms|Music XML|*.mml";


                Nullable <bool> result = dialog.ShowDialog();
                if (result == false)
                {
                    return(false);
                }
                fileName = dialog.FileName;
            }

            if (dialog.FilterIndex == 1)    // Native binary format
            {
                //Score
                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    byte[]          outBytes;
                    using (var ms = new MemoryStream())
                    {
                        foreach (Staff s in data.Staves)
                        {
                            foreach (MusicalSymbol item in s.Elements)
                            {
                                if (item.GetType().IsSubclassOf(typeof(NoteOrRest)) || item.GetType() == typeof(Barline))
                                {
                                    bf.Serialize(ms, item);
                                }
                            }
                        }
                        bf.Serialize(ms, data);
                        outBytes = ms.ToArray();
                    }
                    using (FileStream stream = new FileStream(fileName, FileMode.Create))
                    {
                        using (BinaryWriter writer = new BinaryWriter(stream))
                        {
                            writer.Write(outBytes);
                            writer.Close();
                        }
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show("Could not save to " + fileName + ".\n" + ex.Message);
                    fileName = "";
                    save();
                }
            }
            else
            {
                try     // MusicXML format (not yet implemented in Manufactura)
                {
                    var parser    = new MusicXmlParser();
                    var outputXml = parser.ParseBack(data);
                    outputXml.Save(fileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not save to " + fileName + ".\n" + ex.Message);
                    fileName = "";
                    save();
                }
            }

            return(true);
        }