示例#1
0
        public static void ThrowExceptionForReasonCode(int reasonCode)
        {
            TeVirtualMidiException exception = new TeVirtualMidiException(reasonCodeToString(reasonCode));

            exception.reasonCode = reasonCode;
            throw exception;
        }
示例#2
0
        public void Write(byte[] command)
        {
            if ((command == null) || (command.Length == 0))
            {
                return;
            }

            if (!virtualMIDISendData(fInstance, command, (UInt32)command.Length))
            {
                int lastError = Marshal.GetLastWin32Error();
                TeVirtualMidiException.ThrowExceptionForReasonCode(lastError);
            }
        }
示例#3
0
        public byte[] Read()
        {
            UInt32 length = fMaxSysexLength;

            if (!virtualMIDIGetData(fInstance, fReadBuffer, ref length))
            {
                int lastError = Marshal.GetLastWin32Error();
                TeVirtualMidiException.ThrowExceptionForReasonCode(lastError);
            }

            byte[] outBytes = new byte[length];
            Array.Copy(fReadBuffer, outBytes, length);

            return(outBytes);
        }
示例#4
0
        public UInt64[] GetProcessIds()
        {
            UInt32 length = 17 * sizeof(ulong);
            UInt32 count;

            if (!virtualMIDIGetProcesses(fInstance, fReadProcessIds, ref length))
            {
                int lastError = Marshal.GetLastWin32Error();
                TeVirtualMidiException.ThrowExceptionForReasonCode(lastError);
            }

            count = length / sizeof(ulong);

            UInt64[] outIds = new UInt64[count];
            Array.Copy(fReadProcessIds, outIds, count);

            return(outIds);
        }
示例#5
0
        public VirtualMidiPort(string portName, bool blockingMode, UInt32 maxSysexLength, UInt32 flags, ref Guid manufacturer, ref Guid product)
        {
            SynchronizationContext = SynchronizationContext.Current;
            if (SynchronizationContext == null)
            {
                throw new InvalidOperationException("No synchronization context");
            }

            fInstance = virtualMIDICreatePortEx3(portName, MakeCallback(blockingMode), IntPtr.Zero, maxSysexLength, flags, ref manufacturer, ref product);

            if (fInstance == IntPtr.Zero)
            {
                int lastError = Marshal.GetLastWin32Error();
                TeVirtualMidiException.ThrowExceptionForReasonCode(lastError);
            }

            fReadBuffer     = new byte[maxSysexLength];
            fReadProcessIds = new UInt64[17];
            fMaxSysexLength = maxSysexLength;
        }
示例#6
0
        public VirtualMidiPort(string portName, bool blockingMode, UInt32 maxSysexLength = TE_VM_DEFAULT_SYSEX_SIZE, UInt32 flags = TE_VM_FLAGS_PARSE_RX)
        {
            SynchronizationContext = SynchronizationContext.Current;
            if (SynchronizationContext == null)
            {
                throw new InvalidOperationException("No synchronization context");
            }

            fInstance = virtualMIDICreatePortEx2(portName, MakeCallback(blockingMode), IntPtr.Zero, maxSysexLength, flags);

            if (fInstance == IntPtr.Zero)
            {
                int lastError = Marshal.GetLastWin32Error();
                TeVirtualMidiException.ThrowExceptionForReasonCode(lastError);
            }

            fReadBuffer     = new byte[maxSysexLength];
            fReadProcessIds = new UInt64[17];
            fMaxSysexLength = maxSysexLength;
        }
示例#7
0
        private void Dispose(bool finalizing)
        {
            lock (this) {
                if (!virtualMIDIShutdown(fInstance))
                {
                    if (!finalizing)
                    {
                        int lastError = Marshal.GetLastWin32Error();
                        TeVirtualMidiException.ThrowExceptionForReasonCode(lastError);
                    }
                }

                if (fInstance != IntPtr.Zero)
                {
                    virtualMIDIClosePort(fInstance);
                    fInstance = IntPtr.Zero;
                }
            }

            GC.SuppressFinalize(this);
        }