This commit is contained in:
Maurice Grönwoldt 2020-07-09 16:31:33 +02:00
commit 61482e8d4c
30 changed files with 325 additions and 122 deletions

View file

@ -0,0 +1,136 @@
//
// Created by versustune on 13.06.20.
//
#include "VeNoMatrix.h"
#include "../../Utils/StringUtils.h"
VeNoMatrix::VeNoMatrix (const std::string& processId) : m_processId (processId)
{
}
VeNoMatrix::~VeNoMatrix ()
{
for (auto& m_slot : m_slots)
{
delete m_slot.second;
m_slots.erase (m_slot.first);
}
for (auto& value : m_modulationValues)
{
delete value.second;
m_modulationValues.erase (value.first);
}
for (auto& value : m_modulators)
{
delete value.second;
m_modulators.erase (value.first);
}
}
void VeNoMatrix::removeModulateValue (const std::string& name)
{
m_modulationValues.erase (name);
}
void VeNoMatrix::removeModulator (const std::string& name)
{
m_modulators.erase (name);
}
void VeNoMatrix::addModulateValue (const std::string& name, ModulateValue* modulateValue)
{
m_modulationValues.emplace (std::pair<const std::string&, ModulateValue*> (name, modulateValue));
}
void VeNoMatrix::addModulator (const std::string& name, Modulator* modulator)
{
m_modulators.emplace (std::pair<const std::string&, Modulator*> (name, modulator));
}
//matrix is not in the valueTree-state is some own implementation!
void VeNoMatrix::updateSlots ()
{
for (auto& m_source : m_modulators)
{
m_source.second->update ();
}
for (auto& m_slot : m_slots)
{
auto source = m_modulators[m_slot.second->source];
auto value = m_modulationValues[m_slot.second->name];
auto amount = m_slot.second->amount;
value->addValue (source->getValue () * amount);
}
}
void VeNoMatrix::setMatrixModulation (const std::string& name, const std::string& source, float amount)
{
auto c = std::string (source + name);
if (m_slots.find (c) == m_slots.end ())
{
m_slots[c] = new VeNoMatrixTarget ();
m_slots[c]->source = source;
m_slots[c]->name = name;
}
m_slots[c]->amount = amount;
}
std::unique_ptr<XmlElement> VeNoMatrix::saveMatrixToXML ()
{
auto* tree = new ValueTree ();
for (auto& m_slot : m_slots)
{
std::string name = m_slot.second->source + m_slot.second->name;
tree->setProperty (String (name), String (m_slot.second->toString ()), nullptr);
}
auto xml = tree->createXml ();
delete tree;
return xml;
}
void VeNoMatrix::getMatrixFromXML (std::unique_ptr<XmlElement>& xml)
{
// first we need to delete the state!
for (auto& m_slot : m_slots)
{
delete m_slot.second;
m_slots.erase (m_slot.first);
}
// recreate the matrix from xml...
auto tree = juce::ValueTree::fromXml (*xml);
for (int i = 0; i < tree.getNumChildren (); ++i)
{
auto name = tree.getPropertyName (i);
auto child = tree.getPropertyAsValue (name, nullptr);
auto slot = VeNoMatrixTarget::fromString (child.toString ().toStdString ());
if (slot != nullptr)
{
m_slots[name.toString ().toStdString ()] = slot;
}
}
}
// crate a string to save to ValueTree-State
std::string VeNoMatrixTarget::toString () const
{
return std::string (source + "_#_" + name + "_#_" + std::to_string (amount));
}
// recreate from ValueTree-State... <3 is a very special format
VeNoMatrixTarget* VeNoMatrixTarget::fromString (const std::string& value)
{
auto out = VeNo::StringUtils::split (value, "_#_");
// if size is not 3 this is invalid! return nullptr!
if (out.size () == 3)
{
auto returnValue = new VeNoMatrixTarget ();
returnValue->source = out[0];
returnValue->name = out[1];
returnValue->amount = std::atof (out[2].c_str ());
return new VeNoMatrixTarget ();
}
return nullptr;
}

View file

