# Send message to a component

**URL:** <https://forum.juce.com/t/send-message-to-a-component/16012>\
**Category:** General JUCE discussion\
**Created:** [November 21, 2015, 4:02pm UTC](https://forum.juce.com/t/send-message-to-a-component/16012 "2015-11-21T16:02:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rick\_Owens](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@Rick\_Owens](https://forum.juce.com/u/Rick_Owens)\
**Post date:** [November 21, 2015, 4:02pm UTC](https://forum.juce.com/t/send-message-to-a-component/16012/1 "2015-11-21T16:02:54Z")

</div>

Hello, I'm new to JUCE.. I'm writing an audio plugin, i have an introjucer&nbsp;component into my main component which handles my external MIDI message. The two&nbsp;components have no relationship between each other.

I have to send the value&nbsp;of my&nbsp;MIDI message from my "MIDI component" to my main component.

Can someone please write me an example ?

THANK YOU&nbsp;

---

<div class="post-metadata">

**Author:** ![Jordan\_Harris](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jordan\_Harris](https://forum.juce.com/u/Jordan_Harris)\
**Post date:** [November 21, 2015, 5:09pm UTC](https://forum.juce.com/t/send-message-to-a-component/16012/2 "2015-11-21T17:09:00Z")

</div>

I think the ChangeBroadcaster and ChangeListener might be something you should look at.&nbsp;You could make the main&nbsp;Component a ChangeListener and call ChangeBroadcaster::sendChangeMessage() from the MIDI Component when a MIDI message happens. Maybe someone has a better solution, but I think this would be a good way to do it.

There's actually quite a few ways of communicating between objects.&nbsp;You should search the forum. There was a really good explanation of the choices JUCE gives you in a recent post. &nbsp;

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [November 21, 2015, 5:56pm UTC](https://forum.juce.com/t/send-message-to-a-component/16012/3 "2015-11-21T17:56:43Z")

</div>

Here :-

http://zee.credland.net/jwiki2j/index.php/Sending\_Messages

I expanded the list with some examples...it's incomplete still but it's probably got some useful starting points.

---

<div class="post-metadata">

**Author:** ![Rick\_Owens](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@Rick\_Owens](https://forum.juce.com/u/Rick_Owens)\
**Post date:** [November 22, 2015, 4:43pm UTC](https://forum.juce.com/t/send-message-to-a-component/16012/4 "2015-11-22T16:43:24Z")

</div>

I'm reading the changeBroadcaster but I don't&nbsp;understand so much :(&nbsp;

actually my project is structured as follows:

**PluginEditor**** : public AudioProcessorEditor**: here&nbsp;I have my interface

**PluginProcessor: public AudioProcessor** : it&nbsp;contains the processBlock()

**midiContentComponent: public Component** (which is a component included into the plugineditor) I have a function that insert&nbsp;in a texteditor information about each message received. Every time I receive a message I would like to send directly my MidiMessage into the PluginProcessor or PluginEditor! So i can change the frequency of my oscillator..

I hope I was clear :( maybe it's simpler than it looks..

Can I make my PluginProcessor&nbsp;a&nbsp;ChangeListener, even if it's not a component ?

---

<div class="post-metadata">

**Author:** ![Rick\_Owens](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@Rick\_Owens](https://forum.juce.com/u/Rick_Owens)\
**Post date:** [November 23, 2015, 9:04am UTC](https://forum.juce.com/t/send-message-to-a-component/16012/5 "2015-11-23T09:04:53Z")

</div>

Anyone knows how to solve this problem ? :(

---

<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:** [November 23, 2015, 9:40am UTC](https://forum.juce.com/t/send-message-to-a-component/16012/6 "2015-11-23T09:40:58Z")

</div>

Just call&nbsp;a function..?

I can't quite tell what the problem is that you're facing - if you have any two classes and want to send a message between them, you give one of them a method, and call it from the other. That's just plain old object-oriented programming, not anything specific to JUCE or even C++.

Or maybe you're not explaining your problem clearly?

---

<div class="post-metadata">

**Author:** ![Rick\_Owens](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@Rick\_Owens](https://forum.juce.com/u/Rick_Owens)\
**Post date:** [November 23, 2015, 10:30am UTC](https://forum.juce.com/t/send-message-to-a-component/16012/7 "2015-11-23T10:30:16Z")

</div>

maybe you're right and I don't&nbsp;know how to explain. I was inspired by the tutorial juce http://www.juce.com/doc/tutorial\_handling\_midi\_events and I created my own class MIDIContentComponent which contains everal functions, each time a MIDI message&nbsp;arrives, it prints&nbsp;the content of the message.

So inside this file I have this class:

**IncomingMessageCallback class: public CallbackMessage**  
{  
public:  
&nbsp; &nbsp; IncomingMessageCallback (MIDIContentComponent or \*, const MidiMessage & m, const String & s)  
&nbsp; &nbsp; : Owner (or), message (m), source (s)  
&nbsp; &nbsp; {}  
&nbsp; &nbsp; void messageCallback () override  
&nbsp; &nbsp; {  
&nbsp; &nbsp; &nbsp; &nbsp; if (owner! = nullptr)  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Owner-\> addMessageToList (message, source);  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; Component :: SafePointer \<MIDIContentComponent\> owner;  
&nbsp; &nbsp; MidiMessage message;  
&nbsp; &nbsp; String source;  
};

Maybe I didn't&nbsp;understand how it works but I would like that every time that addMessageToList is called, &nbsp;to pass the MIDImessage to processBlock.. I hope I was clear this time  
&nbsp;

---

<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:** [November 23, 2015, 10:37am UTC](https://forum.juce.com/t/send-message-to-a-component/16012/8 "2015-11-23T10:37:11Z")

</div>

Maybe try again to explain what you're trying to achieve, at a higher level?

---

<div class="post-metadata">

**Author:** ![Rick\_Owens](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@Rick\_Owens](https://forum.juce.com/u/Rick_Owens)\
**Post date:** [November 23, 2015, 10:54am UTC](https://forum.juce.com/t/send-message-to-a-component/16012/9 "2015-11-23T10:54:30Z")

</div>

ok. I'll try my best.. I made a class exactly as the&nbsp;JUCE tutorial:

class **IncomingMessageCallback** : **public CallbackMessage**

{

public:

&nbsp; &nbsp; IncomingMessageCallback (MIDIContentComponent\* o, const MidiMessage& m, const String& s)

&nbsp; &nbsp; : owner (o), message (m), source (s)

&nbsp; &nbsp; {}

&nbsp; &nbsp; void messageCallback() override

&nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; if (owner != nullptr)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; owner-\> **addMessageToList** (message, source);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp;&nbsp; &nbsp;

&nbsp; &nbsp; Component::SafePointer\<MIDIContentComponent\> owner;

&nbsp; &nbsp; MidiMessage message;

&nbsp; &nbsp; String source;

};

&nbsp;

void **MIDIContentComponent::postMessageToList** (const MidiMessage& message, const String& source)

{

&nbsp; &nbsp; (new IncomingMessageCallback (this, message, source))-\>post();

}

and the addMessageToList inserts a text (the description of my MidiMessage) into a TextBox.

&nbsp;

On the other hand, I have my pluginProcessor which contains the processBlock.&nbsp;

&nbsp;

I wish these two classes interacted in some way. In particular I'd like something like that. When a MIDIMessage arrives, send it to my Synth, so I can change the frequency! I'm sure it's easy, but I don't understand

---

<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:** [November 23, 2015, 10:56am UTC](https://forum.juce.com/t/send-message-to-a-component/16012/10 "2015-11-23T10:56:28Z")

</div>

Your processBlock method gets a buffer of midi messages. You don't need to collect them somewhere else and send them, it already has them, and that's how you should process them if you need to react to them in your synth. The tutorial stuff was all just about sending messages to the GUI, not the audio engine.

---

<div class="post-metadata">

**Author:** ![Rick\_Owens](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@Rick\_Owens](https://forum.juce.com/u/Rick_Owens)\
**Post date:** [November 23, 2015, 11:19am UTC](https://forum.juce.com/t/send-message-to-a-component/16012/11 "2015-11-23T11:19:27Z")

</div>

so, inside my&nbsp;processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages), everytime that I hold a button from my keyboard I have the message in real time ? I don't have to implement anything ? It's all in the midiBuffer ?

---

<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:** [November 23, 2015, 11:26am UTC](https://forum.juce.com/t/send-message-to-a-component/16012/12 "2015-11-23T11:26:35Z")

</div>

Well, yes.
