reVeno/Source/Veno/Core/Config.cpp

146 lines
2.7 KiB
C++
Raw Normal View History

2020-04-03 13:23:19 +02:00
//
// Created by versustune on 01.03.20.
//
#include "Config.h"
#include "../Fonts/Fonts.h"
2020-06-14 21:14:28 +02:00
#include "../GUI/GUIParts/Sidebar/VenoLogo.h"
#include "../Utils.h"
2020-04-03 13:23:19 +02:00
std::shared_ptr<Config> Config::m_instance = nullptr;
2020-04-03 13:23:19 +02:00
Config::Config ()
{
// i want to load the m_config file here...
2020-06-14 21:14:28 +02:00
initConfig();
m_theme = std::make_shared<Theme>(m_config);
m_theme->init();
m_fps = m_config->getIntValue("waveform_fps", 60);
startTimer(5000);
2020-04-03 13:23:19 +02:00
}
void Config::saveAll ()
{
if (m_config != nullptr)
{
2020-06-14 21:14:28 +02:00
m_config->saveIfNeeded();
2020-04-03 13:23:19 +02:00
}
}
int Config::getCurrentLook ()
{
if (m_currentLook > 1)
{
m_currentLook = 0;
2020-04-03 13:23:19 +02:00
}
return m_currentLook;
2020-04-03 13:23:19 +02:00
}
void Config::initConfig ()
{
2020-04-03 13:23:19 +02:00
PropertiesFile::Options options;
2020-06-13 10:56:20 +02:00
options.applicationName = "config";
2020-04-03 13:23:19 +02:00
options.folderName = "veno";
options.filenameSuffix = "xml";
2020-06-14 21:14:28 +02:00
m_config = std::make_unique<PropertiesFile>(options);
m_scale = (float) m_config->getDoubleValue("scale", 1.0);
2020-04-03 13:23:19 +02:00
}
std::shared_ptr<Theme> Config::getCurrentTheme ()
{
return m_theme;
2020-04-03 13:23:19 +02:00
}
2020-06-14 21:14:28 +02:00
double Config::getScale () const
{
2020-06-14 21:14:28 +02:00
return m_scale;
2020-04-03 13:23:19 +02:00
}
void Config::setColourForIndex (Colour* colour, ThemeColour index)
{
if (m_theme)
{
2020-06-14 21:14:28 +02:00
m_theme->setColour(index, colour);
2020-04-03 13:23:19 +02:00
}
}
Config::~Config ()
{
2020-06-14 21:14:28 +02:00
m_config->save();
m_config->setNeedsToBeSaved(false);
m_theme.reset();
m_config.reset();
m_lookHandler.reset();
stopTimer();
VenoFonts::destroyAll();
VenoLogo::deleteInstance();
2020-04-03 13:23:19 +02:00
}
//LEAK DETECTOR FIX!
void Config::registerEditor (AudioProcessorEditor* editor, const std::string& name)
{
m_editors[name] = editor;
2020-04-03 13:23:19 +02:00
}
void Config::removeEditor (const std::string& name)
{
2020-06-14 21:14:28 +02:00
m_editors.erase(name);
if (m_editors.empty())
{
m_instance = nullptr;
2020-04-03 13:23:19 +02:00
}
}
//for LCD :P let's be a bit funny xD
int Config::getEditorCount ()
{
2020-06-14 21:14:28 +02:00
return m_editors.size();
}
std::shared_ptr<Config> Config::getInstance ()
{
2020-06-13 10:56:20 +02:00
if (m_instance == nullptr)
2020-06-14 21:14:28 +02:00
m_instance = std::make_shared<Config>();
return m_instance;
2020-04-03 13:23:19 +02:00
}
2020-06-13 10:56:20 +02:00
int Config::getFps () const
{
2020-06-13 10:56:20 +02:00
return m_fps;
}
2020-06-14 21:14:28 +02:00
void Config::setScale (float value)
{
value = VeNo::Utils::clamp(value, 0.5f, 2.5f);
m_scale = value;
m_config->setValue("scale", m_scale);
m_config->setNeedsToBeSaved(true);
for (auto& editor : m_editors)
{
editor.second->setSize(1200 * m_scale, 700 * m_scale);
}
}
void Config::timerCallback ()
{
m_config->saveIfNeeded();
}
void Config::repaintAll ()
{
for (auto& editor : m_editors)
{
if (editor.second->isShowing())
{
editor.second->repaint();
}
}
}
void Config::setFps (float value)
{
m_fps = VeNo::Utils::clamp(value, 15, 90);
m_config->setValue("waveform_fps", m_fps);
m_config->setNeedsToBeSaved(true);
}