MidiOutSysEx is broken

I was asked by a client how our studio indicator lamps (PunchLight) could be used with mAirList.

When testing background scripts in mAirList demo I noticed that while MidiOut() works as expected, MidiOutSysEx() sends invalid MIDI messages.
By checking the data sent to USB MIDI device using a USB data monitor, I saw that messages with 00 status bytes are being sent (the message usually contained a single byte of the original sysex string) instead of valid SysEx messages.

I found this report from 2014 (near the end of the topic), so it appears that the function may be broken for a long time already:
https://www.mairlist.com/forum/index.php?topic=7476.0

Could you please investigate the issue? Thanks.

Actually it’s merely a passthrough to the MMSystem midiOutLongMsg() function:

procedure TMidiScriptPlugin.MidiOutSysEx(iDevice: integer; iData: AnsiString);
var
  hdr: MIDIHDR;
begin
  EnterCriticalSection(MidiOutCS);
  try
    SetLength(MidiOutHandles, max(length(MidiOutHandles), iDevice + 1));
    if MidiOutHandles[iDevice] = 0 then
      raise Exception.CreateFmt('MIDI device %d is not open', [iDevice]);

    hdr.dwBufferLength := Length(iData);
    hdr.lpData := @iData[1];
    hdr.dwFlags := 0;

    midiOutPrepareHeader(MidiOutHandles[iDevice], @hdr, sizeof(hdr));
    try
      midiOutLongMsg(MidiOutHandles[iDevice], @hdr, sizeof(hdr));
    finally
      while midiOutUnprepareHeader(MidiOutHandles[iDevice], @hdr, sizeof(hdr)) = MIDIERR_STILLPLAYING do
        sleep(1);
    end;

  finally
    LeaveCriticalSection(MidiOutCS);
  end;
end;

The only suspicious bit I can see is a mismatch in the string parameter definition (String vs. AnsiString). I fixed that in snapshot build 3630, can you please check if it works now?

You can get it here: http://download.mairlist.com/mAirList/v6.0/snapshot/