Example #1
0
        internal static Exception NewExceptionForReasonCode(int reasonCode)
        {
            var exception = new TeVirtualMidiException(ReasonCodeToString((Code)reasonCode));

            exception.ReasonCode = reasonCode;
            return(exception);
        }
Example #2
0
 public void Shutdown()
 {
     if (!VirtualMIDIShutdown(instance))
     {
         int lastError = Marshal.GetLastWin32Error();
         throw TeVirtualMidiException.NewExceptionForReasonCode(lastError);
     }
 }
Example #3
0
 public TeVirtualMidi(string portName, uint maxSysexLength, CreationOptions options, ref Guid manufacturer, ref Guid product)
 {
     instance = VirtualMIDICreatePortEx3(portName, IntPtr.Zero, IntPtr.Zero, maxSysexLength, (uint)options, ref manufacturer, ref product);
     if (instance == IntPtr.Zero)
     {
         int lastError = Marshal.GetLastWin32Error();
         throw TeVirtualMidiException.NewExceptionForReasonCode(lastError);
     }
     readBuffer          = new byte[maxSysexLength];
     readProcessIds      = new ulong[17];
     this.maxSysexLength = maxSysexLength;
 }
Example #4
0
 public TeVirtualMidi(string portName, uint maxSysexLength = DefaultSysExSize, CreationOptions options = CreationOptions.ParseIncomingDataIntoValidMidi)
 {
     instance = VirtualMIDICreatePortEx2(portName, IntPtr.Zero, IntPtr.Zero, maxSysexLength, (uint)options);
     if (instance == IntPtr.Zero)
     {
         int lastError = Marshal.GetLastWin32Error();
         throw TeVirtualMidiException.NewExceptionForReasonCode(lastError);
     }
     readBuffer          = new byte[maxSysexLength];
     readProcessIds      = new ulong[17];
     this.maxSysexLength = maxSysexLength;
 }
Example #5
0
 public void SendCommand(byte[] command)
 {
     if ((command == null) || (command.Length == 0))
     {
         return;
     }
     if (!VirtualMIDISendData(instance, command, (uint)command.Length))
     {
         int lastError = Marshal.GetLastWin32Error();
         throw TeVirtualMidiException.NewExceptionForReasonCode(lastError);
     }
 }
Example #6
0
        public byte[] GetCommand()
        {
            uint length = maxSysexLength;

            if (!VirtualMIDIGetData(instance, readBuffer, ref length))
            {
                int lastError = Marshal.GetLastWin32Error();
                throw TeVirtualMidiException.NewExceptionForReasonCode(lastError);
            }
            byte[] outBytes = new byte[length];
            Array.Copy(readBuffer, outBytes, length);
            return(outBytes);
        }
Example #7
0
        public ulong[] GetProcessIds()
        {
            uint length = 17 * sizeof(ulong);
            uint count;

            if (!VirtualMIDIGetProcesses(instance, readProcessIds, ref length))
            {
                int lastError = Marshal.GetLastWin32Error();
                throw TeVirtualMidiException.NewExceptionForReasonCode(lastError);
            }
            count = length / sizeof(ulong);
            ulong[] outIds = new ulong[count];
            Array.Copy(readProcessIds, outIds, count);
            return(outIds);
        }