private void Write(Int32 when, MidiMessage msg) { var ret = PortMidiMarshal.Pm_WriteShort(stream, when, msg); if (ret != MidiErrorType.NoError) { throw new MidiException(ret, $"Failed to write message {msg.Value} : {PortMidiMarshal.Pm_GetErrorText((MidiErrorType) ret)}"); } }
private void WriteSysEx(Int32 when, byte[] sysEx) { var ret = PortMidiMarshal.Pm_WriteSysEx(stream, when, sysEx); if (ret != MidiErrorType.NoError) { throw new MidiException(ret, $"Failed to write sysEx message : {PortMidiMarshal.Pm_GetErrorText((MidiErrorType) ret)}"); } }
private void Write(MidiEvent[] buffer, int index, int length) { var gch = GCHandle.Alloc(buffer); try { var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, index); var ret = PortMidiMarshal.Pm_Write(stream, ptr, length); if (ret != MidiErrorType.NoError) { throw new MidiException(ret, $"Failed to write messages : {PortMidiMarshal.Pm_GetErrorText((MidiErrorType) ret)}"); } } finally { gch.Free(); } }
public int Read(byte[] buffer, int index, int length) { var gch = GCHandle.Alloc(buffer); try { var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, index); int size = PortMidiMarshal.Pm_Read(stream, ptr, length); if (size < 0) { throw new MidiException((MidiErrorType)size, PortMidiMarshal.Pm_GetErrorText((MidiErrorType)size)); } return(size * 4); } finally { gch.Free(); } }