Exemplo n.º 1
0
        public void CtorTest(EventType type, int channel, int data1, int data2)
        {
            var midiEvent = new MidiEvent(type, channel, data1, data2);

            Assert.AreEqual(type, midiEvent.Type);
            Assert.AreEqual(channel, midiEvent.Channel);
            Assert.AreEqual(data1, midiEvent.Data1);
            Assert.AreEqual(data2, midiEvent.Data2);
        }
Exemplo n.º 2
0
        public void ToStringTest(EventType type, int channel, int data1)
        {
            var midiEvent = new MidiEvent(type, channel, data1, 0);
            var str = midiEvent.ToString();

            Assert.IsNotNull(str);
            Assert.IsFalse(string.IsNullOrWhiteSpace(str));

            StringAssert.Contains(type.ToString(), str);
            StringAssert.Contains(channel.ToString(), str);
            StringAssert.Contains(data1.ToString(), str);

            // data2 is not contained in MidiEvent#ToString
        }
Exemplo n.º 3
0
 public ReceivedMidiEventEventArgs(MidiEvent @event, MidiIn midiIn)
 {
     Event = @event;
     MidiIn = midiIn;
 }
Exemplo n.º 4
0
        private void MidiProc(IntPtr hMidiIn, int wMsg, IntPtr dwInstance, int dwParam1, int dwParam2)
        {
            if (wMsg == NativeMethods.MIM_DATA)
            {
                if (IsDisposed || !IsPlaying)
                    return;

                if (ReceivedMidiEvent == null)
                    return;

                var @event = new MidiEvent((EventType)(dwParam1 & 0xf0),
                    dwParam1 & 0x0f,
                    dwParam1 >> 8 & 0xff,
                    dwParam1 >> 16 & 0xff);
                ReceivedMidiEvent(this, new ReceivedMidiEventEventArgs(@event, this));
            }
            else if (wMsg == NativeMethods.MIM_LONGDATA)
            {
                if (IsDisposed || !IsPlaying)
                    return;

                midiHeader = (NativeMethods.MIDIHDR)Marshal.PtrToStructure(ptrHeader,
                    typeof(NativeMethods.MIDIHDR));

                var buffer = new byte[BufferSize];
                Marshal.Copy(midiHeader.data, buffer, 0, BufferSize);
                var length = Array.IndexOf<byte>(buffer, 0xf7, 0, BufferSize);

                if (length == -1)
                {
                    exclusiveQueue.Enqueue(buffer);
                }
                else
                {
                    if (ReceivedExclusiveMessage != null)
                    {
                        var data = exclusiveQueue.SelectMany(a => a).Concat(buffer.Take(length)).Skip(1);
                        ReceivedExclusiveMessage(this, new ReceivedExclusiveMessageEventArgs(data.ToArray(), this));
                    }

                    exclusiveQueue.Clear();
                }

                if (!isClosing)
                    NativeMethods.midiInAddBuffer(handle, ptrHeader, headerSize);
            }
            else if (wMsg == NativeMethods.MIM_OPEN)
            {
                Opened?.Invoke(this, new EventArgs());
            }
            else if (wMsg == NativeMethods.MIM_CLOSE)
            {
                Closed?.Invoke(this, new EventArgs());
            }
        }
Exemplo n.º 5
0
 public ReceivedMidiEventEventArgs(MidiEvent @event, MidiIn midiIn)
 {
     Event  = @event;
     MidiIn = midiIn;
 }
Exemplo n.º 6
0
        private void MidiProc(IntPtr hMidiIn, int wMsg, IntPtr dwInstance, int dwParam1, int dwParam2)
        {
            if (wMsg == NativeMethods.MIM_DATA)
            {
                if (IsDisposed || !IsPlaying)
                {
                    return;
                }

                if (ReceivedMidiEvent == null)
                {
                    return;
                }

                var @event = new MidiEvent((EventType)(dwParam1 & 0xf0),
                                           dwParam1 & 0x0f,
                                           dwParam1 >> 8 & 0xff,
                                           dwParam1 >> 16 & 0xff);
                ReceivedMidiEvent(this, new ReceivedMidiEventEventArgs(@event, this));
            }
            else if (wMsg == NativeMethods.MIM_LONGDATA)
            {
                if (IsDisposed || !IsPlaying)
                {
                    return;
                }

                midiHeader = (NativeMethods.MIDIHDR)Marshal.PtrToStructure(ptrHeader,
                                                                           typeof(NativeMethods.MIDIHDR));

                var buffer = new byte[BufferSize];
                Marshal.Copy(midiHeader.data, buffer, 0, BufferSize);
                var length = Array.IndexOf <byte>(buffer, 0xf7, 0, BufferSize);

                if (length == -1)
                {
                    exclusiveQueue.Enqueue(buffer);
                }
                else
                {
                    if (ReceivedExclusiveMessage != null)
                    {
                        var data = exclusiveQueue.SelectMany(a => a).Concat(buffer.Take(length)).Skip(1);
                        ReceivedExclusiveMessage(this, new ReceivedExclusiveMessageEventArgs(data.ToArray(), this));
                    }

                    exclusiveQueue.Clear();
                }

                if (!isClosing)
                {
                    NativeMethods.midiInAddBuffer(handle, ptrHeader, headerSize);
                }
            }
            else if (wMsg == NativeMethods.MIM_OPEN)
            {
                Opened?.Invoke(this, new EventArgs());
            }
            else if (wMsg == NativeMethods.MIM_CLOSE)
            {
                Closed?.Invoke(this, new EventArgs());
            }
        }