From 4af77aee6f52a323cfd1a8364b0c1dcaa3019d1c Mon Sep 17 00:00:00 2001 From: Maxim Dobroselsky Date: Mon, 6 May 2024 22:19:36 +0300 Subject: [PATCH] Default RestDetectionSettings --- .../Rests/RestDetectionSettings.cs | 10 ++++-- .../Interaction/Rests/RestsUtilities.cs | 34 +++++-------------- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/DryWetMidi/Interaction/Rests/RestDetectionSettings.cs b/DryWetMidi/Interaction/Rests/RestDetectionSettings.cs index 885656a60..5bf11c76a 100644 --- a/DryWetMidi/Interaction/Rests/RestDetectionSettings.cs +++ b/DryWetMidi/Interaction/Rests/RestDetectionSettings.cs @@ -11,12 +11,14 @@ public sealed class RestDetectionSettings { #region Constants + private static readonly Func NoNotesKeySelector = obj => obj is Note ? "Note" : null; + /// /// Rests will be built only at spaces without notes at all. /// public static readonly RestDetectionSettings NoNotes = new RestDetectionSettings { - KeySelector = obj => obj is Note ? "Note" : null + KeySelector = NoNotesKeySelector }; /// @@ -66,9 +68,11 @@ public sealed class RestDetectionSettings /// /// Gets or sets a function that returns the key of an object. Please read /// Getting objects: Rests article to - /// understand the key concept. + /// understand the key concept. The default key selector is + /// obj => obj is Note ? "Note" : null which means rests will be built + /// between notes where there are no notes at all. /// - public Func KeySelector { get; set; } + public Func KeySelector { get; set; } = NoNotesKeySelector; #endregion } diff --git a/DryWetMidi/Interaction/Rests/RestsUtilities.cs b/DryWetMidi/Interaction/Rests/RestsUtilities.cs index 305c6ffe9..249dd93a9 100644 --- a/DryWetMidi/Interaction/Rests/RestsUtilities.cs +++ b/DryWetMidi/Interaction/Rests/RestsUtilities.cs @@ -21,23 +21,14 @@ public static class RestsUtilities /// Settings according to which rests should be detected and built. /// Collection with objects from and rests /// between them. - /// - /// One of the following errors occurred: - /// - /// - /// is null. - /// - /// - /// is null. - /// - /// - /// + /// is null. public static IEnumerable WithRests( this IEnumerable timedObjects, - RestDetectionSettings settings) + RestDetectionSettings settings = null) { ThrowIfArgument.IsNull(nameof(timedObjects), timedObjects); - ThrowIfArgument.IsNull(nameof(settings), settings); + + settings = settings ?? new RestDetectionSettings(); timedObjects = GetSortedObjects(timedObjects); var rests = GetSortedRestsFromObjects(timedObjects, settings); @@ -51,23 +42,14 @@ public static IEnumerable WithRests( /// The input objects collection. /// Settings according to which rests should be detected and built. /// Collection of rests between objects within . - /// - /// One of the following errors occurred: - /// - /// - /// is null. - /// - /// - /// is null. - /// - /// - /// + /// is null. public static ICollection GetRests( this IEnumerable timedObjects, - RestDetectionSettings settings) + RestDetectionSettings settings = null) { ThrowIfArgument.IsNull(nameof(timedObjects), timedObjects); - ThrowIfArgument.IsNull(nameof(settings), settings); + + settings = settings ?? new RestDetectionSettings(); timedObjects = GetSortedObjects(timedObjects); return GetSortedRestsFromObjects(timedObjects, settings);