Ejemplo n.º 1
0
        /// <summary>
        /// Adds the note to the staff in the correct location
        /// </summary>
        /// <param name="nr">The note to add</param>
        private void addNoteOrRestToStaff(NoteOrRest nr)
        {
            // New for LStaff
            var        elem  = Viewer.SelectedElement;
            LStaff     staff = getLStaff(elem);
            NoteOrRest noteToPlay;

            if (isValidTarget(elem))
            {
                LMeasure measure = staff.getMeasure(elem);
                staff.AddAfter(elem, nr);
                if (measure.Contains(nr))
                {
                    Viewer.SelectedElement = nr;
                }
                else if (measure.Node.Next != null && measure.Node.Next.Value.Count > 0)
                {
                    Viewer.SelectedElement = measure.Node.Next.Value.First.Value;
                }
                noteToPlay = (NoteOrRest)Viewer.SelectedElement;
            }
            else
            {
                staff.Add(nr);
                noteToPlay = (NoteOrRest)staff.Last.Value.Last(e => e.GetType().IsSubclassOf(typeof(NoteOrRest)));
            }

            // Play the note
            if (noteToPlay.GetType() == typeof(Note))
            {
                model.PlayNote((Note)noteToPlay);
            }

            // Update the view model to make the Play command available
            model.updateView();
        }