// Close the port public string Close() { EMMError result = NativeMethods.midiOutClose(handle); handle = IntPtr.Zero; return(WindowsUtil.StrError(result)); }
// Start the port and setup buffers to receives Sysex public string Start() { // Allocate buffer array if (buffers == null) { const int numBuffers = 4; const int bufferSize = 4096; // ZZZ Param? buffers = new MidiBuffer[numBuffers]; // Allocate and prepare the buffers for (int b = 0; b < buffers.Length; b++) { // Create buffer buffers[b] = new MidiBuffer(bufferSize, (IntPtr)b); // Prepare the buffer and give it to windows EMMError st = buffers[b].AddMidiInBuffer(handle); if (st != EMMError.NOERROR) { return(WindowsUtil.StrError(st)); } } } // Finally, start the port return(WindowsUtil.StrError(NativeMethods.midiInStart(handle))); }
public static string StrError(EMMError error) { if (error == EMMError.NOERROR) { return(null); } else { return(error.ToString()); } }
// Close the port public string Close() { Stop(); Reset(); EMMError result = NativeMethods.midiInClose(handle); handle = IntPtr.Zero; MidiInputReceived = null; return(WindowsUtil.StrError(result)); }
// Reset the port and free the sysex buffers public string Reset() { EMMError st = NativeMethods.midiInReset(handle); if (st == EMMError.NOERROR && buffers != null) { // The buffers have now been released by the callback. Just free the array. buffers = null; } return(WindowsUtil.StrError(st)); }
// Open the input port. Midi events cause the MidiInputReceived event to be raised public string Open() { // Open the port EMMError st = NativeMethods.midiInOpen( out handle, id, midiInProc, IntPtr.Zero, NativeMethods.CALLBACK_FUNCTION); return(WindowsUtil.StrError(st)); }
// Remove this buffer from a midi in port public EMMError RemoveMidiInBuffer(IntPtr handle) { EMMError st = EMMError.DELETEERROR; if (preparedForMidiIn) { st = NativeMethods.midiInUnprepareHeader(handle, header, (uint)Marshal.SizeOf(typeof(NativeMethods.MIDIHDR))); if (st == EMMError.NOERROR) { preparedForMidiIn = false; } } return(st); }
public EMMError UnprepareForMidiOut(IntPtr handle) { EMMError st = EMMError.DELETEERROR; // Un-prepare the buffer if (preparedForMidiOut) { st = NativeMethods.midiOutUnprepareHeader(handle, header, (uint)Marshal.SizeOf(typeof(NativeMethods.MIDIHDR))); if (st == EMMError.NOERROR) { preparedForMidiOut = false; } } return(st); }
// Add this buffer to a midi in port public EMMError AddMidiInBuffer(IntPtr handle) { // Prepare the buffer EMMError st = NativeMethods.midiInPrepareHeader(handle, header, headerSize); if (st != EMMError.NOERROR) { return(st); } preparedForMidiIn = true; // Give it to windows st = NativeMethods.midiInAddBuffer(handle, header, headerSize); if (st != EMMError.NOERROR) { return(st); } return(EMMError.NOERROR); }