Send message to a component

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

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

Can someone please write me an example ?

THANK YOU 

I think the ChangeBroadcaster and ChangeListener might be something you should look at. You could make the main 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. You should search the forum. There was a really good explanation of the choices JUCE gives you in a recent post.  

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.

1 Like

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

actually my project is structured as follows:

PluginEditor: public AudioProcessorEditor: here I have my interface

PluginProcessor: public AudioProcessor: it contains the processBlock()

midiContentComponent: public Component (which is a component included into the plugineditor) I have a function that insert 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 a ChangeListener, even if it's not a component ?

Anyone knows how to solve this problem ? :(

Just call 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?


maybe you're right and I don't 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 arrives, it prints the content of the message.


So inside this file I have this class:


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


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

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

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

class IncomingMessageCallback : public CallbackMessage

{

public:

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

    : owner (o), message (m), source (s)

    {}

    void messageCallback() override

    {

        if (owner != nullptr)

            owner->addMessageToList (message, source);

            }

    

    Component::SafePointer<MIDIContentComponent> owner;

    MidiMessage message;

    String source;

};

 

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

{

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

}

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

 

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

 

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

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.

so, inside my 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 ?

Well, yes.