/// <summary> /// Creates a new <see cref="Pattern"/> by transforming chords in the specified pattern. /// </summary> /// <param name="pattern">Pattern to transform notes of.</param> /// <param name="chordTransformation">Transformation to apply to chords 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 chords 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="chordTransformation"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public static Pattern TransformChords(this Pattern pattern, ChordTransformation chordTransformation, bool recursive = true) { ThrowIfArgument.IsNull(nameof(pattern), pattern); ThrowIfArgument.IsNull(nameof(chordTransformation), chordTransformation); return(TransformChords(pattern, AllChordsSelection, chordTransformation, recursive)); }
public static Pattern TransformChords(this Pattern pattern, ChordTransformation chordTransformation, bool recursive = true) { ThrowIfArgument.IsNull(nameof(pattern), pattern); ThrowIfArgument.IsNull(nameof(chordTransformation), chordTransformation); return(new Pattern(pattern.Actions.Select(a => { var addChordAction = a as AddChordAction; if (addChordAction != null) { var chordDescriptor = chordTransformation(addChordAction.ChordDescriptor); return new AddChordAction(chordDescriptor); } var addPatternAction = a as AddPatternAction; if (addPatternAction != null && recursive) { return new AddPatternAction(addPatternAction.Pattern.TransformChords(chordTransformation)); } return a; }) .ToList())); }
private static Pattern TransformChords(Pattern pattern, ObjectWrapper <int> chordIndexWrapper, ChordSelection chordSelection, ChordTransformation chordTransformation, bool recursive) { return(new Pattern(pattern.Actions.Select(a => { var addChordAction = a as AddChordAction; if (addChordAction != null && chordSelection(chordIndexWrapper.Object++, addChordAction.ChordDescriptor)) { var chordDescriptor = chordTransformation(addChordAction.ChordDescriptor); return new AddChordAction(chordDescriptor); } var addPatternAction = a as AddPatternAction; if (addPatternAction != null && recursive) { return new AddPatternAction(TransformChords(addPatternAction.Pattern, chordIndexWrapper, chordSelection, chordTransformation, recursive)); } return a.Clone(); }) .ToList())); }
/// <summary> /// Creates a new <see cref="Pattern"/> by transforming chords in the specified pattern using predicate /// to select chords to transform.. /// </summary> /// <param name="pattern">Pattern to transform notes of.</param> /// <param name="chordSelection">Predicate to select chords to transform.</param> /// <param name="chordTransformation">Transformation to apply to chords 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 chords 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="chordSelection"/> is <c>null</c>.</description> /// </item> /// <item> /// <description><paramref name="chordTransformation"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public static Pattern TransformChords(this Pattern pattern, ChordSelection chordSelection, ChordTransformation chordTransformation, bool recursive = true) { ThrowIfArgument.IsNull(nameof(pattern), pattern); ThrowIfArgument.IsNull(nameof(chordSelection), chordSelection); ThrowIfArgument.IsNull(nameof(chordTransformation), chordTransformation); var chordIndexWrapper = new ObjectWrapper <int>(); return(TransformChords(pattern, chordIndexWrapper, chordSelection, chordTransformation, recursive)); }