From d5c38efebfb5b96509a5bbc8731fc7774c767b38 Mon Sep 17 00:00:00 2001 From: Will Baldoumas <45316999+wbaldoumas@users.noreply.github.com> Date: Sat, 23 Nov 2024 15:25:54 -0800 Subject: [PATCH] .NET 9 Migration (#205) --- .editorconfig | 11 +++ .github/workflows/test.yml | 2 +- .../BaroquenMelody.Benchmarks.csproj | 2 +- src/BaroquenMelody.App/App.xaml.cs | 8 +- src/BaroquenMelody.App/MauiProgram.cs | 2 + .../Platforms/Android/MainApplication.cs | 7 +- .../Android/WebViewSoftInputPatch.cs | 9 +- .../Choices/ChordChoice.cs | 10 +- .../Choices/SoloChordChoiceRepository.cs | 2 +- .../Domain/BaroquenChord.cs | 25 +---- .../Domain/BaroquenNote.cs | 15 +-- .../Processors/InitialDynamicsProcessor.cs | 13 +-- .../Enums/Extensions/NoteMotionExtensions.cs | 14 +-- .../Repositories/MidiInstrumentRepository.cs | 94 ++++++++++--------- .../Policies/Input/HasTargetOrnamentations.cs | 12 +-- .../Engine/Selection/NotePairSelector.cs | 9 +- .../Engine/OrnamentationEngineBuilder.cs | 7 +- ...amentationProcessorConfigurationFactory.cs | 13 +-- .../Extensions/OrnamentationTypeExtensions.cs | 12 +-- .../Rules/AvoidDissonantLeaps.cs | 10 +- .../Rules/AvoidParallelIntervals.cs | 10 +- src/BaroquenMelody/BaroquenMelody.csproj | 2 +- ...BaroquenMelody.Infrastructure.Tests.csproj | 2 +- .../BaroquenMelody.Library.Tests.csproj | 2 +- .../Composers/ChordComposerTests.cs | 5 +- .../Midi/Enums/MidiInstrumentTypeTests.cs | 2 +- .../Engine/Selection/NotePairSelectorTests.cs | 4 +- .../CompositionConfigurationEffectsTests.cs | 6 +- .../CompositionProgressReducersTests.cs | 2 +- 29 files changed, 112 insertions(+), 200 deletions(-) diff --git a/.editorconfig b/.editorconfig index 762022d5..d3ca9b0e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -73,6 +73,17 @@ dotnet_diagnostic.SA1118.severity = none # force static members to appear before non-static dotnet_diagnostic.SA1204.severity = none +# style warnings +dotnet_diagnostic.IDE0008.severity = none +dotnet_diagnostic.IDE0021.severity = none +dotnet_diagnostic.IDE0022.severity = none +dotnet_diagnostic.IDE0024.severity = none +dotnet_diagnostic.IDE0027.severity = none +dotnet_diagnostic.IDE0046.severity = none +dotnet_diagnostic.IDE0060.severity = none +dotnet_diagnostic.IDE0130.severity = none +dotnet_diagnostic.IDE0055.severity = none + # force abstraction over implementation dotnet_diagnostic.MA0016.severity = none csharp_using_directive_placement = outside_namespace:silent diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77353931..5238ebcb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: - name: 🔨 set up .net uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: 🧪 run tests run: | diff --git a/benchmarks/BaroquenMelody.Benchmarks/BaroquenMelody.Benchmarks.csproj b/benchmarks/BaroquenMelody.Benchmarks/BaroquenMelody.Benchmarks.csproj index c610a362..36df2a94 100644 --- a/benchmarks/BaroquenMelody.Benchmarks/BaroquenMelody.Benchmarks.csproj +++ b/benchmarks/BaroquenMelody.Benchmarks/BaroquenMelody.Benchmarks.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 enable enable true diff --git a/src/BaroquenMelody.App/App.xaml.cs b/src/BaroquenMelody.App/App.xaml.cs index 1674bfdb..7719bf8e 100644 --- a/src/BaroquenMelody.App/App.xaml.cs +++ b/src/BaroquenMelody.App/App.xaml.cs @@ -15,10 +15,12 @@ public App(IThemeProvider themeProvider) _themeProvider = themeProvider; - _themeProvider.IsDarkMode = Preferences.Default.Get("IsDarkMode", true); + _themeProvider.IsDarkMode = Preferences.Default.Get("IsDarkMode", defaultValue: true); - MainPage = new MainPage(); - MainPage.Title = "Baroquen Melody"; + MainPage = new MainPage + { + Title = "Baroquen Melody" + }; } protected override Window CreateWindow(IActivationState? activationState) diff --git a/src/BaroquenMelody.App/MauiProgram.cs b/src/BaroquenMelody.App/MauiProgram.cs index eeb9b6fe..d0dc6b24 100644 --- a/src/BaroquenMelody.App/MauiProgram.cs +++ b/src/BaroquenMelody.App/MauiProgram.cs @@ -9,7 +9,9 @@ using BaroquenMelody.Library.Midi; using CommunityToolkit.Maui; using Microsoft.AspNetCore.Components.WebView.Maui; +#pragma warning disable IDE0005 // Using directive is unnecessary. using Microsoft.Extensions.Logging; +#pragma warning restore IDE0005 // Using directive is unnecessary. namespace BaroquenMelody.App; diff --git a/src/BaroquenMelody.App/Platforms/Android/MainApplication.cs b/src/BaroquenMelody.App/Platforms/Android/MainApplication.cs index fcdd3056..22177292 100644 --- a/src/BaroquenMelody.App/Platforms/Android/MainApplication.cs +++ b/src/BaroquenMelody.App/Platforms/Android/MainApplication.cs @@ -5,12 +5,7 @@ namespace BaroquenMelody.App; [Application] -public class MainApplication : MauiApplication +public class MainApplication(IntPtr handle, JniHandleOwnership ownership) : MauiApplication(handle, ownership) { - public MainApplication(IntPtr handle, JniHandleOwnership ownership) - : base(handle, ownership) - { - } - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); } diff --git a/src/BaroquenMelody.App/Platforms/Android/WebViewSoftInputPatch.cs b/src/BaroquenMelody.App/Platforms/Android/WebViewSoftInputPatch.cs index 4641849c..541bd269 100644 --- a/src/BaroquenMelody.App/Platforms/Android/WebViewSoftInputPatch.cs +++ b/src/BaroquenMelody.App/Platforms/Android/WebViewSoftInputPatch.cs @@ -44,14 +44,7 @@ private static void PossiblyResizeChildOfContent() heightDifference = usableHeightSansKeyboard - usableHeightNow; } - if (heightDifference > usableHeightSansKeyboard / 4) - { - _frameLayoutParams!.Height = usableHeightSansKeyboard - heightDifference; - } - else - { - _frameLayoutParams!.Height = usableHeightNow; - } + _frameLayoutParams!.Height = heightDifference > usableHeightSansKeyboard / 4 ? usableHeightSansKeyboard - heightDifference : usableHeightNow; } _mChildOfContent!.RequestLayout(); diff --git a/src/BaroquenMelody.Library/Choices/ChordChoice.cs b/src/BaroquenMelody.Library/Choices/ChordChoice.cs index 833b634d..86ebb694 100644 --- a/src/BaroquenMelody.Library/Choices/ChordChoice.cs +++ b/src/BaroquenMelody.Library/Choices/ChordChoice.cs @@ -18,15 +18,7 @@ public IList NoteChoices init { _noteChoices = [.. value.OrderBy(static noteChoice => noteChoice.Instrument)]; } } - public bool Equals(ChordChoice? other) - { - if (other is null) - { - return false; - } - - return ReferenceEquals(this, other) || NoteChoices.SequenceEqual(other.NoteChoices); - } + public bool Equals(ChordChoice? other) => other is not null && (ReferenceEquals(this, other) || NoteChoices.SequenceEqual(other.NoteChoices)); public override int GetHashCode() { diff --git a/src/BaroquenMelody.Library/Choices/SoloChordChoiceRepository.cs b/src/BaroquenMelody.Library/Choices/SoloChordChoiceRepository.cs index b0ec1061..e396c330 100644 --- a/src/BaroquenMelody.Library/Choices/SoloChordChoiceRepository.cs +++ b/src/BaroquenMelody.Library/Choices/SoloChordChoiceRepository.cs @@ -21,7 +21,7 @@ public SoloChordChoiceRepository(CompositionConfiguration compositionConfigurati ); } - _noteChoices = noteChoiceGenerator.GenerateNoteChoices(compositionConfiguration.Instruments[0]).ToList(); + _noteChoices = [.. noteChoiceGenerator.GenerateNoteChoices(compositionConfiguration.Instruments[0])]; } public BigInteger Count => _noteChoices.Count; diff --git a/src/BaroquenMelody.Library/Domain/BaroquenChord.cs b/src/BaroquenMelody.Library/Domain/BaroquenChord.cs index 0a3822a9..e8a1c41a 100644 --- a/src/BaroquenMelody.Library/Domain/BaroquenChord.cs +++ b/src/BaroquenMelody.Library/Domain/BaroquenChord.cs @@ -44,15 +44,7 @@ public void ResetOrnamentation(MusicalTimeSpan defaultTimeSpan) /// /// The other to compare against. /// Whether the is equal to the other . - public bool Equals(BaroquenChord? other) - { - if (other is null) - { - return false; - } - - return ReferenceEquals(this, other) || Notes.SequenceEqual(other.Notes); - } + public bool Equals(BaroquenChord? other) => other is not null && (ReferenceEquals(this, other) || Notes.SequenceEqual(other.Notes)); /// /// Determines if the is equal to another object. @@ -75,20 +67,7 @@ public bool Equals(BaroquenChord? other) /// The first to compare. /// The second to compare. /// Whether the is equal to the other . - public static bool operator ==(BaroquenChord? chord, BaroquenChord? otherChord) - { - if (ReferenceEquals(chord, otherChord)) - { - return true; - } - - if (chord is null || otherChord is null) - { - return false; - } - - return chord.Equals(otherChord); - } + public static bool operator ==(BaroquenChord? chord, BaroquenChord? otherChord) => ReferenceEquals(chord, otherChord) || (chord is not null && otherChord is not null && chord.Equals(otherChord)); /// /// Determines if the is not equal to another . diff --git a/src/BaroquenMelody.Library/Domain/BaroquenNote.cs b/src/BaroquenMelody.Library/Domain/BaroquenNote.cs index a71a0533..7f33dcbd 100644 --- a/src/BaroquenMelody.Library/Domain/BaroquenNote.cs +++ b/src/BaroquenMelody.Library/Domain/BaroquenNote.cs @@ -125,20 +125,7 @@ public bool Equals(BaroquenNote? other) /// The first to compare. /// The second to compare. /// Whether the is equal to the other . - public static bool operator ==(BaroquenNote? note, BaroquenNote? otherNote) - { - if (ReferenceEquals(note, otherNote)) - { - return true; - } - - if (note is null || otherNote is null) - { - return false; - } - - return note.Equals(otherNote); - } + public static bool operator ==(BaroquenNote? note, BaroquenNote? otherNote) => ReferenceEquals(note, otherNote) || (note is not null && otherNote is not null && note.Equals(otherNote)); /// /// Determines if the is not equal to another . diff --git a/src/BaroquenMelody.Library/Dynamics/Engine/Processors/InitialDynamicsProcessor.cs b/src/BaroquenMelody.Library/Dynamics/Engine/Processors/InitialDynamicsProcessor.cs index ed8654e6..c596e829 100644 --- a/src/BaroquenMelody.Library/Dynamics/Engine/Processors/InitialDynamicsProcessor.cs +++ b/src/BaroquenMelody.Library/Dynamics/Engine/Processors/InitialDynamicsProcessor.cs @@ -11,16 +11,9 @@ public void Process(DynamicsApplicationItem item) var instrumentConfiguration = configuration.InstrumentConfigurationsByInstrument[item.Instrument]; var note = item.CurrentBeat[item.Instrument]; - double velocity; - - if (instrumentConfiguration.HasSizeableVelocityRange) - { - velocity = instrumentConfiguration.MinVelocity + instrumentConfiguration.VelocityRange * velocityRangeTarget; - } - else - { - velocity = instrumentConfiguration.MaxVelocity; - } + var velocity = instrumentConfiguration.HasSizeableVelocityRange + ? instrumentConfiguration.MinVelocity + instrumentConfiguration.VelocityRange * velocityRangeTarget + : instrumentConfiguration.MaxVelocity; note.Velocity = new SevenBitNumber(Convert.ToByte(velocity)); diff --git a/src/BaroquenMelody.Library/Enums/Extensions/NoteMotionExtensions.cs b/src/BaroquenMelody.Library/Enums/Extensions/NoteMotionExtensions.cs index cc116dc8..967b862f 100644 --- a/src/BaroquenMelody.Library/Enums/Extensions/NoteMotionExtensions.cs +++ b/src/BaroquenMelody.Library/Enums/Extensions/NoteMotionExtensions.cs @@ -22,13 +22,9 @@ internal static class NoteMotionExtensions /// The first note. /// The second note. /// A representing the motion between the two notes. - public static NoteMotion FromNotes(Note previousNote, Note currentNote) - { - if (previousNote == currentNote) - { - return NoteMotion.Oblique; - } - - return previousNote.NoteNumber > currentNote.NoteNumber ? NoteMotion.Descending : NoteMotion.Ascending; - } + public static NoteMotion FromNotes(Note previousNote, Note currentNote) => previousNote == currentNote + ? NoteMotion.Oblique + : previousNote.NoteNumber > currentNote.NoteNumber + ? NoteMotion.Descending + : NoteMotion.Ascending; } diff --git a/src/BaroquenMelody.Library/Midi/Repositories/MidiInstrumentRepository.cs b/src/BaroquenMelody.Library/Midi/Repositories/MidiInstrumentRepository.cs index 0f16f5a5..170fae8b 100644 --- a/src/BaroquenMelody.Library/Midi/Repositories/MidiInstrumentRepository.cs +++ b/src/BaroquenMelody.Library/Midi/Repositories/MidiInstrumentRepository.cs @@ -6,8 +6,8 @@ namespace BaroquenMelody.Library.Midi.Repositories; internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository { - private static readonly IEnumerable Keyboard = new List - { + private static readonly IEnumerable Keyboard = + [ GeneralMidi2Program.AcousticGrandPiano, GeneralMidi2Program.AcousticGrandPianoWide, GeneralMidi2Program.AcousticGrandPianoDark, @@ -32,10 +32,10 @@ internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository GeneralMidi2Program.HarpsichordWithKeyOff, GeneralMidi2Program.Clavi, GeneralMidi2Program.PulseClavi - }; + ]; - private static readonly IEnumerable ChromaticPercussion = new List - { + private static readonly IEnumerable ChromaticPercussion = + [ GeneralMidi2Program.Celesta, GeneralMidi2Program.Glockenspiel, GeneralMidi2Program.MusicBox, @@ -51,10 +51,10 @@ internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository GeneralMidi2Program.YangChin, GeneralMidi2Program.Timpani, GeneralMidi2Program.Kalimba - }; + ]; - private static readonly IEnumerable Organ = new List - { + private static readonly IEnumerable Organ = + [ GeneralMidi2Program.DrawbarOrgan, GeneralMidi2Program.DetunedDrawbarOrgan, GeneralMidi2Program.ItalianSixtiesOrgan, @@ -72,10 +72,10 @@ internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository GeneralMidi2Program.Accordion2, GeneralMidi2Program.Harmonica, GeneralMidi2Program.TangoAccordion - }; + ]; - private static readonly IEnumerable Guitar = new List - { + private static readonly IEnumerable Guitar = + [ GeneralMidi2Program.AcousticGuitarNylon, GeneralMidi2Program.Ukulele, GeneralMidi2Program.AcousticGuitarNylonKeyOff, @@ -100,10 +100,10 @@ internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository GeneralMidi2Program.DistortedRhythmGuitar, GeneralMidi2Program.GuitarHarmonics, GeneralMidi2Program.GuitarFeedback - }; + ]; - private static readonly IEnumerable Bass = new List - { + private static readonly IEnumerable Bass = + [ GeneralMidi2Program.AcousticBass, GeneralMidi2Program.ElectricBassFinger, GeneralMidi2Program.FingerSlapBass, @@ -120,10 +120,10 @@ internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository GeneralMidi2Program.SynthBass4Attack, GeneralMidi2Program.SynthBassRubber, GeneralMidi2Program.AttackPulse - }; + ]; - private static readonly IEnumerable Strings = new List - { + private static readonly IEnumerable Strings = + [ GeneralMidi2Program.Violin, GeneralMidi2Program.ViolinSlowAttack, GeneralMidi2Program.Viola, @@ -139,10 +139,10 @@ internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository GeneralMidi2Program.Koto, GeneralMidi2Program.TaishoKoto, GeneralMidi2Program.Fiddle - }; + ]; - private static readonly IEnumerable Ensemble = new List - { + private static readonly IEnumerable Ensemble = + [ GeneralMidi2Program.StringEnsembles1, GeneralMidi2Program.StringsAndBrass, GeneralMidi2Program.SixtiesStrings, @@ -154,20 +154,20 @@ internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository GeneralMidi2Program.BassHitPlus, GeneralMidi2Program.SixthHit, GeneralMidi2Program.EuroHit - }; + ]; - private static readonly IEnumerable Voice = new List - { + private static readonly IEnumerable Voice = + [ GeneralMidi2Program.ChoirAahs, GeneralMidi2Program.ChoirAahs2, GeneralMidi2Program.VoiceOohs, GeneralMidi2Program.Humming, GeneralMidi2Program.SynthVoice, GeneralMidi2Program.AnalogVoice - }; + ]; - private static readonly IEnumerable Brass = new List - { + private static readonly IEnumerable Brass = + [ GeneralMidi2Program.Trumpet, GeneralMidi2Program.DarkTrumpetSoft, GeneralMidi2Program.Trombone, @@ -187,10 +187,10 @@ internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository GeneralMidi2Program.SynthBrass2, GeneralMidi2Program.SynthBrass4, GeneralMidi2Program.AnalogSynthBrass2 - }; + ]; - private static readonly IEnumerable Woodwind = new List - { + private static readonly IEnumerable Woodwind = + [ GeneralMidi2Program.SopranoSax, GeneralMidi2Program.AltoSax, GeneralMidi2Program.TenorSax, @@ -209,10 +209,10 @@ internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository GeneralMidi2Program.Ocarina, GeneralMidi2Program.Shanai, GeneralMidi2Program.BagPipe - }; + ]; - private static readonly IEnumerable Synth = new List - { + private static readonly IEnumerable Synth = + [ GeneralMidi2Program.Lead1Square, GeneralMidi2Program.Lead1ASquare2, GeneralMidi2Program.Lead1BSine, @@ -229,21 +229,23 @@ internal sealed class MidiInstrumentRepository : IMidiInstrumentRepository GeneralMidi2Program.Lead7Fifths, GeneralMidi2Program.Lead8BassLead, GeneralMidi2Program.Lead8ASoftWrl - }; + ]; - private static readonly IEnumerable All = Keyboard - .Concat(ChromaticPercussion) - .Concat(Organ) - .Concat(Guitar) - .Concat(Bass) - .Concat(Strings) - .Concat(Ensemble) - .Concat(Voice) - .Concat(Brass) - .Concat(Woodwind) - .Concat(Synth) - .OrderBy(instrument => instrument.ToSpaceSeparatedString(), StringComparer.OrdinalIgnoreCase) - .ToList(); + private static readonly IEnumerable All = + [ + .. Keyboard + .Concat(ChromaticPercussion) + .Concat(Organ) + .Concat(Guitar) + .Concat(Bass) + .Concat(Strings) + .Concat(Ensemble) + .Concat(Voice) + .Concat(Brass) + .Concat(Woodwind) + .Concat(Synth) + .OrderBy(instrument => instrument.ToSpaceSeparatedString(), StringComparer.OrdinalIgnoreCase) + ]; public IEnumerable GetMidiInstruments(MidiInstrumentType midiInstrumentType) { diff --git a/src/BaroquenMelody.Library/Ornamentation/Cleaning/Engine/Policies/Input/HasTargetOrnamentations.cs b/src/BaroquenMelody.Library/Ornamentation/Cleaning/Engine/Policies/Input/HasTargetOrnamentations.cs index 97872432..af30b9a0 100644 --- a/src/BaroquenMelody.Library/Ornamentation/Cleaning/Engine/Policies/Input/HasTargetOrnamentations.cs +++ b/src/BaroquenMelody.Library/Ornamentation/Cleaning/Engine/Policies/Input/HasTargetOrnamentations.cs @@ -5,13 +5,7 @@ namespace BaroquenMelody.Library.Ornamentation.Cleaning.Engine.Policies.Input; internal sealed class HasTargetOrnamentations(OrnamentationType primaryOrnamentationType, OrnamentationType secondaryOrnamentationType) : IInputPolicy { - public InputPolicyResult ShouldProcess(OrnamentationCleaningItem item) - { - if (item.Note.OrnamentationType == primaryOrnamentationType && item.OtherNote.OrnamentationType == secondaryOrnamentationType) - { - return InputPolicyResult.Continue; - } - - return InputPolicyResult.Reject; - } + public InputPolicyResult ShouldProcess(OrnamentationCleaningItem item) => item.Note.OrnamentationType == primaryOrnamentationType && item.OtherNote.OrnamentationType == secondaryOrnamentationType + ? InputPolicyResult.Continue + : InputPolicyResult.Reject; } diff --git a/src/BaroquenMelody.Library/Ornamentation/Cleaning/Engine/Selection/NotePairSelector.cs b/src/BaroquenMelody.Library/Ornamentation/Cleaning/Engine/Selection/NotePairSelector.cs index 399e7edf..11409974 100644 --- a/src/BaroquenMelody.Library/Ornamentation/Cleaning/Engine/Selection/NotePairSelector.cs +++ b/src/BaroquenMelody.Library/Ornamentation/Cleaning/Engine/Selection/NotePairSelector.cs @@ -24,11 +24,8 @@ public NotePair Select(OrnamentationCleaningItem item) return new NotePair(item.Note, item.OtherNote); } - if (_primaryNoteOrnamentationTypes.Contains(item.OtherNote.OrnamentationType) && _secondaryNoteOrnamentationTypes.Contains(item.Note.OrnamentationType)) - { - return new NotePair(item.OtherNote, item.Note); - } - - throw new InvalidOperationException("The ornamentation cleaning item does not contain the expected ornamentation types."); + return _primaryNoteOrnamentationTypes.Contains(item.OtherNote.OrnamentationType) && _secondaryNoteOrnamentationTypes.Contains(item.Note.OrnamentationType) + ? new NotePair(item.OtherNote, item.Note) + : throw new InvalidOperationException("The ornamentation cleaning item does not contain the expected ornamentation types."); } } diff --git a/src/BaroquenMelody.Library/Ornamentation/Engine/OrnamentationEngineBuilder.cs b/src/BaroquenMelody.Library/Ornamentation/Engine/OrnamentationEngineBuilder.cs index 43b72876..05da5369 100644 --- a/src/BaroquenMelody.Library/Ornamentation/Engine/OrnamentationEngineBuilder.cs +++ b/src/BaroquenMelody.Library/Ornamentation/Engine/OrnamentationEngineBuilder.cs @@ -72,12 +72,11 @@ and not OrnamentationType.Rest .ToList(); var cleaningSelector = new NoteTargetSelector( - new List - { + [ new CleanTargetOrnamentation(), new CleanLowerNote(), new CleanRandomNote(_weightedRandomBooleanGenerator) - } + ] ); var ornamentationCombinations = new LazyCartesianProduct(ornamentationTypes, ornamentationTypes); @@ -109,7 +108,7 @@ and not OrnamentationType.Rest return PolicyEngineBuilder .Configure() .WithoutInputPolicies() - .WithProcessors(processors.ToArray()) + .WithProcessors([.. processors]) .WithOutputPolicies() .Build(); } diff --git a/src/BaroquenMelody.Library/Ornamentation/Engine/Processors/Factories/OrnamentationProcessorConfigurationFactory.cs b/src/BaroquenMelody.Library/Ornamentation/Engine/Processors/Factories/OrnamentationProcessorConfigurationFactory.cs index 6ba358c9..e0bbba3d 100644 --- a/src/BaroquenMelody.Library/Ornamentation/Engine/Processors/Factories/OrnamentationProcessorConfigurationFactory.cs +++ b/src/BaroquenMelody.Library/Ornamentation/Engine/Processors/Factories/OrnamentationProcessorConfigurationFactory.cs @@ -50,15 +50,10 @@ ILogger logger private readonly IInputPolicy _isFifthOfChord = new IsFifthOfChord(chordNumberIdentifier, compositionConfiguration); - private static readonly Predicate<(BaroquenNote? CurrentNote, BaroquenNote? NextNote)> ShouldInvertBasedOnDirection = notes => - { - if (notes.CurrentNote is null || notes.NextNote is null) - { - return false; - } - - return notes.CurrentNote.NoteNumber > notes.NextNote.NoteNumber; - }; + private static readonly Predicate<(BaroquenNote? CurrentNote, BaroquenNote? NextNote)> ShouldInvertBasedOnDirection = + notes => notes.CurrentNote is not null + && notes.NextNote is not null + && notes.CurrentNote.NoteNumber > notes.NextNote.NoteNumber; private static readonly Predicate<(BaroquenNote? CurrentNote, BaroquenNote? NextNote)> ShouldNotInvert = _ => false; diff --git a/src/BaroquenMelody.Library/Ornamentation/Enums/Extensions/OrnamentationTypeExtensions.cs b/src/BaroquenMelody.Library/Ornamentation/Enums/Extensions/OrnamentationTypeExtensions.cs index ef33e5d3..28374d23 100644 --- a/src/BaroquenMelody.Library/Ornamentation/Enums/Extensions/OrnamentationTypeExtensions.cs +++ b/src/BaroquenMelody.Library/Ornamentation/Enums/Extensions/OrnamentationTypeExtensions.cs @@ -32,13 +32,7 @@ internal static class OrnamentationTypeExtensions { OrnamentationType.Rest, 0 } }.ToFrozenDictionary(); - public static int OrnamentationCount(this OrnamentationType ornamentationType) - { - if (_ornamentationCountsByType.TryGetValue(ornamentationType, out var ornamentationCount)) - { - return ornamentationCount; - } - - throw new ArgumentOutOfRangeException(nameof(ornamentationType), ornamentationType, "Ornamentation type not found."); - } + public static int OrnamentationCount(this OrnamentationType ornamentationType) => _ornamentationCountsByType.TryGetValue(ornamentationType, out var ornamentationCount) + ? ornamentationCount + : throw new ArgumentOutOfRangeException(nameof(ornamentationType), ornamentationType, "Ornamentation type not found."); } diff --git a/src/BaroquenMelody.Library/Rules/AvoidDissonantLeaps.cs b/src/BaroquenMelody.Library/Rules/AvoidDissonantLeaps.cs index 4bbe07ed..10e6bb4f 100644 --- a/src/BaroquenMelody.Library/Rules/AvoidDissonantLeaps.cs +++ b/src/BaroquenMelody.Library/Rules/AvoidDissonantLeaps.cs @@ -9,15 +9,7 @@ internal sealed class AvoidDissonantLeaps(CompositionConfiguration compositionCo { private const int LeapThreshold = 1; - public bool Evaluate(IReadOnlyList precedingChords, BaroquenChord nextChord) - { - if (precedingChords.Count == 0) - { - return true; - } - - return !IsDissonantLeap(precedingChords[^1], nextChord); - } + public bool Evaluate(IReadOnlyList precedingChords, BaroquenChord nextChord) => precedingChords.Count == 0 || !IsDissonantLeap(precedingChords[^1], nextChord); private bool IsDissonantLeap(BaroquenChord lastChord, BaroquenChord nextChord) { diff --git a/src/BaroquenMelody.Library/Rules/AvoidParallelIntervals.cs b/src/BaroquenMelody.Library/Rules/AvoidParallelIntervals.cs index 00aa6a07..a01f9645 100644 --- a/src/BaroquenMelody.Library/Rules/AvoidParallelIntervals.cs +++ b/src/BaroquenMelody.Library/Rules/AvoidParallelIntervals.cs @@ -9,15 +9,7 @@ namespace BaroquenMelody.Library.Rules; /// internal sealed class AvoidParallelIntervals(Interval targetInterval) : ICompositionRule { - public bool Evaluate(IReadOnlyList precedingChords, BaroquenChord nextChord) - { - if (precedingChords.Count == 0) - { - return true; - } - - return !HasParallelIntervals(precedingChords[^1], nextChord); - } + public bool Evaluate(IReadOnlyList precedingChords, BaroquenChord nextChord) => precedingChords.Count == 0 || !HasParallelIntervals(precedingChords[^1], nextChord); private bool HasParallelIntervals(BaroquenChord lastChord, BaroquenChord nextChord) { diff --git a/src/BaroquenMelody/BaroquenMelody.csproj b/src/BaroquenMelody/BaroquenMelody.csproj index a0b90277..d53003e6 100644 --- a/src/BaroquenMelody/BaroquenMelody.csproj +++ b/src/BaroquenMelody/BaroquenMelody.csproj @@ -3,7 +3,7 @@ Exe 0.0.1 - net8.0 + net9.0 enable enable true diff --git a/tests/BaroquenMelody.Infrastructure.Tests/BaroquenMelody.Infrastructure.Tests.csproj b/tests/BaroquenMelody.Infrastructure.Tests/BaroquenMelody.Infrastructure.Tests.csproj index 1a20bf7b..331b30e2 100644 --- a/tests/BaroquenMelody.Infrastructure.Tests/BaroquenMelody.Infrastructure.Tests.csproj +++ b/tests/BaroquenMelody.Infrastructure.Tests/BaroquenMelody.Infrastructure.Tests.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 enable enable true diff --git a/tests/BaroquenMelody.Library.Tests/BaroquenMelody.Library.Tests.csproj b/tests/BaroquenMelody.Library.Tests/BaroquenMelody.Library.Tests.csproj index 0af4fe2d..30f53868 100644 --- a/tests/BaroquenMelody.Library.Tests/BaroquenMelody.Library.Tests.csproj +++ b/tests/BaroquenMelody.Library.Tests/BaroquenMelody.Library.Tests.csproj @@ -1,7 +1,7 @@  - net8.0 + net9.0 enable enable true diff --git a/tests/BaroquenMelody.Library.Tests/Composers/ChordComposerTests.cs b/tests/BaroquenMelody.Library.Tests/Composers/ChordComposerTests.cs index db2dacea..bf513e83 100644 --- a/tests/BaroquenMelody.Library.Tests/Composers/ChordComposerTests.cs +++ b/tests/BaroquenMelody.Library.Tests/Composers/ChordComposerTests.cs @@ -1,5 +1,4 @@ -using BaroquenMelody.Library.Choices; -using BaroquenMelody.Library.Composers; +using BaroquenMelody.Library.Composers; using BaroquenMelody.Library.Domain; using BaroquenMelody.Library.Enums; using BaroquenMelody.Library.Exceptions; @@ -74,7 +73,7 @@ public void WhenComposeIsInvoked_ThenCompositionIsReturned() public void WhenComposeIsInvoked_AndNoValidChordChoicesAreAvailable_ThenNoValidChordChoicesAvailableExceptionIsThrown() { // arrange - _mockCompositionStrategy.GetPossibleChordChoices(Arg.Any>()).Returns(new List()); + _mockCompositionStrategy.GetPossibleChordChoices(Arg.Any>()).Returns([]); var precedingChords = new List { diff --git a/tests/BaroquenMelody.Library.Tests/Midi/Enums/MidiInstrumentTypeTests.cs b/tests/BaroquenMelody.Library.Tests/Midi/Enums/MidiInstrumentTypeTests.cs index 92af85f9..1b0ac380 100644 --- a/tests/BaroquenMelody.Library.Tests/Midi/Enums/MidiInstrumentTypeTests.cs +++ b/tests/BaroquenMelody.Library.Tests/Midi/Enums/MidiInstrumentTypeTests.cs @@ -16,7 +16,7 @@ public void HasFlag_returns_expected_values() // arrange var midiInstrumentTypes = EnumUtils .AsEnumerable() - .Where(midiInstrumentType => midiInstrumentType != MidiInstrumentType.None && midiInstrumentType != MidiInstrumentType.All) + .Where(midiInstrumentType => midiInstrumentType is not MidiInstrumentType.None and not MidiInstrumentType.All) .OrderBy(_ => ThreadLocalRandom.Next()) .ToList(); diff --git a/tests/BaroquenMelody.Library.Tests/Ornamentation/Cleaning/Engine/Selection/NotePairSelectorTests.cs b/tests/BaroquenMelody.Library.Tests/Ornamentation/Cleaning/Engine/Selection/NotePairSelectorTests.cs index d8bc3907..e4d54a7d 100644 --- a/tests/BaroquenMelody.Library.Tests/Ornamentation/Cleaning/Engine/Selection/NotePairSelectorTests.cs +++ b/tests/BaroquenMelody.Library.Tests/Ornamentation/Cleaning/Engine/Selection/NotePairSelectorTests.cs @@ -88,8 +88,8 @@ public void Selector_throws_when_ornamentation_types_do_not_match() { // arrange var selector = new NotePairSelector( - new List { OrnamentationType.Run }, - new List { OrnamentationType.DoubleRun } + [OrnamentationType.Run], + [OrnamentationType.DoubleRun] ); var ornamentationCleaningItem = new OrnamentationCleaningItem( diff --git a/tests/BaroquenMelody.Library.Tests/Store/Effects/CompositionConfigurationEffectsTests.cs b/tests/BaroquenMelody.Library.Tests/Store/Effects/CompositionConfigurationEffectsTests.cs index 586f6027..18769c40 100644 --- a/tests/BaroquenMelody.Library.Tests/Store/Effects/CompositionConfigurationEffectsTests.cs +++ b/tests/BaroquenMelody.Library.Tests/Store/Effects/CompositionConfigurationEffectsTests.cs @@ -109,8 +109,7 @@ public async Task HandleUpdateCompositionConfiguration_updates_instrument_config updateInstrumentConfiguration.MinNote == Notes.B3 && updateInstrumentConfiguration.MaxNote == Notes.B4 && updateInstrumentConfiguration.Status == ConfigurationStatus.Enabled && - updateInstrumentConfiguration.IsUserApplied == false - ) + !updateInstrumentConfiguration.IsUserApplied) ); } @@ -141,8 +140,7 @@ public async Task HandleLoadSavedCompositionConfigurationAsync_dispatches_expect updateInstrumentConfiguration.MaxNote == instrumentConfiguration.MaxNote && updateInstrumentConfiguration.MidiProgram == instrumentConfiguration.MidiProgram && updateInstrumentConfiguration.Status == instrumentConfiguration.Status && - updateInstrumentConfiguration.IsUserApplied == true - ) + updateInstrumentConfiguration.IsUserApplied) ); } diff --git a/tests/BaroquenMelody.Library.Tests/Store/Reducers/CompositionProgressReducersTests.cs b/tests/BaroquenMelody.Library.Tests/Store/Reducers/CompositionProgressReducersTests.cs index f0502e62..ca3eeb81 100644 --- a/tests/BaroquenMelody.Library.Tests/Store/Reducers/CompositionProgressReducersTests.cs +++ b/tests/BaroquenMelody.Library.Tests/Store/Reducers/CompositionProgressReducersTests.cs @@ -21,7 +21,7 @@ public void ReduceUpdateCompositionProgressAction_returns_new_state_with_expecte var newState = CompositionProgressReducers.ReduceUpdateCompositionProgressAction(state, action); // assert - newState.CompletedSteps.Should().BeEquivalentTo(new HashSet { CompositionStep.Waiting }); + newState.CompletedSteps.Should().BeEquivalentTo([CompositionStep.Waiting]); newState.CurrentStep.Should().Be(CompositionStep.Theme); newState.Message.Should().Be("Composing main theme..."); newState.ThemeProgress.Should().Be(0.0d);