How to send MemoryBlock using sendMessageNow

OK, so I have a MemoryBlock which is basically formed from multiple long SysEx Messages that are the Patches in Synthesizer’s Patch Bank.

What I want to do is to pick out a section of that MemoryBlock (mb_2send) and send it to the MidiOutput Device. It is already a correctly formed SysEx Message so this should be easy right?

However I cannot see a simple way of doing this:

You cannot put the MemoryBlock into sendMessageNow because it must be a juce::MidiMessage, so this doesn’t work:

audioProcessor.midiOutputDevice->sendMessageNow(mb_2send);

You can form a SysEx Message to send like this:

juce::MidiMessage sysExOutputMsg = juce::MidiMessage::createSysExMessage(mb_2send, 2);

audioProcessor.midiOutputDevice->sendMessageNow(sysExOutputMsg);

But that won’t work either because you cannot put the MemoryBlock into createSysExMessage because that will only take an Array of chars?

This is the only solution I have found so far that will work:

char sysExData[] = { mb_2send.operator[](1), mb_2send.operator[](2) };

juce::MidiMessage sysExOutputMsg = juce::MidiMessage::createSysExMessage(sysExData, 2);

audioProcessor.midiOutputDevice->sendMessageNow(sysExOutputMsg);

But since the actual size of the MemoryBlock to send is 2054 Bytes, that isn’t really viable :frowning:

Maybe I could build a custom function for generating an Array of chars from a MemoryBlock, but before I go down that route, am I missing something easy here?


MidiMessage (**const** **void*** data, **int** numBytes, **double** timeStamp = 0);

So

MidiMessage msg( mb_2send.getData(), mb_2send.getSize() );

Bingo! I knew there must be something silly I wasn’t doing!

juce::MemoryBlock mb_2send = CustomUtilities::copyMemoryBlockSection(audioProcessor.all_prog_mb, 0, 2054);

juce::MidiMessage sysExOutputMsg (mb_2send.getData(), mb_2send.getSize());

audioProcessor.midiOutputDevice->sendMessageNow(sysExOutputMsg);

This works, thank you very much leehu