예제 #1
0
        /// <summary>
        /// Unprepares/prepares and adds a MIDIHDR header back to the buffer to
        /// record another system exclusive message.
        /// </summary>
        private void ManageSysExHeaders()
        {
            lock(lockObject)
            {
                while(IsRecording())
                {
                    Monitor.Wait(lockObject);

                    while(sysExHeaderQueue.Count > 0 && IsRecording())
                    {
                        IntPtr header = (IntPtr)sysExHeaderQueue.Dequeue();

                        // Unprepare header.
                        int result = midiInUnprepareHeader(handle, header,
                            Marshal.SizeOf(typeof(MidiHeader)));

                        if(result == MMSYSERR_NOERROR)
                        {
                            // Prepare header to be used again.
                            result = midiInPrepareHeader(handle, header,
                                Marshal.SizeOf(typeof(MidiHeader)));
                        }

                        if(result == MMSYSERR_NOERROR)
                        {
                            // Add header back to buffer.
                            result = midiInAddBuffer(handle, header,
                                Marshal.SizeOf(typeof(MidiHeader)));
                        }

                        if(result != MMSYSERR_NOERROR)
                        {
                            // Raise event letting clients know an error has occurred.
                            if(SysExHeaderErrorOccurred != null)
                            {
                                InputDeviceException ex = new InputDeviceException(result);
                                SysExHeaderErrorOccurred(this,
                                    new SysExHeaderErrorEventArgs(ex.Message));
                            }
                        }
                    }
                }
            }
        }