private void HandleLongData(IntPtr wParam1, IntPtr wParam2) { if (MidiEventLongDataReceived == null) { return; } byte[]? data = null; byte status; lock (_syncRoot) { MidiInputLongDataBuffer buffer = _longMessageBuffers[wParam1]; // FIXME: this is a nasty workaround for https://github.com/atsushieno/managed-midi/issues/49 // We have no idea when/how this message is sent (midi in proc is not well documented). if (buffer.Header.dwBytesRecorded == 0) { return; } status = Marshal.ReadByte(buffer.Header.lpData); if (buffer.Header.dwBytesRecorded > 1) { data = new byte[buffer.Header.dwBytesRecorded - 1]; Marshal.Copy(buffer.Header.lpData, data, 1, ((int)buffer.Header.dwBytesRecorded) - 1); } if (!IsClosed) { buffer.Recycle(); } else { _longMessageBuffers.Remove(buffer.Ptr); buffer.Dispose(); } } MidiEventLongData e; if (data == null) { e = new MidiEventLongData(status, null, 0, 0, (long)wParam2); } else { e = new MidiEventLongData(status, data, 0, data.Length, (long)wParam2); } MidiEventLongDataReceived?.Invoke(this, new MidiEventLongDataReceivedEventArgs(e)); }
public Win32MidiInput(uint id) { lock (_syncRoot) { _midiInProc = new NativeImports.MidiInProc(MidiInProc); NativeImports.ThrowOnError(NativeImports.midiInOpen(out _midiHandle, id, _midiInProc, IntPtr.Zero)); NativeImports.ThrowOnError(NativeImports.midiInStart(_midiHandle)); while (_longMessageBuffers.Count < LongMessageBufferCount) { var b = new MidiInputLongDataBuffer(_midiHandle); b.PrepareHeader(); b.AddBuffer(); _longMessageBuffers.Add(b.Ptr, b); } } }