public void StartReceiving(Clock clock, bool handleSysEx) { if (isInsideInputHandler) { throw new InvalidOperationException("Device is receiving."); } lock (this) { CheckOpen(); CheckNotReceiving(); #region SysEx if (handleSysEx) { LongMsgBuffers.Add(CreateLongMsgBuffer()); } #endregion CheckReturnCode(Win32API.midiInStart(handle)); isReceiving = true; this.clock = clock; } }
/// <summary> /// Releases the resources associated with the specified MidiHeader pointer. /// </summary> /// <param name="ptr"> /// The pointer to MIDIHDR buffer. /// </param> private bool DestroyLongMsgBuffer(UIntPtr ptr) { IntPtr newPtr = unchecked ((IntPtr)(long)(ulong)ptr); UInt32 size = (UInt32)Marshal.SizeOf <Win32API.MIDIHDR>(); CheckReturnCode(Win32API.midiInUnprepareHeader(handle, newPtr, size)); Win32API.MIDIHDR header = Marshal.PtrToStructure <Win32API.MIDIHDR>(newPtr); System.Runtime.InteropServices.Marshal.FreeHGlobal(header.lpData); System.Runtime.InteropServices.Marshal.FreeHGlobal(newPtr); LongMsgBuffers.Remove(newPtr); return(true); }