diff --git a/DryWetMidi/Interaction/TimeSpan/Converters/BarBeatFractionTimeSpanConverter.cs b/DryWetMidi/Interaction/TimeSpan/Converters/BarBeatFractionTimeSpanConverter.cs index 33b552f31..d8f2c1b53 100644 --- a/DryWetMidi/Interaction/TimeSpan/Converters/BarBeatFractionTimeSpanConverter.cs +++ b/DryWetMidi/Interaction/TimeSpan/Converters/BarBeatFractionTimeSpanConverter.cs @@ -158,6 +158,7 @@ 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; diff --git a/DryWetMidi/Interaction/TimeSpan/Converters/BarBeatTicksTimeSpanConverter.cs b/DryWetMidi/Interaction/TimeSpan/Converters/BarBeatTicksTimeSpanConverter.cs index f10fe7858..987e260c6 100644 --- a/DryWetMidi/Interaction/TimeSpan/Converters/BarBeatTicksTimeSpanConverter.cs +++ b/DryWetMidi/Interaction/TimeSpan/Converters/BarBeatTicksTimeSpanConverter.cs @@ -148,6 +148,7 @@ 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; diff --git a/DryWetMidi/Tools/Splitter/Splitter.SplitByObjects.cs b/DryWetMidi/Tools/Splitter/Splitter.SplitByObjects.cs index 235ef39f1..871ec3cfa 100644 --- a/DryWetMidi/Tools/Splitter/Splitter.SplitByObjects.cs +++ b/DryWetMidi/Tools/Splitter/Splitter.SplitByObjects.cs @@ -41,14 +41,11 @@ public static IEnumerable SplitByObjects( var objectsByKeys = new Dictionary>(); var allFilesObjects = new List(); - List nullKeyObjects = null; - foreach (var obj in objects) { if (settings.Filter?.Invoke(obj) == false) continue; - var key = keySelector(obj) ?? obj.GetObjectId(); if (writeToAllFilesPredicate(obj)) { if (settings.AllFilesObjectsFilter?.Invoke(obj) == false) @@ -60,21 +57,13 @@ public static IEnumerable SplitByObjects( { objectsByKey.Add(obj); } - - nullKeyObjects?.Add(obj); } else { - List objectsByKey; + var key = keySelector(obj) ?? obj.GetObjectId(); - if (key == null) - { - if (nullKeyObjects == null) - nullKeyObjects = new List(allFilesObjects); - - objectsByKey = nullKeyObjects; - } - else if (!objectsByKeys.TryGetValue(key, out objectsByKey)) + List objectsByKey; + if (!objectsByKeys.TryGetValue(key, out objectsByKey)) { objectsByKeys.Add(key, objectsByKey = new List(allFilesObjects)); } @@ -85,7 +74,6 @@ public static IEnumerable SplitByObjects( return objectsByKeys .Values - .Concat(new[] { nullKeyObjects ?? Enumerable.Empty() }) .Where(objectsByKey => objectsByKey.Any()) .Select(objectsByKey => { diff --git a/Utilities/SendMidiData/DataSender.cs b/Utilities/SendMidiData/DataSender.cs index fb93c9ad2..87e95b9b5 100644 --- a/Utilities/SendMidiData/DataSender.cs +++ b/Utilities/SendMidiData/DataSender.cs @@ -43,11 +43,13 @@ private static SendResult SendData(string[] array, IOutputDevice outputDevice) try { - var converter = new BytesToMidiEventConverter(); - var midiEvents = converter.ConvertMultiple(bytes.ToArray()); - var playback = midiEvents.GetPlayback(TempoMap.Default, outputDevice); - playback.Play(); - return SendResult.Sent; + using (var converter = new BytesToMidiEventConverter()) + { + var midiEvents = converter.ConvertMultiple(bytes.ToArray()); + var playback = midiEvents.GetPlayback(TempoMap.Default, outputDevice); + playback.Play(); + return SendResult.Sent; + } } catch (Exception ex) {