- cleanup vars

- added LICENSE.txt
- added LabelComponent.cpp
- renamed some variables
- moved instance id to processor
This commit is contained in:
Maurice Grönwoldt 2020-06-08 21:27:17 +02:00
commit d735c1d076
19 changed files with 948 additions and 180 deletions

View file

@ -2,26 +2,24 @@
#include "PluginEditor.h"
#include "Veno/Core/Config.h"
//==============================================================================
VenoAudioProcessorEditor::VenoAudioProcessorEditor(VenoAudioProcessor &p)
: AudioProcessorEditor(&p), processor(p) {
Config::getInstance()->registerEditor(this, id);
LookAndFeel::setDefaultLookAndFeel(look);
m_id = p.m_id;
Config::getInstance()->registerEditor(this, m_id);
LookAndFeel::setDefaultLookAndFeel(m_look);
setSize(400, 300);
}
VenoAudioProcessorEditor::~VenoAudioProcessorEditor() {
LookAndFeel::setDefaultLookAndFeel(nullptr);
Config::getInstance()->removeEditor(id);
delete look;
Config::getInstance()->removeEditor(m_id);
delete m_look;
}
//==============================================================================
void VenoAudioProcessorEditor::paint(Graphics &g) {
g.fillAll(getLookAndFeel().findColour(ResizableWindow::backgroundColourId));
g.setColour(Colours::white);
g.setFont(15.0f);
g.drawFittedText("Hello World!", getLocalBounds(), Justification::centred, 1);
}
void VenoAudioProcessorEditor::resized() {

View file

@ -14,8 +14,8 @@ public:
private:
VenoAudioProcessor& processor;
std::string id = Uuid().toString().toStdString();
LookAndFeel_V4 *look = new LookHandler();
std::string m_id = "";
LookAndFeel_V4 *m_look = new LookHandler();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessorEditor)
};

View file

