Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double Pickup Ornamentation #215

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</MudStack>
</div>
<MudGrid Spacing="0" Justify="Justify.Center">
@foreach (var compositionRule in CompositionRules)
@foreach (var compositionRule in CompositionRules.OrderBy(rule => rule.ToSpaceSeparatedString()))
{
<MudItem xs="12" sm="12" md="6" lg="6" xl="6" xxl="6">
<CompositionRuleConfigurationCard CompositionRule="compositionRule"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</MudStack>
</div>
<MudGrid Spacing="0" Justify="Justify.Center">
@foreach (var ornamentation in Ornamentations)
@foreach (var ornamentation in Ornamentations.OrderBy(ornamentation => ornamentation.ToSpaceSeparatedString()))
{
<MudItem xs="12" sm="12" md="6" lg="6" xl="6" xxl="6">
<OrnamentationConfigurationCard OrnamentationType="ornamentation"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public sealed record AggregateOrnamentationConfiguration(ISet<OrnamentationConfi
new(OrnamentationType.RepeatedNote, ConfigurationStatus.Enabled, 15),
new(OrnamentationType.DelayedRepeatedNote, ConfigurationStatus.Enabled, 15),
new(OrnamentationType.Pickup, ConfigurationStatus.Enabled, 25),
new(OrnamentationType.DelayedPickup, ConfigurationStatus.Enabled, 25)
new(OrnamentationType.DelayedPickup, ConfigurationStatus.Enabled, 25),
new(OrnamentationType.DoublePickup, ConfigurationStatus.Enabled, 25)
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public sealed record InstrumentConfiguration(

public static readonly SevenBitNumber DefaultMinVelocity = new(50);

public static readonly SevenBitNumber DefaultMaxVelocity = new(75);
public static readonly SevenBitNumber DefaultMaxVelocity = new(60);

[JsonIgnore]
public bool IsEnabled => Status.IsEnabled();
Expand All @@ -57,8 +57,8 @@ public sealed record InstrumentConfiguration(
public static readonly FrozenDictionary<Instrument, InstrumentConfiguration> DefaultConfigurations = new Dictionary<Instrument, InstrumentConfiguration>
{
{ Instrument.One, new InstrumentConfiguration(Instrument.One, Notes.C5, Notes.E6, DefaultMinVelocity, DefaultMaxVelocity, GeneralMidi2Program.AcousticGrandPiano, ConfigurationStatus.Enabled) },
{ Instrument.Two, new InstrumentConfiguration(Instrument.Two, Notes.G3, Notes.B4, DefaultMinVelocity, DefaultMaxVelocity, GeneralMidi2Program.AcousticGrandPiano, ConfigurationStatus.Enabled) },
{ Instrument.Three, new InstrumentConfiguration(Instrument.Three, Notes.D3, Notes.F4, DefaultMinVelocity, DefaultMaxVelocity, GeneralMidi2Program.AcousticGrandPiano, ConfigurationStatus.Enabled) },
{ Instrument.Four, new InstrumentConfiguration(Instrument.Four, Notes.C2, Notes.E3, DefaultMinVelocity, DefaultMaxVelocity, GeneralMidi2Program.AcousticGrandPiano, ConfigurationStatus.Disabled) }
{ Instrument.Two, new InstrumentConfiguration(Instrument.Two, Notes.B3, Notes.D5, DefaultMinVelocity, DefaultMaxVelocity, GeneralMidi2Program.AcousticGrandPiano, ConfigurationStatus.Enabled) },
{ Instrument.Three, new InstrumentConfiguration(Instrument.Three, Notes.A2, Notes.C4, DefaultMinVelocity, DefaultMaxVelocity, GeneralMidi2Program.AcousticGrandPiano, ConfigurationStatus.Enabled) },
{ Instrument.Four, new InstrumentConfiguration(Instrument.Four, Notes.G1, Notes.B2, DefaultMinVelocity, DefaultMaxVelocity, GeneralMidi2Program.AcousticGrandPiano, ConfigurationStatus.Disabled) }
}.ToFrozenDictionary();
}
1 change: 1 addition & 0 deletions src/BaroquenMelody.Library/Midi/MidiExampleGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public MidiFile GenerateExampleOrnamentationMidiFile(OrnamentationType ornamenta
OrnamentationType.DelayedNeighborTone => new BaroquenNote(Instrument.One, Note.Get(compositionConfiguration.Scale.Tonic, 4), compositionConfiguration.DefaultNoteTimeSpan),
OrnamentationType.Pickup => new BaroquenNote(Instrument.One, Note.Get(compositionConfiguration.Scale.Mediant, 4), compositionConfiguration.DefaultNoteTimeSpan),
OrnamentationType.DelayedPickup => new BaroquenNote(Instrument.One, Note.Get(compositionConfiguration.Scale.Mediant, 4), compositionConfiguration.DefaultNoteTimeSpan),
OrnamentationType.DoublePickup => new BaroquenNote(Instrument.One, Note.Get(compositionConfiguration.Scale.Mediant, 4), compositionConfiguration.DefaultNoteTimeSpan),
_ => throw new ArgumentOutOfRangeException(nameof(ornamentationType), ornamentationType, "Ornamentation type not supported.")
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,26 @@ public IEnumerable<OrnamentationProcessorConfiguration> Create(OrnamentationConf
)
);
break;
case OrnamentationType.DoublePickup:
processorConfigurations.Add(
new OrnamentationProcessorConfiguration(
OrnamentationType.DoublePickup,
InputPolicies:
[
wantsToOrnament,
_hasNoOrnamentation,
_hasNextBeat,
_isNotRepeatedNote,
new IsNextNoteIntervalWithinInstrumentRange(compositionConfiguration, 2).And(new IsIntervalWithinInstrumentRange(compositionConfiguration, -2))
],
OutputPolicies: [logOrnamentation],
Translations: [2, 1],
ShouldInvertBasedOnDirection,
TranslationInversionIndices: new HashSet<int> { 0, 1 }.ToFrozenSet(),
ShouldTranslateOnCurrentNote: false
)
);
break;
case OrnamentationType.None:
case OrnamentationType.Sustain:
case OrnamentationType.MidSustain:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace BaroquenMelody.Library.Ornamentation.Enums.Extensions;

internal static class OrnamentationTypeExtensions
{
private static readonly FrozenDictionary<OrnamentationType, int> _ornamentationCountsByType = new Dictionary<OrnamentationType, int>
private static readonly FrozenDictionary<OrnamentationType, int> OrnamentationCountsByType = new Dictionary<OrnamentationType, int>
{
{ OrnamentationType.DecorateInterval, 3 },
{ OrnamentationType.DelayedRun, 4 },
Expand All @@ -26,13 +26,14 @@ internal static class OrnamentationTypeExtensions
{ OrnamentationType.Turn, 3 },
{ OrnamentationType.Pickup, 1 },
{ OrnamentationType.DelayedPickup, 1 },
{ OrnamentationType.DoublePickup, 2 },
{ OrnamentationType.None, 0 },
{ OrnamentationType.Sustain, 0 },
{ OrnamentationType.MidSustain, 0 },
{ OrnamentationType.Rest, 0 }
}.ToFrozenDictionary();

public static int OrnamentationCount(this OrnamentationType ornamentationType) => _ornamentationCountsByType.TryGetValue(ornamentationType, out var ornamentationCount)
public static int OrnamentationCount(this OrnamentationType ornamentationType) => OrnamentationCountsByType.TryGetValue(ornamentationType, out var ornamentationCount)
? ornamentationCount
: throw new ArgumentOutOfRangeException(nameof(ornamentationType), ornamentationType, "Ornamentation type not found.");
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,10 @@ public enum OrnamentationType : byte
/// <summary>
/// A delayed pickup note before another note.
/// </summary>
DelayedPickup
DelayedPickup,

/// <summary>
/// A double pickup note before another note.
/// </summary>
DoublePickup
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ internal sealed class MusicalTimeSpanCalculator : IMusicalTimeSpanCalculator
OrnamentationType.DelayedPickup when meter == Meter.ThreeFour => MusicalTimeSpan.Half + MusicalTimeSpan.Eighth,
OrnamentationType.DelayedPickup when meter == Meter.FiveEight => MusicalTimeSpan.Half,

OrnamentationType.DoublePickup when meter == Meter.FourFour => MusicalTimeSpan.Quarter,
OrnamentationType.DoublePickup when meter == Meter.ThreeFour => MusicalTimeSpan.Half,
OrnamentationType.DoublePickup when meter == Meter.FiveEight => MusicalTimeSpan.Quarter.Dotted(1),

OrnamentationType.Run when meter == Meter.FourFour => MusicalTimeSpan.Eighth,
OrnamentationType.Run when meter == Meter.ThreeFour => MusicalTimeSpan.Quarter.Dotted(1),
OrnamentationType.Run when meter == Meter.FiveEight => MusicalTimeSpan.Quarter,
Expand Down Expand Up @@ -121,6 +125,10 @@ internal sealed class MusicalTimeSpanCalculator : IMusicalTimeSpanCalculator
OrnamentationType.DelayedPickup when meter == Meter.ThreeFour => MusicalTimeSpan.Eighth,
OrnamentationType.DelayedPickup when meter == Meter.FiveEight => MusicalTimeSpan.Eighth,

OrnamentationType.DoublePickup when meter == Meter.FourFour => MusicalTimeSpan.Eighth,
OrnamentationType.DoublePickup when meter == Meter.ThreeFour => MusicalTimeSpan.Eighth,
OrnamentationType.DoublePickup when meter == Meter.FiveEight => MusicalTimeSpan.Eighth,

OrnamentationType.Run when meter == Meter.FourFour => MusicalTimeSpan.Eighth,
OrnamentationType.Run when meter == Meter.ThreeFour => MusicalTimeSpan.Eighth,
OrnamentationType.Run when meter == Meter.FiveEight => MusicalTimeSpan.Eighth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void ConfigurableOrnamentations_returns_expected_values()
OrnamentationType.RepeatedNote,
OrnamentationType.DelayedRepeatedNote,
OrnamentationType.Pickup,
OrnamentationType.DelayedPickup
OrnamentationType.DelayedPickup,
OrnamentationType.DoublePickup
};

// act
Expand Down Expand Up @@ -101,7 +102,8 @@ public void Randomize_dispatches_expected_actions()
{ OrnamentationType.RepeatedNote, new OrnamentationConfiguration(OrnamentationType.RepeatedNote, ConfigurationStatus.Disabled, 100) },
{ OrnamentationType.DelayedRepeatedNote, new OrnamentationConfiguration(OrnamentationType.DelayedRepeatedNote, ConfigurationStatus.Locked, 100) },
{ OrnamentationType.Pickup, new OrnamentationConfiguration(OrnamentationType.Pickup, ConfigurationStatus.Enabled, 100) },
{ OrnamentationType.DelayedPickup, new OrnamentationConfiguration(OrnamentationType.DelayedPickup, ConfigurationStatus.Enabled, 100) }
{ OrnamentationType.DelayedPickup, new OrnamentationConfiguration(OrnamentationType.DelayedPickup, ConfigurationStatus.Enabled, 100) },
{ OrnamentationType.DoublePickup, new OrnamentationConfiguration(OrnamentationType.DoublePickup, ConfigurationStatus.Enabled, 100) }
};

_mockState.Value.Returns(new CompositionOrnamentationConfigurationState(configurations));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal sealed class OrnamentationTypeExtensionsTests
[TestCase(OrnamentationType.Turn, 3)]
[TestCase(OrnamentationType.Pickup, 1)]
[TestCase(OrnamentationType.DelayedPickup, 1)]
[TestCase(OrnamentationType.DoublePickup, 2)]
[TestCase(OrnamentationType.None, 0)]
[TestCase(OrnamentationType.Sustain, 0)]
[TestCase(OrnamentationType.MidSustain, 0)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ private static IEnumerable<TestCaseData> PrimaryNoteTestCases
yield return new TestCaseData(OrnamentationType.DelayedPickup, Meter.FourFour, MusicalTimeSpan.Quarter.Dotted(1));

yield return new TestCaseData(OrnamentationType.DelayedPickup, Meter.ThreeFour, MusicalTimeSpan.Half + MusicalTimeSpan.Eighth);

yield return new TestCaseData(OrnamentationType.DoublePickup, Meter.FourFour, MusicalTimeSpan.Quarter);

yield return new TestCaseData(OrnamentationType.DoublePickup, Meter.ThreeFour, MusicalTimeSpan.Half);
}
}

Expand Down Expand Up @@ -296,6 +300,10 @@ private static IEnumerable<TestCaseData> OrnamentedNoteTestCases
yield return new TestCaseData(OrnamentationType.DelayedPickup, Meter.FourFour, MusicalTimeSpan.Eighth, 1);

yield return new TestCaseData(OrnamentationType.DelayedPickup, Meter.ThreeFour, MusicalTimeSpan.Eighth, 1);

yield return new TestCaseData(OrnamentationType.DoublePickup, Meter.FourFour, MusicalTimeSpan.Eighth, 1);

yield return new TestCaseData(OrnamentationType.DoublePickup, Meter.ThreeFour, MusicalTimeSpan.Eighth, 1);
}
}
}
Loading