MIDIoutput

Hello everybody, I am new to Juce so there a lot of things I have to discover :slight_smile:
I would like to now which are the essentials steps to create a button that sends out a MIDI note to an external MIDI device. I am missing something somehow on the creation of the MIDIoutput and on the actual sending of the note.
thanks.
d

Post your code, then we can see where your problem might be.

What I don’t understand is how I create an Instance of the MidiOutput class,
Or what I have to do once the MidiMessage:: noteOn is ready.

From the docs:

To create one of these, use the static getAvailableDevices() method to find out what outputs are available, and then use the openDevice() method to try to open one.

Calling getAvailableDevices gets you an Array of MidiDeviceInfo. So you need to pick one of those and use its deviceIdentifier to create a MIDIOutput instance, as a std::unique_ptr, e.g. to get the first available device:

auto availableOutputDevices = MidiOutput::getAvailableDevices();
if (availableOutputDevices.size() > 0) 
{
    auto midiOutput = MidiOutput::openDevice (availableOutputDevices[0].deviceIdentifier);
}

A more convoluted example at https://github.com/juce-framework/JUCE/blob/02bbe31c0d2fb59ed32fb725b56ad25536c7ed75/examples/Audio/MidiDemo.h#L418

thanks Adam, I was missing that part.
then another related question, is there a way to do something like this:
sendNote.onClick = [this] {myMidiOutput->sendMessageNow(MidiMessage::noteOn (3, 36, (uint8) 127));};

which now does not work because ‘myMidiOutput’ cannot be implicitly captured in a lambda

The MIDI output object should be a member variable in your class and then capturing “this” would allow using it. Do you have the MIDI output as a local variable now…?

yes now, it is Local. I will try again to declare it in the class definition. thanks for the advice.

Hey,

I’m also trying to send out midi but i can’t get it to work, receiving midi is fine but I want to send out and can’t get it to work…

When i try to send out: midiOutput->sendMessageNow(mySysEx); I get use of undeclared identifier midiOutput.

I’m also not sure how to open a midiout, preferably i would want to send it out to the daw so the user can select where to send it out…

To send MIDI to the DAW, just modify the MidiBuffer that is passed to your plugin’s processBlock.

Hey, tx for your answer, I’m actually doing this but I only receive 5 bytes from this code (but as my plugin is recognized by Ableton as an audio plugin I’m not even sure if it can work)

So first question, how do i change my plugin to be recognized as a midi plugin in my DAW?

This is the code but as said, it’s an audio plugin so not sure it can work:

const uint8 rawSysEx[13] = {0x65, 0x16, 0x0, 0x0, 0x0, 0x69, 0x18, 0x16, 0x2, 0x4, 0x4, 0x5, 0x4};
MidiMessage mySysEx = MidiMessage::createSysExMessage(rawSysEx,13);
processedBuffer.clear();
processedBuffer.addEvent(mySysEx, samplePos);

As you said, this isn’t possible in Live, but it’s possible to route MIDI from Instrument/FX plugins to other channels.

The code you posted looks like it should work, provided Live doesn’t do any additional filtering/processing of sysex messages.

*Update, ok I just found out AU doesn’t handle Midi :smiley: I used VST3 now and I’m getting one step closer, ow boy this is gonna take a while :smiley:

In the youtube tutorial by Eyal Amir he talks about that Logic handles it also different so I’m curious if you know anything about that?

Unlike Live, Logic does let you insert dedicated MIDI FX before an instrument plugin. If you set the “Plugin MIDI Input”, “Plugin MIDI Output”, and “MIDI Effect Plugin” options in the Projucer, your AU plugin should be usable in MIDI FX slots in Logic.

Oh ok, that is very usefull! If i set the “Midi effect plugin” option and load it into live (using AU) It doesn’t load the AU plugin. That’s why i got really confused.
Thank you for clarifying! This gives me hope!

Ok, still stuck, I tested to send altered midi notes through the VST3 and that works but it won’t pass sysex messages, any thoughts?

Have you tried sending sysex messages from Logic’s built-in “Scripter” plugin when inserted as a MIDI FX plugin? If that doesn’t work, then you’ll probably need to adjust your Logic configuration to allow Sysex output. Or, this may not be possible in Logic at all. Either way, you’d need to refer to Logic-specfic documentation/FAQs etc. in order to find out whether this functionality can be enabled.

I’m using Ableton, sysex doesn’t seem to work (regular midi does) I don’t have Logic so can’t test that

This page gives the impression that SysEx is only supported via Max4Live. It’s not clear whether SysEx from VST3s is supported.

Yeah, I think I’m gonna try and create a standalone JUCE app for this, any tips or examples would be highly appreciated.

In the meantime I’ve succesfully sent midi sysex out, I’ve created a standalone app as vst’s and DAW all react differently on sysex.