From dfa4550a5359caf40c007a1cac47099b4f545801 Mon Sep 17 00:00:00 2001 From: Maxim Dobroselsky Date: Sun, 17 Dec 2023 18:53:00 +0300 Subject: [PATCH] Support .NET 8 --- Docs/articles/dev/Support.md | 2 +- .../Melanchall.DryWetMidi.Benchmarks.csproj | 2 +- .../Melanchall.DryWetMidi.Tests.csproj | 2 +- DryWetMidi/Tools/Splitter/MidiFileSlicer.cs | 62 ++++++++++++------- README.md | 2 +- Resources/CI/Templates/job-build-utility.yaml | 2 +- ...net-selfcontained-package-integration.yaml | 8 +++ .../DwmNetConsoleApp/DwmNetConsoleApp.csproj | 2 +- .../DwmNetSelfContainedConsoleApp.csproj | 2 +- .../ConvertReSharperReportToHtml.csproj | 2 +- .../ExportGitHubStatistics.csproj | 2 +- .../ExportNuGetStatistics.csproj | 2 +- .../ExportStackExchangeStatistics.csproj | 2 +- Utilities/Common/Melanchall.Common.csproj | 2 +- .../Melanchall.ReceiveMidiData.csproj | 2 +- .../Melanchall.SendMidiData.csproj | 2 +- 16 files changed, 62 insertions(+), 36 deletions(-) diff --git a/Docs/articles/dev/Support.md b/Docs/articles/dev/Support.md index c8f0c6629..10138311e 100644 --- a/Docs/articles/dev/Support.md +++ b/Docs/articles/dev/Support.md @@ -16,7 +16,7 @@ Things to pay attention for are: 3. Provide your code (as text, not as a screenshot!) and point me to the place there where the error occurred or where you need to do something. 4. What is your operating system? 5. What version of the library do you use? -6. Use proper MIDI terminology. Official MIDI specification can be found on the [midi.org](https://midi.org/specifications/midi1-specifications/m1-v4-2-1-midi-1-0-detailed-specification-96-1-4). +6. Use proper MIDI terminology. Official MIDI specification can be found on the [midi.org](https://www.midi.org/specifications/midi1-specifications/midi-1-0-core-specifications/midi-1-0-detailed-specification-2). 7. Use formatting for your messages (especially for code blocks): * on GitHub use [Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax); * on emails use formatting provided by your mail client. diff --git a/DryWetMidi.Benchmarks/Melanchall.DryWetMidi.Benchmarks.csproj b/DryWetMidi.Benchmarks/Melanchall.DryWetMidi.Benchmarks.csproj index 95958de78..0badd0b2c 100644 --- a/DryWetMidi.Benchmarks/Melanchall.DryWetMidi.Benchmarks.csproj +++ b/DryWetMidi.Benchmarks/Melanchall.DryWetMidi.Benchmarks.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1;net48;net7.0 + netcoreapp3.1;net48;net8.0 Library Debug;Release;Coverage;DebugTest;ReleaseTest true diff --git a/DryWetMidi.Tests/Melanchall.DryWetMidi.Tests.csproj b/DryWetMidi.Tests/Melanchall.DryWetMidi.Tests.csproj index 6f57ef339..7ca9bbc7a 100644 --- a/DryWetMidi.Tests/Melanchall.DryWetMidi.Tests.csproj +++ b/DryWetMidi.Tests/Melanchall.DryWetMidi.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1;net48;net7.0 + netcoreapp3.1;net48;net8.0 Library Debug;Release;Coverage;DebugTest;ReleaseTest true diff --git a/DryWetMidi/Tools/Splitter/MidiFileSlicer.cs b/DryWetMidi/Tools/Splitter/MidiFileSlicer.cs index 1d48a74bf..96a2ae0ce 100644 --- a/DryWetMidi/Tools/Splitter/MidiFileSlicer.cs +++ b/DryWetMidi/Tools/Splitter/MidiFileSlicer.cs @@ -14,6 +14,8 @@ private sealed class TimedEventsHolder : IDisposable { #region Fields + private readonly IEnumerator _enumerator; + private bool _disposed = false; #endregion @@ -22,15 +24,15 @@ private sealed class TimedEventsHolder : IDisposable public TimedEventsHolder(IEnumerator timedEventsEnumerator) { - Enumerator = timedEventsEnumerator; - Enumerator.MoveNext(); + _enumerator = timedEventsEnumerator; + CanBeEnumerated = _enumerator.MoveNext(); } #endregion #region Properties - public IEnumerator Enumerator { get; } + public bool CanBeEnumerated { get; private set; } public List EventsToCopyToNextPart { get; } = new List(); @@ -38,6 +40,20 @@ public TimedEventsHolder(IEnumerator timedEventsEnumerator) #endregion + #region Methods + + public bool MoveToNextEvent() + { + return CanBeEnumerated = _enumerator.MoveNext(); + } + + public TimedEvent GetCurrentEvent() + { + return _enumerator.Current; + } + + #endregion + #region IDisposable private void Dispose(bool disposing) @@ -46,7 +62,7 @@ private void Dispose(bool disposing) return; if (disposing) - Enumerator.Dispose(); + _enumerator.Dispose(); _disposed = true; } @@ -142,7 +158,7 @@ private MidiFileSlicer(TimeDivision timeDivision, IEnumerator[] time #region Properties - public bool AllEventsProcessed => _timedEventsHolders.All(c => !c.EventsToStartNextPart.Any() && c.Enumerator.Current == null); + public bool AllEventsProcessed => _timedEventsHolders.All(c => !c.EventsToStartNextPart.Any() && !c.CanBeEnumerated); #endregion @@ -191,7 +207,6 @@ private IEnumerable> GetNextTimedEvents( { var timedEventsHolder = _timedEventsHolders[i]; - var timedEventsEnumerator = timedEventsHolder.Enumerator; var eventsToCopyToNextPart = timedEventsHolder.EventsToCopyToNextPart; var eventsToStartNextPart = timedEventsHolder.EventsToStartNextPart; @@ -202,29 +217,32 @@ private IEnumerable> GetNextTimedEvents( eventsToStartNextPart, out newEventsStartIndex); - do + if (timedEventsHolder.CanBeEnumerated) { - var timedEvent = timedEventsEnumerator.Current; - if (timedEvent == null) - break; + do + { + var timedEvent = timedEventsHolder.GetCurrentEvent(); + if (timedEvent == null) + break; - var time = timedEvent.Time; - if (time > endTime) - break; + var time = timedEvent.Time; + if (time > endTime) + break; - if (time == endTime) - { - if (!TryToMoveEdgeNoteOffsToPreviousPart(timedEvent, takenTimedEvents)) - eventsToStartNextPart.Add(timedEvent); + if (time == endTime) + { + if (!TryToMoveEdgeNoteOffsToPreviousPart(timedEvent, takenTimedEvents)) + eventsToStartNextPart.Add(timedEvent); - continue; - } + continue; + } - UpdateEventsToCopyToNextPart(eventsToCopyToNextPart, timedEvent); + UpdateEventsToCopyToNextPart(eventsToCopyToNextPart, timedEvent); - takenTimedEvents.Add(timedEvent); + takenTimedEvents.Add(timedEvent); + } + while (timedEventsHolder.MoveToNextEvent()); } - while (timedEventsEnumerator.MoveNext()); isPartEmpty &= newEventsStartIndex >= takenTimedEvents.Count; diff --git a/README.md b/README.md index e94c6d32d..253474012 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ DryWetMIDI is the .NET library to work with MIDI data and MIDI devices. It allows: -* Read, write and create [Standard MIDI Files (SMF)](https://www.midi.org/specifications/category/smf-specifications). It is also possible to read [RMID](https://www.loc.gov/preservation/digital/formats/fdd/fdd000120.shtml) files where SMF wrapped to RIFF chunk. You can easily catch specific error when reading or writing MIDI file since all possible errors in a MIDI file are presented as separate exception classes. +* Read, write and create [Standard MIDI Files (SMF)](https://www.midi.org/specifications/file-format-specifications/standard-midi-files). It is also possible to read [RMID](https://www.loc.gov/preservation/digital/formats/fdd/fdd000120.shtml) files where SMF wrapped to RIFF chunk. You can easily catch specific error when reading or writing MIDI file since all possible errors in a MIDI file are presented as separate exception classes. * [Send](https://melanchall.github.io/drywetmidi/articles/devices/Output-device.html) MIDI events to/[receive](https://melanchall.github.io/drywetmidi/articles/devices/Input-device.html) them from MIDI devices, [play](https://melanchall.github.io/drywetmidi/articles/playback/Overview.html) MIDI data and [record](https://melanchall.github.io/drywetmidi/articles/recording/Overview.html) it. This APIs support Windows and macOS. * Finely adjust process of reading and writing. It allows, for example, to read corrupted files and repair them, or build MIDI file validators. * Implement [custom meta events](https://melanchall.github.io/drywetmidi/articles/custom-data-structures/Custom-meta-events.html) and [custom chunks](https://melanchall.github.io/drywetmidi/articles/custom-data-structures/Custom-chunks.html) that can be written to and read from MIDI files. diff --git a/Resources/CI/Templates/job-build-utility.yaml b/Resources/CI/Templates/job-build-utility.yaml index 459aca6d5..8bbef4a3b 100644 --- a/Resources/CI/Templates/job-build-utility.yaml +++ b/Resources/CI/Templates/job-build-utility.yaml @@ -42,7 +42,7 @@ jobs: - task: ArchiveFiles@2 displayName: Archive utility inputs: - rootFolderOrFile: 'Utilities\${{ parameters.projectName }}\bin\$(BuildConfiguration)\net7.0\${{ rid }}\publish' + rootFolderOrFile: 'Utilities\${{ parameters.projectName }}\bin\$(BuildConfiguration)\$(Build.Framework.Net.Tfm)\${{ rid }}\publish' includeRootFolder: false archiveType: 'zip' archiveFile: '$(Build.ArtifactStagingDirectory)\Utility\Melanchall.${{ parameters.projectName }}.$(LibraryVersion)-${{ rid }}.zip' diff --git a/Resources/CI/test-net-selfcontained-package-integration.yaml b/Resources/CI/test-net-selfcontained-package-integration.yaml index db9bbb9a9..1f7aaac1f 100644 --- a/Resources/CI/test-net-selfcontained-package-integration.yaml +++ b/Resources/CI/test-net-selfcontained-package-integration.yaml @@ -81,6 +81,14 @@ stages: parameters: enabled: contains(variables.vmImage, 'macos') + - task: PowerShell@2 + displayName: Restore NuGet packages + inputs: + targetType: 'inline' + script: | + $path = Resolve-Path 'Resources\PackageIntegrationTestUtilities\DwmNetSelfContainedConsoleApp\DwmNetSelfContainedConsoleApp\DwmNetSelfContainedConsoleApp.csproj' + dotnet restore "$path" -s "https://api.nuget.org/v3/index.json" + - task: PowerShell@2 displayName: Add package to the project inputs: diff --git a/Resources/PackageIntegrationTestUtilities/DwmNetConsoleApp/DwmNetConsoleApp/DwmNetConsoleApp.csproj b/Resources/PackageIntegrationTestUtilities/DwmNetConsoleApp/DwmNetConsoleApp/DwmNetConsoleApp.csproj index a1d08ff2d..6819caa9d 100644 --- a/Resources/PackageIntegrationTestUtilities/DwmNetConsoleApp/DwmNetConsoleApp/DwmNetConsoleApp.csproj +++ b/Resources/PackageIntegrationTestUtilities/DwmNetConsoleApp/DwmNetConsoleApp/DwmNetConsoleApp.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 diff --git a/Resources/PackageIntegrationTestUtilities/DwmNetSelfContainedConsoleApp/DwmNetSelfContainedConsoleApp/DwmNetSelfContainedConsoleApp.csproj b/Resources/PackageIntegrationTestUtilities/DwmNetSelfContainedConsoleApp/DwmNetSelfContainedConsoleApp/DwmNetSelfContainedConsoleApp.csproj index 1ab9dc5c0..74c1cd1a0 100644 --- a/Resources/PackageIntegrationTestUtilities/DwmNetSelfContainedConsoleApp/DwmNetSelfContainedConsoleApp/DwmNetSelfContainedConsoleApp.csproj +++ b/Resources/PackageIntegrationTestUtilities/DwmNetSelfContainedConsoleApp/DwmNetSelfContainedConsoleApp/DwmNetSelfContainedConsoleApp.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 true true true diff --git a/Resources/Utilities/ConvertReSharperReportToHtml/ConvertReSharperReportToHtml/ConvertReSharperReportToHtml.csproj b/Resources/Utilities/ConvertReSharperReportToHtml/ConvertReSharperReportToHtml/ConvertReSharperReportToHtml.csproj index f02677bf6..91b464afe 100644 --- a/Resources/Utilities/ConvertReSharperReportToHtml/ConvertReSharperReportToHtml/ConvertReSharperReportToHtml.csproj +++ b/Resources/Utilities/ConvertReSharperReportToHtml/ConvertReSharperReportToHtml/ConvertReSharperReportToHtml.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 enable enable diff --git a/Resources/Utilities/ExportGitHubStatistics/ExportGitHubStatistics/ExportGitHubStatistics.csproj b/Resources/Utilities/ExportGitHubStatistics/ExportGitHubStatistics/ExportGitHubStatistics.csproj index 08aacf3d8..34cad2e51 100644 --- a/Resources/Utilities/ExportGitHubStatistics/ExportGitHubStatistics/ExportGitHubStatistics.csproj +++ b/Resources/Utilities/ExportGitHubStatistics/ExportGitHubStatistics/ExportGitHubStatistics.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 diff --git a/Resources/Utilities/ExportNuGetStatistics/ExportNuGetStatistics/ExportNuGetStatistics.csproj b/Resources/Utilities/ExportNuGetStatistics/ExportNuGetStatistics/ExportNuGetStatistics.csproj index 94b073c45..a95b20abc 100644 --- a/Resources/Utilities/ExportNuGetStatistics/ExportNuGetStatistics/ExportNuGetStatistics.csproj +++ b/Resources/Utilities/ExportNuGetStatistics/ExportNuGetStatistics/ExportNuGetStatistics.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 diff --git a/Resources/Utilities/ExportStackExchangeStatistics/ExportStackExchangeStatistics/ExportStackExchangeStatistics.csproj b/Resources/Utilities/ExportStackExchangeStatistics/ExportStackExchangeStatistics/ExportStackExchangeStatistics.csproj index 86c47e3ab..ff4a60374 100644 --- a/Resources/Utilities/ExportStackExchangeStatistics/ExportStackExchangeStatistics/ExportStackExchangeStatistics.csproj +++ b/Resources/Utilities/ExportStackExchangeStatistics/ExportStackExchangeStatistics/ExportStackExchangeStatistics.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 diff --git a/Utilities/Common/Melanchall.Common.csproj b/Utilities/Common/Melanchall.Common.csproj index 132c02c59..30402ac0e 100644 --- a/Utilities/Common/Melanchall.Common.csproj +++ b/Utilities/Common/Melanchall.Common.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable diff --git a/Utilities/ReceiveMidiData/Melanchall.ReceiveMidiData.csproj b/Utilities/ReceiveMidiData/Melanchall.ReceiveMidiData.csproj index 76bed00d5..ac6d50582 100644 --- a/Utilities/ReceiveMidiData/Melanchall.ReceiveMidiData.csproj +++ b/Utilities/ReceiveMidiData/Melanchall.ReceiveMidiData.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 true true win-x64;osx-x64 diff --git a/Utilities/SendMidiData/Melanchall.SendMidiData.csproj b/Utilities/SendMidiData/Melanchall.SendMidiData.csproj index 154dff048..be294adc7 100644 --- a/Utilities/SendMidiData/Melanchall.SendMidiData.csproj +++ b/Utilities/SendMidiData/Melanchall.SendMidiData.csproj @@ -2,7 +2,7 @@ Exe - net7.0 + net8.0 true true win-x64;osx-x64