MidiOutput How to send messages?

I’m trying to open a midi output device to send some notes but how can I connect to the device, as MidiOutput is a private member, so

MidiOutput* midioutdevice;

midioutdevice = new MidiOutput(); //This is not working!

I can get a list of available midi out devices, whats the simplest way to send a midi message to this?

Use MidiOutput::openDevice()…

MidiOutput midiOutput;

midiOutput = MidiOutput::openDevice(0);

This gives me the following error

‘juce::MidiOutput::MidiOutput’ : cannot access private member declared in class ‘juce::MidiOutput’

Or if I do the following:

MidiOutput::openDevice(0); MidiMessage m (MidiMessage::noteOn(1,50,1.0f)); MidiOutput::sendMessageNow(m);

I get the error

Do I have to inherit from something, what am I missing?

you’re NEARLY there…

you started with

MidiOutput* midioutdevice;
midioutdevice = new MidiOutput(); //This is not working! 

which doesn’t work because you can’t just create a new MidiOutput using the constructor - you have to use the openDevice function which will return a pointer to an open device. Then you tried…

MidiOutput midiOutput;
midiOutput = MidiOutput::openDevice(0); 

Which is so close, but notice what you’ve done wrong… openDevice returns a pointer to a MidiOutput, but your variable midiOutput is not a pointer. Not only does this mean that you can’t store the result of openDevice to it, but when you say “MidiOutput midiOutput;”, it’s giving you the same problem as saying “MidiOutput *midiOutput = new MidiOutput()” - the constructor cannot be used to create a new instance.

So you want it to be…

MidiOutput midiOutput;
midiOutput = MidiOutput::openDevice(0); 

Then, assuming your returned device is valid, you can call stuff from it using the pointer ‘arrow’ operator.

e.g.

midiOutput->sendMessageNow (MidiMessage::noteOn(1,50,1.0f));
1 Like

Thanx haydxn!!! awesome stuff… Ok, working now, I can trigger sounds of the SW synth, which is being found as device 0, but I cant get cubase to respond to the midiout messages that Iam sending, Im trying to send the midi messages with the mpu-401 device and cubase is setup to listen to this but it doesn’t seem to get any midi messages, have any ideas?

The only way your program’s output will be recieved by cubase is if

(a) you’ve got a wire connecting your MIDI out to your MIDI in, or
(b) you’re using a virtual midi loopback driver.

the one you’ve chosen isn’t a loopback driver, it’s just the standard interface for onboard/cheap soundcards.