Ejemplo n.º 1
0
        public void Save()
        {
            var xmlFileName = new FileInfo(_fileName);
              if (!xmlFileName.Exists || xmlFileName.Extension != MuseScoreApp.XMLFileExt)
              {
            return;

              }
              var outputDirectory = Settings.Default.OutputPath.Trim('\\') + "\\";
              if (!Directory.Exists(outputDirectory))
              {
            Directory.CreateDirectory(outputDirectory);
              }

              var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
              var tempDir = Directory.CreateDirectory(dir + "\\temp\\" + Guid.NewGuid());
              try
              {
            var mxmlFileName = tempDir.FullName + "\\" + xmlFileName.Name;
            File.Copy(xmlFileName.FullName, mxmlFileName);
            var mxmlDoc = new XmlDocument();
            mxmlDoc.Load(mxmlFileName);
            foreach (XmlElement creditNode in mxmlDoc.SelectNodes("//credit").Cast<XmlElement>().ToList())
            {
              // remove all existing credit nodes
              creditNode.ParentNode.RemoveChild(creditNode);
            }

            AppendCreditNode(mxmlDoc.DocumentElement, "595.238", "1626.98", "24", "center", "top", Title.Trim());
            AppendCreditNode(mxmlDoc.DocumentElement, "595.238", "1570.29", "14", "center", "top", GetSubTitleAndPattern());
            AppendCreditNode(mxmlDoc.DocumentElement, "1133.79", "1559.98", "12", "right", "top", GetComposerAndTexter());
            AppendCreditNode(mxmlDoc.DocumentElement, "1133.79", "1583.98", "10", "right", "top", GetArrangedBy());
            mxmlDoc.Save(mxmlFileName);

            var museScore = new MuseScoreApp();
            var museScoreFile = museScore.ConvertXMLtoMuseScore(mxmlFileName);

            if (museScoreFile != null && File.Exists(museScoreFile))
            {
              ProcessMuseScoreFile(museScoreFile, ArrangedByTransformer, RemoveCaptionsTransformer, PageSettingsTransformer, AutoBreakTransformer);
              var compressedMuseScoreFile = museScore.ConvertMuseScoretoCompressedMuseScore(museScoreFile);

              var targetMuseScoreFile = GetFileName(outputDirectory);

              File.Copy(compressedMuseScoreFile, targetMuseScoreFile, true);

              if (ExportPNG)
              {
            museScore.ConvertMuseScoreToPNG(compressedMuseScoreFile, targetMuseScoreFile.Replace(MuseScoreApp.CompressedMuseScoreFileExt, MuseScoreApp.PNGFileExt), 96);
              }

              if (ExportPDF)
              {
            museScore.ConvertMuseScoreToPDF(compressedMuseScoreFile, targetMuseScoreFile.Replace(MuseScoreApp.CompressedMuseScoreFileExt, MuseScoreApp.PDFFileExt));
              }

              if (ExtractVoice)
              {
            StoreVoiceOnlyVersion(tempDir, xmlFileName, museScore, GetFileVoiceName(outputDirectory));
              }

              if (!_nextMode && xmlFileName.Name.EndsWith(Pattern + MuseScoreApp.XMLFileExt))
              {
            for (int i = 1; i < 8; i++)
            {
              if (i == Pattern)
              {
                i++;
              }

              TrySaveNext(xmlFileName.FullName.Replace(Pattern + MuseScoreApp.XMLFileExt, i + MuseScoreApp.XMLFileExt), i);
            }
              }

              if (!_nextMode)
              {
            Process.Start("file://" + Path.GetDirectoryName(targetMuseScoreFile));
              }
              // WriteBatchAndXML(Path.GetDirectoryName(targetMuseScoreFile) + "\\__generate" +
              //                  (Pattern > 0 ? Pattern.ToString() : "") + ".cmd");
            }
              }
              catch (Exception ex)
              {
            throw new HandledErrorException("Fehler!",
                                        "Beim Speichern ist ein Fehler aufgetreten." + Environment.NewLine +
                                        Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
              }
              finally
              {
            tempDir.Delete(true);
              }
        }
Ejemplo n.º 2
0
        private void StoreVoiceOnlyVersion(DirectoryInfo tempDir, FileInfo xmlFileName, MuseScoreApp museScore, string targetMuseScoreVoiceFile)
        {
            if (!ExtractVoice)
              {
            return;
              }

              var mxmlVoiceOnlyFileName = tempDir.FullName + "\\" + xmlFileName.Name.Replace(MuseScoreApp.XMLFileExt, VoiceOnlySuffix + MuseScoreApp.XMLFileExt);
              File.Copy(xmlFileName.FullName, mxmlVoiceOnlyFileName);

              var mxmlVoiceDoc = new XmlDocument();
              mxmlVoiceDoc.Load(mxmlVoiceOnlyFileName);

              foreach (XmlElement creditNode in mxmlVoiceDoc.SelectNodes("//credit").Cast<XmlElement>().ToList())
              {
            // remove all existing credit nodes
            creditNode.ParentNode.RemoveChild(creditNode);
              }

              AppendCreditNode(mxmlVoiceDoc.DocumentElement, "595.238", "1626.98", "24", "center", "top", Title.Trim());
              AppendCreditNode(mxmlVoiceDoc.DocumentElement, "1133.79", "1559.98", "12", "right", "top", GetComposerAndTexter());
              mxmlVoiceDoc.Save(mxmlVoiceOnlyFileName);

              var part2Node = mxmlVoiceDoc.SelectSingleNode("//part[@id='P2']") as XmlElement;
              if (part2Node == null)
              {
            return;
              }
              part2Node.ParentNode.RemoveChild(part2Node);
              mxmlVoiceDoc.Save(mxmlVoiceOnlyFileName);

              var museScoreVoiceFile = museScore.ConvertXMLtoMuseScore(mxmlVoiceOnlyFileName);

              if (museScoreVoiceFile == null || !File.Exists(museScoreVoiceFile))
              {
            throw new HandledErrorException("Fehler!", "\"Nur Stimme\" Version konnte nicht gespeichert werden");
              }

              ProcessMuseScoreFile(museScoreVoiceFile, RemoveCaptionsTransformer, PageSettingsTransformer, AutoBreakTransformer);

              var compressedMuseScoreVoiceFile = museScore.ConvertMuseScoretoCompressedMuseScore(museScoreVoiceFile);
              File.Copy(compressedMuseScoreVoiceFile, targetMuseScoreVoiceFile, true);
              museScore.ConvertMuseScoreToPNG(compressedMuseScoreVoiceFile, targetMuseScoreVoiceFile.Replace(MuseScoreApp.CompressedMuseScoreFileExt, MuseScoreApp.PNGFileExt), 96);
        }
Ejemplo n.º 3
0
 private void ConvertMusicXMLFile()
 {
     IsBusy = true;
       BusyText = "Konvertiere Datei...";
       var task = Task.Factory.StartNew(() =>
                                    {
                                      var museScore = new MuseScoreApp();
                                      museScore.ConvertXMLtoMuseScore(CurrentDocument.FileName);
                                    });
       task.ContinueWith(resultTask =>
       {
     IsBusy = false;
       });
 }