示例#1
0
        public void Read_Handler_Mixed()
        {
            var timeDivision = new TicksPerQuarterNoteTimeDivision(1000);

            var handler = new MixedReadingHandler();

            MidiFileTestUtilities.ReadUsingHandlers(
                new MidiFile(
                    new TrackChunk(new TextEvent("test"), new TextEvent("test 2")),
                    new TrackChunk(),
                    new TrackChunk(new SetTempoEvent(100000)),
                    new TrackChunk())
            {
                TimeDivision = timeDivision
            },
                handler);

            Assert.AreEqual(1, handler.FileStartHandledCount, "File: Start Handled Count is invalid.");
            Assert.AreEqual(1, handler.FileEndHandledCount, "File: End Handled Count is invalid.");
            Assert.AreEqual(timeDivision, handler.FileTimeDivision, "File: Time division is invalid.");

            Assert.AreEqual(4, handler.TrackChunkStartHandledCount, "Track chunk: Start Handled Count is invalid.");
            Assert.AreEqual(4, handler.TrackChunkContentStartHandledCount, "Track chunk: Content Start Handled Count is invalid.");
            Assert.AreEqual(4, handler.TrackChunkEndHandledCount, "Track chunk: End Handled Count is invalid.");

            Assert.AreEqual(3, handler.EventHandledCount, "Event: Handled Count is invalid.");
        }
示例#2
0
        private TimedEventsReadingHandler ReadWithTimedEventsReadingHandler(MidiFile midiFile, bool sortEvents)
        {
            var timedEventsReadingHandler = new TimedEventsReadingHandler(sortEvents);

            MidiFileTestUtilities.ReadUsingHandlers(midiFile, timedEventsReadingHandler);
            return(timedEventsReadingHandler);
        }
示例#3
0
        public void Read_Handler_AllHandlers()
        {
            var timeDivision = new TicksPerQuarterNoteTimeDivision(1000);

            var fileReadingHandler       = new FileReadingHandler();
            var trackChunkReadingHandler = new TrackChunkReadingHandler();
            var eventReadingHandler      = new EventReadingHandler();

            MidiFileTestUtilities.ReadUsingHandlers(
                new MidiFile(
                    new TrackChunk(new TextEvent("test"), new TextEvent("test 2")),
                    new TrackChunk(),
                    new TrackChunk(new SetTempoEvent(100000)),
                    new TrackChunk())
            {
                TimeDivision = timeDivision
            },
                fileReadingHandler,
                trackChunkReadingHandler,
                eventReadingHandler);

            Assert.AreEqual(1, fileReadingHandler.StartHandledCount, "File: Start Handled Count is invalid.");
            Assert.AreEqual(1, fileReadingHandler.EndHandledCount, "File: End Handled Count is invalid.");
            Assert.AreEqual(timeDivision, fileReadingHandler.TimeDivision, "File: Time division is invalid.");
            Assert.AreEqual(0, fileReadingHandler.BadHandledCount, "File: Scope wasn't used correctly.");

            Assert.AreEqual(4, trackChunkReadingHandler.StartHandledCount, "Track chunk: Start Handled Count is invalid.");
            Assert.AreEqual(4, trackChunkReadingHandler.ContentStartHandledCount, "Track chunk: Content Start Handled Count is invalid.");
            Assert.AreEqual(4, trackChunkReadingHandler.EndHandledCount, "Track chunk: End Handled Count is invalid.");
            Assert.AreEqual(0, trackChunkReadingHandler.BadHandledCount, "Track chunk: Scope wasn't used correctly.");

            Assert.AreEqual(3, eventReadingHandler.HandledCount, "Event: Handled Count is invalid.");
            Assert.AreEqual(0, eventReadingHandler.BadHandledCount, "Event: Scope wasn't used correctly.");
        }
