Understanding the JUCE Docs

Hi all :wave:

Just started learning JUCE and C++ recently. I’ve prior to this done a lot of coding with Javascript and python in React, React Native and Djang. So I thought getting a hang of the C++ would be rather easy.
In parallell to this I am also taking a course on C++.

I am having some issues with reading and then implementing the library functions from the JUCE docs.

For instance I see a JUCE Graphics function I want to use like this:

I then try and write it like this:

I am assuming the GlowEffect() is available here as I am using the juce::Graphics lib extension in this void function.
But I get this error.

Welcome! I haven’t used that class myself, but maybe I can help steer you in the right direction.

The docs say GlowEffect is a class, so you’ll need to create a GlowEffect somewhere before you can call its function, setGlowProperties. I’m guessing you are supposed to create the GlowEffect as a member of whichever component you want to glow.

If the glow properties don’t need to be refreshed every time you repaint your component, then you can move that outside the paint call as well, maybe into the constructor of your component.

Since GlowEffect::applyEffect takes a reference to a Graphics object as an argument, we can guess that is the function you call in your ‘paint’ function, which is where you have access to the Graphics object.

So, once you have created your GlowEffect object in your class, set up its glow properties, then you can apply the effect every time your component is repainted.

Hope that makes sense…

1 Like

Hey - Although I have never used this GlowEffect I found from the doc’s that GlowEffect is a class itself, so the method you tories to use is not for the Graphics class - but for the GlowEffect class.

Try to look af the GlowEffect class, and it seems that you should attach a GlowEffect, which derives from the ImageEffectFilter - to the Component you want’s to have the effect on. I’m sure that will work.

BR
Bo

1 Like

As @AdamVenn @bissov say it’s a class so you’ll need an instance but to apply it you can simply call setComponentEffect on your component and pass a pointer to the instance of the GlowEffect.

1 Like

Thanks, Great plugins Adam btw will try em out :clap:

So this is my first at making a class in C++.
I am trying to figurie out how the public and private connect, but cant yet see how this works.
So here I dont know how to continue with the private for this class.
This is in the thumbnailComponent.h. The thumbnailComponent.cpp will draw a waveform from a soundfile that the user opens. The GlowEffect is then applied to this waveform sort of like a CSS styling.

Good going. Here’s the lowdown on public/private inheritance:

https://www.learncpp.com/cpp-tutorial/inheritance-and-access-specifiers/

It’s pretty confusing. I think you’ll be fine using public everwhere for quite a while. There’s plenty of more fun stuff to learn.

1 Like

One more tip: you should name your class something other than GlowEffect, because that name is already taken. It will still work most of the time because of the juce:: namespace, but there are some cases where the compiler won’t be able to disambiguate them, and you’ll be left having to make sense of the error messages.

1 Like

Ok so I think I got the new class right:


Its not doing anything yet to the thumbnail when compiling it and loading a new audio file.

Please don’t take this the wrong way, but the code you’re writing doesn’t make any sense. I know you only just got started with C++ but it’s clear you do not understand the basics. This is fine, we’ve all been there.

I’m just writing this to say that you will progress quicker if you took a step back and worked through a beginner’s book on C++ first, rather than just “guessing” what the code should look like.

You “thought getting a hang of the C++ would be rather easy” but that was a wrong assumption. However, you’re also making it harder on yourself than you need to by following your current path. Learn the basics of C++ first and all of this will become a lot easier.

6 Likes

It looks like you’re confused about classes, and you should probably read up about classes and structs on learncpp.com. I won’t explain it here, because there are plenty of resources online. But I’ll try to help you understand why your code doesn’t make sense.

It looks like you are trying to write something like the following:

juce::GlowEffect shine ();  // instantiates a new GlowEffect object called "shine"

void setShine()   // define a function which sets the properties on "shine"
{
   shine.setGlowProperties(0.8f, juce::Colours::red, 0.8f);
}

setShine();  // run that function

Instead what you’ve written is this:

class Shine    // defined a class called Shine
{
  void setGlowProperties()    // define a member function called setGlowProperties()
  {
      0.8f;                // do nothing!
      juce::Colours::red;
      0.8f;
  }
}

Look at where the brackets and curly brackets are to see the difference. It still compiles because it’s syntactically correct, but 0.8f; juce::Colours::red; 0.8f are not arguments to a function, they’re just values which aren’t being assigned to anything.

I personally don’t mind people posting beginner questions and code, so long as they don’t have a bad attitude (which the OP does not have). I vividly remember how difficult it was to learn C++ and wouldn’t want to scare off new learners. That being said, kerfuffle is right that it’s really difficult to approach a library like juce before you know the basics, so you should really invest some time into that first and foremost.

2 Likes

Yeah going to read through the docs more. I usually learn better by a project based approach, having the docs ready at hand when working on an app. But this was like my first encounter with Javascript :laughing:

The structure of the header / source files became more clear this weekend, so I see why it doesnt make any sense.