Skip to content

Commit 53ee10f

Browse files
committed
[Release] Code cleanup
1 parent 0039abc commit 53ee10f

File tree

9 files changed

+50
-16
lines changed

9 files changed

+50
-16
lines changed

DryWetMidi/Common/MathUtilities.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
43

54
namespace Melanchall.DryWetMidi.Common

DryWetMidi/Common/ThrowIfArgument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ internal static void IsNullOrEmptyString(string parameterName, string value, str
151151

152152
internal static void IsInvalidIndex(string parameterName, int index, int collectionSize)
153153
{
154-
IsOutOfRange(parameterName, index, MinNonnegativeValue, collectionSize, "Index is out of range.");
154+
IsOutOfRange(parameterName, index, MinNonnegativeValue, collectionSize - 1, "Index is out of range.");
155155
}
156156

157157
internal static void IsEmptyCollection<T>(string parameterName, IEnumerable<T> collection, string message)

DryWetMidi/Interaction/Notes/NotesManagingUtilities.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6-
using System.Runtime;
76

87
namespace Melanchall.DryWetMidi.Interaction
98
{
@@ -98,7 +97,7 @@ private interface IObjectDescriptor
9897

9998
private class NoteDescriptor : IObjectDescriptor
10099
{
101-
private TimedEvent _noteOnTimedEvent;
100+
private readonly TimedEvent _noteOnTimedEvent;
102101

103102
public NoteDescriptor(TimedEvent noteOnTimedEvent)
104103
{
@@ -144,7 +143,7 @@ public ITimedObject GetObject(Func<NoteData, Note> constructor)
144143

145144
private class TimedEventDescriptor : IObjectDescriptor
146145
{
147-
private TimedEvent _timedEvent;
146+
private readonly TimedEvent _timedEvent;
148147

149148
public TimedEventDescriptor(TimedEvent timedEvent)
150149
{

DryWetMidi/Interaction/TimedEvents/TimedEventsManagingUtilities.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Data;
43
using System.Linq;
54
using Melanchall.DryWetMidi.Common;
65
using Melanchall.DryWetMidi.Core;
@@ -768,7 +767,6 @@ internal static int ProcessTimedEventsInternal(
768767

769768
foreach (var eventsCollection in eventsCollectionsIn)
770769
{
771-
var eventsCount = eventsCollection.Count;
772770
var matchedCount = 0;
773771

774772
var timesChanged = false;

DryWetMidi/Interaction/TimedObject/TimedObjectUtilities.ProcessObjects.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ internal static int ProcessObjectsInternal(
493493

494494
foreach (var eventsCollection in eventsCollectionsIn)
495495
{
496-
var eventsCount = eventsCollection.Count;
497496
var iMatched = 0;
498497

499498
var processingContext = new ProcessingContext

DryWetMidi/Interaction/TimedObject/TimedObjectsCollection.cs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Generic;
55
using System.Diagnostics;
66
using System.Linq;
7-
using System.Xml.Linq;
87

98
namespace Melanchall.DryWetMidi.Interaction
109
{
@@ -50,6 +49,10 @@ internal TimedObjectsCollection(IEnumerable<TObject> objects, TimedObjectsCompar
5049
/// </summary>
5150
public int Count => _objects.Count;
5251

52+
/// <summary>
53+
/// Gets a value indicating whether the <see cref="TimedObjectsCollection{TObject}"/>
54+
/// is read-only.
55+
/// </summary>
5356
public bool IsReadOnly => false;
5457

5558
#endregion
@@ -175,13 +178,52 @@ public void Clear()
175178
OnObjectsRemoved(removedObjects);
176179
}
177180

178-
public bool Contains(TObject item)
181+
/// <summary>
182+
/// Determines whether the <see cref="TimedObjectsCollection{TObject}"/> contains a
183+
/// specific object.
184+
/// </summary>
185+
/// <param name="obj">The object to locate in the <see cref="TimedObjectsCollection{TObject}"/>.</param>
186+
/// <returns><c>true</c> if the object is found; otherwise, <c>false</c>.</returns>
187+
public bool Contains(TObject obj)
179188
{
180-
return _objects.Contains(item);
189+
return _objects.Contains(obj);
181190
}
182191

192+
193+
/// <summary>
194+
/// Copies the objects of the <see cref="TimedObjectsCollection{TObject}"/> to an
195+
/// array, starting at a particular index.
196+
/// </summary>
197+
/// <param name="array">The one-dimensional array that is the destination of the objects
198+
/// copied from <see cref="TimedObjectsCollection{TObject}"/>. The array must have
199+
/// zero-based indexing.</param>
200+
/// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
201+
/// <exception cref="ArgumentNullException"><paramref name="array"/> is <c>null</c>.</exception>
202+
/// <exception cref="ArgumentOutOfRangeException">
203+
/// One of the following errors occurred:
204+
/// <list type="bullet">
205+
/// <item>
206+
/// <description><paramref name="arrayIndex"/> is less than zero or greater than the length of the array.</description>
207+
/// </item>
208+
/// <item>
209+
/// <description>The number of elements in the <see cref="TimedObjectsCollection{TObject}"/> is greater than
210+
/// the available space from the <paramref name="arrayIndex"/> to the end of the <paramref name="array"/>.</description>
211+
/// </item>
212+
/// </list>
213+
/// </exception>
183214
public void CopyTo(TObject[] array, int arrayIndex)
184215
{
216+
ThrowIfArgument.IsNull(nameof(array), array);
217+
ThrowIfArgument.IsInvalidIndex(
218+
nameof(arrayIndex),
219+
arrayIndex,
220+
array.Length);
221+
ThrowIfArgument.IsLessThan(
222+
nameof(array),
223+
array.Length - arrayIndex,
224+
Count,
225+
"The number of elements in the source collection is greater than the available space from the index to the end of the destination array.");
226+
185227
_objects.CopyTo(array, arrayIndex);
186228
}
187229

DryWetMidi/Interaction/ValueLine/ValueLine.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ public bool SetValueInternal(long time, TValue value)
230230
var nextIndex = index;
231231
var nextValueChange = nextIndex >= 0 ? _valueChanges[nextIndex] : null;
232232
var nextValue = nextValueChange != null ? nextValueChange.Value : _defaultValue;
233-
var nextTime = nextValueChange != null ? nextValueChange.Time : long.MaxValue;
234233

235234
var previousIndex = index > 0 ? index - 1 : (index < 0 ? _valueChanges.Count - 1 : -1);
236235
var previousValueChange = previousIndex >= 0 ? _valueChanges[previousIndex] : null;

DryWetMidi/Multimedia/Playback/Source/FixedPlaybackSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal sealed class FixedPlaybackSource : IPlaybackSource
99
{
1010
#region Fields
1111

12-
private IList<PlaybackEvent> _playbackEventsBuffer = new List<PlaybackEvent>();
12+
private readonly IList<PlaybackEvent> _playbackEventsBuffer = new List<PlaybackEvent>();
1313
private PlaybackEvent[] _playbackEvents = null;
1414
private int _playbackEventsPosition = -1;
1515
private bool _isCompleted;

DryWetMidi/Multimedia/Playback/Source/IPlaybackSource.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Melanchall.DryWetMidi.Common;
2-
using System;
3-
using System.Collections.Generic;
1+
using System;
42

53
namespace Melanchall.DryWetMidi.Multimedia
64
{

0 commit comments

Comments
 (0)