This commit is contained in:
Maurice Grönwoldt 2020-06-13 10:56:20 +02:00
commit 26a2935e1c
52 changed files with 1513 additions and 107 deletions

View file

@ -3,13 +3,16 @@
//
#include "BaseComponent.h"
#include "../../Fonts/Fonts.h"
#include <utility>
BaseComponent::BaseComponent(const std::string& processId) {
m_processId = processId;
}
BaseComponent::~BaseComponent() {
m_label.reset();
setLookAndFeel(nullptr);
m_lookHandler.reset();
}
void BaseComponent::addLabel(const std::string &label_text, LabelPosition labelPosition) {
@ -30,11 +33,7 @@ void BaseComponent::resized() {
}
void BaseComponent::paint(Graphics &g) {
}
BaseComponent::BaseComponent() {
m_lookHandler = std::make_shared<LookHandler>();
setLookAndFeel(m_lookHandler->getLook());
g.setFont(VenoFonts::getNormal());
}
void BaseComponent::setParameter(std::string name, std::string group) {

View file

@ -19,15 +19,15 @@ private:
std::string m_name;
bool m_enableLabel = false;
std::shared_ptr<LabelComponent> m_label;
std::shared_ptr<LookHandler> m_lookHandler;
public:
BaseComponent();
explicit BaseComponent(const std::string& processId);
~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:
std::string m_processId;
};

View file

@ -0,0 +1,55 @@
//
// Created by versustune on 11.06.20.
//
#include "SidebarLCD.h"
#include "../../../Utils.h"
#include "../../../Core/Config.h"
#include "../../../Fonts/Fonts.h"
SidebarLCD::SidebarLCD(const std::string &process_id) : BaseComponent(process_id) {
waveform = std::make_unique<Waveforms>(process_id);
addAndMakeVisible(*waveform);
}
SidebarLCD::~SidebarLCD() {
waveform.reset(nullptr);
}
void SidebarLCD::drawHeadline(Graphics &g) {
float fontSize = VeNo::Utils::setFontSize(12.0f, g) + 2;
int line = m_innerY + fontSize + 2;
g.drawText(">>> VeNo <<<", 0, m_innerY, getWidth() - m_width, fontSize,
Justification::centred,
true);
g.drawLine(0, line, getWidth(), line);
}
void SidebarLCD::drawFooter(Graphics &g) {
float fontSize = VeNo::Utils::setFontSize(8.0f, g) + 4;
int space = m_innerY + fontSize;
int line = getHeight() - space;
g.drawText("by VersusTuneZ", 0, line, getWidth() - m_width, fontSize,
Justification::horizontallyCentred,
true);
g.drawLine(0, line - 4, getWidth(), line - 4);
}
void SidebarLCD::resized() {
float topSpace = (12 * Config::getInstance()->getScale()) + 4 + m_innerY;
if (waveform != nullptr) {
waveform->setBounds(0, topSpace*2, getWidth(), getHeight() - (topSpace*4));
}
}
void SidebarLCD::paint(Graphics &g) {
std::shared_ptr<Theme> theme = Config::getInstance()->getCurrentTheme();
auto colour = theme->getColour(ThemeColour::lcd_bg);
g.fillAll(colour);
// background
auto accent = theme->getColour(ThemeColour::lcd);
g.setColour(accent);
g.setFont(VenoFonts::getLCD());
drawHeadline(g);
drawFooter(g);
}

View file

@ -0,0 +1,32 @@
//
// Created by versustune on 11.06.20.
//
#ifndef VENO_SIDEBARLCD_H
#define VENO_SIDEBARLCD_H
#include "JuceHeader.h"
#include "../BaseComponent.h"
#include "Waveforms.h"
class SidebarLCD : public BaseComponent {
private:
int m_innerX = 5;
int m_innerY = 5;
int m_width = m_innerX * 2;
public:
explicit SidebarLCD(const std::string &process_id);
~SidebarLCD();
void resized() override;
void paint(Graphics &g) override;
protected:
void drawHeadline(Graphics &g);
void drawFooter(Graphics &g);
std::unique_ptr<Waveforms> waveform;
};
#endif //VENO_SIDEBARLCD_H

View file

@ -0,0 +1,235 @@
//
// Created by versustune on 11.06.20.
//
#include "Waveforms.h"
#include <utility>
#include "../../../Core/Config.h"
#include "../../../Utils.h"
#include "../../../VenoInstance.h"
#include "../../../Fonts/Fonts.h"
Waveforms::Waveforms(const std::string &processId) : BaseComponent(processId) {
m_context.setOpenGLVersionRequired(OpenGLContext::OpenGLVersion::openGL3_2);
m_context.setRenderer(this);
m_context.setContinuousRepainting(false);
m_context.setComponentPaintingEnabled(true);
m_context.attachTo(*this);
auto fps = Config::getInstance()->getFps();
startTimerHz(Config::getInstance()->getFps());
std::srand(unsigned(time(nullptr)));
pickRandomText = (std::rand() % RANDOM_TEXT_COUNT);
m_ticks = 0;
// is something that
m_time_needed = roundToInt(4000 / (1000 / fps));
m_time_needed_startup = roundToInt(1000 / (1000 / fps));
}
Waveforms::~Waveforms() {
stopTimer();
shaderProgram.reset();
m_context.detach();
}
void Waveforms::newOpenGLContextCreated() {
compileOpenGLShaderProgram();
}
void Waveforms::openGLContextClosing() {
}
void Waveforms::renderOpenGL() {
if (!isShowing() || shaderProgram == nullptr || !shaderProgram->getLastError().isEmpty()) {
return;
}
auto theme = Config::getInstance()->getCurrentTheme();
if (theme == nullptr) {
return;
}
glViewport(0, 0, getWidth(), getHeight());
OpenGLHelpers::clear(theme->getColour(ThemeColour::lcd_bg));
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
shaderProgram->use();
auto color = theme->getColour(ThemeColour::lcd);
shaderProgram->setUniform("color", color.getFloatRed(), color.getFloatGreen(), color.getFloatBlue(),
color.getFloatAlpha());
if (m_isWelcome || m_isStarting || m_isChangingData) {
return;
}
switch (m_mode) {
case 1:
drawAudioOutput();
break;
case 2:
drawWaveTable();
break;
case 3:
drawSpectrum();
break;
default:
drawPeakMeter();
}
}
void Waveforms::handleAsyncUpdate() {
}
void Waveforms::compileOpenGLShaderProgram() {
std::unique_ptr<OpenGLShaderProgram> shaderProgramAttempt
= std::make_unique<OpenGLShaderProgram>(m_context);
if (shaderProgramAttempt->addVertexShader({BinaryData::WaveForm_vertex_glsl})
&& shaderProgramAttempt->addFragmentShader({BinaryData::WaveForm_fragment_glsl})
&& shaderProgramAttempt->link()) {
shaderProgram = std::move(shaderProgramAttempt);
}
}
void Waveforms::mouseDown(const MouseEvent &e) {
if (!m_enableModeToggle) {
return;
}
m_mode++;
if (m_mode > 3) {
m_mode = 0;
}
}
void Waveforms::mouseDrag(const MouseEvent &e) {
//do nothing... you faggot
}
void Waveforms::timerCallback() {
if (m_isWelcome || m_isStarting || m_isChangingData || needToClear) {
repaint();
} else {
if (m_context.isAttached()) {
m_context.triggerRepaint();
}
}
}
void Waveforms::drawWaveTable() {
// this will draw the current selected oscillator :D
}
void Waveforms::drawAudioOutput() {
// draw audio from the oscillators
auto instance = VenoInstance::getInstance(BaseComponent::m_processId);
auto buffer = instance->audioBuffer->getBuffer();
glBegin(GL_LINE_STRIP);
float posX = -1;
float inc = 2.0f / buffer.size();
for (float i : buffer) {
glVertex2f(posX, i);
posX += inc;
}
glEnd();
}
void Waveforms::drawPeakMeter() {
auto theme = Config::getInstance()->getCurrentTheme();
if (theme == nullptr) {
return;
}
auto instance = VenoInstance::getInstance(BaseComponent::m_processId);
instance->audioBuffer->calcPeak();
// draw peak signal
auto leftChannel = jmap(Decibels::gainToDecibels(instance->audioBuffer->leftPeak, -80.0f), -80.0f, 6.0f, -1.0f,
1.0f);
selectColourByPeak(leftChannel);
glBegin(GL_TRIANGLES);
glVertex2f(-0.9f, leftChannel);
glVertex2f(-0.9f, -1.0f);
glVertex2f(-0.01f, -1.0f);
glVertex2f(-0.9f, leftChannel);
glVertex2f(-0.01f, leftChannel);
glVertex2f(-0.01f, -1.0f);
glEnd();
auto rightChannel = jmap(Decibels::gainToDecibels(instance->audioBuffer->rightPeak, -80.0f), -80.0f, 6.0f, -1.0f,
1.0f);
selectColourByPeak(rightChannel);
glBegin(GL_TRIANGLES);
glVertex2f(0.9f, rightChannel);
glVertex2f(0.9f, -1.0f);
glVertex2f(0.01f, -1.0f);
glVertex2f(0.9f, rightChannel);
glVertex2f(0.01f, rightChannel);
glVertex2f(0.01f, -1.0f);
glEnd();
}
void Waveforms::paint(Graphics &g) {
std::shared_ptr<Theme> theme = Config::getInstance()->getCurrentTheme();
auto accent = theme->getColour(ThemeColour::lcd);
g.setColour(accent);
g.setFont(VenoFonts::getLCD());
VeNo::Utils::setFontSize(16.0f, g);
if (m_isWelcome) {
drawWelcome(g, getWidth(), getHeight(), 0, 0);
m_ticks++;
if (m_ticks > m_time_needed_startup) {
m_isWelcome = false;
m_ticks = 0;
needToClear = true;
}
} else if (m_isStarting) {
g.drawText(m_warmUpText[pickRandomText], 0, 0, getWidth(), getHeight(),
Justification::centred, true);
m_ticks++;
if (m_ticks > m_time_needed_startup) {
m_isStarting = false;
m_ticks = 0;
needToClear = true;
}
} else if (m_isChangingData) {
drawChangedParameter(g, getWidth(), getHeight(), 0, 0);
m_ticks++;
if (m_ticks > m_time_needed) {
m_isChangingData = false;
m_ticks = 0;
needToClear = true;
}
} else {
g.resetToDefaultState();
needToClear = false;
}
}
void Waveforms::drawChangedParameter(Graphics &g, int w, int h, int x, int y) const {
int halfHeight = h / 2;
float font = VeNo::Utils::setFontSize(12, g);
g.drawText(changingParameter, x, y + halfHeight - font, w, font, Justification::centred, true);
g.drawText(std::to_string(changedValue), x, y + halfHeight + 4, w, font, Justification::centred,
true);
}
void Waveforms::drawWelcome(Graphics &g, int w, int h, int x, int y) {
float font = VeNo::Utils::setFontSize(12, g);
int halfHeight = h / 2;
g.drawText(m_readyText, x, y + halfHeight - font, w, font, Justification::centred, true);
g.drawText(SystemStats::getLogonName(), x, y + halfHeight + 4, w, font, Justification::centred,
true);
}
void Waveforms::drawSpectrum() {
}
void Waveforms::selectColourByPeak(float value) {
auto theme = Config::getInstance()->getCurrentTheme();
if (theme == nullptr) {
return;
}
auto color = theme->getColour(ThemeColour::lcd);
if (value > 0.8 && value < 0.9) {
color = theme->getColour(ThemeColour::warning);
}
if (value > 0.9) {
color = theme->getColour(ThemeColour::clip);
}
shaderProgram->setUniform("color", color.getFloatRed(), color.getFloatGreen(), color.getFloatBlue(),
color.getFloatAlpha());
}

View file

@ -0,0 +1,73 @@
//
// Created by versustune on 11.06.20.
//
#ifndef VENO_WAVEFORMS_H
#define VENO_WAVEFORMS_H
#include "JuceHeader.h"
#include "../BaseComponent.h"
#define RANDOM_TEXT_COUNT 5
// opengl context :D
class Waveforms : public BaseComponent,
private OpenGLRenderer,
private AsyncUpdater,
private Timer {
protected:
bool m_enableModeToggle = true;
int m_mode = 0;
std::string m_readyText = "=WELCOME=";
std::string m_warmUpText[RANDOM_TEXT_COUNT] = {"Warmup...", "Mayonnaise", "Dont shake the baby", "Awesome stuff", "drink beer"};
int pickRandomText = 0;
bool m_isWelcome = true;
bool m_isStarting = true;
int m_ticks = 0;
int m_time_needed_startup = 0;
int m_time_needed = 0;
bool needToClear = false;
public:
explicit Waveforms(const std::string &processId);
~Waveforms() override;
void newOpenGLContextCreated() override;
void openGLContextClosing() override;
void renderOpenGL() override;
void handleAsyncUpdate() override;
void mouseDown(const MouseEvent &e) override;
void mouseDrag(const MouseEvent &e) override;
void paint(Graphics &g) override;
bool m_isChangingData = false;
std::string changingParameter = "";
float changedValue = 0;
private:
void timerCallback() override;
void drawWaveTable();
void drawAudioOutput();
void drawSpectrum();
void drawPeakMeter(); //?!
void drawChangedParameter(Graphics &g, int w, int h, int x, int y) const;
void drawWelcome(Graphics &g, int w, int h, int x, int y);
void compileOpenGLShaderProgram();
void selectColourByPeak(float value);
OpenGLContext m_context;
std::unique_ptr<OpenGLShaderProgram> shaderProgram;
};
#endif //VENO_WAVEFORMS_H

View file

@ -29,7 +29,6 @@ void Theme::setColour(ThemeColour index, Colour *colour) {
}
void Theme::init() {
setLEDTheme(this);
getColourFromConfig(ThemeColour::bg);
getColourFromConfig(ThemeColour::bg_two);
getColourFromConfig(ThemeColour::accent);
@ -45,6 +44,35 @@ void Theme::getColourFromConfig(ThemeColour index) {
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);
delete m_colours[index];
m_colours[index] = colour;
} else {
// should only trigger if config is broken or empty :)
setLEDTheme(this);
}
}
Colour Theme::getColour(ThemeColour index) {
if (m_colours[index] != nullptr) {
return *m_colours[index];
}
return Colour(255, 255, 255);
}
void Theme::setColourThemeById(int id) {
switch (id) {
case 1:
setLEDTheme(this);
break;
case 2:
setOrangeDreamTheme(this);
break;
case 3:
setBloodTheme(this);
break;
case 4:
setOceanTheme(this);
default:
break;
}
}

