예제 #1
0
        public void SendBuffer(byte[] byteBuffer)
        {
            MidiInterop.MIDIHDR midihdr = default(MidiInterop.MIDIHDR);
            midihdr.lpData = Marshal.AllocHGlobal(byteBuffer.Length);
            Marshal.Copy(byteBuffer, 0, midihdr.lpData, byteBuffer.Length);
            midihdr.dwBufferLength  = byteBuffer.Length;
            midihdr.dwBytesRecorded = byteBuffer.Length;
            int uSize = Marshal.SizeOf(midihdr);

            MidiInterop.midiOutPrepareHeader(this.hMidiOut, ref midihdr, uSize);
            MmResult mmResult = MidiInterop.midiOutLongMsg(this.hMidiOut, ref midihdr, uSize);

            if (mmResult != MmResult.NoError)
            {
                MidiInterop.midiOutUnprepareHeader(this.hMidiOut, ref midihdr, uSize);
            }
            Marshal.FreeHGlobal(midihdr.lpData);
        }
예제 #2
0
        /// <summary>
        /// Send a long message, for example sysex.
        /// </summary>
        /// <param name="byteBuffer">The bytes to send.</param>
        public void SendBuffer(byte[] byteBuffer)
        {
            var header = new MidiInterop.MIDIHDR();

            header.lpData = Marshal.AllocHGlobal(byteBuffer.Length);
            Marshal.Copy(byteBuffer, 0, header.lpData, byteBuffer.Length);

            header.dwBufferLength  = byteBuffer.Length;
            header.dwBytesRecorded = byteBuffer.Length;
            int size = Marshal.SizeOf(header);

            MidiInterop.midiOutPrepareHeader(this.hMidiOut, ref header, size);
            var errcode = MidiInterop.midiOutLongMsg(this.hMidiOut, ref header, size);

            if (errcode != MmResult.NoError)
            {
                MidiInterop.midiOutUnprepareHeader(this.hMidiOut, ref header, size);
            }
            Marshal.FreeHGlobal(header.lpData);
        }