- 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

@ -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) {