you have to inherit and override String getWhiteNoteText (int midiNoteNumber);
Do you have an Example ?
If I inherit MidiKeyboardComponent
it is not overridable either:
And it make all my other Methods ambiguos
:
If I inherit and override:
And fix all ambiguos
Issues:
I get the Error that getWhiteNoteText
virtual Class is already defined:
Hi dschiller,
you’re not approaching it the right way. imho you should take some time to learn a bit more about cpp and a few programming concepts like inheritance, otherwise coding will be difficult and might result in a frustrating experience. Take some time to read more about it, it might be boring at first, but you will have much more fun coding afterward!
you don’t want your plugin editor to inherit from MidiKeyboardComponent. because your plugin editor is not a midiKeyboardComponent.
You want to create a new midi keyboard component class that inherits MidiKeyboardComponent to match your needs, and then use it in your editor.
it’s just some pseudo code, but basically you want something like that :
struct MyKeyboardComp : public MidiKeyboardComponent
{
using MidiKeyboardComponent::MidiKeyboardComponent;
String getWhiteNoteText (int) override { return {}; }
};
and then you can use that in your editor :
struct MyEditor : public AudioProcessorEditor
{
MyEditor()
{
addAndMakeVisible (keyboard);
}
.....
MyKeyboardComp keyboard { keyboardState, orientation);
};
Thank’s a lot. Fully agree with the C++ Knowledge Lack! I still reading a lot from “C++ from Bjarne Stroustrup”. Now I see the way. Sure it needs to be an own Component. Thanks a lot!
The reason why it didn’t work for you was, because you mixed up declaration and definition of the function:
- declaration is in the class declaration and there you put the
override
keyword. - the definition can be inside the class declaration (lalala’s example) or in the cpp.
- if it is in the cpp, it is already declared, so no
override
keyword is accepted. - only in the cpp outside the class declaration you need the class name as namespace.
All four mistakes occur in your posted examples in various combinations, that’s why you were stuck.
Thanks Daniel.
I tried to create a new Component but stuck with no default constructor exists for class juce::MidiKeyboardComponent
:
I also tried to create a new GUI Component
. Same Issue.
As far as I inherit from MidiKeyboardComponent
I get the no default constructor exists for class juce::MidiKeyboardComponent
Error.
You need to also call the base class constructor in your inherited class constructor’s initializer list:
E.g.
MyClass::MyClass(int param) : ParentClass(param)
{
//...
}
The Solution:
// AulusMidiKeyboardComponent.h
#pragma once
#include <JuceHeader.h>
//==============================================================================
/*
*/
class AulusMidiKeyboardComponent : public MidiKeyboardComponent
{
public:
AulusMidiKeyboardComponent(MidiKeyboardState& state, Orientation orientation);
String getWhiteNoteText(int) override;
};
// AulusMidiKeyboardComponent.cpp
#include <JuceHeader.h>
#include "AulusMidiKeyboardComponent.h"
AulusMidiKeyboardComponent::AulusMidiKeyboardComponent(MidiKeyboardState& state, Orientation orientation) : MidiKeyboardComponent(state, orientation)
{
}
//==============================================================================
String AulusMidiKeyboardComponent::getWhiteNoteText(int midiNumber)
{
return "";
}
// PluginEditor.h
private:
...
AulusMidiKeyboardComponent keyboardComponent;
//MidiKeyboardComponent keyboardComponent;
...
Thank’s a lot to lalala, daniel and adamski !!
Thank you everyone!