Whenever I use MIDI_SetTextSysexEvt to update a text event, ReaScript adds an additional null character to the end of the string (on top of the one that's already used to terminate the string). This seems like a really minor detail, but it is preventing us from achieving our ideal workflow. Oddly enough, opening the "Edit text event" window removes this additional null character, but this is a bit cumbersome to do for every text event.
To reproduce:
- Open up any MIDI track.
- Add a text event with some non-empty message.
- Select the text event.
- Run the EEL script below in the debugger.
Code:
// Get the first selected event.
take = MIDIEditor_GetTake(MIDIEditor_GetActive());
sel_event = MIDI_EnumSelTextSysexEvts(take, -1);
// Measure the length of the message.
retval = MIDI_GetTextSysexEvt(take, sel_event, selected, muted, ppqpos, event_type, #msg);
before_length = strlen(#msg);
// Place the event again exactly as it is.
MIDI_SetTextSysexEvt(take, sel_event, selected, muted, ppqpos, event_type, #msg);
// Measure the length of the message again.
retval = MIDI_GetTextSysexEvt(take, sel_event, selected, muted, ppqpos, event_type, #msg);
after_length = strlen(#msg);
last_char = str_getchar(#msg, strlen(#msg) - 1, 'c');
The before_length and the after_length should be the same, but the after_length is greater by one; the last_char confirms that a null character was added to the end of the string. Oddly, if you run the script again, it won't continue to tack on additional null characters; it only adds the one.
This also happens with Lua; I haven't tried it with Python. I'm running Windows 10 Pro, but it occurs on other machines as well. This bug also occurs on REAPER 4.78.