Skip to content

Commit

Permalink
[Release] Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
melanchall committed Dec 22, 2023
1 parent dfa4550 commit 1748f93
Show file tree
Hide file tree
Showing 30 changed files with 47 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Docs/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"_enableSearch": true,
"_appLogoPath": "images/logo.png",
"_appFaviconPath": "images/favicon.png",
"_appFooter": "2024 / Generated by <a href=\"https://dotnet.github.io/docfx\">DocFX</a>",
"_appFooter": "2023 / Generated by <a href=\"https://dotnet.github.io/docfx\">DocFX</a>",
"_disableContribution": true
},
"template": [
Expand Down
4 changes: 1 addition & 3 deletions DryWetMidi/Common/MathUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,9 @@ public static long LeastCommonMultiple(long a, long b)

public static long GreatestCommonDivisor(long a, long b)
{
long remainder;

while (b != 0)
{
remainder = a % b;
var remainder = a % b;
a = b;
b = remainder;
}
Expand Down
2 changes: 1 addition & 1 deletion DryWetMidi/Composing/Actions/StepAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal abstract class StepAction : PatternAction
{
#region Constructor

public StepAction(ITimeSpan step)
protected StepAction(ITimeSpan step)
{
Step = step;
}
Expand Down
2 changes: 1 addition & 1 deletion DryWetMidi/Core/Events/Base/MidiEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class MidiEvent
/// Initializes a new instance of the <see cref="MidiEvent"/> with the specified event type.
/// </summary>
/// <param name="eventType">The type of event.</param>
public MidiEvent(MidiEventType eventType)
protected MidiEvent(MidiEventType eventType)
{
EventType = eventType;
}
Expand Down
4 changes: 2 additions & 2 deletions DryWetMidi/Core/Events/Meta/BaseTextEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class BaseTextEvent : MetaEvent
/// <summary>
/// Initializes a new instance of the <see cref="BaseTextEvent"/>.
/// </summary>
public BaseTextEvent(MidiEventType eventType)
protected BaseTextEvent(MidiEventType eventType)
: base(eventType)
{
}
Expand All @@ -29,7 +29,7 @@ public BaseTextEvent(MidiEventType eventType)
/// <param name="eventType">The type of event.</param>
/// <param name="text">Text contained in the event.</param>
/// <exception cref="InvalidEnumArgumentException"><paramref name="eventType"/> specified an invalid value.</exception>
public BaseTextEvent(MidiEventType eventType, string text)
protected BaseTextEvent(MidiEventType eventType, string text)
: this(eventType)
{
Text = text;
Expand Down
3 changes: 2 additions & 1 deletion DryWetMidi/Core/MidiReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,11 @@ public int ReadVlqNumber()
public long ReadVlqLongNumber()
{
long result = 0;
byte b;

try
{
byte b;

do
{
b = ReadByte();
Expand Down
2 changes: 1 addition & 1 deletion DryWetMidi/Interaction/Chords/ChordsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private class ChordDescriptor
{
private readonly int _notesMinCount;

public ChordDescriptor(Note firstNote, int notesMinCount)
protected ChordDescriptor(Note firstNote, int notesMinCount)
{
Time = firstNote.Time;
Notes.Add(firstNote);
Expand Down
2 changes: 1 addition & 1 deletion DryWetMidi/Interaction/Chords/ChordsManagingUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ internal static int ProcessChordsInternal(
: null;

var chordsBuilder = new ChordsBuilder(settings);
var chords = chordsBuilder.GetChordsLazy(eventsCollections.GetTimedEventsLazy(eventsCount, settings?.NoteDetectionSettings?.TimedEventDetectionSettings, false), collectedTimedEvents != null, collectedTimedEvents);
var chords = chordsBuilder.GetChordsLazy(eventsCollections.GetTimedEventsLazy(eventsCount, settings.NoteDetectionSettings?.TimedEventDetectionSettings, false), collectedTimedEvents != null, collectedTimedEvents);

foreach (var chordAt in chords)
{
Expand Down
6 changes: 0 additions & 6 deletions DryWetMidi/Interaction/GetObjects/GetObjectsUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ private static IEnumerable<ITimedObject> EnumerateObjectsFromSortedTimedObjects(
?? (getChords ? settings.ChordDetectionSettings?.NoteDetectionSettings : null)
?? new NoteDetectionSettings();
var chordDetectionSettings = settings.ChordDetectionSettings ?? new ChordDetectionSettings();
var restDetectionSettings = settings.RestDetectionSettings ?? new RestDetectionSettings();

var timedObjects = processedTimedObjects;

Expand All @@ -429,11 +428,6 @@ private static IEnumerable<ITimedObject> EnumerateObjectsFromSortedTimedObjects(

//

var notesLastEndTimes = new Dictionary<object, long>();
var noteDescriptorProvider = NoteDescriptorProviders[restDetectionSettings.RestSeparationPolicy];
var setRestChannel = SetRestChannel[restDetectionSettings.RestSeparationPolicy];
var setRestNoteNumber = SetRestNoteNumber[restDetectionSettings.RestSeparationPolicy];

foreach (var timedObject in timedObjects)
{
var processed = false;
Expand Down
22 changes: 11 additions & 11 deletions DryWetMidi/Interaction/Notes/NotesManagingUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private abstract class NoteOnsHolderBase<TDescriptor> where TDescriptor : IObjec
private readonly Stack<LinkedListNode<TDescriptor>> _nodesStack;
private readonly Queue<LinkedListNode<TDescriptor>> _nodesQueue;

public NoteOnsHolderBase(NoteStartDetectionPolicy noteStartDetectionPolicy)
protected NoteOnsHolderBase(NoteStartDetectionPolicy noteStartDetectionPolicy)
{
switch (noteStartDetectionPolicy)
{
Expand Down Expand Up @@ -110,13 +110,13 @@ private interface IObjectDescriptorIndexed : IObjectDescriptor

private class NoteDescriptor : IObjectDescriptor
{
private TimedEvent _noteOnTimedEvent;

public NoteDescriptor(TimedEvent noteOnTimedEvent)
{
NoteOnTimedEvent = noteOnTimedEvent;
_noteOnTimedEvent = noteOnTimedEvent;
}

public TimedEvent NoteOnTimedEvent { get; }

public TimedEvent NoteOffTimedEvent { get; set; }

public bool IsCompleted => NoteOffTimedEvent != null;
Expand All @@ -125,9 +125,9 @@ public ITimedObject GetObject(Func<NoteData, Note> constructor)
{
return IsCompleted
? (constructor == null
? new Note(NoteOnTimedEvent, NoteOffTimedEvent, false)
: constructor(new NoteData(NoteOnTimedEvent, NoteOffTimedEvent)))
: (ITimedObject)NoteOnTimedEvent;
? new Note(_noteOnTimedEvent, NoteOffTimedEvent, false)
: constructor(new NoteData(_noteOnTimedEvent, NoteOffTimedEvent)))
: (ITimedObject)_noteOnTimedEvent;
}
}

Expand Down Expand Up @@ -166,18 +166,18 @@ public TimedObjectAt<ITimedObject> GetIndexedObject(Func<NoteData, Note> constru

private class TimedEventDescriptor : IObjectDescriptor
{
private TimedEvent _timedEvent;

public TimedEventDescriptor(TimedEvent timedEvent)
{
TimedEvent = timedEvent;
_timedEvent = timedEvent;
}

public TimedEvent TimedEvent { get; }

public bool IsCompleted { get; } = true;

public ITimedObject GetObject(Func<NoteData, Note> constructor)
{
return TimedEvent;
return _timedEvent;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ public long ConvertFrom(ITimeSpan timeSpan, long time, TempoMap tempoMap)
lastBarLength = BarBeatUtilities.GetBarLength(lastTimeSignature, ticksPerQuarterNote);
lastBeatLength = BarBeatUtilities.GetBeatLength(lastTimeSignature, ticksPerQuarterNote);

// TODO: lastBarLength can be 0
var currentBars = Math.Min(deltaTime / lastBarLength, bars);
bars -= currentBars;
lastTime += currentBars * lastBarLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public long ConvertFrom(ITimeSpan timeSpan, long time, TempoMap tempoMap)
lastBarLength = BarBeatUtilities.GetBarLength(lastTimeSignature, ticksPerQuarterNote);
lastBeatLength = BarBeatUtilities.GetBeatLength(lastTimeSignature, ticksPerQuarterNote);

// TODO: lastBarLength can be 0
var currentBars = Math.Min(deltaTime / lastBarLength, bars);
bars -= currentBars;
lastTime += currentBars * lastBarLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static class MidiTimeSpanParser

private static readonly string[] Patterns = new[]
{
$@"{TimeSpanGroup}",
TimeSpanGroup,
};

private const string OutOfRange = "Time span is out of range.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ internal static ParsingResult TryParse(string input, out MusicalTimeSpan timeSpa

private static string GetMnemonicGroup(string groupName, IEnumerable<string> mnemonics)
{
return $@"(?<{groupName}>[{string.Join(string.Empty, mnemonics)}])";
return $"(?<{groupName}>[{string.Join(string.Empty, mnemonics)}])";
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,6 @@ internal static IEnumerable<TimedEvent> GetTimedEventsLazy(this IEnumerable<Midi

time += midiEvent.DeltaTime;

TimedEvent timedEvent = null;

if (useCustomConstructor)
{
yield return constructor(new TimedEventData(
Expand All @@ -855,7 +853,7 @@ internal static IEnumerable<TimedEvent> GetTimedEventsLazy(this IEnumerable<Midi
}
else
{
timedEvent = new TimedEvent(cloneEvent ? midiEvent.Clone() : midiEvent);
var timedEvent = new TimedEvent(cloneEvent ? midiEvent.Clone() : midiEvent);
timedEvent._time = time;
yield return timedEvent;
}
Expand Down
2 changes: 0 additions & 2 deletions DryWetMidi/Interaction/TimedObject/TimedObjectsWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ private void WriteTimedEvent(TimedEvent timedEvent)

private TimedEvent[] GetObjectTimedEvents(ITimedObject timedObject)
{
var result = new List<TimedEvent>();

var timedEvent = timedObject as TimedEvent;
if (timedEvent != null)
return new[] { timedEvent };
Expand Down
2 changes: 1 addition & 1 deletion DryWetMidi/Melanchall.DryWetMidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* Build musical compositions.
* Perform complex musical tasks like quantizing, notes splitting or converting MIDI files to CSV.
</Description>
<Copyright>Copyright © Melanchall 2024</Copyright>
<Copyright>Copyright © Melanchall 2023</Copyright>
<PackageTags>midi smf music composing notes chords device playback record</PackageTags>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public static IntPtr GetSessionHandle()
{
if (_handle == IntPtr.Zero)
{
var apiType = CommonApiProvider.Api.Api_GetApiType();
NativeApiUtilities.HandleTickGeneratorNativeApiResult(
TickGeneratorSessionApiProvider.Api.Api_OpenSession(out _handle));
}
Expand Down
6 changes: 3 additions & 3 deletions DryWetMidi/Multimedia/InputDevice/InputDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ private void OnPacket_Mac(IntPtr pktlist, int packetIndex, out int packetsCount)
}
catch (Exception ex)
{
var exception = new MidiDeviceException($"Failed to parse message.", ex);
var exception = new MidiDeviceException("Failed to parse message.", ex);
exception.Data.Add("Data", data);
OnError(exception);
}
Expand Down Expand Up @@ -717,7 +717,7 @@ private void OnShortMessage(int message)
}
catch (Exception ex)
{
var exception = new MidiDeviceException($"Failed to parse short message.", ex);
var exception = new MidiDeviceException("Failed to parse short message.", ex);
exception.Data.Add("Message", message);
OnError(exception);
}
Expand Down Expand Up @@ -755,7 +755,7 @@ private void OnSysExMessage(IntPtr sysExHeaderPointer)
}
catch (Exception ex)
{
var exception = new MidiDeviceException($"Failed to parse system exclusive message.", ex);
var exception = new MidiDeviceException("Failed to parse system exclusive message.", ex);
exception.Data.Add("Data", data);
OnError(exception);
}
Expand Down
6 changes: 3 additions & 3 deletions DryWetMidi/Multimedia/MidiDevice.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Melanchall.DryWetMidi.Common;
using System;
using System.Collections.Generic;
using Melanchall.DryWetMidi.Common;

namespace Melanchall.DryWetMidi.Multimedia
{
Expand Down Expand Up @@ -157,7 +157,7 @@ public override string ToString()
public void Dispose()
{
if (Context == CreationContext.VirtualDevice)
throw new InvalidOperationException($"Disposing of a subdevice of a virtual device is prohibited.");
throw new InvalidOperationException("Disposing of a subdevice of a virtual device is prohibited.");

Dispose(true);
GC.SuppressFinalize(this);
Expand Down
2 changes: 1 addition & 1 deletion DryWetMidi/Multimedia/NativeHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal abstract class NativeHandle : SafeHandle
{
#region Constructor

public NativeHandle(IntPtr validHandle)
protected NativeHandle(IntPtr validHandle)
: base(IntPtr.Zero, true)
{
SetHandle(validHandle);
Expand Down
6 changes: 3 additions & 3 deletions DryWetMidi/Multimedia/Playback/PlaybackDataTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public EventWithMetadata(MidiEvent midiEvent, object metadata)

private abstract class DataChange<TData> : IMetadata
{
public DataChange(TData data, object metadata)
protected DataChange(TData data, object metadata)
{
Data = data;
Metadata = metadata;
}

public DataChange(TData data, object metadata, bool isDefault)
protected DataChange(TData data, object metadata, bool isDefault)
: this(data, metadata)
{
IsDefault = isDefault;
Expand All @@ -56,7 +56,7 @@ public DataChange(TData data, object metadata, bool isDefault)

public object Metadata { get; set; }

public bool IsDefault { get; set; }
public bool IsDefault { get; }
}

private sealed class ProgramChange : DataChange<SevenBitNumber>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ internal static class ChordProgressionParser

private const string ScaleDegreeGroupName = "sd";

private static readonly string ScaleDegreeGroup = $@"(?<{ScaleDegreeGroupName}>(?i:M{{0,4}}(CM|CD|D?C{{0,3}})(XC|XL|L?X{{0,3}})(IX|IV|V?I{{0,3}})))";
private static readonly string ScaleDegreeGroup = $"(?<{ScaleDegreeGroupName}>(?i:M{{0,4}}(CM|CD|D?C{{0,3}})(XC|XL|L?X{{0,3}})(IX|IV|V?I{{0,3}})))";

private static readonly string[] Patterns = new[]
{
$@"{ScaleDegreeGroup}\s*{ChordParser.ChordCharacteristicsGroup}"
};

private static Dictionary<char, int> RomanMap = new Dictionary<char, int>
private static readonly Dictionary<char, int> RomanMap = new Dictionary<char, int>
{
['i'] = 1,
['v'] = 5,
Expand Down
2 changes: 1 addition & 1 deletion DryWetMidi/MusicTheory/Note/NoteNameParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static class NoteNameParser
private static readonly string[] Patterns = new[]
{
$@"{NoteNameGroup}\s*{AccidentalGroup}",
$@"{NoteNameGroup}",
NoteNameGroup,
};

#endregion
Expand Down
Loading

0 comments on commit 1748f93

Please sign in to comment.