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)
        {
            // Get the currently selected note, rest, or staff fragment
            var elem = Viewer.SelectedElement;

            if (elem == null)
            {
                //MessageBox.Show("You must select a staff to write to or a note to insert after.");
                //return;
                elem = model.Data.FirstStaff.Elements[0];
            }

            //If user selects the staff itself, append to last note. Else insert after selected note.
            //int staffIndex = model.Data.Staves.IndexOf(elem.Staff); // Get current staff **PROBABLY NOT NEEDED**
            if (elem.GetType().IsSubclassOf(typeof(NoteOrRest)))
            {   // Not staff fragment, so insert note after selected element
                int index = elem.Staff.Elements.IndexOf(elem);
                elem.Staff.Elements.Insert(index + 1, nr);
                elem.Measure.Elements.Insert(elem.Measure.Elements.IndexOf(elem) + 1, nr);
                model.fitMeasure(elem.Measure, model.TimeSig);
            }
            else
            {
                elem.Staff.Elements.Add(nr);  // Staff fragment, so add note to end of staff
                model.fitMeasure(nr.Measure, model.TimeSig);
            }

            // Trigger an update in the viewmodel
            model.updateView();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the note to the staff in the correct location
        /// </summary>
        /// <param name="note">The note to add</param>
        private void addNoteToStaff(Note note)
        {
            // Get the currently selected note, rest, or staff fragment
            var elem = Viewer.SelectedElement;

            if (elem == null)
            {
                MessageBox.Show("You must select a staff to write to or a note to insert after.");
                return;
            }

            //If user selects the staff itself, append to last note. Else insert after selected note.
            int staffIndex = model.Data.Staves.IndexOf(elem.Staff); // Get current staff

            if (elem.GetType() == typeof(StaffFragment))
            {
                model.Data.Staves[staffIndex].Elements.Add(note);                                           // Staff fragment, so add note to end of staff
            }
            else
            {   // Not staff fragment, so insert note after selected element
                int index = elem.Staff.Elements.IndexOf(elem);
                model.Data.Staves[staffIndex].Elements.Insert(index + 1, note);
            }

            // Recusively fix overflowing measures, starting from the current one
            model.fitMeasure(note.Measure, model.TimeSig);

            // Trigger an update in the viewmodel
            model.updateView();

            // TODO: handle when clefs and signatures are selected
        }