View file

@ -15,12 +15,14 @@ enum class ThemeColour {
class Theme {
private:
public:
Theme(std::shared_ptr<PropertiesFile> file);
explicit Theme(std::shared_ptr<PropertiesFile> file);
~Theme();
void setColour(ThemeColour index, Colour *colour);
void setColourThemeById(int id);
void init();
void getColourFromConfig(ThemeColour index);
Colour getColour(ThemeColour index);
protected:
std::map<ThemeColour, Colour*> m_colours;
std::shared_ptr<PropertiesFile> m_configFile;

View file

@ -20,18 +20,59 @@ void setLEDTheme(Theme *theme) {
theme->setColour(ThemeColour::lcd, new Colour(169, 208, 142));
}
void setBloodTheme(Theme *theme) {
theme->setColour(ThemeColour::bg, new Colour(41, 47, 54));
theme->setColour(ThemeColour::bg_two, new Colour(64, 67, 78));
theme->setColour(ThemeColour::accent, new Colour(180, 38, 50));
theme->setColour(ThemeColour::accent_two, new Colour(115, 47, 64));
theme->setColour(ThemeColour::clip, new Colour(255, 23, 68));
theme->setColour(ThemeColour::warning, new Colour(255, 143, 0));
theme->setColour(ThemeColour::lcd_bg, new Colour(0, 0, 0));
theme->setColour(ThemeColour::lcd, new Colour(180, 38, 78));
}
void setOrangeDreamTheme(Theme *theme) {
theme->setColour(ThemeColour::bg, new Colour(21, 21, 21));
theme->setColour(ThemeColour::bg_two, new Colour(42, 42, 42));
theme->setColour(ThemeColour::accent, new Colour(255, 160, 0));
theme->setColour(ThemeColour::accent_two, new Colour(255, 11, 0));
theme->setColour(ThemeColour::clip, new Colour(255, 23, 68));
theme->setColour(ThemeColour::warning, new Colour(255, 143, 0));
theme->setColour(ThemeColour::lcd_bg, new Colour(33, 33, 33));
theme->setColour(ThemeColour::lcd, new Colour(255, 160, 0));
}
void setOceanTheme(Theme *theme) {
theme->setColour(ThemeColour::bg, new Colour(55, 63, 81));
theme->setColour(ThemeColour::bg_two, new Colour(64, 67, 78));
theme->setColour(ThemeColour::accent, new Colour(0, 141, 213));
theme->setColour(ThemeColour::accent_two, new Colour(0, 129, 194));
theme->setColour(ThemeColour::clip, new Colour(255, 23, 68));
theme->setColour(ThemeColour::warning, new Colour(255, 143, 0));
theme->setColour(ThemeColour::lcd_bg, new Colour(21, 21, 21));
theme->setColour(ThemeColour::lcd, new Colour(0, 129, 194));
}
std::string ThemeColourToString(ThemeColour index) {
switch (index)
{
case ThemeColour::bg: return "colour_bg";
case ThemeColour::bg_two: return "colour_bg_two";
case ThemeColour::accent: return "colour_accent";
case ThemeColour::accent_two: return "colour_accent_two";
case ThemeColour::clip: return "colour_clip";
case ThemeColour::warning: return "colour_warning";
case ThemeColour::lcd_bg: return "colour_lcd_bg";
case ThemeColour::lcd: return "colour_lcd";
default: return "";
switch (index) {
case ThemeColour::bg:
return "colour_bg";
case ThemeColour::bg_two:
return "colour_bg_two";
case ThemeColour::accent:
return "colour_accent";
case ThemeColour::accent_two:
return "colour_accent_two";
case ThemeColour::clip:
return "colour_clip";
case ThemeColour::warning:
return "colour_warning";
case ThemeColour::lcd_bg:
return "colour_lcd_bg";
case ThemeColour::lcd:
return "colour_lcd";
default:
return "";
}
}