private ScoreNote AddScoreNote(ScoreBar scoreBar, int row, int column, Note dataTemplate)
        {
            if (row < 0 || column < 0 || column >= 5)
            {
                return(null);
            }
            var gridCount = scoreBar.Bar.TotalGridCount;

            if (row >= gridCount)
            {
                return(null);
            }
            var bar       = scoreBar.Bar;
            var scoreNote = AnyNoteExistOnPosition(bar.Index, column, row);

            if (scoreNote != null)
            {
                return(null);
            }
            var barHeight = ScoreBars[0].Height;
            var baseY     = -MinimumScrollOffset + bar.Index * barHeight;
            var extraY    = barHeight * row / bar.TotalGridCount;

            scoreNote = new ScoreNote();
            Note note;

            if (dataTemplate != null)
            {
                note = dataTemplate;
            }
            else
            {
                note = bar.AddNote();
                note.StartPosition = note.FinishPosition = (NotePosition)(column + 1);
                note.IndexInGrid   = row;
                note.FixSync();
            }
            scoreNote.Note = note;
            EditableScoreNotes.Add(scoreNote);
            NoteLayer.Children.Add(scoreNote);
            scoreNote.X                 = NoteLayer.ActualWidth * (TrackCenterXPositions[column] - TrackCenterXPositions[0]) / (TrackCenterXPositions[4] - TrackCenterXPositions[0]);
            scoreNote.Y                 = baseY + extraY;
            scoreNote.MouseDown        += ScoreNote_MouseDown;
            scoreNote.MouseUp          += ScoreNote_MouseUp;
            scoreNote.MouseDoubleClick += ScoreNote_MouseDoubleClick;
            scoreNote.MouseEnter       += ScoreNote_MouseEnter;
            scoreNote.MouseLeave       += ScoreNote_MouseLeave;
            if (dataTemplate == null)
            {
                Project.IsChanged = true;
            }
            return(scoreNote);
        }
 private void RemoveScoreNote(ScoreNote scoreNote, bool modifiesModel, bool repositionLines)
 {
     if (!ScoreNotes.Contains(scoreNote))
     {
         throw new ArgumentException("Invalid ScoreNote.", nameof(scoreNote));
     }
     scoreNote.MouseDown        -= ScoreNote_MouseDown;
     scoreNote.MouseUp          -= ScoreNote_MouseUp;
     scoreNote.MouseDoubleClick -= ScoreNote_MouseDoubleClick;
     scoreNote.MouseEnter       -= ScoreNote_MouseEnter;
     scoreNote.MouseLeave       -= ScoreNote_MouseLeave;
     scoreNote.ContextMenu       = null;
     EditableScoreNotes.Remove(scoreNote);
     LineLayer.NoteRelations.RemoveAll(scoreNote);
     if (modifiesModel)
     {
         var note = scoreNote.Note;
         if (Score.Bars.Contains(note.Bar))
         {
             // Remove note from sync group
             // See Note.RemoveSync()
             if (note.HasPrevSync && note.HasNextSync)
             {
                 var prevNote      = note.PrevSyncTarget;
                 var nextNote      = note.NextSyncTarget;
                 var prevScoreNote = FindScoreNote(prevNote);
                 var nextScoreNote = FindScoreNote(nextNote);
                 LineLayer.NoteRelations.Add(prevScoreNote, nextScoreNote, NoteRelation.Sync);
             }
             note.RemoveSync();
             // The Reset() call is necessary.
             note.Reset();
             note.Bar.RemoveNote(note);
         }
     }
     NoteLayer.Children.Remove(scoreNote);
     // TODO: Query if there is a need to do that.
     if (repositionLines)
     {
         RepositionLineLayer();
     }
     if (modifiesModel)
     {
         Project.IsChanged = true;
     }
 }