# MidiOutput How to send messages?

**URL:** <https://forum.juce.com/t/midioutput-how-to-send-messages/1911>\
**Category:** General JUCE discussion\
**Created:** [July 15, 2007, 10:28am UTC](https://forum.juce.com/t/midioutput-how-to-send-messages/1911 "2007-07-15T10:28:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayman](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jayman](https://forum.juce.com/u/jayman)\
**Post date:** [July 15, 2007, 10:28am UTC](https://forum.juce.com/t/midioutput-how-to-send-messages/1911/1 "2007-07-15T10:28:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 15, 2007, 11:47am UTC](https://forum.juce.com/t/midioutput-how-to-send-messages/1911/2 "2007-07-15T11:47:06Z")

</div>

Use MidiOutput::openDevice()…

---

<div class="post-metadata">

**Author:** ![jayman](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jayman](https://forum.juce.com/u/jayman)\
**Post date:** [July 15, 2007, 11:50am UTC](https://forum.juce.com/t/midioutput-how-to-send-messages/1911/3 "2007-07-15T11:50:40Z")

</div>

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

```auto

```

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

---

<div class="post-metadata">

**Author:** ![haydxn](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@haydxn](https://forum.juce.com/u/haydxn)\
**Post date:** [July 15, 2007, 12:13pm UTC](https://forum.juce.com/t/midioutput-how-to-send-messages/1911/4 "2007-07-15T12:13:31Z")

</div>

you’re NEARLY there…

you started with

```auto
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…

```auto
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…

```auto
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.

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

---

<div class="post-metadata">

**Author:** ![jayman](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jayman](https://forum.juce.com/u/jayman)\
**Post date:** [July 15, 2007, 12:46pm UTC](https://forum.juce.com/t/midioutput-how-to-send-messages/1911/5 "2007-07-15T12:46:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![haydxn](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@haydxn](https://forum.juce.com/u/haydxn)\
**Post date:** [July 15, 2007, 1:23pm UTC](https://forum.juce.com/t/midioutput-how-to-send-messages/1911/6 "2007-07-15T13:23:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 10:27am UTC](https://forum.juce.com/t/midioutput-how-to-send-messages/1911/7 "2017-05-12T10:27:10Z")

</div>


