From a27c62f062a9278c469284fd42862b113fd591b6 Mon Sep 17 00:00:00 2001 From: versustunez Date: Sun, 14 Jun 2020 21:14:28 +0200 Subject: [PATCH] - save --- Source/PluginEditor.cpp | 33 +-- Source/PluginEditor.h | 6 +- Source/PluginProcessor.cpp | 42 ++-- Source/PluginProcessor.h | 66 ++---- Source/Veno/Audio/Engine/VenoMatrix.cpp | 20 +- Source/Veno/Audio/Synth/SynthInstance.cpp | 2 +- Source/Veno/Audio/VenoBuffer.cpp | 22 +- Source/Veno/Audio/WaveTable/SawWaves.cpp | 6 +- Source/Veno/Audio/WaveTable/TableHelper.cpp | 20 +- .../Audio/WaveTable/WaveTableGenerator.cpp | 28 +-- Source/Veno/Core/AudioConfig.cpp | 6 +- Source/Veno/Core/Config.cpp | 77 +++++-- Source/Veno/Core/Config.h | 12 +- Source/Veno/Core/VeNoState.cpp | 16 ++ Source/Veno/Core/VeNoState.h | 20 ++ Source/Veno/Fonts/Fonts.cpp | 16 +- Source/Veno/GUI/Components/BaseComponent.cpp | 23 +- Source/Veno/GUI/Components/BaseComponent.h | 2 +- .../Veno/GUI/Components/Config/VeNoColour.cpp | 65 ++++++ .../Veno/GUI/Components/Config/VeNoColour.h | 27 +++ .../Components/Config/VenoConfigButton.cpp | 34 +++ .../GUI/Components/Config/VenoConfigButton.h | 21 ++ .../GUI/Components/Config/VenoPreColours.cpp | 84 +++++++ .../GUI/Components/Config/VenoPreColours.h | 30 +++ Source/Veno/GUI/Components/LCD/SidebarLCD.cpp | 50 ++-- Source/Veno/GUI/Components/LCD/Waveforms.cpp | 214 +++++++++--------- Source/Veno/GUI/Components/LCD/Waveforms.h | 5 +- Source/Veno/GUI/Components/LabelComponent.cpp | 7 +- .../GUIParts/ConfigScreen/ConfigComponent.cpp | 77 +++++++ .../GUIParts/ConfigScreen/ConfigComponent.h | 30 +++ .../ConfigScreen/VenoConfigScreen.cpp | 49 ++++ .../GUIParts/ConfigScreen/VenoConfigScreen.h | 28 +++ Source/Veno/GUI/GUIParts/Sidebar/Sidebar.cpp | 45 ++++ Source/Veno/GUI/GUIParts/Sidebar/Sidebar.h | 12 +- Source/Veno/GUI/GUIParts/Sidebar/VenoLogo.cpp | 36 +++ Source/Veno/GUI/GUIParts/Sidebar/VenoLogo.h | 25 ++ Source/Veno/GUI/LookAndFeel/FlatLook.cpp | 17 ++ Source/Veno/GUI/LookAndFeel/FlatLook.h | 2 + Source/Veno/GUI/LookAndFeel/LookHandler.cpp | 2 +- Source/Veno/GUI/LookAndFeel/LookHandler.h | 2 +- Source/Veno/GUI/Theme/Theme.cpp | 66 ++++-- Source/Veno/GUI/Theme/Theme.h | 1 + Source/Veno/GUI/Theme/ThemePresets.cpp | 70 +++--- Source/Veno/Utils.cpp | 56 ++++- Source/Veno/Utils.h | 10 + Source/Veno/Utils/FFT.cpp | 10 +- Source/Veno/VenoInstance.cpp | 35 +-- Source/Veno/VenoInstance.h | 3 + Veno.jucer | 26 +++ 49 files changed, 1171 insertions(+), 385 deletions(-) create mode 100644 Source/Veno/Core/VeNoState.cpp create mode 100644 Source/Veno/Core/VeNoState.h create mode 100644 Source/Veno/GUI/Components/Config/VeNoColour.cpp create mode 100644 Source/Veno/GUI/Components/Config/VeNoColour.h create mode 100644 Source/Veno/GUI/Components/Config/VenoConfigButton.cpp create mode 100644 Source/Veno/GUI/Components/Config/VenoConfigButton.h create mode 100644 Source/Veno/GUI/Components/Config/VenoPreColours.cpp create mode 100644 Source/Veno/GUI/Components/Config/VenoPreColours.h create mode 100644 Source/Veno/GUI/GUIParts/ConfigScreen/ConfigComponent.cpp create mode 100644 Source/Veno/GUI/GUIParts/ConfigScreen/ConfigComponent.h create mode 100644 Source/Veno/GUI/GUIParts/ConfigScreen/VenoConfigScreen.cpp create mode 100644 Source/Veno/GUI/GUIParts/ConfigScreen/VenoConfigScreen.h create mode 100644 Source/Veno/GUI/GUIParts/Sidebar/VenoLogo.cpp create mode 100644 Source/Veno/GUI/GUIParts/Sidebar/VenoLogo.h diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index ed5a69f..90df73e 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -3,36 +3,43 @@ #include "Veno/Core/Config.h" #include "Veno/Utils/Logger.h" #include "Veno/Fonts/Fonts.h" +#include "Veno/Utils.h" + +#define SIDEBAR_WIDTH 300 VenoAudioProcessorEditor::VenoAudioProcessorEditor (VenoAudioProcessor& p) - : AudioProcessorEditor (&p), processor (p) + : AudioProcessorEditor(&p), processor(p) { m_id = p.m_id; - Config::getInstance ()->registerEditor (this, m_id); - LookAndFeel::setDefaultLookAndFeel (m_look); - waveform = std::make_unique (m_id); - setSize (600, 400); - addAndMakeVisible (*waveform); + Config::getInstance()->registerEditor(this, m_id); + LookAndFeel::setDefaultLookAndFeel(m_look); + m_sidebar = std::make_unique(m_id); + setSize(1200 * Config::getInstance()->getScale(), 700 * Config::getInstance()->getScale()); + addAndMakeVisible(*m_sidebar); } VenoAudioProcessorEditor::~VenoAudioProcessorEditor () { - LookAndFeel::setDefaultLookAndFeel (nullptr); - waveform.reset (nullptr); + LookAndFeel::setDefaultLookAndFeel(nullptr); + m_sidebar.reset(nullptr); delete m_look; - Config::getInstance ()->removeEditor (m_id); + Config::getInstance()->removeEditor(m_id); } void VenoAudioProcessorEditor::paint (Graphics& g) { - g.setFont (*VenoFonts::getNormal ()); - g.fillAll (Colour (0, 0, 0)); + auto theme = Config::getInstance()->getCurrentTheme(); + g.setFont(*VenoFonts::getNormal()); + g.fillAll(theme->getColour(ThemeColour::bg_two)); + g.setColour(theme->getColour(ThemeColour::bg)); + g.fillRect(0, 0, VeNo::Utils::getCalculatedWidth(SIDEBAR_WIDTH), getHeight()); + g.setColour(theme->getColour(ThemeColour::accent)); } void VenoAudioProcessorEditor::resized () { - if (waveform != nullptr) + if (m_sidebar != nullptr) { - waveform->setBounds (0, 0, getWidth (), getHeight ()); + m_sidebar->setBounds(0, 0, VeNo::Utils::getCalculatedWidth(SIDEBAR_WIDTH), getHeight()); } } diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index cbbb03e..e35245a 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -3,7 +3,7 @@ #include #include "PluginProcessor.h" #include "Veno/GUI/LookAndFeel/LookHandler.h" -#include "Veno/GUI/Components/LCD/SidebarLCD.h" +#include "Veno/GUI/GUIParts/Sidebar/Sidebar.h" class VenoAudioProcessorEditor : public AudioProcessorEditor { @@ -15,7 +15,7 @@ public: private: VenoAudioProcessor& processor; std::string m_id = ""; - LookAndFeel_V4* m_look = new LookHandler (); - std::unique_ptr waveform; + LookAndFeel_V4* m_look = new LookHandler(); + std::unique_ptr m_sidebar; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessorEditor) }; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index c0f00b8..6dfee7e 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -13,16 +13,16 @@ VenoAudioProcessor::VenoAudioProcessor () #endif ) #endif*/ - : AudioProcessor (BusesProperties ().withInput ("Input", AudioChannelSet::stereo (), true).withOutput ("Output", - AudioChannelSet::stereo (), - true)) + : AudioProcessor(BusesProperties().withInput("Input", AudioChannelSet::stereo(), true).withOutput("Output", + AudioChannelSet::stereo(), + true)) { - instance = VenoInstance::createInstance (m_id); + instance = VenoInstance::createInstance(m_id); } VenoAudioProcessor::~VenoAudioProcessor () { - VenoInstance::deleteInstance (m_id); + VenoInstance::deleteInstance(m_id); } const String VenoAudioProcessor::getName () const @@ -88,9 +88,9 @@ void VenoAudioProcessor::changeProgramName (int index, const String& newName) //============================================================================== void VenoAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock) { - auto audioConfig = AudioConfig::getInstance (); - audioConfig->setSampleRate (sampleRate); - audioConfig->initWaveTables (); + auto audioConfig = AudioConfig::getInstance(); + audioConfig->setSampleRate(sampleRate); + audioConfig->initWaveTables(); } void VenoAudioProcessor::releaseResources () @@ -105,8 +105,8 @@ bool VenoAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) con ignoreUnused (layouts); return true; #else - if (layouts.getMainOutputChannelSet () != AudioChannelSet::mono () - && layouts.getMainOutputChannelSet () != AudioChannelSet::stereo ()) + if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono() + && layouts.getMainOutputChannelSet() != AudioChannelSet::stereo()) return false; #if !JucePlugin_IsSynth if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet()) @@ -121,23 +121,23 @@ bool VenoAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) con void VenoAudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer& midiMessages) { ScopedNoDenormals noDenormals; - instance->matrix.updateSlots (); - instance->audioBuffer->reset (buffer.getNumSamples ()); - int numChannels = buffer.getNumChannels (); + instance->matrix.updateSlots(); + instance->audioBuffer->reset(buffer.getNumSamples()); + int numChannels = buffer.getNumChannels(); for (int i = 0; i < numChannels; ++i) { - auto c = buffer.getReadPointer (i); - for (int j = 0; j < buffer.getNumSamples (); ++j) + auto c = buffer.getReadPointer(i); + for (int j = 0; j < buffer.getNumSamples(); ++j) { - instance->fft.pushNextSampleIntoFifo (c[j]); - instance->audioBuffer->addMonoSample (c[j], j); + instance->fft.pushNextSampleIntoFifo(c[j]); + instance->audioBuffer->addMonoSample(c[j], j); if (i == 0) { - instance->audioBuffer->addLeftSample (c[j], j); + instance->audioBuffer->addLeftSample(c[j], j); } if (i == 1 || numChannels == 1) { - instance->audioBuffer->addRightSample (c[j], j); + instance->audioBuffer->addRightSample(c[j], j); } } } @@ -151,7 +151,7 @@ bool VenoAudioProcessor::hasEditor () const AudioProcessorEditor* VenoAudioProcessor::createEditor () { - return new VenoAudioProcessorEditor (*this); + return new VenoAudioProcessorEditor(*this); } //============================================================================== @@ -165,5 +165,5 @@ void VenoAudioProcessor::setStateInformation (const void* data, int sizeInBytes) AudioProcessor* JUCE_CALLTYPE createPluginFilter () { - return new VenoAudioProcessor (); + return new VenoAudioProcessor(); } diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index b29225f..cfc1063 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -3,57 +3,35 @@ #include #include "Veno/VenoInstance.h" -class VenoAudioProcessor : public AudioProcessor { +class VenoAudioProcessor : public AudioProcessor +{ public: //============================================================================== - VenoAudioProcessor(); - - ~VenoAudioProcessor(); - - void prepareToPlay(double sampleRate, int samplesPerBlock) override; - - void releaseResources() override; - + VenoAudioProcessor (); + ~VenoAudioProcessor (); + void prepareToPlay (double sampleRate, int samplesPerBlock) override; + void releaseResources () override; #ifndef JucePlugin_PreferredChannelConfigurations - - bool isBusesLayoutSupported(const BusesLayout &layouts) const override; - + bool isBusesLayoutSupported (const BusesLayout& layouts) const override; #endif - - void processBlock(AudioBuffer &, MidiBuffer &) 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 processBlock (AudioBuffer&, MidiBuffer&) 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; // Variable to communicate with the GUI and the Processor std::string m_id = Uuid().toString().toStdString(); std::shared_ptr instance; - private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessor) }; diff --git a/Source/Veno/Audio/Engine/VenoMatrix.cpp b/Source/Veno/Audio/Engine/VenoMatrix.cpp index 84c4697..17fcb51 100644 --- a/Source/Veno/Audio/Engine/VenoMatrix.cpp +++ b/Source/Veno/Audio/Engine/VenoMatrix.cpp @@ -4,11 +4,11 @@ #include "VenoMatrix.h" -VenoMatrix::VenoMatrix (const std::string& processId) : m_processId (processId) +VenoMatrix::VenoMatrix (const std::string& processId) : m_processId(processId) { for (auto& m_slot : m_slots) { - m_slot = new VenoMatrixSlot (); + m_slot = new VenoMatrixSlot(); } } @@ -27,22 +27,22 @@ VenoMatrixSlot* VenoMatrix::getSlotById (int id) void VenoMatrix::removeModulateValue (const std::string& name) { - m_modulationValues.erase (name); + m_modulationValues.erase(name); } void VenoMatrix::removeModulator (const std::string& name) { - m_modulators.erase (name); + m_modulators.erase(name); } void VenoMatrix::addModulateValue (const std::string& name, ModulateValue* modulateValue) { - m_modulationValues.emplace (std::pair (name, modulateValue)); + m_modulationValues.emplace(std::pair(name, modulateValue)); } void VenoMatrix::addModulator (const std::string& name, Modulator* modulator) { - m_modulators.emplace (std::pair (name, modulator)); + m_modulators.emplace(std::pair(name, modulator)); } void VenoMatrix::updateSlots () @@ -53,26 +53,26 @@ void VenoMatrix::updateSlots () { continue; } - if (m_modulators.find (m_slot->sourceName) != m_modulators.end ()) + if (m_modulators.find(m_slot->sourceName) != m_modulators.end()) { auto modulator = m_modulators[m_slot->sourceName]; if (modulator == nullptr) { continue; } - modulator->update (); + modulator->update(); for (auto& value : m_slot->targets) { if (value.name != "none") { - if (m_modulationValues.find (value.name) != m_modulationValues.end ()) + if (m_modulationValues.find(value.name) != m_modulationValues.end()) { auto modValue = m_modulationValues[value.name]; if (modValue == nullptr) { continue; } - modValue->addValue (modulator->getValue () * value.amount); + modValue->addValue(modulator->getValue() * value.amount); } } } diff --git a/Source/Veno/Audio/Synth/SynthInstance.cpp b/Source/Veno/Audio/Synth/SynthInstance.cpp index 3e3a660..73f47b2 100644 --- a/Source/Veno/Audio/Synth/SynthInstance.cpp +++ b/Source/Veno/Audio/Synth/SynthInstance.cpp @@ -6,6 +6,6 @@ #include SynthInstance::SynthInstance (std::string processId) - : m_processId (std::move (processId)) + : m_processId(std::move(processId)) { } diff --git a/Source/Veno/Audio/VenoBuffer.cpp b/Source/Veno/Audio/VenoBuffer.cpp index 874609b..f261d62 100644 --- a/Source/Veno/Audio/VenoBuffer.cpp +++ b/Source/Veno/Audio/VenoBuffer.cpp @@ -12,18 +12,18 @@ VenoBuffer::VenoBuffer () VenoBuffer::~VenoBuffer () { - buffer.clear (); - right.clear (); - left.clear (); + buffer.clear(); + right.clear(); + left.clear(); } void VenoBuffer::reset (int size) { - if (size != buffer.size ()) + if (size != buffer.size()) { - buffer.resize (size); - right.resize (size); - left.resize (size); + buffer.resize(size); + right.resize(size); + left.resize(size); } // reset to 0 dc :D for (int i = 0; i < size; ++i) @@ -54,11 +54,11 @@ void VenoBuffer::addRightSample (float value, int index) void VenoBuffer::calcPeak () { - for (int i = 0; i < buffer.size (); ++i) + for (int i = 0; i < buffer.size(); ++i) { - auto l = std::abs (left[i]); - auto r = std::abs (right[i]); - auto m = std::abs (buffer[i]); + auto l = std::abs(left[i]); + auto r = std::abs(right[i]); + auto m = std::abs(buffer[i]); if (m > monoPeak) { monoPeak = m; diff --git a/Source/Veno/Audio/WaveTable/SawWaves.cpp b/Source/Veno/Audio/WaveTable/SawWaves.cpp index bb6333b..0100efb 100644 --- a/Source/Veno/Audio/WaveTable/SawWaves.cpp +++ b/Source/Veno/Audio/WaveTable/SawWaves.cpp @@ -12,7 +12,7 @@ void generateSaw (WaveTableGroup* group) { return; } - int tableLen = findTableLen (); + int tableLen = findTableLen(); int idx; auto* freqWaveRe = new double[tableLen]; auto* freqWaveIm = new double[tableLen]; @@ -26,6 +26,6 @@ void generateSaw (WaveTableGroup* group) freqWaveRe[idx] = 1.0 / idx; // sawtooth spectrum freqWaveRe[tableLen - idx] = -freqWaveRe[idx]; // mirror } - fillTables (group, freqWaveRe, freqWaveIm, tableLen); - VeNo::Logger::infoDebugMessage ("Generated clean Saw Wave"); + fillTables(group, freqWaveRe, freqWaveIm, tableLen); + VeNo::Logger::infoDebugMessage("Generated clean Saw Wave"); } \ No newline at end of file diff --git a/Source/Veno/Audio/WaveTable/TableHelper.cpp b/Source/Veno/Audio/WaveTable/TableHelper.cpp index 6a8ea41..4a7f5a1 100644 --- a/Source/Veno/Audio/WaveTable/TableHelper.cpp +++ b/Source/Veno/Audio/WaveTable/TableHelper.cpp @@ -51,8 +51,8 @@ void fft (int N, double* ar, double* ai) LE *= 2; // (LE = 2^L) Ur = 1.0; Ui = 0.; - Wr = std::cos (M_PI / (float) LE1); - Wi = -std::sin (M_PI / (float) LE1); // Cooley, Lewis, and Welch have "+" here + Wr = std::cos(M_PI / (float) LE1); + Wi = -std::sin(M_PI / (float) LE1); // Cooley, Lewis, and Welch have "+" here for (j = 1; j <= LE1; j++) { for (i = j; i <= N; i += LE) @@ -74,14 +74,14 @@ void fft (int N, double* ar, double* ai) float makeWaveTable (WaveTableGroup* group, int len, double* ar, double* ai, double scale, double topFreq) { - fft (len, ar, ai); + fft(len, ar, ai); if (scale == 0.0) { // calc normal double max = 0; for (int idx = 0; idx < len; idx++) { - double temp = fabs (ai[idx]); + double temp = fabs(ai[idx]); if (max < temp) max = temp; } @@ -94,7 +94,7 @@ float makeWaveTable (WaveTableGroup* group, int len, double* ar, double* ai, dou wave[idx] = ai[idx] * scale; if (group->m_numWaveTables < WaveTableGroup::numWaveTableSlots) { - auto table = group->m_WaveTables[group->m_numWaveTables] = new WaveTableObject (); + auto table = group->m_WaveTables[group->m_numWaveTables] = new WaveTableObject(); float* waveTable = group->m_WaveTables[group->m_numWaveTables]->m_waveTable = new float[len + 1]; table->m_waveTableLen = len; table->m_topFreq = topFreq; @@ -121,7 +121,7 @@ int fillTables (WaveTableGroup* group, double* freqWaveRe, double* freqWaveIm, i freqWaveRe[numSamples >> 1] = freqWaveIm[numSamples >> 1] = 0.0; int maxHarmonic = numSamples >> 1; const double minVal = 0.000001; // -120 dB - while ((fabs (freqWaveRe[maxHarmonic]) + fabs (freqWaveIm[maxHarmonic]) < minVal) && maxHarmonic) --maxHarmonic; + while ((fabs(freqWaveRe[maxHarmonic]) + fabs(freqWaveIm[maxHarmonic]) < minVal) && maxHarmonic) --maxHarmonic; double topFreq = 2.0 / 3.0 / maxHarmonic; double* ar = new double[numSamples]; double* ai = new double[numSamples]; @@ -141,7 +141,7 @@ int fillTables (WaveTableGroup* group, double* freqWaveRe, double* freqWaveIm, i } // make the wavetable - scale = makeWaveTable (group, numSamples, ar, ai, scale, topFreq); + scale = makeWaveTable(group, numSamples, ar, ai, scale, topFreq); numTables++; // prepare for next table @@ -153,11 +153,11 @@ int fillTables (WaveTableGroup* group, double* freqWaveRe, double* freqWaveIm, i float getNextRand () { - return std::rand () / double (RAND_MAX); + return std::rand() / double(RAND_MAX); } int findTableLen () { - int maxHarms = AudioConfig::getInstance ()->getSampleRate () / (5.0 * 20) + 0.5; - return VeNo::Utils::nextPowerOfTwo (maxHarms) * 2; + int maxHarms = AudioConfig::getInstance()->getSampleRate() / (5.0 * 20) + 0.5; + return VeNo::Utils::nextPowerOfTwo(maxHarms) * 2; } \ No newline at end of file diff --git a/Source/Veno/Audio/WaveTable/WaveTableGenerator.cpp b/Source/Veno/Audio/WaveTable/WaveTableGenerator.cpp index f7ccac8..68e0c4a 100644 --- a/Source/Veno/Audio/WaveTable/WaveTableGenerator.cpp +++ b/Source/Veno/Audio/WaveTable/WaveTableGenerator.cpp @@ -9,25 +9,25 @@ void WaveTableGenerator::init () { //if the sampleRate changed... the WaveTables are not harmonic Save anymore and are needed to rebuild... pls stay save later! - if (AudioConfig::getInstance ()->isNeedToReInit ()) + if (AudioConfig::getInstance()->isNeedToReInit()) { - cleanTables (); - AudioConfig::getInstance ()->setNeedToReInit (false); + cleanTables(); + AudioConfig::getInstance()->setNeedToReInit(false); } if (m_isInit) { return; } - m_waveTables[WaveForms::SAW] = new WaveTableGroup (); - m_waveTables[WaveForms::SINE] = new WaveTableGroup (); - m_waveTables[WaveForms::SQUARE] = new WaveTableGroup (); - m_waveTables[WaveForms::TRIANGLE] = new WaveTableGroup (); - m_waveTables[WaveForms::wSaw] = new WaveTableGroup (); - m_waveTables[WaveForms::wSQUARE] = new WaveTableGroup (); - m_waveTables[WaveForms::SYNTHONE] = new WaveTableGroup (); - m_waveTables[WaveForms::SYNTHTWO] = new WaveTableGroup (); - m_waveTables[WaveForms::VENOX] = new WaveTableGroup (); - generateSaw (m_waveTables[WaveForms::SAW]); + m_waveTables[WaveForms::SAW] = new WaveTableGroup(); + m_waveTables[WaveForms::SINE] = new WaveTableGroup(); + m_waveTables[WaveForms::SQUARE] = new WaveTableGroup(); + m_waveTables[WaveForms::TRIANGLE] = new WaveTableGroup(); + m_waveTables[WaveForms::wSaw] = new WaveTableGroup(); + m_waveTables[WaveForms::wSQUARE] = new WaveTableGroup(); + m_waveTables[WaveForms::SYNTHONE] = new WaveTableGroup(); + m_waveTables[WaveForms::SYNTHTWO] = new WaveTableGroup(); + m_waveTables[WaveForms::VENOX] = new WaveTableGroup(); + generateSaw(m_waveTables[WaveForms::SAW]); m_isInit = true; } @@ -35,7 +35,7 @@ WaveTableGroup* WaveTableGenerator::getGroup (int id) { if (!m_isInit) { - init (); + init(); } if (id < 40) { diff --git a/Source/Veno/Core/AudioConfig.cpp b/Source/Veno/Core/AudioConfig.cpp index dd8d139..08bfb5c 100644 --- a/Source/Veno/Core/AudioConfig.cpp +++ b/Source/Veno/Core/AudioConfig.cpp @@ -43,16 +43,16 @@ void AudioConfig::setNeedToReInit (bool _needToReInit) std::shared_ptr AudioConfig::getInstance () { if (AudioConfig::m_instance == nullptr) - AudioConfig::m_instance = std::make_shared (); + AudioConfig::m_instance = std::make_shared(); return m_instance; } void AudioConfig::initWaveTables () { - WaveTableGenerator::getInstance ().init (); + WaveTableGenerator::getInstance().init(); } AudioConfig::~AudioConfig () { - WaveTableGenerator::getInstance ().cleanTables (); + WaveTableGenerator::getInstance().cleanTables(); } diff --git a/Source/Veno/Core/Config.cpp b/Source/Veno/Core/Config.cpp index 69caa4e..ba6d3d9 100644 --- a/Source/Veno/Core/Config.cpp +++ b/Source/Veno/Core/Config.cpp @@ -4,23 +4,26 @@ #include "Config.h" #include "../Fonts/Fonts.h" +#include "../GUI/GUIParts/Sidebar/VenoLogo.h" +#include "../Utils.h" std::shared_ptr Config::m_instance = nullptr; Config::Config () { // i want to load the m_config file here... - initConfig (); - m_theme = std::make_shared (m_config); - m_theme->init (); - m_fps = m_config->getIntValue ("waveform_fps", 60); + initConfig(); + m_theme = std::make_shared(m_config); + m_theme->init(); + m_fps = m_config->getIntValue("waveform_fps", 60); + startTimer(5000); } void Config::saveAll () { if (m_config != nullptr) { - m_config->saveIfNeeded (); + m_config->saveIfNeeded(); } } @@ -39,7 +42,8 @@ void Config::initConfig () options.applicationName = "config"; options.folderName = "veno"; options.filenameSuffix = "xml"; - m_config = std::make_unique (options); + m_config = std::make_unique(options); + m_scale = (float) m_config->getDoubleValue("scale", 1.0); } std::shared_ptr Config::getCurrentTheme () @@ -47,24 +51,29 @@ std::shared_ptr Config::getCurrentTheme () return m_theme; } -double Config::getScale () +double Config::getScale () const { - return 1; + return m_scale; } void Config::setColourForIndex (Colour* colour, ThemeColour index) { if (m_theme) { - m_theme->setColour (index, colour); + m_theme->setColour(index, colour); } } Config::~Config () { - m_config->save (); - m_theme.reset (); - m_config.reset (); + m_config->save(); + m_config->setNeedsToBeSaved(false); + m_theme.reset(); + m_config.reset(); + m_lookHandler.reset(); + stopTimer(); + VenoFonts::destroyAll(); + VenoLogo::deleteInstance(); } //LEAK DETECTOR FIX! @@ -75,10 +84,9 @@ void Config::registerEditor (AudioProcessorEditor* editor, const std::string& na void Config::removeEditor (const std::string& name) { - m_editors.erase (name); - if (m_editors.empty ()) + m_editors.erase(name); + if (m_editors.empty()) { - VenoFonts::destroyAll (); m_instance = nullptr; } } @@ -86,13 +94,13 @@ void Config::removeEditor (const std::string& name) //for LCD :P let's be a bit funny xD int Config::getEditorCount () { - return m_editors.size (); + return m_editors.size(); } std::shared_ptr Config::getInstance () { if (m_instance == nullptr) - m_instance = std::make_shared (); + m_instance = std::make_shared(); return m_instance; } @@ -100,3 +108,38 @@ int Config::getFps () const { return m_fps; } + +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); +} diff --git a/Source/Veno/Core/Config.h b/Source/Veno/Core/Config.h index cf4fc17..48a7b09 100644 --- a/Source/Veno/Core/Config.h +++ b/Source/Veno/Core/Config.h @@ -10,7 +10,7 @@ #include "../GUI/Theme/Theme.h" #include -class Config +class Config : public Timer { private: std::shared_ptr m_config = nullptr; @@ -18,14 +18,16 @@ private: static std::shared_ptr m_instance; int m_currentLook = 0; //nah move the bitch logic from current to next std::unordered_map m_editors; - int m_fps = 60; + std::shared_ptr m_lookHandler; public: + int m_fps = 60; + float m_scale = 1.0f; static std::shared_ptr getInstance (); void saveAll (); int getCurrentLook (); void setColourForIndex (Colour* colour, ThemeColour index); std::shared_ptr getCurrentTheme (); - double getScale (); + double getScale () const; // can be public but doesnt need! Config (); ~Config (); @@ -33,6 +35,10 @@ public: void removeEditor (const std::string& name); int getEditorCount (); int getFps () const; + void setScale(float value); + void setFps(float value); + void timerCallback () override; + void repaintAll(); protected: void initConfig (); }; diff --git a/Source/Veno/Core/VeNoState.cpp b/Source/Veno/Core/VeNoState.cpp new file mode 100644 index 0000000..e7de798 --- /dev/null +++ b/Source/Veno/Core/VeNoState.cpp @@ -0,0 +1,16 @@ +// +// Created by versustune on 14.06.20. +// + +#include "VeNoState.h" + +VeNoState::VeNoState (std::string pid) +{ + m_pid = pid; +} + +VeNoState::~VeNoState () +{ + delete configScreen; + configScreen = nullptr; +} diff --git a/Source/Veno/Core/VeNoState.h b/Source/Veno/Core/VeNoState.h new file mode 100644 index 0000000..ce07275 --- /dev/null +++ b/Source/Veno/Core/VeNoState.h @@ -0,0 +1,20 @@ +// +// Created by versustune on 14.06.20. +// + +#ifndef VENO_VENOSTATE_H +#define VENO_VENOSTATE_H + +#include +#include "../GUI/GUIParts/ConfigScreen/VenoConfigScreen.h" + +class VeNoState +{ +protected: + std::string m_pid = ""; +public: + VeNoState(std::string pid); + ~VeNoState(); + VenoConfigScreen* configScreen = nullptr; +}; +#endif //VENO_VENOSTATE_H diff --git a/Source/Veno/Fonts/Fonts.cpp b/Source/Veno/Fonts/Fonts.cpp index 3d232bc..b859723 100644 --- a/Source/Veno/Fonts/Fonts.cpp +++ b/Source/Veno/Fonts/Fonts.cpp @@ -4,23 +4,23 @@ #include "Fonts.h" -VenoFonts* VenoFonts::instance = new VenoFonts (); +VenoFonts* VenoFonts::instance = new VenoFonts(); Font* VenoFonts::getNormal () { - return getInstance ()->arvo; + return getInstance()->arvo; } Font* VenoFonts::getLCD () { - return getInstance ()->lcdFont; + return getInstance()->lcdFont; } VenoFonts* VenoFonts::getInstance () { if (instance == nullptr) { - instance = new VenoFonts (); + instance = new VenoFonts(); } return instance; } @@ -33,10 +33,10 @@ void VenoFonts::destroyAll () VenoFonts::VenoFonts () { - arvo = new Font (Typeface::createSystemTypefaceFor (BinaryData::arvo_ttf, - BinaryData::arvo_ttfSize)); - lcdFont = new Font (Typeface::createSystemTypefaceFor (BinaryData::lcd_ttf, - BinaryData::lcd_ttfSize)); + arvo = new Font(Typeface::createSystemTypefaceFor(BinaryData::arvo_ttf, + BinaryData::arvo_ttfSize)); + lcdFont = new Font(Typeface::createSystemTypefaceFor(BinaryData::lcd_ttf, + BinaryData::lcd_ttfSize)); } VenoFonts::~VenoFonts () diff --git a/Source/Veno/GUI/Components/BaseComponent.cpp b/Source/Veno/GUI/Components/BaseComponent.cpp index f9a5408..1175e14 100644 --- a/Source/Veno/GUI/Components/BaseComponent.cpp +++ b/Source/Veno/GUI/Components/BaseComponent.cpp @@ -3,6 +3,7 @@ // #include "BaseComponent.h" +#include "../../Utils.h" #include "../../Fonts/Fonts.h" #include @@ -13,40 +14,42 @@ BaseComponent::BaseComponent (const std::string& processId) BaseComponent::~BaseComponent () { - m_label.reset (); + m_label.reset(); } void BaseComponent::addLabel (const std::string& label_text, LabelPosition labelPosition) { m_enableLabel = true; - m_label = std::make_shared (this, label_text); - m_label->setPosition (labelPosition); + m_label = std::make_shared(this, label_text); + m_label->setPosition(labelPosition); + addAndMakeVisible(*m_label); } void BaseComponent::resized () { if (m_enableLabel && m_label != nullptr) { - LabelPosition position = m_label->getLabelPosition (); + LabelPosition position = m_label->getLabelPosition(); if (position == LabelPosition::TOP) { - m_label->setBounds (0, 0, getWidth (), 15); + m_label->setBounds(0, 0, getWidth(), VeNo::Utils::getCalculatedHeight(15)); } else if (position == LabelPosition::BOTTOM) { - m_label->setBounds (0, getHeight () - 20, getWidth (), 15); + auto height = VeNo::Utils::getCalculatedHeight(15); + m_label->setBounds(0, getHeight() - height, getWidth(), height); } } } void BaseComponent::paint (Graphics& g) { - g.setFont (*VenoFonts::getNormal ()); + g.setFont(*VenoFonts::getNormal()); } void BaseComponent::setParameter (std::string name, std::string group) { - m_name = std::move (name); - m_group = std::move (group); - setName (m_name); + m_name = std::move(name); + m_group = std::move(group); + setName(m_name); } diff --git a/Source/Veno/GUI/Components/BaseComponent.h b/Source/Veno/GUI/Components/BaseComponent.h index 48fde32..affb704 100644 --- a/Source/Veno/GUI/Components/BaseComponent.h +++ b/Source/Veno/GUI/Components/BaseComponent.h @@ -19,7 +19,6 @@ private: std::string m_group; std::string m_name; bool m_enableLabel = false; - std::shared_ptr m_label; public: explicit BaseComponent (const std::string& processId); ~BaseComponent () override; @@ -29,5 +28,6 @@ public: void paint (Graphics& g) override; protected: std::string m_processId; + std::shared_ptr m_label; }; #endif //VENO_BASECOMPONENT_H diff --git a/Source/Veno/GUI/Components/Config/VeNoColour.cpp b/Source/Veno/GUI/Components/Config/VeNoColour.cpp new file mode 100644 index 0000000..8013245 --- /dev/null +++ b/Source/Veno/GUI/Components/Config/VeNoColour.cpp @@ -0,0 +1,65 @@ +// +// Created by versustune on 14.06.20. +// + +#include "VeNoColour.h" +#include +#include "../../../Core/Config.h" +#include "../../../Utils.h" + +using ColourOption = ColourSelector::ColourSelectorOptions; +VeNoColour::~VeNoColour () +{ + BaseComponent::m_label.reset(); + m_selector.reset(); +} + +VeNoColour::VeNoColour (const std::string& processId, ThemeColour index) + : BaseComponent(processId) +{ + m_index = index; + m_selector = std::make_unique( + ColourOption::showColourAtTop|ColourOption::editableColour|ColourOption::showColourspace); + m_selector->setCurrentColour(Config::getInstance()->getCurrentTheme()->getColour(index), + NotificationType::dontSendNotification); + m_selector->addChangeListener(this); + m_selector->setOpaque(false); + addAndMakeVisible(*m_selector); +} + +void VeNoColour::setName (std::string name) +{ + m_name = std::move(name); + if (BaseComponent::m_label == nullptr) + { + BaseComponent::addLabel(m_name, LabelPosition::TOP); + } +} + +void VeNoColour::changeListenerCallback (ChangeBroadcaster* source) +{ + auto selector = m_selector->getCurrentColour(); + auto* colour = new Colour(selector.getRed(), selector.getGreen(), selector.getBlue(), + 1.0f); + Config::getInstance()->getCurrentTheme()->setColour(m_index, colour); + Config::getInstance()->repaintAll(); +} + +void VeNoColour::resized () +{ + auto h = VeNo::Utils::getCalculatedHeight(30); + if (BaseComponent::m_label != nullptr) + { + BaseComponent::m_label->setBounds(0, 0, getWidth(), h); + } + if (m_selector != nullptr) + { + m_selector->setBounds(0, h, getWidth(), getHeight() - h); + } +} + +void VeNoColour::paint (Graphics& g) +{ + g.setColour(Colours::white); + BaseComponent::paint(g); +} diff --git a/Source/Veno/GUI/Components/Config/VeNoColour.h b/Source/Veno/GUI/Components/Config/VeNoColour.h new file mode 100644 index 0000000..2140191 --- /dev/null +++ b/Source/Veno/GUI/Components/Config/VeNoColour.h @@ -0,0 +1,27 @@ +// +// Created by versustune on 14.06.20. +// + +#ifndef VENO_VENOCOLOUR_H +#define VENO_VENOCOLOUR_H + +#include "JuceHeader.h" +#include "../BaseComponent.h" +#include "../../Theme/Theme.h" + +class VeNoColour : public BaseComponent, ChangeListener +{ +private: + ThemeColour m_index; + std::unique_ptr m_selector; + std::string m_name; +public: + explicit VeNoColour (const std::string& processId, ThemeColour index); + ~VeNoColour () override; + void setName(std::string name); + void resized () override; + void paint (Graphics& g) override; +private: + void changeListenerCallback (ChangeBroadcaster* source) override; +}; +#endif //VENO_VENOCOLOUR_H diff --git a/Source/Veno/GUI/Components/Config/VenoConfigButton.cpp b/Source/Veno/GUI/Components/Config/VenoConfigButton.cpp new file mode 100644 index 0000000..84bcbb8 --- /dev/null +++ b/Source/Veno/GUI/Components/Config/VenoConfigButton.cpp @@ -0,0 +1,34 @@ +// +// Created by versustune on 14.06.20. +// + +#include "VenoConfigButton.h" +#include "../../../Core/Config.h" +#include "../../../Utils.h" +#include "../../../VenoInstance.h" +#include "../../../Utils/Logger.h" + +VenoConfigButton::VenoConfigButton (const std::string& processId) : BaseComponent(processId) +{ + setMouseCursor(MouseCursor::PointingHandCursor); +} + +void VenoConfigButton::paint (Graphics& g) +{ + auto theme = Config::getInstance()->getCurrentTheme(); + VeNo::Utils::setFontSize(16.0f, g); + g.setColour(theme->getColour(ThemeColour::accent)); + g.drawRect(0, 0, getWidth(), getHeight()); + g.drawFittedText("Config", 0, 0, getWidth(), getHeight(), Justification::centred, 1, 1); +} + +void VenoConfigButton::mouseDown (const MouseEvent& event) +{ + // open Window on click :) + auto state = VenoInstance::getInstance(m_processId)->state; + if (state->configScreen != nullptr) + { + return; + } + state->configScreen = new VenoConfigScreen(m_processId); +} diff --git a/Source/Veno/GUI/Components/Config/VenoConfigButton.h b/Source/Veno/GUI/Components/Config/VenoConfigButton.h new file mode 100644 index 0000000..79e3075 --- /dev/null +++ b/Source/Veno/GUI/Components/Config/VenoConfigButton.h @@ -0,0 +1,21 @@ +// +// Created by versustune on 14.06.20. +// + +#ifndef VENO_VENOCONFIGBUTTON_H +#define VENO_VENOCONFIGBUTTON_H + +#include "JuceHeader.h" +#include "../BaseComponent.h" + +class VenoConfigButton : public BaseComponent +{ +public: + VenoConfigButton (const std::string& processId); + ~VenoConfigButton() = default; + void paint (Graphics& g) override; + void mouseDown (const MouseEvent& event) override; +private: + +}; +#endif //VENO_VENOCONFIGBUTTON_H diff --git a/Source/Veno/GUI/Components/Config/VenoPreColours.cpp b/Source/Veno/GUI/Components/Config/VenoPreColours.cpp new file mode 100644 index 0000000..026167f --- /dev/null +++ b/Source/Veno/GUI/Components/Config/VenoPreColours.cpp @@ -0,0 +1,84 @@ +// +// Created by versustune on 14.06.20. +// + +#include "VenoPreColours.h" +#include "../../../Core/Config.h" + +VenoPreColours::VenoPreColours (const std::string& processId) : BaseComponent(processId) +{ + initSliders(); + initButtons(); +} + +VenoPreColours::~VenoPreColours () +{ + m_scaleSlider.reset(); + m_fpsSlider.reset(); + for (int i = 0; i < 4; ++i) + { + m_pre[i].reset(); + } +} + +void VenoPreColours::initSliders () +{ + m_fpsSlider = std::make_shared(); + m_fpsSlider->setRange(15, 90, 1); + m_fpsSlider->setValue(Config::getInstance()->getFps()); + m_fpsSlider->setSliderStyle(Slider::SliderStyle::LinearHorizontal); + m_fpsSlider->setTooltip("FPS"); + m_scaleSlider = std::make_shared(); + m_scaleSlider->setRange(0.5f, 2.5f, 0.1); + m_scaleSlider->setValue(Config::getInstance()->getScale()); + m_scaleSlider->setSliderStyle(Slider::SliderStyle::LinearHorizontal); + m_scaleSlider->setTooltip("Scale"); + m_scaleSlider->addListener(this); + m_fpsSlider->addListener(this); + addAndMakeVisible(*m_fpsSlider); + addAndMakeVisible(*m_scaleSlider); +} + +void VenoPreColours::sliderValueChanged (Slider* slider) +{ + if (slider == m_fpsSlider.get()) + { + Config::getInstance()->setFps(slider->getValue()); + } + if (slider == m_scaleSlider.get()) + { + Config::getInstance()->setScale(slider->getValue()); + } +} + +void VenoPreColours::initButtons () +{ + //4 + m_pre.resize(4); + for (int i = 0; i < 4; ++i) + { + m_pre[i] = std::make_unique(m_names[i]); + m_pre[i]->addListener(this); + addAndMakeVisible(m_pre[i].get()); + } +} + +void VenoPreColours::buttonClicked (Button* button) +{ + auto text = button->getButtonText().toStdString(); + Config::getInstance()->getCurrentTheme()->setDefault(text); +} + +void VenoPreColours::resized () +{ + auto bounds = Rectangle(); + bounds.setBounds(0,0,getWidth(), getHeight()-100); + auto bWidth = (getWidth()-80) / 4; + for (int i = 0; i < 4 ; ++i) + { + m_pre[i]->setBounds((bWidth * i) + 40, 110, bWidth, 50); + } + // set slider and button position + m_fpsSlider->setBounds(20, 0, getWidth()-40, 50); + m_scaleSlider->setBounds(20, 50, getWidth()-40, 50); +} diff --git a/Source/Veno/GUI/Components/Config/VenoPreColours.h b/Source/Veno/GUI/Components/Config/VenoPreColours.h new file mode 100644 index 0000000..9f2a821 --- /dev/null +++ b/Source/Veno/GUI/Components/Config/VenoPreColours.h @@ -0,0 +1,30 @@ +// +// Created by versustune on 14.06.20. +// + +#ifndef VENO_VENOPRECOLOURS_H +#define VENO_VENOPRECOLOURS_H + +#include "JuceHeader.h" +#include "../../Components/BaseComponent.h" + +class VenoPreColours : public BaseComponent, public Slider::Listener, Button::Listener +{ +public: + VenoPreColours (const std::string& processId); + ~VenoPreColours(); + void initSliders(); + void initButtons(); + void sliderValueChanged (Slider* slider) override; + void resized () override; +private: + void buttonClicked (Button* button) override; +protected: + std::shared_ptr m_fpsSlider; + std::shared_ptr m_scaleSlider; + std::vector> m_pre; + std::string m_names[4]{ + "LED", "Blood", "Orange Dream", "Ocean" + }; +}; +#endif //VENO_VENOPRECOLOURS_H diff --git a/Source/Veno/GUI/Components/LCD/SidebarLCD.cpp b/Source/Veno/GUI/Components/LCD/SidebarLCD.cpp index 8bc8089..1e368a0 100644 --- a/Source/Veno/GUI/Components/LCD/SidebarLCD.cpp +++ b/Source/Veno/GUI/Components/LCD/SidebarLCD.cpp @@ -7,56 +7,56 @@ #include "../../../Core/Config.h" #include "../../../Fonts/Fonts.h" -SidebarLCD::SidebarLCD (const std::string& process_id) : BaseComponent (process_id) +SidebarLCD::SidebarLCD (const std::string& process_id) : BaseComponent(process_id) { - waveform = std::make_unique (process_id); - addAndMakeVisible (*waveform); + waveform = std::make_unique(process_id); + addAndMakeVisible(*waveform); } SidebarLCD::~SidebarLCD () { - waveform.reset (nullptr); + waveform.reset(nullptr); } void SidebarLCD::drawHeadline (Graphics& g) { - float fontSize = VeNo::Utils::setFontSize (12.0f, g) + 2; + 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); + 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; + 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); + 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; + float topSpace = (12 * Config::getInstance()->getScale()) + 4 + m_innerY; if (waveform != nullptr) { - waveform->setBounds (0, topSpace * 2, getWidth (), getHeight () - (topSpace * 4)); + waveform->setBounds(0, topSpace * 2, getWidth(), getHeight() - (topSpace * 4)); } } void SidebarLCD::paint (Graphics& g) { - std::shared_ptr theme = Config::getInstance ()->getCurrentTheme (); - auto colour = theme->getColour (ThemeColour::lcd_bg); - g.fillAll (colour); + std::shared_ptr 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); + auto accent = theme->getColour(ThemeColour::lcd); + g.setColour(accent); + g.setFont(*VenoFonts::getLCD()); + drawHeadline(g); + drawFooter(g); } \ No newline at end of file diff --git a/Source/Veno/GUI/Components/LCD/Waveforms.cpp b/Source/Veno/GUI/Components/LCD/Waveforms.cpp index 2d630fe..93d5c52 100644 --- a/Source/Veno/GUI/Components/LCD/Waveforms.cpp +++ b/Source/Veno/GUI/Components/LCD/Waveforms.cpp @@ -9,33 +9,30 @@ #include "../../../VenoInstance.h" #include "../../../Fonts/Fonts.h" -Waveforms::Waveforms (const std::string& processId) : BaseComponent (processId) +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); + setMouseCursor(MouseCursor::PointingHandCursor); + m_context.setOpenGLVersionRequired(OpenGLContext::OpenGLVersion::openGL3_2); + m_context.setRenderer(this); + m_context.setContinuousRepainting(false); + m_context.setComponentPaintingEnabled(true); + m_context.attachTo(*this); + setFps(); + 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 (); + stopTimer(); + shaderProgram.reset(); + m_context.detach(); } void Waveforms::newOpenGLContextCreated () { - compileOpenGLShaderProgram (); + compileOpenGLShaderProgram(); } void Waveforms::openGLContextClosing () @@ -45,23 +42,23 @@ void Waveforms::openGLContextClosing () void Waveforms::renderOpenGL () { - if (!isShowing () || shaderProgram == nullptr || !shaderProgram->getLastError ().isEmpty ()) + if (!isShowing() || shaderProgram == nullptr || !shaderProgram->getLastError().isEmpty()) { return; } - auto theme = Config::getInstance ()->getCurrentTheme (); + 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 ()); + 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; @@ -69,33 +66,28 @@ void Waveforms::renderOpenGL () switch (m_mode) { case 1: - drawAudioOutput (); + drawAudioOutput(); break; case 2: - drawWaveTable (); + drawWaveTable(); break; case 3: - drawSpectrum (); + drawSpectrum(); break; default: - drawPeakMeter (); + drawPeakMeter(); } } -void Waveforms::handleAsyncUpdate () -{ - -} - void Waveforms::compileOpenGLShaderProgram () { std::unique_ptr shaderProgramAttempt - = std::make_unique (m_context); - if (shaderProgramAttempt->addVertexShader ({BinaryData::WaveForm_vertex_glsl}) - && shaderProgramAttempt->addFragmentShader ({BinaryData::WaveForm_fragment_glsl}) - && shaderProgramAttempt->link ()) + = std::make_unique(m_context); + if (shaderProgramAttempt->addVertexShader({BinaryData::WaveForm_vertex_glsl}) + && shaderProgramAttempt->addFragmentShader({BinaryData::WaveForm_fragment_glsl}) + && shaderProgramAttempt->link()) { - shaderProgram = std::move (shaderProgramAttempt); + shaderProgram = std::move(shaderProgramAttempt); } } @@ -121,15 +113,16 @@ void Waveforms::timerCallback () { if (m_isWelcome || m_isStarting || m_isChangingData || needToClear) { - repaint (); + repaint(); } else { - if (m_context.isAttached ()) + if (m_context.isAttached()) { - m_context.triggerRepaint (); + m_context.triggerRepaint(); } } + setFps(); } void Waveforms::drawWaveTable () @@ -140,63 +133,61 @@ void Waveforms::drawWaveTable () void Waveforms::drawAudioOutput () { // draw audio from the oscillators - auto instance = VenoInstance::getInstance (BaseComponent::m_processId); - auto buffer = instance->audioBuffer->getBuffer (); - glBegin (GL_LINE_STRIP); + 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 (); + float inc = 2.0f / buffer.size(); for (float i : buffer) { - glVertex2f (posX, i); + glVertex2f(posX, i); posX += inc; } - glEnd (); + glEnd(); } void Waveforms::drawPeakMeter () { - auto theme = Config::getInstance ()->getCurrentTheme (); + auto theme = Config::getInstance()->getCurrentTheme(); if (theme == nullptr) { return; } - auto instance = VenoInstance::getInstance (BaseComponent::m_processId); - instance->audioBuffer->calcPeak (); + 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 (); + auto leftChannel = getdBForChannel(instance->audioBuffer->leftPeak); + 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 = getdBForChannel(instance->audioBuffer->rightPeak); + 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 = Config::getInstance ()->getCurrentTheme (); - auto accent = theme->getColour (ThemeColour::lcd); - g.setColour (accent); - g.setFont (*VenoFonts::getLCD ()); - VeNo::Utils::setFontSize (16.0f, g); + std::shared_ptr 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); + drawWelcome(g, getWidth(), getHeight(), 0, 0); m_ticks++; if (m_ticks > m_time_needed_startup) { @@ -207,8 +198,8 @@ void Waveforms::paint (Graphics& g) } else if (m_isStarting) { - g.drawText (m_warmUpText[pickRandomText], 0, 0, getWidth (), getHeight (), - Justification::centred, true); + g.drawText(m_warmUpText[pickRandomText], 0, 0, getWidth(), getHeight(), + Justification::centred, true); m_ticks++; if (m_ticks > m_time_needed_startup) { @@ -219,7 +210,7 @@ void Waveforms::paint (Graphics& g) } else if (m_isChangingData) { - drawChangedParameter (g, getWidth (), getHeight (), 0, 0); + drawChangedParameter(g, getWidth(), getHeight(), 0, 0); m_ticks++; if (m_ticks > m_time_needed) { @@ -230,7 +221,7 @@ void Waveforms::paint (Graphics& g) } else { - g.resetToDefaultState (); + g.resetToDefaultState(); needToClear = false; } } @@ -238,19 +229,19 @@ void Waveforms::paint (Graphics& g) 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); + 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); + 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); + 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 () @@ -259,20 +250,39 @@ void Waveforms::drawSpectrum () void Waveforms::selectColourByPeak (float value) { - auto theme = Config::getInstance ()->getCurrentTheme (); + 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); - } + auto color = theme->getColour(ThemeColour::lcd); if (value > 0.9) { - color = theme->getColour (ThemeColour::clip); + color = theme->getColour(ThemeColour::clip); + } + else if (value > 0.8) + { + color = theme->getColour(ThemeColour::warning); + } + shaderProgram->setUniform("color", color.getFloatRed(), color.getFloatGreen(), color.getFloatBlue(), + color.getFloatAlpha()); +} + +float Waveforms::getdBForChannel (float value) +{ + float v = VeNo::Utils::clamp(Decibels::gainToDecibels(value, -60.0f), -60.0f, 6.0f); + return jmap(v, -60.0f, 6.0f, -1.0f, + 1.0f); +} + +void Waveforms::setFps () +{ + if(m_currentFps != Config::getInstance()->getFps()) { + m_currentFps = Config::getInstance()->getFps(); + // is something that + m_time_needed = roundToInt(4000 / (1000 / m_currentFps)); + m_time_needed_startup = roundToInt(1000 / (1000 / m_currentFps)); + stopTimer(); + startTimer(m_currentFps); } - shaderProgram->setUniform ("color", color.getFloatRed (), color.getFloatGreen (), color.getFloatBlue (), - color.getFloatAlpha ()); } diff --git a/Source/Veno/GUI/Components/LCD/Waveforms.h b/Source/Veno/GUI/Components/LCD/Waveforms.h index 98c5364..c71c3ca 100644 --- a/Source/Veno/GUI/Components/LCD/Waveforms.h +++ b/Source/Veno/GUI/Components/LCD/Waveforms.h @@ -12,7 +12,6 @@ // opengl context :D class Waveforms : public BaseComponent, private OpenGLRenderer, - private AsyncUpdater, private Timer { protected: @@ -34,7 +33,6 @@ public: 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; @@ -51,7 +49,10 @@ private: void drawWelcome (Graphics& g, int w, int h, int x, int y); void compileOpenGLShaderProgram (); void selectColourByPeak (float value); + float getdBForChannel (float value); + void setFps(); OpenGLContext m_context; std::unique_ptr shaderProgram; + int m_currentFps = 0; }; #endif //VENO_WAVEFORMS_H diff --git a/Source/Veno/GUI/Components/LabelComponent.cpp b/Source/Veno/GUI/Components/LabelComponent.cpp index 0293bfe..88397d5 100644 --- a/Source/Veno/GUI/Components/LabelComponent.cpp +++ b/Source/Veno/GUI/Components/LabelComponent.cpp @@ -8,19 +8,20 @@ LabelComponent::LabelComponent (Component* parent, std::string name) { m_text = name; m_parent = parent; - m_label = std::make_shared