Initializing constructor

Hey everyone,

Ik keep bumping my head agains this, i have a knowledge gap on initializing contsructors, if anyone knows a good resource or could explain it would be highly appreciated!

I'm following a tutorial where they initialize an unlockform:

1
2
3
 MainContentComponent()
        : unlockForm (marketplaceStatus)
    {


Now my own code is a bit more complicated and I don't know how to initialize it in MyAppAudiProcessorEditor..

1
2
3
 MyAppAudioProcessorEditor::MyAppAudioProcessorEditor (MyAppAudioProcessor& p )
    : AudioProcessorEditor (&p), audioProcessor (p)
{
Last edited on
You have to show (at least) from definition of MyAppAudioProcessorEditor what members and bases it has, and from definitions of those bases (and members) what argument types their constructors accept.
Last edited on
I suspect the AudioProcessorEditor(&p) should be AudioProcessorEditor(p) - although without knowing the type of AudioProcessorEditor...

In this context, & means address of - not reference. In the context of (MyAppAudioProcessor& p) then & does mean ref. I know it can be confusing.
ok sorry, here is more info :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

class MayAppAudioProcessorEditor  : public juce::AudioProcessorEditor,
public juce::Slider::Listener, public juce::Button::Listener, public juce::ComboBox::Listener, private juce::Timer
{
public:
    MyAppAudioProcessorEditor (MyAppAudioProcessor&);
    ~MyAppAudioProcessorEditor() override;

    void paint (juce::Graphics&) override;
    void resized() override;
    void sliderValueChanged(juce::Slider *slider) override;
    void buttonClicked(juce::Button *button) override;
    void comboBoxChanged(juce::ComboBox *comboBox) override;
    
private:
   
    MyAppAudioProcessor& audioProcessor;

    ModernDial kitDial, trackDial, velocityDial, minvelocityDial, afterTouchDial, voiceDial, voiceStartDial, midiChannelSelectDial;

    juce::Label kitLabel, trackLabel, noteOnButtonLabel, velocityLabel, minvelocityLabel, afterTouchLabel, voiceDialLabel, voiceStartDialLabel, midiChannelSelectDialLabel;
    juce::ToggleButton noteOnButton;
    juce::ComboBox modeMenu, chordMenu, scaleMenu, rootNoteMenu, scaleModeMenu;
    

    struct Rect_Sequencer : public juce::Component
    {
        Rect_Sequencer() {setPaintingIsUnclipped(true);}
        std::vector<std::unique_ptr<juce::ToggleButton>> channelActiveToggles;
        
        
        void paint (juce::Graphics& g) override
        {
            g.setColour(juce::Colours::black);
            g.fillRect(getLocalBounds());

        }
    };
    

    
    
    Rect_Sequencer rect_Sequencer;
    juce::TooltipWindow tooltipWindow;
    CustomLookAndFeel customLookAndFeel;
    
    
    void timerCallback() override
    {
        if (! isUnlocked && marketplaceStatus.isUnlocked())
        {
            isUnlocked = true;
            unlockApp();
        }
    }
    
    void showForm()
    {
        unlockForm.setVisible (true);
    }
    
    void unlockApp()
    {
        secretButton.setEnabled (true);
        unlockButton.setEnabled (false);
        
        unlockLabel.setText ("Status: Unlocked", juce::dontSendNotification);
        unlockLabel.setColour (juce::Label::textColourId, juce::Colours::green);
    }
    
    void checkFeature()
    {
        if (marketplaceStatus.isUnlocked())
            DBG ("App unlocked!");
        else
            DBG ("Beware of hackers!");
    }
    
    juce::Label      unlockLabel  { {}, "Status: Locked" };
    juce::TextButton unlockButton { "Unlock" },
    secretButton { "Super Secret Feature" };
    
    TutorialMarketplaceStatus marketplaceStatus;
    TutorialUnlockForm unlockForm;
    
    bool isUnlocked = false;
    

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MyAppAudioProcessorEditor)
};
1
2
3
4
5
MyAppAudioProcessorEditor::MyAppAudioProcessorEditor(MyAppAudioProcessor& p)
:	AudioProcessorEditor(p), // If I read the docs correctly you could instead pass &p here (I assume the result is the same).
	audioProcessor(p)
{
}


Note that you can write juce:: in front of AudioProcessorEditor if you want.

Edit: Hmm, this ended up essentially the same as your original code. Is it causing problems or are you just unsure how it works?
Last edited on
well, now i have to pass this aditional unlockform: here in the example its in a maincontentcomponent: MainContentComponent()
: unlockForm (marketplaceStatus)
{

As you indeed noticed i'm unsure how it works, i'm a beginner and understand the basics but this is a bit too much for me, i'm trying to incorporate this tutorial in my own code:
https://docs.juce.com/master/tutorial_online_unlock_status.html#tutorial_online_unlock_status_demo_project
Topic archived. No new replies allowed.