Exemple #1
0
        /// <summary>
        /// Handles the long and short error messages.
        /// </summary>
        /// <param name="umsg">Type of message.</param>
        /// <param name="param1">First parameter.</param>
        /// <param name="param2">Second parameter.</param>
        /// <returns>Returns true if the <paramref name="umsg"/> has been handled.</returns>
        private bool HandleErrorMessage(uint umsg, IntPtr param1, IntPtr param2)
        {
            bool handled = true;

            switch (umsg)
            {
            case NativeMethods.MIM_ERROR:
                NextErrorReceiver.ShortError(param1.ToInt32(), param2.ToInt32());
                break;

            case NativeMethods.MIM_LONGERROR:
                var buffer = BufferManager.FindBuffer(param1);

                if (buffer != null)
                {
                    NextErrorReceiver.LongError(buffer, param2.ToInt32());

                    if (AutoReturnBuffers)
                    {
                        BufferManager.ReturnBuffer(buffer);
                    }
                }
                break;

            default:
                handled = false;
                break;
            }

            return(handled);
        }
Exemple #2
0
        /// <summary>
        /// Handles the port events for all message types.
        /// </summary>
        /// <param name="umsg">Type of message.</param>
        /// <param name="param1">First parameter.</param>
        /// <param name="param2">Second parameter.</param>
        /// <returns>Returns true if the <paramref name="umsg"/> has been handled.</returns>
        private bool HandlePortEvent(uint umsg, IntPtr param1, IntPtr param2)
        {
            bool handled = true;

            switch (umsg)
            {
            case NativeMethods.MIM_DATA:
                NextPortEventReceiver.PortEvent(new MidiPortEvent(MidiPortEventType.ShortData, param1.ToInt32(), param2.ToInt32()));
                break;

            case NativeMethods.MIM_LONGDATA:
                var buffer = BufferManager.FindBuffer(param1);

                if (buffer != null)
                {
                    if (buffer.BytesRecorded > 0)
                    {
                        NextPortEventReceiver.PortEvent(new MidiPortEvent(MidiPortEventType.LongData, buffer, param2.ToInt32()));

                        if (AutoReturnBuffers)
                        {
                            BufferManager.ReturnBuffer(buffer);
                        }
                    }
                    else
                    {
                        BufferManager.ReturnBuffer(buffer);
                    }
                }
                break;

            case NativeMethods.MIM_MOREDATA:
                NextPortEventReceiver.PortEvent(new MidiPortEvent(MidiPortEventType.MoreData, param1.ToInt32(), param2.ToInt32()));
                break;

            case NativeMethods.MIM_ERROR:
                NextPortEventReceiver.PortEvent(new MidiPortEvent(MidiPortEventType.ShortError, param1.ToInt32(), param2.ToInt32()));
                break;

            case NativeMethods.MIM_LONGERROR:
                var errBuffer = BufferManager.FindBuffer(param1);

                if (errBuffer != null)
                {
                    NextPortEventReceiver.PortEvent(new MidiPortEvent(MidiPortEventType.LongError, errBuffer, param2.ToInt32()));

                    if (AutoReturnBuffers)
                    {
                        BufferManager.ReturnBuffer(errBuffer);
                    }
                }
                break;

            default:
                handled = false;
                break;
            }

            return(handled);
        }
Exemple #3
0
        /// <summary>
        /// Midi out device callback handler.
        /// </summary>
        /// <param name="message">The type of callback event.</param>
        /// <param name="parameter1">First parameter dependent on <paramref name="message"/>.</param>
        /// <param name="parameter2">Second parameter dependent on <paramref name="message"/>.</param>
        /// <returns>Returns true when handled.</returns>
        protected override bool OnMessage(int message, IntPtr parameter1, IntPtr parameter2)
        {
            bool handled = true;

            switch ((uint)message)
            {
            case NativeMethods.MOM_OPEN:
                // don't change status here, MidiSafeHandle has not been set yet.
                break;

            case NativeMethods.MOM_CLOSE:
                Status         = MidiPortStatus.Closed;
                MidiSafeHandle = null;
                break;

            case NativeMethods.MOM_DONE:
                MidiBufferStream buffer = BufferManager.FindBuffer(parameter1);
                if (buffer != null)
                {
                    if (NextCallback != null)
                    {
                        NextCallback.LongData(buffer, MidiDataCallbackType.Done);
                    }

                    BufferManager.ReturnBuffer(buffer);
                }
                break;

            default:
                handled = false;
                break;
            }

            return(handled);
        }
Exemple #4
0
        /// <inheritdocs/>
        protected override bool OnMessage(int message, IntPtr parameter1, IntPtr parameter2)
        {
            switch ((uint)message)
            {
            case NativeMethods.MOM_POSITIONCB:
                var buffer = BufferManager.FindBuffer(parameter1);

                if (buffer != null && NextCallback != null)
                {
                    NextCallback.LongData(buffer, MidiDataCallbackType.Notification);
                }
                return(true);
            }
            return(base.OnMessage(message, parameter1, parameter2));
        }
Exemple #5
0
        /// <summary>
        /// Handles the long and short data messages.
        /// </summary>
        /// <param name="umsg">Type of message.</param>
        /// <param name="param1">First parameter.</param>
        /// <param name="param2">Second parameter.</param>
        /// <returns>Returns true if the <paramref name="umsg"/> has been handled.</returns>
        private bool HandleDataMessage(uint umsg, IntPtr param1, IntPtr param2)
        {
            bool handled = true;

            switch (umsg)
            {
            case NativeMethods.MIM_DATA:
                Successor.ShortData(param1.ToInt32(), param2.ToInt32());
                break;

            case NativeMethods.MIM_LONGDATA:
                var buffer = BufferManager.FindBuffer(param1);

                if (buffer != null)
                {
                    if (buffer.BytesRecorded > 0)
                    {
                        Successor.LongData(buffer, param2.ToInt32());

                        if (AutoReturnBuffers)
                        {
                            BufferManager.ReturnBuffer(buffer);
                        }
                    }
                    else
                    {
                        BufferManager.ReturnBuffer(buffer);
                    }
                }
                break;

            case NativeMethods.MIM_MOREDATA:
                Successor.ShortData(param1.ToInt32(), param2.ToInt32());
                break;

            default:
                handled = false;
                break;
            }

            return(handled);
        }
Exemple #6
0
        /// <summary>
        /// Returns buffers to the buffer manager if the message is unhandled.
        /// </summary>
        /// <param name="umsg">The type of message.</param>
        /// <param name="parameter1">The midi header pointer.</param>
        /// <returns>Returns true when buffers were returned.</returns>
        private bool HandleUnhandledMessage(uint umsg, IntPtr parameter1)
        {
            bool handled = false;

            switch (umsg)
            {
            case NativeMethods.MIM_LONGDATA:
            case NativeMethods.MIM_LONGERROR:
                var buffer = BufferManager.FindBuffer(parameter1);

                if (buffer != null)
                {
                    // make sure buffers are returned when there's no handler to take care of it.
                    BufferManager.ReturnBuffer(buffer);
                    handled = true;
                }
                break;
            }

            return(handled);
        }