Ejemplo n.º 1
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
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
 private void Viewer_MouseUp(object sender, MouseButtonEventArgs e)
 {
     model.updateView(); // Needed to keep the notes from jumping around when you click on them
 }