Exemple #1
0
 public virtual void Select(
     NoteSelection selection,
     RectangleF rectangle,
     SheetMusicRenderSettings settings,
     float width
     )
 {
 }
        /// <summary>
        /// Creates a new <see cref="Pattern"/> by transforming notes in the specified pattern using predicate
        /// to select notes to transform.
        /// </summary>
        /// <param name="pattern">Pattern to transform notes of.</param>
        /// <param name="noteSelection">Predicate to select notes to transform.</param>
        /// <param name="noteTransformation">Transformation to apply to notes of the <paramref name="pattern"/>.</param>
        /// <param name="recursive">A value indicating whether nested patterns should be processed or not. The
        /// default value is <c>true</c>.</param>
        /// <returns><see cref="Pattern"/> that created by transforming notes of the <paramref name="pattern"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <para>One of the following errors occured:</para>
        /// <list type="bullet">
        /// <item>
        /// <description><paramref name="pattern"/> is <c>null</c>.</description>
        /// </item>
        /// <item>
        /// <description><paramref name="noteSelection"/> is <c>null</c>.</description>
        /// </item>
        /// <item>
        /// <description><paramref name="noteTransformation"/> is <c>null</c>.</description>
        /// </item>
        /// </list>
        /// </exception>
        public static Pattern TransformNotes(this Pattern pattern, NoteSelection noteSelection, NoteTransformation noteTransformation, bool recursive = true)
        {
            ThrowIfArgument.IsNull(nameof(pattern), pattern);
            ThrowIfArgument.IsNull(nameof(noteSelection), noteSelection);
            ThrowIfArgument.IsNull(nameof(noteTransformation), noteTransformation);

            var noteIndexWrapper = new ObjectWrapper <int>();

            return(TransformNotes(pattern, noteIndexWrapper, noteSelection, noteTransformation, recursive));
        }
        /// <summary>
        /// Sets the state of notes within the specified pattern.
        /// </summary>
        /// <param name="pattern">Pattern to set notes state within.</param>
        /// <param name="noteSelection">Predicate to select notes to set state.</param>
        /// <param name="state">State of notes selected with <paramref name="noteSelection"/>.</param>
        /// <param name="recursive">A value indicating whether nested patterns should be processed or not. The
        /// default value is <c>true</c>.</param>
        /// <exception cref="ArgumentNullException">
        /// <para>One of the following errors occured:</para>
        /// <list type="bullet">
        /// <item>
        /// <description><paramref name="pattern"/> is <c>null</c>.</description>
        /// </item>
        /// <item>
        /// <description><paramref name="noteSelection"/> is <c>null</c>.</description>
        /// </item>
        /// </list>
        /// </exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="state"/> specified an invalid value.</exception>
        public static void SetNotesState(this Pattern pattern, NoteSelection noteSelection, PatternActionState state, bool recursive = true)
        {
            ThrowIfArgument.IsNull(nameof(pattern), pattern);
            ThrowIfArgument.IsNull(nameof(noteSelection), noteSelection);
            ThrowIfArgument.IsInvalidEnumValue(nameof(state), state);

            var noteIndexWrapper = new ObjectWrapper <int>();

            SetNotesState(pattern, noteIndexWrapper, noteSelection, state, recursive);
        }
