Lost sending SysEx, Win 10

I tried this using both juce::MIdiMessage::createSysExMessage() and juce::MidiMessage::MidiMessage(const void* data, int size).
I am making MIDI real-time tuning messages, of the format:
F0 7F 7F 08 02 01 01 nn nn pb pb F7 (I input the base-10 values, not hex)
And I’m getting output like:
142573552 1040253186 -149477058 -33686019 -572662307 0 -1902887754 -1879045377 3801155 5701724 5111881 5177412
Of course, when using createSysExMessage, I omitted the leading and trailing bytes, but, looking at the code, it looks like it does the exact same thing.

But I believe I’m doing something wrong in feeding it the array, or in reading it, because the messages that are being constructed and sent are random.

The goal is for my program to calculate MIDI tuning for notes in a microtonal score, and each RatNoteOn also has a pointer to a preMessage, which is the real-time SysEx tuning message that must be sent before the NoteOn message. The list of MIDI events only knows about note-on and note-off messages, because, when it sorts by timestamp, it mustn’t accidentally put the note-on before the sysex. So the sysex is referenced by a pointer in the RatNoteOn class, and when playing, if it is a note-on, this preMessage is looked for and sent, after I try to print its bytes for debugging.
The bytes I get out of it are not the bytes I put into it, and a MIDI monitor indeed shows the wrong messages coming out.

I suspect I haven’t quite grasped how to put in and get out void pointers, although what I’m doing seems like it should work.


#include <JuceHeader.h>
#include <memory>
#include <array>

class RatMidiMessage : public juce::MidiMessage
    RatMidiMessage(uint8, uint8, uint8, double, uint8, uint32, std::shared_ptr<RatMidiMessage>);
    virtual ~RatMidiMessage();
    void setPreMessage();
    juce::MidiMessage* getPreMessage();
    uint8 getTuningByte(uint8);
    void setTuningByte(uint8, uint8);
    std::shared_ptr<juce::MidiMessage> preMessage;
    std::array<uint8, 12> tuningBytes;


#include "RatMidiMessage.h"

RatMidiMessage::RatMidiMessage(uint8 b1, uint8 b2, uint8 b3, double timestamp_, uint8 instrument_, uint32 id_, std::shared_ptr<RatMidiMessage> ptnr_)
    : juce::MidiMessage(b1, b2, b3, timestamp_),
    partner(ptnr_), tuningBytes{ 240, 127, 127, 8, 2, 1, 1, 0, 0, 0, 0, 247 }
    preMessage = std::make_shared<juce::MidiMessage>(&tuningBytes, 12);

void RatMidiMessage::setPreMessage()
    std::cerr << "tuningBytes: ";
    for (auto bt_ : tuningBytes)
        std::cerr << int(bt_) << " ";
    std::cerr << std::endl;
    void* voidPtr{ &tuningBytes };
    preMessage = std::make_shared<juce::MidiMessage>(voidPtr, 12);


void RatMidiManager::sendRatMidiMessage(RatMidiMessage &msg)

    if (activeMidiOutputs.count(identifier) && activeMidiOutputs[identifier] != nullptr)
	if (msg.isNoteOn() && msg.getPreMessage() != nullptr)
	    juce::MidiMessage premsg = *msg.getPreMessage();
	    const void* preraw = premsg.getRawData();
	    const int* preint{ static_cast<const int*>(preraw) };
	    int presz_ = premsg.getRawDataSize();
	    std::cerr << presz_ << " premessage bytes......";
	    for (int i = 0; i < presz_; i++)
		std::cerr << preint[i] << " ";
	    std::cerr << std::endl;

this is incorrect. the data is unsigned chars, not ints.