@ -0,0 +1,48 @@
//
// Created by versustune on 13.06.20.
//
#ifndef VENO_VENOMATRIX_H
#define VENO_VENOMATRIX_H
#include <string>
#include <unordered_map>
#include <vector>
#include "Modulator.h"
#include "ModulateValue.h"
#include "JuceHeader.h"
// class that modulate everything :D
struct VeNoMatrixTarget
{
std::string name;
std::string source;
float amount = 0; // always 0 to 1 <-- apply amount to modulator
std::string toString() const;
static VeNoMatrixTarget* fromString(const std::string& value);
};
//@todo rebuild to new unlimited implementation!
// and make compatible with the value class that is used for saving and sync the ValueTree...
class VeNoMatrix
{
public:
explicit VeNoMatrix (const std::string& processId);
~VeNoMatrix ();
void updateSlots ();
void addModulator (const std::string& name, Modulator* modulator);
void addModulateValue (const std::string& name, ModulateValue* modulateValue);
void removeModulator (const std::string& name);
void removeModulateValue (const std::string& name);
void setMatrixModulation(const std::string& name, const std::string& source, float amount);
std::unique_ptr<XmlElement> saveMatrixToXML();
void getMatrixFromXML(std::unique_ptr<XmlElement>& xml);
private:
std::unordered_map<std::string, Modulator*> m_modulators; //all sources
std::unordered_map<std::string, ModulateValue*> m_modulationValues;
std::unordered_map<std::string, VeNoMatrixTarget*> m_slots;
std::string m_processId;
protected:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VeNoMatrix)
};
#endif //VENO_VENOMATRIX_H

View file

@ -1,81 +0,0 @@
//
// Created by versustune on 13.06.20.
//
#include "VenoMatrix.h"
VenoMatrix::VenoMatrix (const std::string& processId) : m_processId(processId)
{
for (auto& m_slot : m_slots)
{
m_slot = new VenoMatrixSlot();
}
}
VenoMatrix::~VenoMatrix ()
{
for (auto& m_slot : m_slots)
{
delete m_slot;
}
}
VenoMatrixSlot* VenoMatrix::getSlotById (int id)
{
return m_slots[id];
}
void VenoMatrix::removeModulateValue (const std::string& name)
{
m_modulationValues.erase(name);
}
void VenoMatrix::removeModulator (const std::string& name)
{
m_modulators.erase(name);
}
void VenoMatrix::addModulateValue (const std::string& name, ModulateValue* modulateValue)
{
m_modulationValues.emplace(std::pair<const std::string&, ModulateValue*>(name, modulateValue));
}
void VenoMatrix::addModulator (const std::string& name, Modulator* modulator)
{
m_modulators.emplace(std::pair<const std::string&, Modulator*>(name, modulator));
}
void VenoMatrix::updateSlots ()
{
for (auto& m_slot : m_slots)
{
if (m_slot->sourceName == "none")
{
continue;
}
if (m_modulators.find(m_slot->sourceName) != m_modulators.end())
{
auto modulator = m_modulators[m_slot->sourceName];
if (modulator == nullptr)
{
continue;
}
modulator->update();
for (auto& value : m_slot->targets)
{
if (value.name != "none")
{
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);
}
}
}
}
}
}

View file

@ -6,6 +6,7 @@
#define VENO_SYNTHINSTANCE_H
#include <string>
#include "JuceHeader.h"
// class that hold all voices, oscillators and other stuff :)
class SynthInstance
@ -16,5 +17,6 @@ public:
explicit SynthInstance (std::string processId);
~SynthInstance () = default;
protected:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SynthInstance)
};
#endif //VENO_SYNTHINSTANCE_H

View file

@ -33,9 +33,9 @@ void VenoBuffer::reset (int size)
left[i] = 0;
right[i] = 0;
}
leftPeak = 0;
rightPeak = 0;
monoPeak = 0;
leftPeak = -30;
rightPeak = -30;
monoPeak = -30;
}
void VenoBuffer::addMonoSample (float value, int index)
@ -55,10 +55,6 @@ void VenoBuffer::addRightSample (float value, int index)
void VenoBuffer::calcPeak ()
{
if (monoPeak != 0 && rightPeak != 0 && leftPeak != 0)
{
return;
}
float leftRMS = 0;
float rightRMS = 0;
auto size = buffer.size();
@ -70,7 +66,6 @@ void VenoBuffer::calcPeak ()
rightPeak = VeNo::Utils::clamp (Decibels::gainToDecibels (std::sqrt (rightRMS / size), -30.0f), -30.0f, 0.0f);
leftPeak = VeNo::Utils::clamp (Decibels::gainToDecibels (std::sqrt (leftRMS / size), -30.0f), -30.0f, 0.0f);
monoPeak = leftPeak;
//monoPeak = VeNo::Utils::clamp (Decibels::gainToDecibels (monoPeak, -70.0f), -70.0f, 0.0f);
}
const std::vector<float>& VenoBuffer::getBuffer () const

