private void RemoveScoreBar(ScoreBar scoreBar, bool modifiesModel, bool recalcLayout)
 {
     if (!ScoreBars.Contains(scoreBar))
     {
         throw new ArgumentException("Invalid ScoreBar.", nameof(scoreBar));
     }
     scoreBar.MouseUp   -= ScoreBar_MouseUp;
     scoreBar.MouseDown -= ScoreBar_MouseDown;
     if (modifiesModel)
     {
         Score.RemoveBarAt(scoreBar.Bar.Index);
     }
     EditableScoreBars.Remove(scoreBar);
     BarLayer.Children.Remove(scoreBar);
     TrimScoreNotes(scoreBar, modifiesModel);
     if (recalcLayout)
     {
         UpdateBarTexts();
         RecalcEditorLayout();
     }
     if (modifiesModel)
     {
         Project.IsChanged = true;
     }
 }
        private ScoreBar AddScoreBar(ScoreBar before, bool recalculateLayout, Bar dataTemplate)
        {
            var project = Project;

            Debug.Assert(project != null, "project != null");
            var score = Score;
            var bar   = dataTemplate ?? (before == null ? score.AddBar() : score.InsertBar(before.Bar.Index));

            if (bar == null)
            {
                return(null);
            }
            var scoreBar = new ScoreBar();

            scoreBar.Bar = bar;
            if (ScoreBars.Count == 0)
            {
                scoreBar.Height = ScoreBar.DefaultHeight;
            }
            else
            {
                scoreBar.Height = ScoreBars[0].Height;
            }
            scoreBar.MouseUp   += ScoreBar_MouseUp;
            scoreBar.MouseDown += ScoreBar_MouseDown;
            if (before == null)
            {
                BarLayer.Children.Add(scoreBar);
                EditableScoreBars.Add(scoreBar);
            }
            else
            {
                BarLayer.Children.Add(scoreBar);
                EditableScoreBars.Insert(ScoreBars.IndexOf(before), scoreBar);
            }
            if (recalculateLayout)
            {
                UpdateBarTexts();
                RecalcEditorLayout();
            }
            if (dataTemplate == null)
            {
                Project.IsChanged = true;
            }
            return(scoreBar);
        }