Example #1
0
        public int SendSysex(byte[] sx)
        {
            int result = -1;
            int shdr   = Marshal.SizeOf(typeof(MidiHeader));
            var mhdr   = new MidiHeader();

            mhdr.bufferLength = mhdr.bytesRecorded = sx.Length;
            mhdr.data         = Marshal.AllocHGlobal(mhdr.bufferLength);
            Marshal.Copy(sx, 0, mhdr.data, mhdr.bufferLength);
            IntPtr nhdr = Marshal.AllocHGlobal(shdr);

            Marshal.StructureToPtr(mhdr, nhdr, false);
            result = WinMM.midiOutPrepareHeader(outHandle, nhdr, shdr);
            if (result != 0)
            {
                throw new Exception("Cannot prepare OUT header");
            }
            result = WinMM.midiOutLongMsg(outHandle, nhdr, shdr);
            if (result != 0)
            {
                throw new Exception("Cannot send long message");
            }
            result = WinMM.midiOutUnprepareHeader(outHandle, nhdr, shdr);
            if (result != 0)
            {
                throw new Exception("Cannot ");
            }
            AfterLongSent?.Invoke(sx);                                  // if not null Invoke
            return(result);
        }