View file

@ -6,6 +6,7 @@
#define VENO_VENOBUFFER_H
#include <vector>
#include "JuceHeader.h"
class VenoBuffer
{
@ -27,5 +28,7 @@ public:
const std::vector<float>& getBuffer () const;
const std::vector<float>& getRight () const;
const std::vector<float>& getLeft () const;
protected:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoBuffer);
};
#endif //VENO_VENOBUFFER_H

View file

@ -48,6 +48,13 @@ void WaveTableGenerator::cleanTables ()
{
for (auto& m_waveTable : m_waveTables)
{
for (int i = 0; i < numWaveTableSlots; ++i)
{
if (m_waveTable != nullptr && m_waveTable->m_WaveTables[i] != nullptr) {
delete[] m_waveTable->m_WaveTables[i]->m_waveTable;
delete m_waveTable->m_WaveTables[i];
}
}
delete m_waveTable;
}
m_isInit = false;

View file

@ -4,6 +4,9 @@
#ifndef VENO_WAVETABLEGENERATOR_H
#define VENO_WAVETABLEGENERATOR_H
#include "JuceHeader.h"
struct WaveTableObject
{
double m_topFreq;
@ -47,5 +50,6 @@ protected:
bool m_isInit = false;
WaveTableGenerator () = default;
~WaveTableGenerator () = default;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WaveTableGenerator)
};
#endif //VENO_WAVETABLEGENERATOR_H

View file

@ -5,6 +5,7 @@
#include "../Audio/WaveTable/WaveTableGenerator.h"
std::shared_ptr<AudioConfig> AudioConfig::m_instance;
std::unordered_map<std::string, std::string> AudioConfig::m_instances;
float AudioConfig::getSampleRate ()
{
@ -43,16 +44,35 @@ void AudioConfig::setNeedToReInit (bool _needToReInit)
std::shared_ptr<AudioConfig> AudioConfig::getInstance ()
{
if (AudioConfig::m_instance == nullptr)
AudioConfig::m_instance = std::make_shared<AudioConfig>();
AudioConfig::m_instance = std::make_shared<AudioConfig> ();
return m_instance;
}
void AudioConfig::initWaveTables ()
{
WaveTableGenerator::getInstance().init();
WaveTableGenerator::getInstance ().init ();
}
AudioConfig::~AudioConfig ()
{
WaveTableGenerator::getInstance().cleanTables();
WaveTableGenerator::getInstance ().cleanTables ();
}
AudioConfig::AudioConfig ()
{
}
void AudioConfig::registerInstance (std::string id)
{
m_instances[id] = id;
}
void AudioConfig::deleteInstance (std::string id)
{
m_instances.erase (id);
if (m_instances.size () == 0)
{
m_instance.reset ();
}
}

View file

@ -17,6 +17,7 @@ private:
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
static std::unordered_map<std::string, std::string> m_instances;
public:
static std::shared_ptr<AudioConfig> getInstance ();
float getSampleRate ();
@ -26,7 +27,11 @@ public:
bool isNeedToReInit () const;
void setNeedToReInit (bool _needToReInit);
static void initWaveTables ();
AudioConfig();
~AudioConfig ();
static void registerInstance (std::string id);
static void deleteInstance (std::string id);
protected:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioConfig);
};
#endif //VENO_AUDIOCONFIG_H

View file

@ -41,5 +41,6 @@ public:
void repaintAll();
protected:
void initConfig ();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Config);
};
#endif //VENO_CONFIG_H

View file

@ -12,6 +12,7 @@ class VeNoState
{
protected:
std::string m_pid = "";
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VeNoState);
public:
VeNoState(std::string pid);
~VeNoState();

View file

