JUCE


Stuff I learned making VSTs
Some stuff are specific to my use of cmake (I don't use the projucer)

First you got to transform the SVG into a binary file.
For this drop the the file in /assets
Then add a line in the /src makelist (in the juce_add_binary_data() function)

The compiler will now create a binary file on build.
The binary will be named Example_svg for an Example.svg file.

You can then adapt this snippet of code in paint() for example:
const auto svg = Drawable::createFromImageData(BinaryData::NOI_svg, BinaryData::NOI_svgSize);
            
// juce::AffineTransform scale = Set::scale(0.2);
juce::Rectangle position = {140.f, 495.f, 35.f, 35.f};
juce::RectanglePlacement placement = (36);
svg->setTransformToFit(position, placement);
svg->draw(g, 1.0);
  1. Add Listener inheritance to Editor
    public juce::AudioProcessorParameter::Listener
  2. This will allow you to override
    void parameterValueChanged(int parameterIndex, float newvalue) override;
  3. Then add Time inheritance
    public juce::Timer
  4. Which allow us to override
    void timerCallback() override;
  5. Start it in the editor constructor with
    startTimerHz(60)
  6. Add a variable
    juce::atomic<bool> parametersChanged
  7. That you modify in parameterValueChanged() with
    parametersChanged.set(true);
  8. In the timerCallback() function you can add
  9. if (parametersChanged.compareAndSetBool(false, true)) {repaint();}
    Or just repaint if you need a constant refresh
To make a background that is only rendered once :

  1. Make a class that inherit the from juce::component
  2. Add an background_component object to the editor
  3. addAndMakeVisible(background_component) in the editor constructor
    ⚠️ before widget to avoid overlap ⚠️
  4. To only render once, add background_component.setBufferedToImage(true);
  5. Use paintOverChildren() instead of paint() (by default, background_component is a children of the editor and thus painted over)
  6. In resized() add background_component.setBounds(getBounds())
  7. Don't call background_component.paint() in paintOverChildren()
namespace CustomColors {
const juce::Colour brown = juce::Colour::fromString("FF50322a");
const juce::Colour green = juce::Colour::fromString("FF608537");
}

- home -