I am struggling to create a working plugin … well I have a simple 300 x 300 screen loading fine in Logic … However when I look at all the tutorials I see the following
For simplicity, we have bundled the processor code into a single .h file rather than being split across a .cpp and an .h file.
For someone trying to learn C++ this is not simplifying … when I create my own plug in and I want to model something on a tutorial … now I have to know/decide what parts of the tutorial goes into the .h or the .cpp that was created for me by the tool.
Not looking for everything to be done for me … but there seems to be a gap here (probably my knowledge to be honest, I am coming from Java)
The AudioProcessor parts should go into the Projucer generated PluginProcessor.h/.cpp files and the AudioProcessorEditor parts into PluginEditor.h/.cpp.
I think “simplicity” in the tutorial refers to simplicity for the author of the tutorial…
But which parts go to the .h and which to the .cpp? That is where I am getting into trouble. I copy all the relevant bits into my .h but then get errors about duplicate methods etc … Are they interchangeable?
In a header, you put usually declarations. You can also put implementations into the header, but that was the point of your question.
In the cpp you put the implementation. If you put the class declaration in the cpp, you get the duplicate symbol problem.
Instead you copy the method declarations and add the class name as namespace to each method:
class Foo : public Component
{
public:
Foo() {}
void bar (const String& text)
{
// do something
}
};
becomes:
// header
class Foo : public Component
{
public:
Foo();
void bar (const String& text);
};
// implementation (cpp file)
#include "foo.h"
Foo::Foo()
{
}
void Foo::bar (const String& text)
{
// do something
}
As a quick example, but looking at some C++ first steps would be a good idea
it is legit to implement in a header.
It has technical implications when included from different cpp files though, especially dangerous when mixed with #ifdef blocks
it is possible to declare classes in a cpp file. That is specifically useful if you want to be sure the code is only available in that one translation unit, e.g. in connection with the PIMPL paradigm.
you can mix, implement some functions in the declaration and some others in the cpp.
But it is usually easier to maintain, if you stick to one or the other, otherwise you will search in the wrong file every time
Sometimes there is a technical reason to do so though, e.g. small inline functions…
header files are copied whenever #include is called
Thanks for all the help. I was missing a deconstructor definition in my .cpp file … who knows how that got deleted haha … It was probably me while trying to solve redefinition errors. So know I know all about deconstructors
So now it compiles but does not pass Logic validation … I will spend a few hours digging around and perhaps remove all the lines of code that I had added and then add back in one at a time.
Quite humbling to move to a new language and be a n00b again