Exemple #1
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);
        }
        /// <summary>
        /// Receives a port event.
        /// </summary>
        /// <param name="midiEvent">The port event. Must not be null.</param>
        /// <remarks>A new event is created with a new timestamp and send to the component's successors.</remarks>
        public override void PortEvent(MidiPortEvent midiEvent)
        {
            Check.IfArgumentNull(midiEvent, nameof(midiEvent));

            if (NextPortEventReceiver != null)
            {
                MidiPortEvent newEvent;

                if (midiEvent.IsShortMessage)
                {
                    newEvent = new MidiPortEvent(midiEvent.RecordType, midiEvent.Data, GetCurrentTimestamp());
                }
                else
                {
                    newEvent = new MidiPortEvent(midiEvent.RecordType, midiEvent.Buffer, GetCurrentTimestamp());
                }

                NextPortEventReceiver.PortEvent(newEvent);
            }
        }
Exemple #3
0
        /// <summary>
        /// Dispatches the <paramref name="record"/> to the appropriate receiver component.
        /// </summary>
        /// <param name="record">Must not be null.</param>
        private void DispatchRecord(MidiPortEvent record)
        {
            Contract.Requires(record != null);
            Check.IfArgumentNull(record, "record");

            if (NextReceiver != null)
            {
                switch (record.RecordType)
                {
                case MidiPortEventType.MoreData:
                case MidiPortEventType.ShortData:
                    NextReceiver.ShortData(record.Data, (int)record.Timestamp);
                    break;

                case MidiPortEventType.LongData:
                    NextReceiver.LongData(record.Buffer, (int)record.Timestamp);
                    break;
                }
            }

            if (NextErrorReceiver != null)
            {
                switch (record.RecordType)
                {
                case MidiPortEventType.ShortError:
                    NextErrorReceiver.ShortError(record.Data, (int)record.Timestamp);
                    break;

                case MidiPortEventType.LongError:
                    NextErrorReceiver.LongError(record.Buffer, (int)record.Timestamp);
                    break;
                }
            }

            if (NextPortEventReceiver != null)
            {
                NextPortEventReceiver.PortEvent(record);
            }
        }