Beginner tutorial help

Hi All, I am new to JUCE and specifically coding an AU plugin and I’ve been closely following the JUCE tutorial for creating a basic Audio/MIDI plugin. I’ve become stuck at the following section:

Create a new public float variable called noteOnVel in the processor class header. This is the variable that we will set with the slider.

public:

float noteOnVel;

We need to set this value whenever the slider is changed. To do this we use a slider listener callback function. Any class can inherit slider listener functionality but for the purposes of this tutorial we will add this functionality to the editor class.

Note
For a more in-depth description of listeners please see Tutorial: Listeners and Broadcasters.

Add the inheritance [2] and the default callback function [3] so the editor class looks like this:

class TutorialPluginAudioProcessorEditor : public juce::AudioProcessorEditor,

private juce::Slider::Listener // [2]

{

public:

TutorialPluginAudioProcessorEditor (TutorialPluginAudioProcessor&);

~TutorialPluginAudioProcessorEditor();

//==================================================================

// This is just a standard Juce paint method…

void paint (juce::Graphics& g) override;

void resized() override;

private:

void sliderValueChanged (juce::Slider* slider) override; // [3]

//==================================================================

// This reference is provided as a quick way for your editor to

// access the processor object that created it.

TutorialPluginAudioProcessor& audioProcessor;

juce::Slider midiVolume;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TutorialPluginAudioProcessorEditor)

};

My question is, where/how do I add the following float noteOnVel; ?
I’ve been trying to work out exactly where this should go in the processor class header as it isn’t clear in the documentation as to where or how this should be added. I hope someone can clarify this for me and thank you in advance for your help.

B

In the public section of the TutorialPluginAudioProcessor. The public section is denoted by public:. You can add the float noteOnVel; declaration anywhere following that.

// Thank you! I have done this and it seemed to work fine. The only other issue I have in the code is now as follows (expected unqualified-id):

#include <JuceHeader.h>
#include "PluginProcessor.h"

//==============================================================================

class MidiPluginAudioProcessorEditor  : public juce::AudioProcessorEditor, private juce::Slider::Listener     // [2]


{
    public:
    MidiPluginAudioProcessorEditor (MidiPluginAudioProcessor&);
    ~MidiPluginAudioProcessorEditor() override;
    
    //==============================================================================
    void paint (juce::Graphics&) override;
    void resized() override;
    
   private:
    // This reference is provided as a quick way for your editor to
    // access the processor object that created it.
    MidiPluginAudioProcessor& audioProcessor;
    juce::Slider midiVolume; // [1]
    
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiPluginAudioProcessorEditor)```
    
};
{ 

public:
    MidiPluginAudioProcessorEditor (MidiPluginAudioProcessor&);
    ~MidilPluginAudioProcessorEditor();
 
    //==================================================================
    // This is just a standard Juce paint method...
    void paint (juce::Graphics& g) override;
 
    void resized() override;
 
private:
    void sliderValueChanged (juce::Slider* slider) override; // [3]
 
    //==================================================================
    // This reference is provided as a quick way for your editor to
    // access the processor object that created it.
    MidiPluginAudioProcessor& audioProcessor;
    juce::Slider midiVolume;
    audioProcessor.noteOnVel = midiVolume.getValue();
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiPluginAudioProcessorEditor)
}; 

I can’t really read your code, could you edit the post to surround the code with a “triple tic” (three if these ` right next to each other) at the start and end of the code block

I have done this. Hopefully it is easier to read now. The error is coming up at the beginning of the second block of code.

audioProcessor.noteOnVel = midiVolume.getValue(); line of code belongs in a function somewhere. It does not belong in the class declaration

It’s also confusing that you have pasted two blocks of code that look like they are mostly the same thing, ie. a class declaration for MidiPluginAudioProcessorEditor. Oh, maybe you are just showing the working version, and the non-working version.

Yes, that is correct. I’ve managed to get it so that there are no errors showing in the compiler but when I build the project, I’m getting an error that says

“Undefined symbols for architecture x86_64:
“MidiPluginAudioProcessor::createEditor()”, referenced from:
vtable for MidiPluginAudioProcessor in libMidiPlugin.a2
ld: symbol(s) not found for architecture x86_64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)”. I can paste the code from the Editor and Processor parts if that would help debug?

No need to see the full code.

The linker doesn’t find an implementation for createEditor. That means it is declared in the header, but not implemented.
A common oversight is forgetting the namespace/classname when implementing the function:

juce::AudioProcessorEditor* MidiPluginAudioProcessor::createEditor()
{
    return new MidiPluginAudioProcessorEditor (*this);
}

The error would occur when you wrote only this instead

juce::AudioProcessorEditor* createEditor()