示例#1
0
 private void Send(byte[] message)
 {
     _runningStatus = 0;
     if (IsDisposed)
     {
         throw new ObjectDisposedException(GetType().Name);
     }
     lock (_lockObject)
     {
         _headerBuilder.InitializeBuffer(message);
         _headerBuilder.Build();
         int result = WindowsMultimediaDevice.midiOutPrepareHeader(Handle, _headerBuilder.Result, SizeOfMidiHeader);
         if (result == (int)EDeviceException.MmsyserrNoerror)
         {
             _bufferCount++;
             result = WindowsMultimediaDevice.midiOutLongMsg(Handle, _headerBuilder.Result, SizeOfMidiHeader);
             if (result != (int)EDeviceException.MmsyserrNoerror)
             {
                 WindowsMultimediaDevice.midiOutUnprepareHeader(Handle, _headerBuilder.Result, SizeOfMidiHeader);
                 _bufferCount--;
                 _headerBuilder.Destroy();
                 OnError(new ErrorEventArgs(new OutputDeviceException(result)));
             }
         }
         else
         {
             _headerBuilder.Destroy();
             OnError(new ErrorEventArgs(new OutputDeviceException(result)));
         }
     }
 }
示例#2
0
    private void ReleaseBuffer(IntPtr headerPtr)
    {
        int result = midiInUnprepareHeader(Handle, headerPtr, SizeOfMidiHeader);

        if (result != MIDIExceptions.MMSYSERR_NOERROR)
        {
            Exception ex = new InputDeviceException(result);

            OnError(new ErrorEventArgs(ex));
        }

        headerBuilder.Destroy(headerPtr);

        bufferCount--;

        Debug.Assert(bufferCount >= 0);

        Monitor.Pulse(lockObject);
    }
示例#3
0
        public int AddSysExBuffer()
        {
            _headerBuilder.BufferLength = _sysExBufferSize;
            _headerBuilder.Build();
            var headerPtr = _headerBuilder.Result;
            var result    = WindowsMultimediaDevice.midiInPrepareHeader(Handle, headerPtr, SizeOfMidiHeader);

            if (result == 0)
            {
                _bufferCount++;
                result = WindowsMultimediaDevice.midiInAddBuffer(Handle, headerPtr, SizeOfMidiHeader);
                if (result != 0)
                {
                    WindowsMultimediaDevice.midiInUnprepareHeader(Handle, headerPtr, SizeOfMidiHeader);
                    _bufferCount--;
                    _headerBuilder.Destroy();
                }
                return(result);
            }
            _headerBuilder.Destroy();
            return(result);
        }