Ejemplo n.º 1
0
        // Close the port
        public string Close()
        {
            EMMError result = NativeMethods.midiOutClose(handle);

            handle = IntPtr.Zero;
            return(WindowsUtil.StrError(result));
        }
Ejemplo n.º 2
0
        // Start the port and setup buffers to receives Sysex
        public string Start()
        {
            // Allocate buffer array
            if (buffers == null)
            {
                const int numBuffers = 4;
                const int bufferSize = 4096; // ZZZ Param?

                buffers = new MidiBuffer[numBuffers];

                // Allocate and prepare the buffers
                for (int b = 0; b < buffers.Length; b++)
                {
                    // Create buffer
                    buffers[b] = new MidiBuffer(bufferSize, (IntPtr)b);

                    // Prepare the buffer and give it to windows
                    EMMError st = buffers[b].AddMidiInBuffer(handle);
                    if (st != EMMError.NOERROR)
                    {
                        return(WindowsUtil.StrError(st));
                    }
                }
            }

            // Finally, start the port
            return(WindowsUtil.StrError(NativeMethods.midiInStart(handle)));
        }
Ejemplo n.º 3
0
 public static string StrError(EMMError error)
 {
     if (error == EMMError.NOERROR)
     {
         return(null);
     }
     else
     {
         return(error.ToString());
     }
 }
Ejemplo n.º 4
0
        // Close the port
        public string Close()
        {
            Stop();
            Reset();
            EMMError result = NativeMethods.midiInClose(handle);

            handle            = IntPtr.Zero;
            MidiInputReceived = null;

            return(WindowsUtil.StrError(result));
        }
Ejemplo n.º 5
0
        // Reset the port and free the sysex buffers
        public string Reset()
        {
            EMMError st = NativeMethods.midiInReset(handle);

            if (st == EMMError.NOERROR && buffers != null)
            {
                // The buffers have now been released by the callback. Just free the array.
                buffers = null;
            }

            return(WindowsUtil.StrError(st));
        }
Ejemplo n.º 6
0
        // Open the input port. Midi events cause the MidiInputReceived event to be raised
        public string Open()
        {
            // Open the port
            EMMError st = NativeMethods.midiInOpen(
                out handle,
                id,
                midiInProc,
                IntPtr.Zero,
                NativeMethods.CALLBACK_FUNCTION);

            return(WindowsUtil.StrError(st));
        }
Ejemplo n.º 7
0
        // Remove this buffer from a midi in port
        public EMMError RemoveMidiInBuffer(IntPtr handle)
        {
            EMMError st = EMMError.DELETEERROR;

            if (preparedForMidiIn)
            {
                st = NativeMethods.midiInUnprepareHeader(handle, header, (uint)Marshal.SizeOf(typeof(NativeMethods.MIDIHDR)));
                if (st == EMMError.NOERROR)
                {
                    preparedForMidiIn = false;
                }
            }

            return(st);
        }
Ejemplo n.º 8
0
        public EMMError UnprepareForMidiOut(IntPtr handle)
        {
            EMMError st = EMMError.DELETEERROR;

            // Un-prepare the buffer
            if (preparedForMidiOut)
            {
                st = NativeMethods.midiOutUnprepareHeader(handle, header, (uint)Marshal.SizeOf(typeof(NativeMethods.MIDIHDR)));
                if (st == EMMError.NOERROR)
                {
                    preparedForMidiOut = false;
                }
            }

            return(st);
        }
Ejemplo n.º 9
0
        // Add this buffer to a midi in port
        public EMMError AddMidiInBuffer(IntPtr handle)
        {
            // Prepare the buffer
            EMMError st = NativeMethods.midiInPrepareHeader(handle, header, headerSize);

            if (st != EMMError.NOERROR)
            {
                return(st);
            }

            preparedForMidiIn = true;

            // Give it to windows
            st = NativeMethods.midiInAddBuffer(handle, header, headerSize);
            if (st != EMMError.NOERROR)
            {
                return(st);
            }

            return(EMMError.NOERROR);
        }