public void SetNotesState_SelectNone([Values] PatternActionState state) { var pattern = new PatternBuilder() .Note(Notes.A2) .Note(Notes.D3) .Build(); pattern.SetNotesState((i, d) => false, PatternActionState.Excluded); PatternTestUtilities.TestNotes(pattern, new[] { new NoteInfo(NoteName.A, 2, null, PatternBuilder.DefaultNoteLength, PatternBuilder.DefaultVelocity), new NoteInfo(NoteName.D, 3, PatternBuilder.DefaultNoteLength, PatternBuilder.DefaultNoteLength, PatternBuilder.DefaultVelocity) }); }
private static void SetChordsState(Pattern pattern, ObjectWrapper <int> chordIndexWrapper, ChordSelection chordSelection, PatternActionState state, bool recursive) { foreach (var a in pattern.Actions) { var addChordAction = a as AddChordAction; if (addChordAction != null && chordSelection(chordIndexWrapper.Object++, addChordAction.ChordDescriptor)) { addChordAction.State = state; } var addPatternAction = a as AddPatternAction; if (addPatternAction != null && recursive) { SetChordsState(addPatternAction.Pattern, chordIndexWrapper, chordSelection, state, recursive); } } }
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); } } }
/// <summary> /// Sets the state of chords within the specified pattern. /// </summary> /// <param name="pattern">Pattern to set chords state within.</param> /// <param name="chordSelection">Predicate to select chords to set state.</param> /// <param name="state">State of chords selected with <paramref name="chordSelection"/>.</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="chordSelection"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> /// <exception cref="InvalidEnumArgumentException"><paramref name="state"/> specified an invalid value.</exception> public static void SetChordsState(this Pattern pattern, ChordSelection chordSelection, PatternActionState state, bool recursive = true) { ThrowIfArgument.IsNull(nameof(pattern), pattern); ThrowIfArgument.IsNull(nameof(chordSelection), chordSelection); ThrowIfArgument.IsInvalidEnumValue(nameof(state), state); var chordIndexWrapper = new ObjectWrapper <int>(); SetChordsState(pattern, chordIndexWrapper, chordSelection, state, recursive); }