Esempio n. 1
0
        public void CloneEvent()
        {
            var random = new Random();

            foreach (var type in TypesProvider.GetAllEventTypes())
            {
                var midiEvent = type == typeof(UnknownMetaEvent)
                    ? new UnknownMetaEvent(1)
                    : (MidiEvent)Activator.CreateInstance(type);

                if (midiEvent is ChannelEvent channelEvent)
                {
                    channelEvent.Channel = (FourBitNumber)(random.Next(5) + 5);
                }

                if (midiEvent is BaseTextEvent baseTextEvent)
                {
                    baseTextEvent.Text = random.Next(1000).ToString();
                }

                midiEvent.DeltaTime = random.Next(1000) + 1;

                var midiEventClone = midiEvent.Clone();
                MidiAsserts.AreEventsEqual(midiEvent, midiEventClone, true, $"Clone of {type} is invalid.");
            }
        }
Esempio n. 2
0
        public void AllEventTypesAreReadCorrectly(Func <Type, MidiEvent> createMidiEvent)
        {
            var events = TypesProvider.GetAllEventTypes()
                         .Where(t => !typeof(SystemCommonEvent).IsAssignableFrom(t) &&
                                !typeof(SystemRealTimeEvent).IsAssignableFrom(t) &&
                                t != typeof(EndOfTrackEvent) &&
                                t != typeof(UnknownMetaEvent))
                         .Select(createMidiEvent)
                         .ToArray();

            var midiFile = MidiFileTestUtilities.Read(
                new MidiFile(new TrackChunk(events)),
                null,
                new ReadingSettings {
                SilentNoteOnPolicy = SilentNoteOnPolicy.NoteOn
            },
                MidiFileFormat.SingleTrack);

            var readEvents = midiFile.GetEvents().ToArray();

            for (var i = 0; i < events.Length; i++)
            {
                var expectedEvent = events[i];
                var actualEvent   = readEvents[i];

                MidiAsserts.AreEventsEqual(expectedEvent, actualEvent, true, $"Event {i} is invalid.");
            }
        }
Esempio n. 3
0
        public void CheckEventsReceiving_AllEventTypes_ExceptSysEx()
        {
            var events = TypesProvider.GetAllEventTypes()
                         .Where(t => !typeof(MetaEvent).IsAssignableFrom(t) && !typeof(SysExEvent).IsAssignableFrom(t))
                         .Select(t => (MidiEvent)Activator.CreateInstance(t))
                         .ToArray();

            CollectionAssert.IsNotEmpty(events, "Events collection is empty.");
            SendReceiveUtilities.CheckEventsReceiving(events.Select(e => new EventToSend(e, TimeSpan.Zero)).ToArray());
        }
Esempio n. 4
0
 public void AllEventTypesAreCorrect()
 {
     foreach (var type in TypesProvider.GetAllEventTypes())
     {
         var instance = type == typeof(UnknownMetaEvent)
             ? new UnknownMetaEvent(0)
             : (MidiEvent)Activator.CreateInstance(type);
         var eventType = instance.EventType;
         Assert.IsTrue(
             type.Name.StartsWith(eventType.ToString()),
             $"Type '{eventType}' is invalid for events of type '{type.Name}'.");
     }
 }
Esempio n. 5
0
        public void AllEventTypesHaveParameterlessConstructor()
        {
            foreach (var type in TypesProvider.GetAllEventTypes())
            {
                if (type == typeof(UnknownMetaEvent))
                {
                    continue;
                }

                Assert.IsNotNull(
                    type.GetConstructor(Type.EmptyTypes),
                    $"Type '{type.Name}' has no parameterless constructor.");
            }
        }
Esempio n. 6
0
        public void EventPlayed_AllEventsTypes()
        {
            var delay        = 10;
            var eventsToSend = TypesProvider
                               .GetAllEventTypes()
                               .Select(type => type == typeof(UnknownMetaEvent)
                    ? new UnknownMetaEvent(0)
                    : (MidiEvent)Activator.CreateInstance(type))
                               .Select(midiEvent => new EventToSend(midiEvent, TimeSpan.FromMilliseconds(delay)))
                               .ToArray();

            CheckEventPlayedEvent(
                eventsToSend: eventsToSend,
                expectedPlayedEvents: eventsToSend.Select((e, i) => new ReceivedEvent(e.Event, TimeSpan.FromMilliseconds(delay * (i + 1)))).ToArray());
        }
Esempio n. 7
0
        public void AllEventTypesAreReadCorrectly()
        {
            var events = TypesProvider.GetAllEventTypes()
                         .Where(t => !typeof(SystemCommonEvent).IsAssignableFrom(t) &&
                                !typeof(SystemRealTimeEvent).IsAssignableFrom(t) &&
                                t != typeof(EndOfTrackEvent) &&
                                t != typeof(UnknownMetaEvent))
                         .Select(t =>
            {
                var instance = (MidiEvent)Activator.CreateInstance(t);

                if (instance is SysExEvent sysExEvent)
                {
                    sysExEvent.Data = new byte[] { 1, 2, 3 }
                }
                ;

                if (instance is SequencerSpecificEvent sequencerSpecificEvent)
                {
                    sequencerSpecificEvent.Data = new byte[] { 1, 2, 3 }
                }
                ;

                if (instance is NoteOnEvent noteOnEvent)
                {
                    noteOnEvent.Velocity = (SevenBitNumber)100;
                }

                if (instance is BaseTextEvent baseTextEvent)
                {
                    baseTextEvent.Text = Guid.NewGuid().ToString();
                }

                return(instance);
            })
                         .ToArray();

            var midiFile   = MidiFileTestUtilities.Read(new MidiFile(new TrackChunk(events)), null, null, MidiFileFormat.SingleTrack);
            var readEvents = midiFile.GetEvents().ToArray();

            for (var i = 0; i < events.Length; i++)
            {
                var expectedEvent = events[i];
                var actualEvent   = readEvents[i];

                MidiAsserts.AreEventsEqual(expectedEvent, actualEvent, true, $"Event {i} is invalid.");
            }
        }