private void SetDeviceInformation() { var caps = default(MidiInWinApi.MIDIINCAPS); ProcessMmResult(MidiInWinApi.midiInGetDevCaps(new IntPtr(Id), ref caps, (uint)Marshal.SizeOf(caps))); SetBasicDeviceInformation(caps.wMid, caps.wPid, caps.vDriverVersion, caps.szPname); }
public void Start() { EnsureDeviceIsNotDisposed(); EnsureHandleIsCreated(); PrepareSysExBuffer(); ProcessMmResult(() => MidiInWinApi.midiInStart(_handle)); _startTime = DateTime.UtcNow; }
private void EnsureHandleIsCreated() { if (_handle != IntPtr.Zero) { return; } _callback = OnMessage; ProcessMmResult(MidiInWinApi.midiInOpen(out _handle, Id, _callback, IntPtr.Zero, MidiWinApi.CallbackFunction)); }
private void DestroyHandle() { if (_handle == IntPtr.Zero) { return; } MidiInWinApi.midiInReset(_handle); MidiInWinApi.midiInClose(_handle); }
/// <summary> /// Starts listening for incoming MIDI events on the current input device. /// </summary> /// <exception cref="ObjectDisposedException">The current <see cref="InputDevice"/> is disposed.</exception> /// <exception cref="MidiDeviceException">An error occurred on device.</exception> public void StartEventsListening() { EnsureDeviceIsNotDisposed(); EnsureHandleIsCreated(); PrepareSysExBuffer(); ProcessMmResult(MidiInWinApi.midiInStart(_handle)); IsListeningForEvents = true; }
/// <summary> /// Stops listening for incoming MIDI events on the current <see cref="InputDevice"/> and flushes /// all pending data. /// </summary> /// <exception cref="ObjectDisposedException">The current <see cref="InputDevice"/> is disposed.</exception> /// <exception cref="MidiDeviceException">An error occurred on device.</exception> public void Reset() { EnsureDeviceIsNotDisposed(); if (_handle == IntPtr.Zero) { return; } ProcessMmResult(MidiInWinApi.midiInReset(_handle)); }
public void Reset() { EnsureDeviceIsNotDisposed(); if (_handle == IntPtr.Zero) { return; } ProcessMmResult(() => MidiInWinApi.midiInReset(_handle)); _startTime = DateTime.UtcNow; }
/// <summary> /// Stops listening for incoming MIDI events on the current input device. /// </summary> /// <exception cref="ObjectDisposedException">The current <see cref="InputDevice"/> is disposed.</exception> /// <exception cref="MidiDeviceException">An error occurred on device.</exception> public void StopEventsListening() { EnsureDeviceIsNotDisposed(); if (_handle == IntPtr.Zero) { return; } IsListeningForEvents = false; ProcessMmResult(MidiInWinApi.midiInStop(_handle)); }
private void PrepareSysExBuffer() { var buffer = new byte[SysExBufferLength]; _sysExBufferPointer = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, _sysExBufferPointer, buffer.Length); _sysExHeader = new MidiWinApi.MIDIHDR(); _sysExHeader.lpData = _sysExBufferPointer; _sysExHeader.dwBufferLength = _sysExHeader.dwBytesRecorded = (uint)buffer.Length; ProcessMmResult(() => MidiInWinApi.midiInPrepareHeader(_handle, ref _sysExHeader, Marshal.SizeOf(_sysExHeader))); ProcessMmResult(() => MidiInWinApi.midiInAddBuffer(_handle, ref _sysExHeader, Marshal.SizeOf(_sysExHeader))); }
private void UnprepareSysExBuffer(IntPtr headerPointer) { if (headerPointer == IntPtr.Zero) { return; } MidiInWinApi.midiInUnprepareHeader(_handle, headerPointer, MidiWinApi.MidiHeaderSize); var header = (MidiWinApi.MIDIHDR)Marshal.PtrToStructure(headerPointer, typeof(MidiWinApi.MIDIHDR)); Marshal.FreeHGlobal(header.lpData); Marshal.FreeHGlobal(headerPointer); }
private void PrepareSysExBuffer() { var header = new MidiWinApi.MIDIHDR { lpData = Marshal.AllocHGlobal(SysExBufferLength), dwBufferLength = SysExBufferLength, dwBytesRecorded = SysExBufferLength }; _sysExHeaderPointer = Marshal.AllocHGlobal(MidiWinApi.MidiHeaderSize); Marshal.StructureToPtr(header, _sysExHeaderPointer, false); ProcessMmResult(MidiInWinApi.midiInPrepareHeader(_handle, _sysExHeaderPointer, MidiWinApi.MidiHeaderSize)); ProcessMmResult(MidiInWinApi.midiInAddBuffer(_handle, _sysExHeaderPointer, MidiWinApi.MidiHeaderSize)); }
public static int GetDevicesCount() { // TODO: process last error // TODO: uint instead of int return(MidiInWinApi.midiInGetNumDevs()); }
private void UnprepareSysExBuffer() { ProcessMmResult(() => MidiInWinApi.midiInUnprepareHeader(_handle, ref _sysExHeader, Marshal.SizeOf(_sysExHeader))); Marshal.FreeHGlobal(_sysExBufferPointer); }
private void DestroyHandle() { MidiInWinApi.midiInClose(_handle); }
/// <summary> /// Gets error description for the specified MMRESULT which is return value of winmm function. /// </summary> /// <param name="mmrError">MMRESULT which is return value of winmm function.</param> /// <param name="pszText"><see cref="StringBuilder"/> to write error description to.</param> /// <param name="cchText">Size of <paramref name="pszText"/> buffer.</param> /// <returns>Return value of winmm function which gets error description.</returns> protected override uint GetErrorText(uint mmrError, StringBuilder pszText, uint cchText) { return(MidiInWinApi.midiInGetErrorText(mmrError, pszText, cchText)); }
/// <summary> /// Retrieves the number of input MIDI devices presented in the system. /// </summary> /// <returns>Number of input MIDI devices presented in the system.</returns> public static int GetDevicesCount() { return((int)MidiInWinApi.midiInGetNumDevs()); }
internal override MMRESULT GetErrorText(MMRESULT mmrError, StringBuilder pszText, uint cchText) { return(MidiInWinApi.midiInGetErrorText(mmrError, pszText, cchText)); }
private uint StopEventsListeningSilently() { IsListeningForEvents = false; return(MidiInWinApi.midiInStop(_handle)); }