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

@ -3,7 +3,7 @@
#include "Veno/Core/AudioConfig.h"
VenoAudioProcessor::VenoAudioProcessor ()
/*#ifndef JucePlugin_PreferredChannelConfigurations
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
@ -12,17 +12,17 @@ VenoAudioProcessor::VenoAudioProcessor ()
.withOutput ("Output", AudioChannelSet::stereo(), true)
#endif
)
#endif*/
: AudioProcessor(BusesProperties().withInput("Input", AudioChannelSet::stereo(), true).withOutput("Output",
AudioChannelSet::stereo(),
true))
#endif
{
instance = VenoInstance::createInstance(m_id);
AudioConfig::registerInstance(m_id);
}
VenoAudioProcessor::~VenoAudioProcessor ()
{
instance.reset();
VenoInstance::deleteInstance(m_id);
AudioConfig::deleteInstance(m_id);
}
const String VenoAudioProcessor::getName () const
@ -129,7 +129,6 @@ void VenoAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& m
auto c = buffer.getReadPointer(i);
for (int j = 0; j < buffer.getNumSamples(); ++j)
{
instance->fft.pushNextSampleIntoFifo(c[j]);
instance->audioBuffer->addMonoSample(c[j], j);
if (i == 0)
{
@ -141,6 +140,7 @@ void VenoAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& m
}
}
}
instance->audioBuffer->calcPeak ();
}
//==============================================================================
@ -157,10 +157,19 @@ AudioProcessorEditor* VenoAudioProcessor::createEditor ()
//==============================================================================
void VenoAudioProcessor::getStateInformation (MemoryBlock& destData)
{
auto matrixXML = instance->matrix.saveMatrixToXML();
if (matrixXML != nullptr) {
copyXmlToBinary(*matrixXML, destData);
} else {
DBG("Sorry something went wrong! xml is nullptr");
}
}
void VenoAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
std::unique_ptr<XmlElement> xmlState(getXmlFromBinary(data, sizeInBytes));
if (xmlState != nullptr)
instance->matrix.getMatrixFromXML(xmlState);
}
AudioProcessor* JUCE_CALLTYPE createPluginFilter ()

View file

@ -33,5 +33,5 @@ public:
std::string m_id = Uuid().toString().toStdString();
std::shared_ptr<VenoInstance> instance;
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessor)
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VenoAudioProcessor);
};

View file

@ -1,8 +1,18 @@
#version 330 core
in vec4 newColor;
in vec4 newGradientColor;
in vec4 sPosition;
out vec4 fragColor;
void main()
{
if (newColor == newGradientColor) {
fragColor = newColor;
} else {
vec2 st = sPosition.xy;
float mixValue = distance(st, vec2(0, 0));
vec3 color = mix(newGradientColor.xyz, newColor.xyz, mixValue);
fragColor = vec4(color, mixValue);
}
}

View file

@ -1,10 +1,15 @@
#version 330 core
in vec4 position;
uniform vec4 color = vec4(1f, 1f, 1f, 1f);
uniform vec4 gradientColor = vec4(1f, 1f, 1f, 1f);
out vec4 newColor;
out vec4 newGradientColor;
out vec4 sPosition;
void main()
{
gl_Position = position;
newColor = color;
newGradientColor = gradientColor;
sPosition = position;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Before After
Before After

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 ()
{
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

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