This commit is contained in:
Maurice Grönwoldt 2020-07-09 16:31:33 +02:00
commit 61482e8d4c
36 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

@ -10,33 +10,39 @@
#include <vector>
#include "Modulator.h"
#include "ModulateValue.h"
#include "JuceHeader.h"
// class that modulate everything :D
struct VenoMatrixTarget
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);
};
struct VenoMatrixSlot
{
std::string sourceName;
VenoMatrixTarget targets[8];
};
class VenoMatrix
//@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 ();
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);
VenoMatrixSlot* getSlotById (int id);
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;
VenoMatrixSlot* m_slots[8]{}; // 8 source slots
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