Beispiel #1
0
        public override void execute()
        {
            if (Piece == null)
            {
                return;
            }

            LilypondLoader lilypondLoader = new LilypondLoader();

            lilypondLoader.IsFixingBars = true;
            var piece   = lilypondLoader.LoadLilypond(LilypondText);
            var message = FileHelper.Instance.WriteFile(piece, _filter);

            if (message != null)
            {
                MessageBox.Show(message);
            }

            EventBus.Fire(new PieceSavedEvent());
        }
Beispiel #2
0
        public override void execute()
        {
            if (_fixAllBars)
            {
                try
                {
                    // Fix bars
                    LilypondLoader lilypondLoader = new LilypondLoader();
                    lilypondLoader.IsFixingBars = true;
                    Piece = lilypondLoader.LoadLilypond(LilypondText);

                    // Piece changed
                    EventBus.Fire(new PieceChangedEvent(Piece));
                }
                catch (Exception) { }
            }
            else
            {
                // Lilypond text of parts
                string begin  = LilypondText.Substring(0, SelectionStart);
                string select = LilypondText.Substring(SelectionStart, SelectionLength);
                string end    = LilypondText.Substring(SelectionStart + SelectionLength);

                // Regex
                string regexWithoutBar = "[a-gr][,']*[\\d][\\d]*[.]*[~]*";

                // Matches
                int totalNotesBeginning = Regex.Matches(begin, regexWithoutBar).Count;
                int totalNotesSelection = Regex.Matches(select, regexWithoutBar).Count;
                int totalNotesEnding    = Regex.Matches(end, regexWithoutBar).Count;

                // Fix all bars
                LilypondLoader lilypondLoader = new LilypondLoader();
                lilypondLoader.IsFixingBars = true;
                LilypondConverter lilypondConverter = new LilypondConverter();

                try
                {
                    string lilypondTextWithoutBars = LilypondText.Replace("|", " ").Replace("\n", "\n ").Replace("\n  ", "\n ");
                    Piece = lilypondLoader.LoadLilypond(lilypondTextWithoutBars);
                    string newLilypondText = lilypondConverter.Convert(Piece);

                    // Matches renewed text
                    MatchCollection matchesWithoutBar   = Regex.Matches(newLilypondText, regexWithoutBar);
                    int             firstIndexSelection = matchesWithoutBar[totalNotesBeginning].Index;
                    int             firstIndexEnding    = matchesWithoutBar[totalNotesBeginning + totalNotesSelection].Index;

                    // Selection renewed text
                    int    selectionLength  = firstIndexEnding - firstIndexSelection;
                    string newSelectionText = newLilypondText.Substring(firstIndexSelection, selectionLength);

                    // Combine old and new lilypond text
                    LilypondText   = begin + newSelectionText + end;
                    lilypondLoader = new LilypondLoader();
                    Piece          = lilypondLoader.LoadLilypond(LilypondText);

                    // Piece changed
                    EventBus.Fire(new PieceChangedEvent(Piece));
                }
                catch (Exception) { }
            }
        }