-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TimedObjectUtilities.ProcessObjects methods
- Loading branch information
1 parent
4af77ae
commit 5983bdd
Showing
12 changed files
with
10,913 additions
and
4 deletions.
There are no files selected for viewing
444 changes: 444 additions & 0 deletions
444
DryWetMidi.Tests/Interaction/TimedObject/TimedObjectUtilitiesTests.Common.cs
Large diffs are not rendered by default.
Oops, something went wrong.
967 changes: 967 additions & 0 deletions
967
...ion/TimedObject/TimedObjectUtilitiesTests.ProcessObjects.Chords.ChordDetectionSettings.cs
Large diffs are not rendered by default.
Oops, something went wrong.
3,040 changes: 3,040 additions & 0 deletions
3,040
DryWetMidi.Tests/Interaction/TimedObject/TimedObjectUtilitiesTests.ProcessObjects.Chords.cs
Large diffs are not rendered by default.
Oops, something went wrong.
1,462 changes: 1,462 additions & 0 deletions
1,462
...teraction/TimedObject/TimedObjectUtilitiesTests.ProcessObjects.Notes.DetectionSettings.cs
Large diffs are not rendered by default.
Oops, something went wrong.
2,566 changes: 2,566 additions & 0 deletions
2,566
DryWetMidi.Tests/Interaction/TimedObject/TimedObjectUtilitiesTests.ProcessObjects.Notes.cs
Large diffs are not rendered by default.
Oops, something went wrong.
1,797 changes: 1,797 additions & 0 deletions
1,797
...idi.Tests/Interaction/TimedObject/TimedObjectUtilitiesTests.ProcessObjects.TimedEvents.cs
Large diffs are not rendered by default.
Oops, something went wrong.
252 changes: 252 additions & 0 deletions
252
DryWetMidi.Tests/Interaction/TimedObject/TimedObjectUtilitiesTests.ProcessObjects.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
using Melanchall.DryWetMidi.Common; | ||
using Melanchall.DryWetMidi.Core; | ||
using Melanchall.DryWetMidi.Interaction; | ||
using Melanchall.DryWetMidi.Tests.Utilities; | ||
using NUnit.Framework; | ||
|
||
namespace Melanchall.DryWetMidi.Tests.Interaction | ||
{ | ||
[TestFixture] | ||
public sealed partial class TimedObjectUtilitiesTests | ||
{ | ||
#region Test methods | ||
|
||
[Test] | ||
public void ProcessObjects_TimedEventsAndNotes_WithPredicate_1([Values] ContainerType containerType) => ProcessObjects_EventsCollection_WithPredicate( | ||
containerType: containerType, | ||
objectType: ObjectType.TimedEvent | ObjectType.Note, | ||
midiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A"), | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
}, | ||
action: obj => | ||
{ | ||
if (obj is TimedEvent timedEvent && timedEvent.Event is TextEvent textEvent && textEvent.Text == "A") | ||
textEvent.Text = "B"; | ||
else | ||
obj.Time += 10; | ||
}, | ||
match: obj => true, | ||
expectedMidiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("B"), | ||
new NoteOnEvent { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
}, | ||
expectedProcessedCount: 3); | ||
|
||
[Test] | ||
public void ProcessObjects_TimedEventsAndNotes_WithPredicate_2([Values] ContainerType containerType) => ProcessObjects_EventsCollection_WithPredicate( | ||
containerType: containerType, | ||
objectType: ObjectType.TimedEvent | ObjectType.Note, | ||
midiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A"), | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
}, | ||
action: obj => obj.Time += 10, | ||
match: obj => obj is TimedEvent timedEvent && timedEvent.Event is TextEvent textEvent && textEvent.Text == "A", | ||
expectedMidiEvents: new MidiEvent[] | ||
{ | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
new TextEvent("A") { DeltaTime = 10 }, | ||
}, | ||
expectedProcessedCount: 1); | ||
|
||
[Test] | ||
public void ProcessObjects_TimedEventsAndChords_WithPredicate_1([Values] ContainerType containerType) => ProcessObjects_EventsCollection_WithPredicate( | ||
containerType: containerType, | ||
objectType: ObjectType.TimedEvent | ObjectType.Chord, | ||
midiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A"), | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
new NoteOnEvent { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent((SevenBitNumber)70, SevenBitNumber.MaxValue), | ||
new NoteOffEvent((SevenBitNumber)70, SevenBitNumber.MinValue), | ||
}, | ||
action: obj => obj.Time += obj is TimedEvent ? 10 : 20, | ||
match: obj => true, | ||
expectedMidiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A") { DeltaTime = 10 }, | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
new NoteOnEvent { DeltaTime = 20 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent((SevenBitNumber)70, SevenBitNumber.MaxValue), | ||
new NoteOffEvent((SevenBitNumber)70, SevenBitNumber.MinValue), | ||
}, | ||
expectedProcessedCount: 5, | ||
settings: new ObjectDetectionSettings | ||
{ | ||
ChordDetectionSettings = new ChordDetectionSettings | ||
{ | ||
NotesMinCount = 2 | ||
} | ||
}); | ||
|
||
[Test] | ||
public void ProcessObjects_TimedEventsAndChords_WithPredicate_2([Values] ContainerType containerType) => ProcessObjects_EventsCollection_WithPredicate( | ||
containerType: containerType, | ||
objectType: ObjectType.TimedEvent | ObjectType.Chord, | ||
midiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A"), | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
new NoteOnEvent { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent((SevenBitNumber)70, SevenBitNumber.MaxValue), | ||
new NoteOffEvent((SevenBitNumber)70, SevenBitNumber.MinValue), | ||
}, | ||
action: obj => obj.Time += obj is TimedEvent ? 10 : 20, | ||
match: obj => true, | ||
expectedMidiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A") { DeltaTime = 10 }, | ||
new TextEvent("C"), | ||
new NoteOnEvent() { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent((SevenBitNumber)70, SevenBitNumber.MaxValue), | ||
new NoteOffEvent((SevenBitNumber)70, SevenBitNumber.MinValue), | ||
}, | ||
expectedProcessedCount: 4); | ||
|
||
[Test] | ||
public void ProcessObjects_TimedEventsAndChords_WithPredicate_3([Values] ContainerType containerType) => ProcessObjects_EventsCollection_WithPredicate( | ||
containerType: containerType, | ||
objectType: ObjectType.TimedEvent | ObjectType.Chord, | ||
midiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A"), | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
new NoteOnEvent { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent((SevenBitNumber)70, SevenBitNumber.MaxValue), | ||
new NoteOffEvent((SevenBitNumber)70, SevenBitNumber.MinValue), | ||
}, | ||
action: obj => obj.Time += 10, | ||
match: obj => obj is Chord, | ||
expectedMidiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A"), | ||
new TextEvent("C"), | ||
new NoteOnEvent() { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent((SevenBitNumber)70, SevenBitNumber.MaxValue), | ||
new NoteOffEvent((SevenBitNumber)70, SevenBitNumber.MinValue), | ||
}, | ||
expectedProcessedCount: 2); | ||
|
||
[Test] | ||
public void ProcessObjects_TimedEventsAndNotes_WithoutPredicate([Values] ContainerType containerType) => ProcessObjects_EventsCollection_WithoutPredicate( | ||
containerType: containerType, | ||
objectType: ObjectType.TimedEvent | ObjectType.Note, | ||
midiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A"), | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
}, | ||
action: obj => | ||
{ | ||
if (obj is TimedEvent timedEvent && timedEvent.Event is TextEvent textEvent && textEvent.Text == "A") | ||
textEvent.Text = "B"; | ||
else | ||
obj.Time += 10; | ||
}, | ||
expectedMidiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("B"), | ||
new NoteOnEvent { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
}); | ||
|
||
[Test] | ||
public void ProcessObjects_TimedEventsAndChords_WithoutPredicate_1([Values] ContainerType containerType) => ProcessObjects_EventsCollection_WithoutPredicate( | ||
containerType: containerType, | ||
objectType: ObjectType.TimedEvent | ObjectType.Chord, | ||
midiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A"), | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
new NoteOnEvent { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent((SevenBitNumber)70, SevenBitNumber.MaxValue), | ||
new NoteOffEvent((SevenBitNumber)70, SevenBitNumber.MinValue), | ||
}, | ||
action: obj => obj.Time += obj is TimedEvent ? 10 : 20, | ||
expectedMidiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A") { DeltaTime = 10 }, | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
new NoteOnEvent { DeltaTime = 20 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent((SevenBitNumber)70, SevenBitNumber.MaxValue), | ||
new NoteOffEvent((SevenBitNumber)70, SevenBitNumber.MinValue), | ||
}, | ||
settings: new ObjectDetectionSettings | ||
{ | ||
ChordDetectionSettings = new ChordDetectionSettings | ||
{ | ||
NotesMinCount = 2 | ||
} | ||
}); | ||
|
||
[Test] | ||
public void ProcessObjects_TimedEventsAndChords_WithoutPredicate_2([Values] ContainerType containerType) => ProcessObjects_EventsCollection_WithoutPredicate( | ||
containerType: containerType, | ||
objectType: ObjectType.TimedEvent | ObjectType.Chord, | ||
midiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A"), | ||
new NoteOnEvent(), | ||
new NoteOffEvent(), | ||
new TextEvent("C"), | ||
new NoteOnEvent { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent((SevenBitNumber)70, SevenBitNumber.MaxValue), | ||
new NoteOffEvent((SevenBitNumber)70, SevenBitNumber.MinValue), | ||
}, | ||
action: obj => obj.Time += obj is TimedEvent ? 10 : 20, | ||
expectedMidiEvents: new MidiEvent[] | ||
{ | ||
new TextEvent("A") { DeltaTime = 10 }, | ||
new TextEvent("C"), | ||
new NoteOnEvent() { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent { DeltaTime = 10 }, | ||
new NoteOffEvent(), | ||
new NoteOnEvent((SevenBitNumber)70, SevenBitNumber.MaxValue), | ||
new NoteOffEvent((SevenBitNumber)70, SevenBitNumber.MinValue), | ||
}); | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
DryWetMidi/Interaction/TimedObject/ObjectProcessingHint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
|
||
namespace Melanchall.DryWetMidi.Interaction | ||
{ | ||
[Flags] | ||
public enum ObjectProcessingHint | ||
{ | ||
None = 0, | ||
|
||
TimeOrLengthCanBeChanged = 1, | ||
NotesCollectionCanBeChanged = 2, | ||
NoteTimeOrLengthCanBeChanged = 4, | ||
|
||
Default = TimeOrLengthCanBeChanged, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.