Exemple #4
0
        public override void Select(
            NoteSelection selection,
            RectangleF rectangle,
            SheetMusicRenderSettings settings,
            float width
            )
        {
            rectangle.X -= Margin;

            foreach (var chord in layoutmeasure.Chords)
            {
                var x = chord.X * width;
                var w = chord.Width * width;

                foreach (var note in chord.Notes)
                {
                    var y = settings.YVal(note.HalfLine);

                    var noteID = note.Core.Note.ID;

                    var rect_head =
                        new RectangleF(
                            x - settings.NoteHeadRadius,
                            y - settings.NoteHeadRadius,
                            2 * settings.NoteHeadRadius,
                            2 * settings.NoteHeadRadius
                            );

                    if (rect_head.IntersectsWith(rectangle))
                    {
                        selection.Selected_Start.Add(noteID);
                        selection.Selected_End.Add(noteID);
                        selection.Selected_Tone.Add(noteID);
                    }
                    else
                    {
                        var boxy = y;
                        boxy -= settings.PixelsPerHalfLine * note.Transform.Steps;

                        var rect_tail =
                            new RectangleF(
                                x + w - 2 * settings.ThumbMarginX,
                                boxy - settings.PixelsPerHalfLine / 2,
                                2 * settings.ThumbMarginX,
                                settings.PixelsPerHalfLine
                                );

                        if (rect_tail.IntersectsWith(rectangle))
                        {
                            selection.Selected_End.Add(noteID);
                        }
                    }
                }
            }
        }
        private static void SetNotesState(Pattern pattern, ObjectWrapper <int> noteIndexWrapper, NoteSelection noteSelection, PatternActionState state, bool recursive)
        {
            foreach (var a in pattern.Actions)
            {
                var addNoteAction = a as AddNoteAction;
                if (addNoteAction != null && noteSelection(noteIndexWrapper.Object++, addNoteAction.NoteDescriptor))
                {
                    addNoteAction.State = state;
                }

                var addPatternAction = a as AddPatternAction;
                if (addPatternAction != null && recursive)
                {
                    SetNotesState(addPatternAction.Pattern, noteIndexWrapper, noteSelection, state, recursive);
                }
            }
        }
        private static Pattern TransformNotes(Pattern pattern, ObjectWrapper <int> noteIndexWrapper, NoteSelection noteSelection, NoteTransformation noteTransformation, bool recursive)
        {
            return(new Pattern(pattern.Actions.Select(a =>
            {
                var addNoteAction = a as AddNoteAction;
                if (addNoteAction != null && noteSelection(noteIndexWrapper.Object++, addNoteAction.NoteDescriptor))
                {
                    var noteDescriptor = noteTransformation(addNoteAction.NoteDescriptor);
                    return new AddNoteAction(noteDescriptor);
                }

                var addPatternAction = a as AddPatternAction;
                if (addPatternAction != null && recursive)
                {
                    return new AddPatternAction(TransformNotes(addPatternAction.Pattern, noteIndexWrapper, noteSelection, noteTransformation, recursive));
                }

                return a.Clone();
            })
                               .ToList()));
        }
        private void Mouseselector_Selected(RectangleF rect, NoteSelectionMode mode)
        {
            //TODO: does this work when a track has different staves throughout its duration?

            var effectedarea = default(Duration);

            if (mode == NoteSelectionMode.Replace)
            {
                foreach (var selectionkvp in editor.NoteSelections)
                {
                    var track     = selectionkvp.Key;
                    var selection = selectionkvp.Value;

                    foreach (var noteID in selection.Selected_NoteIDs)
                    {
                        effectedarea = track.Melody[noteID].Duration.Union(effectedarea);
                    }

                    selection.Selected_Start.Clear();
                    selection.Selected_End.Clear();
                    selection.Selected_Tone.Clear();
                }
            }

            for (int i = 0; i < editor.Tracks.Count; i++)
            {
                var track =
                    editor.Tracks[i] as MusicTrack;

                var selection = editor.NoteSelections[track];

                var fakeselection = new NoteSelection();

                foreach (var itemtuple in GetItemsWithRects(track))
                {
                    if (itemtuple.Item1.IntersectsWith(rect))
                    {
                        rect.Offset(-itemtuple.Item1.X, -itemtuple.Item1.Y);

                        itemtuple.Item3.Select(fakeselection, rect, itemtuple.Item2, itemtuple.Item1.Width);

                        rect.Offset(+itemtuple.Item1.X, +itemtuple.Item1.Y);
                    }
                }

                switch (mode)
                {
                case NoteSelectionMode.Replace:
                case NoteSelectionMode.Add:
                    foreach (var noteID in fakeselection.Selected_Start)
                    {
                        var note = track.Melody[noteID];
                        effectedarea = note.Duration.Union(effectedarea);

                        selection.Selected_Start.Add(noteID);
                    }
                    foreach (var noteID in fakeselection.Selected_End)
                    {
                        var note = track.Melody[noteID];
                        effectedarea = note.Duration.Union(effectedarea);

                        selection.Selected_End.Add(noteID);
                    }
                    foreach (var noteID in fakeselection.Selected_Tone)
                    {
                        var note = track.Melody[noteID];
                        effectedarea = note.Duration.Union(effectedarea);

                        selection.Selected_Tone.Add(noteID);
                    }
                    break;

                case NoteSelectionMode.Intersect:
                    foreach (var noteID in selection.Selected_Start.ToArray())
                    {
                        if (!fakeselection.Selected_Start.Contains(noteID))
                        {
                            var note = track.Melody[noteID];
                            effectedarea = note.Duration.Union(effectedarea);

                            selection.Selected_Start.Remove(noteID);
                        }
                    }
                    foreach (var noteID in selection.Selected_End.ToArray())
                    {
                        if (!fakeselection.Selected_End.Contains(noteID))
                        {
                            var note = track.Melody[noteID];
                            effectedarea = note.Duration.Union(effectedarea);

                            selection.Selected_End.Remove(noteID);
                        }
                    }
                    foreach (var noteID in selection.Selected_Tone.ToArray())
                    {
                        if (!fakeselection.Selected_Tone.Contains(noteID))
                        {
                            var note = track.Melody[noteID];
                            effectedarea = note.Duration.Union(effectedarea);

                            selection.Selected_Tone.Remove(noteID);
                        }
                    }
                    break;

                case NoteSelectionMode.Subtract:
                    foreach (var noteID in selection.Selected_Start.ToArray())
                    {
                        if (fakeselection.Selected_Start.Contains(noteID))
                        {
                            var note = track.Melody[noteID];
                            effectedarea = note.Duration.Union(effectedarea);

                            selection.Selected_Start.Remove(noteID);
                        }
                    }
                    foreach (var noteID in selection.Selected_End.ToArray())
                    {
                        if (fakeselection.Selected_End.Contains(noteID))
                        {
                            var note = track.Melody[noteID];
                            effectedarea = note.Duration.Union(effectedarea);

                            selection.Selected_End.Remove(noteID);
                        }
                    }
                    foreach (var noteID in selection.Selected_Tone.ToArray())
                    {
                        if (fakeselection.Selected_Tone.Contains(noteID))
                        {
                            var note = track.Melody[noteID];
                            effectedarea = note.Duration.Union(effectedarea);

                            selection.Selected_Tone.Remove(noteID);
                        }
                    }
                    break;

                case NoteSelectionMode.Xor:
                    foreach (var noteID in fakeselection.Selected_Start)
                    {
                        var note = track.Melody[noteID];
                        effectedarea = note.Duration.Union(effectedarea);

                        if (selection.Selected_Start.Contains(noteID))
                        {
                            selection.Selected_Start.Remove(noteID);
                        }
                        else
                        {
                            selection.Selected_Start.Add(noteID);
                        }
                    }
                    foreach (var noteID in fakeselection.Selected_End)
                    {
                        var note = track.Melody[noteID];
                        effectedarea = note.Duration.Union(effectedarea);

                        if (selection.Selected_End.Contains(noteID))
                        {
                            selection.Selected_End.Remove(noteID);
                        }
                        else
                        {
                            selection.Selected_End.Add(noteID);
                        }
                    }
                    foreach (var noteID in fakeselection.Selected_Tone)
                    {
                        var note = track.Melody[noteID];
                        effectedarea = note.Duration.Union(effectedarea);

                        if (selection.Selected_Tone.Contains(noteID))
                        {
                            selection.Selected_Tone.Remove(noteID);
                        }
                        else
                        {
                            selection.Selected_Tone.Add(noteID);
                        }
                    }
                    break;
                }
            }

            if (effectedarea != null)
            {
                editor.InvalidateTime(effectedarea);
            }

            Invalidate();
        }