@ -27,7 +27,9 @@ VenoFonts* VenoFonts::getInstance ()
void VenoFonts::destroyAll ()
{
delete instance;
if (instance != nullptr) {
delete instance;
}
instance = nullptr;
}
@ -43,4 +45,6 @@ VenoFonts::~VenoFonts ()
{
delete arvo;
delete lcdFont;
arvo = nullptr;
lcdFont = nullptr;
}

View file

@ -13,6 +13,7 @@ protected:
static VenoFonts* instance;
Font* lcdFont;
Font* arvo;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoFonts)
public:
VenoFonts ();
~VenoFonts ();

View file

@ -29,5 +29,6 @@ public:
protected:
std::string m_processId;
std::shared_ptr<LabelComponent> m_label;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BaseComponent);
};
#endif //VENO_BASECOMPONENT_H

View file

@ -24,5 +24,6 @@ protected:
void drawHeadline (Graphics& g);
void drawFooter (Graphics& g);
std::unique_ptr<Waveforms> waveform;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SidebarLCD);
};
#endif //VENO_SIDEBARLCD_H

View file

@ -63,6 +63,9 @@ void Waveforms::renderOpenGL ()
auto color = theme->getColour (ThemeColour::lcd);
shaderProgram->setUniform ("color", color.getFloatRed (), color.getFloatGreen (), color.getFloatBlue (),
color.getFloatAlpha ());
// same color currently! will set to a diff if peak is detected!
shaderProgram->setUniform ("gradientColor", color.getFloatRed (), color.getFloatGreen (), color.getFloatBlue (),
color.getFloatAlpha ());
if (m_isWelcome || m_isStarting || m_isChangingData)
{
return;
@ -92,6 +95,8 @@ void Waveforms::compileOpenGLShaderProgram ()
&& shaderProgramAttempt->link ())
{
shaderProgram = std::move (shaderProgramAttempt);
} else {
DBG(shaderProgramAttempt->getLastError().toStdString());
}
}
@ -144,10 +149,17 @@ void Waveforms::drawAudioOutput ()
glBegin (GL_LINE_STRIP);
float posX = -1;
float inc = 2.0f / buffer.size ();
for (float i : buffer)
for (int j = 0; j < buffer.size(); ++j)
{
glVertex2f (posX, i);
posX += inc;
try
{
glVertex2f (posX, buffer.at(j));
posX += inc;
} catch (_exception e)
{
//something is wrong skip the draw and end it!
break;
}
}
glEnd ();
}
@ -160,7 +172,6 @@ void Waveforms::drawPeakMeter ()
return;
}
auto instance = VenoInstance::getInstance (BaseComponent::m_processId);
instance->audioBuffer->calcPeak ();
repaint();
// draw peak signal
auto leftChannel = getdBForChannel (instance->audioBuffer->leftPeak);
@ -276,6 +287,8 @@ void Waveforms::selectColourByPeak (float value)
return;
}
auto color = theme->getColour (ThemeColour::lcd);
shaderProgram->setUniform ("color", color.getFloatRed (), color.getFloatGreen (), color.getFloatBlue (),
color.getFloatAlpha ());
if (value > 0.87)
{
color = theme->getColour (ThemeColour::clip);
@ -284,7 +297,7 @@ void Waveforms::selectColourByPeak (float value)
{
color = theme->getColour (ThemeColour::warning);
}
shaderProgram->setUniform ("color", color.getFloatRed (), color.getFloatGreen (), color.getFloatBlue (),
shaderProgram->setUniform ("gradientColor", color.getFloatRed (), color.getFloatGreen (), color.getFloatBlue (),
color.getFloatAlpha ());
}

View file

@ -28,6 +28,7 @@ protected:
int m_time_needed_startup = 0;
int m_time_needed = 0;
bool needToClear = false;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Waveforms);
public:
explicit Waveforms (const std::string& processId);
~Waveforms () override;

View file

@ -38,6 +38,7 @@ ConfigComponent::~ConfigComponent ()
color.reset();
}
m_colors.clear();
m_preColours.reset(nullptr);
}
ThemeColour ConfigComponent::getColorForId (int id)

View file

@ -18,6 +18,8 @@ Sidebar::~Sidebar ()
{
m_lcd.reset(nullptr);
m_configButton.reset(nullptr);
m_mixer.reset(nullptr);
VenoLogo::deleteInstance();
}
void Sidebar::resized ()

Some files were not shown because too many files have changed in this diff Show more