forked from naudio/NAudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMidiEventCollectionTest.cs
95 lines (91 loc) · 4.65 KB
/
MidiEventCollectionTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using NAudio.Midi;
namespace NAudioTests.Midi
{
[TestFixture]
[Category("UnitTest")]
public class MidiEventCollectionTest
{
[Test]
public void TestType1()
{
MidiEventCollection collection = new MidiEventCollection(1,120);
collection.AddEvent(new TextEvent("Test",MetaEventType.TextEvent,0),0);
collection.AddEvent(new NoteOnEvent(0, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(15, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(30, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(0, 10, 60, 100, 15), 10);
collection.AddEvent(new NoteOnEvent(15, 10, 60, 100, 15), 10);
collection.AddEvent(new NoteOnEvent(30, 10, 60, 100, 15), 10);
Assert.AreEqual(collection.Tracks, 11);
collection.PrepareForExport();
Assert.AreEqual(collection.Tracks, 3);
IList<MidiEvent> track0 = collection.GetTrackEvents(0);
Assert.AreEqual(track0.Count, 2);
Assert.AreEqual(collection.GetTrackEvents(1).Count, 4);
Assert.AreEqual(collection.GetTrackEvents(2).Count, 4);
Assert.IsTrue(MidiEvent.IsEndTrack(track0[track0.Count - 1]));
}
[Test]
public void TestType0()
{
MidiEventCollection collection = new MidiEventCollection(0, 120);
collection.AddEvent(new TextEvent("Test", MetaEventType.TextEvent, 0), 0);
collection.AddEvent(new NoteOnEvent(0, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(15, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(30, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(0, 10, 60, 100, 15), 10);
collection.AddEvent(new NoteOnEvent(15, 10, 60, 100, 15), 10);
collection.AddEvent(new NoteOnEvent(30, 10, 60, 100, 15), 10);
Assert.AreEqual(collection.Tracks, 1);
collection.PrepareForExport();
Assert.AreEqual(collection.Tracks, 1);
IList<MidiEvent> track0 = collection.GetTrackEvents(0);
Assert.AreEqual(track0.Count, 8);
Assert.IsTrue(MidiEvent.IsEndTrack(track0[track0.Count - 1]));
}
[Test]
public void TestType1ToType0()
{
MidiEventCollection collection = new MidiEventCollection(1, 120);
collection.AddEvent(new TextEvent("Test", MetaEventType.TextEvent, 0), 0);
collection.AddEvent(new NoteOnEvent(0, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(15, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(30, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(0, 10, 60, 100, 15), 10);
collection.AddEvent(new NoteOnEvent(15, 10, 60, 100, 15), 10);
collection.AddEvent(new NoteOnEvent(30, 10, 60, 100, 15), 10);
Assert.AreEqual(collection.Tracks, 11);
collection.MidiFileType = 0;
collection.PrepareForExport();
Assert.AreEqual(collection.Tracks, 1);
IList<MidiEvent> track0 = collection.GetTrackEvents(0);
Assert.AreEqual(track0.Count, 8);
Assert.IsTrue(MidiEvent.IsEndTrack(track0[track0.Count - 1]));
}
[Test]
public void TestType0ToType1()
{
MidiEventCollection collection = new MidiEventCollection(0, 120);
collection.AddEvent(new TextEvent("Test", MetaEventType.TextEvent, 0), 0);
collection.AddEvent(new NoteOnEvent(0, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(15, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(30, 1, 30, 100, 15), 1);
collection.AddEvent(new NoteOnEvent(0, 10, 60, 100, 15), 10);
collection.AddEvent(new NoteOnEvent(15, 10, 60, 100, 15), 10);
collection.AddEvent(new NoteOnEvent(30, 10, 60, 100, 15), 10);
Assert.AreEqual(collection.Tracks, 1);
collection.MidiFileType = 1;
collection.PrepareForExport();
Assert.AreEqual(3, collection.Tracks, "Wrong number of tracks");
IList<MidiEvent> track0 = collection.GetTrackEvents(0);
Assert.AreEqual(track0.Count, 2);
Assert.AreEqual(collection.GetTrackEvents(1).Count, 4);
Assert.AreEqual(collection.GetTrackEvents(2).Count, 4);
Assert.IsTrue(MidiEvent.IsEndTrack(track0[track0.Count - 1]));
}
}
}