示例#4
0
        private TempoMapReadingHandler ReadWithTempoMapReadingHandler(MidiFile midiFile)
        {
            var tempoMapReadingHandler = new TempoMapReadingHandler();

            MidiFileTestUtilities.ReadUsingHandlers(midiFile, tempoMapReadingHandler);
            return(tempoMapReadingHandler);
        }
        private NotesReadingHandler ReadWithNotesReadingHandler(MidiFile midiFile, bool sortNotes)
        {
            var notesReadingHandler = new NotesReadingHandler(sortNotes);

            MidiFileTestUtilities.ReadUsingHandlers(midiFile, notesReadingHandler);
            return(notesReadingHandler);
        }
示例#6
0
        public void Read_Handler_Event()
        {
            var handler = new EventReadingHandler();

            MidiFileTestUtilities.ReadUsingHandlers(new MidiFile(new TrackChunk(new TextEvent("test"), new TextEvent("test 2")), new TrackChunk(), new TrackChunk(new SetTempoEvent(100000))), handler);
            Assert.AreEqual(3, handler.HandledCount, "Handled Count is invalid.");
            Assert.AreEqual(0, handler.BadHandledCount, "Scope wasn't used correctly.");
        }
示例#7
0
        public void Read_Handler_Event_EmptyTrackChunk()
        {
            var handler = new EventReadingHandler();

            MidiFileTestUtilities.ReadUsingHandlers(new MidiFile(new TrackChunk()), handler);
            Assert.AreEqual(0, handler.HandledCount, "Handled Count is invalid.");
            Assert.AreEqual(0, handler.BadHandledCount, "Scope wasn't used correctly.");
        }
示例#8
0
        public void Read_Handler_TrackChunk()
        {
            var handler = new TrackChunkReadingHandler();

            MidiFileTestUtilities.ReadUsingHandlers(new MidiFile(new TrackChunk(), new TrackChunk()), handler);
            Assert.AreEqual(2, handler.StartHandledCount, "Start Handled Count is invalid.");
            Assert.AreEqual(2, handler.ContentStartHandledCount, "Content Start Handled Count is invalid.");
            Assert.AreEqual(2, handler.EndHandledCount, "End Handled Count is invalid.");
            Assert.AreEqual(0, handler.BadHandledCount, "Scope wasn't used correctly.");
        }
示例#9
0
        public void Read_Handler_File()
        {
            var timeDivision = new TicksPerQuarterNoteTimeDivision(1000);
            var handler      = new FileReadingHandler();

            MidiFileTestUtilities.ReadUsingHandlers(new MidiFile {
                TimeDivision = timeDivision
            }, handler);
            Assert.AreEqual(1, handler.StartHandledCount, "Start Handled Count is invalid.");
            Assert.AreEqual(1, handler.EndHandledCount, "End Handled Count is invalid.");
            Assert.AreEqual(timeDivision, handler.TimeDivision, "Time division is invalid.");
            Assert.AreEqual(0, handler.BadHandledCount, "Scope wasn't used correctly.");
        }
示例#10
0
        public void CheckTempoMapReadingHandler_MultipleTrackChunks_DontAllowTempoMapUsageDuringReading_AccessDuringReading()
        {
            var timeDivision = new TicksPerQuarterNoteTimeDivision(100);
            var handler      = new TempoMapReadingHandler();

            var exceptionThrown = false;

            try
            {
                var tempoMap = handler.TempoMap;
            }
            catch (InvalidOperationException)
            {
                exceptionThrown = true;
            }

            MidiFileTestUtilities.ReadUsingHandlers(
                new MidiFile(
                    new TrackChunk(
                        new NoteOnEvent(),
                        new SetTempoEvent(100000),
                        new SetTempoEvent(150000)
            {
                DeltaTime = 50
            },
                        new SetTempoEvent(200000),
                        new NoteOffEvent()
            {
                DeltaTime = 100
            },
                        new TimeSignatureEvent(3, 4)),
                    new TrackChunk(
                        new SetTempoEvent(300000)
            {
                DeltaTime = 50
            },
                        new TimeSignatureEvent(5, 8)
            {
                DeltaTime = 1000
            }))
            {
                TimeDivision = timeDivision
            },
                handler);

            Assert.IsTrue(exceptionThrown, "Exception was not thrown on get during read.");
            Assert.DoesNotThrow(() => { var tempoMap = handler.TempoMap; }, "Exception thrown on get after read.");
        }