@ -1,17 +1,5 @@
/*
==============================================================================
This file was auto-generated!
It contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
//==============================================================================
VenoAudioProcessor::VenoAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties()
@ -30,7 +18,6 @@ VenoAudioProcessor::~VenoAudioProcessor()
{
}
//==============================================================================
const String VenoAudioProcessor::getName() const
{
return JucePlugin_Name;
@ -70,8 +57,7 @@ double VenoAudioProcessor::getTailLengthSeconds() const
int VenoAudioProcessor::getNumPrograms()
{
return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
// so this should be at least 1, even if you're not really implementing programs.
return 1;
}
int VenoAudioProcessor::getCurrentProgram()
@ -95,14 +81,10 @@ void VenoAudioProcessor::changeProgramName (int index, const String& newName)
//==============================================================================
void VenoAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
// Use this method as the place to do any pre-playback
// initialisation that you need..
}
void VenoAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
#ifndef JucePlugin_PreferredChannelConfigurations
@ -112,13 +94,10 @@ bool VenoAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) con
ignoreUnused (layouts);
return true;
#else
// This is the place where you check if the layout is supported.
// In this template code we only support mono or stereo.
if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
&& layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
return false;
// This checks if the input layout matches the output layout
#if ! JucePlugin_IsSynth
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
return false;
@ -134,34 +113,18 @@ void VenoAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& m
ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
// In case we have more outputs than inputs, this code clears any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
// This is here to avoid people getting screaming feedback
// when they first compile a plugin, but obviously you don't need to keep
// this code if your algorithm always overwrites all the output channels.
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
// This is the place where you'd normally do the guts of your plugin's
// audio processing...
// Make sure to reset the state if your inner loop is processing
// the samples and the outer loop is handling the channels.
// Alternatively, you can process the samples with the channels
// interleaved by keeping the same state.
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
auto* channelData = buffer.getWritePointer (channel);
// ..do something to the data...
}
}
//==============================================================================
bool VenoAudioProcessor::hasEditor() const
{
return true; // (change this to false if you choose to not supply an editor)
return true;
}
AudioProcessorEditor* VenoAudioProcessor::createEditor()
@ -172,19 +135,12 @@ AudioProcessorEditor* VenoAudioProcessor::createEditor()
//==============================================================================
void VenoAudioProcessor::getStateInformation (MemoryBlock& destData)
{
// You should use this method to store your parameters in the memory block.
// You could do that either as raw data, or use the XML or ValueTree classes
// as intermediaries to make it easy to save and load complex data.
}
void VenoAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.
}
//==============================================================================
// This creates new instances of the plugin..
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new VenoAudioProcessor();

View file

@ -1,61 +1,56 @@
/*
==============================================================================
This file was auto-generated!
It contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#pragma once
#include <JuceHeader.h>
//==============================================================================
/**
*/
class VenoAudioProcessor : public AudioProcessor
{
class VenoAudioProcessor : public AudioProcessor {
public:
//==============================================================================
VenoAudioProcessor();
~VenoAudioProcessor();
//==============================================================================
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
void prepareToPlay(double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
#ifndef JucePlugin_PreferredChannelConfigurations
bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
#endif
#ifndef JucePlugin_PreferredChannelConfigurations
void processBlock (AudioBuffer<float>&, MidiBuffer&) override;
bool isBusesLayoutSupported(const BusesLayout &layouts) const override;
#endif
void processBlock(AudioBuffer<float> &, MidiBuffer &) override;
AudioProcessorEditor *createEditor() override;
//==============================================================================
AudioProcessorEditor* createEditor() override;
bool hasEditor() const override;
//==============================================================================
const String getName() const override;
bool acceptsMidi() const override;
bool producesMidi() const override;
bool isMidiEffect() const override;
double getTailLengthSeconds() const override;
//==============================================================================
int getNumPrograms() override;
int getCurrentProgram() override;
void setCurrentProgram (int index) override;
const String getProgramName (int index) override;
void changeProgramName (int index, const String& newName) override;
//==============================================================================
void getStateInformation (MemoryBlock& destData) override;
void setStateInformation (const void* data, int sizeInBytes) override;
void setCurrentProgram(int index) override;
const String getProgramName(int index) override;
void changeProgramName(int index, const String &newName) override;
void getStateInformation(MemoryBlock &destData) override;
void setStateInformation(const void *data, int sizeInBytes) override;
// Variable to communicate with the GUI and the Processor
std::string m_id = Uuid().toString().toStdString();
private:
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessor)
};

View file

@ -0,0 +1,37 @@
//
// Created by versustune on 22.03.20.
//
#include "AudioConfig.h"
float AudioConfig::getSampleRate() {
return m_sampleRate;
}
void AudioConfig::setSampleRate(float _sampleRate) {
if (m_sampleRate != _sampleRate) {
m_sampleRate = _sampleRate;
m_needToReInit = true;
}
}
float AudioConfig::getBufferSize() {
return m_bufferSize;
}
void AudioConfig::setBufferSize(float _bufferSize) {
m_bufferSize = _bufferSize;
}
bool AudioConfig::isNeedToReInit() {
return m_needToReInit;
}
void AudioConfig::setNeedToReInit(bool _needToReInit) {
m_needToReInit = _needToReInit;
}
std::shared_ptr<AudioConfig> AudioConfig::getInstance() {
if (!m_instance)
m_instance = std::make_shared<AudioConfig>();
return m_instance;
}

View file

@ -12,43 +12,24 @@
*/
class AudioConfig {
private:
static std::shared_ptr<AudioConfig> instance;
float sampleRate = 44100;
float bufferSize = 512; //maybe we need that... but this will update always!
bool needToReInit = false; //this is to reInit the Oscillators, ADSR and other stuff
static std::shared_ptr<AudioConfig> m_instance;
float m_sampleRate = 44100;
float m_bufferSize = 512; //maybe we need that... but this will update always!
bool m_needToReInit = false; //this is to reInit the Oscillators, ADSR and other stuff
public:
static std::shared_ptr<AudioConfig> getInstance() {
if (!instance)
instance = std::make_shared<AudioConfig>();
return instance;
}
static std::shared_ptr<AudioConfig> getInstance();
float getSampleRate() const {
return sampleRate;
}
float getSampleRate();
void setSampleRate(float _sampleRate) {
if (sampleRate != _sampleRate) {
sampleRate = _sampleRate;
needToReInit = true;
}
}
void setSampleRate(float _sampleRate);
float getBufferSize() const {
return bufferSize;
}
float getBufferSize();
void setBufferSize(float _bufferSize) {
AudioConfig::bufferSize = _bufferSize;
}
void setBufferSize(float _bufferSize);
bool isNeedToReInit() const {
return needToReInit;
}
bool isNeedToReInit();
void setNeedToReInit(bool _needToReInit) {
AudioConfig::needToReInit = _needToReInit;
}
void setNeedToReInit(bool _needToReInit);
protected:
};

View file

@ -4,39 +4,39 @@
#include "Config.h"
std::shared_ptr<Config> Config::instance = nullptr;
std::shared_ptr<Config> Config::m_instance = nullptr;
Config::Config() {
// i want to load the config file here...
// i want to load the m_config file here...
initConfig();
theme = std::make_shared<Theme>(config);
theme->init();
m_theme = std::make_shared<Theme>(m_config);
m_theme->init();
}
void Config::saveAll() {
if (config != nullptr) {
config->saveIfNeeded();
if (m_config != nullptr) {
m_config->saveIfNeeded();
}
}
int Config::getCurrentLook() {
if (currentLook > 1) {
currentLook = 0;
if (m_currentLook > 1) {
m_currentLook = 0;
}
return currentLook;
return m_currentLook;
}
void Config::initConfig() {
PropertiesFile::Options options;
options.applicationName = "config";
options.applicationName = "m_config";
options.folderName = "veno";
options.filenameSuffix = "xml";
config = std::make_unique<PropertiesFile>(options);
m_config = std::make_unique<PropertiesFile>(options);
}
std::shared_ptr<Theme> Config::getCurrentTheme() {
return theme;
return m_theme;
}
double Config::getScale() {
@ -44,30 +44,36 @@ double Config::getScale() {
}
void Config::setColourForIndex(Colour *colour, ThemeColour index) {
if (theme) {
theme->setColour(index, colour);
if (m_theme) {
m_theme->setColour(index, colour);
}
}
Config::~Config() {
config->save();
theme.reset();
config.reset();
m_config->save();
m_theme.reset();
m_config.reset();
}
//LEAK DETECTOR FIX!
void Config::registerEditor(AudioProcessorEditor *editor, const std::string &name) {
editors[name] = editor;
m_editors[name] = editor;
}
void Config::removeEditor(const std::string &name) {
editors.erase(name);
if (editors.empty()) {
instance = nullptr;
m_editors.erase(name);
if (m_editors.empty()) {
m_instance = nullptr;
}
}
//for LCD :P let's be a bit funny xD
int Config::getEditorCount() {
editors.size();
return m_editors.size();
}
std::shared_ptr<Config> Config::getInstance() {
if (!m_instance)
m_instance = std::make_shared<Config>();
return m_instance;
}

View file

@ -12,17 +12,13 @@
class Config {
private:
std::shared_ptr<PropertiesFile> config = nullptr;
std::shared_ptr<Theme> theme = nullptr;
static std::shared_ptr<Config> instance;
int currentLook = 0; //nah move the bitch logic from current to next
std::unordered_map<std::string, AudioProcessorEditor *> editors;
std::shared_ptr<PropertiesFile> m_config = nullptr;
std::shared_ptr<Theme> m_theme = nullptr;
static std::shared_ptr<Config> m_instance;
int m_currentLook = 0; //nah move the bitch logic from current to next
std::unordered_map<std::string, AudioProcessorEditor *> m_editors;
public:
static std::shared_ptr<Config> getInstance() {
if (!instance)
instance = std::make_shared<Config>();
return instance;
}
static std::shared_ptr<Config> getInstance();
void saveAll();

View file

@ -3,3 +3,42 @@
//
#include "BaseComponent.h"
#include <utility>
BaseComponent::~BaseComponent() {
m_label.reset();
setLookAndFeel(nullptr);
m_lookHandler.reset();
}
void BaseComponent::addLabel(const std::string &label_text, LabelPosition labelPosition) {
m_enableLabel = true;
m_label = std::make_shared<LabelComponent>(this, label_text);
m_label->setPosition(labelPosition);
}
void BaseComponent::resized() {
if (m_enableLabel && m_label != nullptr) {
LabelPosition position = m_label->getLabelPosition();
if (position == LabelPosition::TOP) {
m_label->setBounds(0, 0, getWidth(), 15);
} else if (position == LabelPosition::BOTTOM) {
m_label->setBounds(0, getHeight() - 20, getWidth(), 15);
}
}
}
void BaseComponent::paint(Graphics &g) {
}
BaseComponent::BaseComponent() {
m_lookHandler = std::make_shared<LookHandler>();
setLookAndFeel(m_lookHandler->getLook());
}
void BaseComponent::setParameter(std::string name, std::string group) {
m_name = std::move(name);
m_group = std::move(group);
setName(m_name);
}

View file

@ -6,6 +6,8 @@
#define VENO_BASECOMPONENT_H
#include "JuceHeader.h"
#include "LabelComponent.h"
#include "../LookAndFeel/LookHandler.h"
#include <string>
/**
@ -13,11 +15,18 @@
*/
class BaseComponent : public Component {
private:
std::string prefix;
std::string m_group;
std::string m_name;
bool m_enableLabel = false;
std::shared_ptr<LabelComponent> m_label;
std::shared_ptr<LookHandler> m_lookHandler;
public:
BaseComponent() = default;
~BaseComponent() = default;
BaseComponent();
~BaseComponent() override;
void addLabel(const std::string& label, LabelPosition labelPosition);
void setParameter(std::string name, std::string group);
void resized() override;
void paint(Graphics &g) override;
protected:
};

View file

@ -0,0 +1,32 @@
//
// Created by versustune on 07.06.20.
//
#include "LabelComponent.h"
LabelComponent::LabelComponent(Component *parent, std::string name) {
m_text = name;
m_parent = parent;
m_label = std::make_shared<Label>(m_parent->getName(), name);
}
LabelComponent::~LabelComponent() {
m_label.reset();
}
void LabelComponent::resized() {
if (m_label != nullptr) {
m_label->setBounds(0, 0, getWidth(), getHeight());
}
}
void LabelComponent::paint(Graphics &g) {
}
void LabelComponent::setPosition(LabelPosition position) {
m_position = position;
}
LabelPosition LabelComponent::getLabelPosition() {
return m_position;
}

View file

@ -0,0 +1,34 @@
//
// Created by versustune on 07.06.20.
//
#ifndef VENO_LABELCOMPONENT_H
#define VENO_LABELCOMPONENT_H
#include "JuceHeader.h"
enum LabelPosition {
NO_LABEL,
TOP,
BOTTOM
};
class LabelComponent : public Component {
public:
LabelComponent(Component *parent, std::string name);
~LabelComponent() override;
void resized() override;
void paint(Graphics &g) override;
void setPosition(LabelPosition position);
LabelPosition getLabelPosition();
protected:
private:
std::string m_text;
Component *m_parent;
LabelPosition m_position = LabelPosition::NO_LABEL;
std::shared_ptr<Label> m_label;
};
#endif //VENO_LABELCOMPONENT_H

View file

@ -11,10 +11,14 @@ LookHandler::LookHandler() {
LookHandler::~LookHandler() {
//delete this shit!
delete feels[0];
delete feels[1];
delete m_feels[0];
delete m_feels[1];
}
void LookHandler::selectLook(int index) {
currentLook = index;
m_currentLook = index;
}
LookAndFeel_V4* LookHandler::getLook() {
return m_feels[m_currentLook];
}

View file

@ -11,19 +11,20 @@
#include <memory>
/**
* overwrite the basic look and feel based on the selected Look and Feel :)
* overwrite the basic m_look and feel based on the selected Look and Feel :)
*/
class LookHandler : public LookAndFeel_V4 {
private:
std::shared_ptr<LookAndFeel_V4> look;
int currentLook = 0;
std::shared_ptr<LookAndFeel_V4> m_look;
int m_currentLook = 0;
public:
LookHandler();
~LookHandler();
~LookHandler() override;
void selectLook(int index);
LookAndFeel_V4* getLook();
protected:
//currently both available themes are CrazyLook <-- (this is a fun one xD) and FlatLook
LookAndFeel_V4 *feels[2] = {new FlatLook(), new CrazyLook()};
LookAndFeel_V4 *m_feels[2] = {new FlatLook(), new CrazyLook()};
};

View file

@ -6,25 +6,25 @@
#include "ThemePresets.cpp"
Theme::Theme(std::shared_ptr<PropertiesFile> file) {
configFile = file;
m_configFile = file;
}
Theme::~Theme() {
colours.clear();
configFile.reset();
m_colours.clear();
m_configFile.reset();
}
void Theme::setColour(ThemeColour index, Colour *colour) {
auto c = colours[index];
auto c = m_colours[index];
if (c) {
delete c;
colours[index] = colour;
m_colours[index] = colour;
} else {
colours[index] = colour;
m_colours[index] = colour;
}
configFile->setValue(ThemeColourToString(index), colour->toString());
configFile->save();
m_configFile->setValue(ThemeColourToString(index), colour->toString());
m_configFile->save();
}
@ -42,8 +42,8 @@ void Theme::init() {
void Theme::getColourFromConfig(ThemeColour index) {
std::string key = ThemeColourToString(index);
if (configFile->containsKey(key)) {
auto baseColour = Colour::fromString(configFile->getValue(key));
if (m_configFile->containsKey(key)) {
auto baseColour = Colour::fromString(m_configFile->getValue(key));
auto *colour = new Colour(baseColour.getRed(), baseColour.getGreen(), baseColour.getBlue());
setColour(index, colour);
}

View file

@ -22,8 +22,8 @@ public:
void init();
void getColourFromConfig(ThemeColour index);
protected:
std::map<ThemeColour, Colour*> colours;
std::shared_ptr<PropertiesFile> configFile;
std::map<ThemeColour, Colour*> m_colours;
std::shared_ptr<PropertiesFile> m_configFile;
};

View file

@ -4,9 +4,9 @@
* this file holds function that read some presets
* in the current Theme class
* so we doesn't have lot's of classes that only save some hex codes... and make the coding harder
* also good on this is that the user can slightly change the preset theme and doesn't have to make all of them himself
* also good on this is that the user can slightly change the preset m_theme and doesn't have to make all of them himself
*
* maybe i want a double look and feel... that's make it easier to implement different knob styles, slider styles and co
* maybe i want a double m_look and feel... that's make it easier to implement different knob styles, slider styles and co
*/
void setLEDTheme(Theme *theme) {