kopia lustrzana https://github.com/jameshball/osci-render
Change precedence of effects when order in list is changed
rodzic
4cf64c9654
commit
945acf1df9
|
@ -1,7 +1,7 @@
|
||||||
#include "EffectsComponent.h"
|
#include "EffectsComponent.h"
|
||||||
#include "audio/BitCrushEffect.h"
|
#include "audio/BitCrushEffect.h"
|
||||||
|
|
||||||
EffectsComponent::EffectsComponent(OscirenderAudioProcessor& p) : audioProcessor(p), listBoxModel(listBox, itemData) {
|
EffectsComponent::EffectsComponent(OscirenderAudioProcessor& p) : audioProcessor(p), itemData(p), listBoxModel(listBox, itemData) {
|
||||||
setText("Audio Effects");
|
setText("Audio Effects");
|
||||||
|
|
||||||
addAndMakeVisible(frequency);
|
addAndMakeVisible(frequency);
|
||||||
|
|
|
@ -173,14 +173,32 @@ void OscirenderAudioProcessor::enableEffect(std::shared_ptr<Effect> effect) {
|
||||||
for (auto& e : *enabledEffects) {
|
for (auto& e : *enabledEffects) {
|
||||||
newEffects->push_back(e);
|
newEffects->push_back(e);
|
||||||
}
|
}
|
||||||
if (std::find(newEffects->begin(), newEffects->end(), effect) == newEffects->end()) {
|
// remove any existing effects with the same id
|
||||||
// insert according to precedence (sorts from lowest to highest precedence)
|
for (auto it = newEffects->begin(); it != newEffects->end();) {
|
||||||
auto it = newEffects->begin();
|
if ((*it)->getId() == effect->getId()) {
|
||||||
while (it != newEffects->end() && (*it)->getPrecedence() <= effect->getPrecedence()) {
|
it = newEffects->erase(it);
|
||||||
|
} else {
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
newEffects->insert(it, effect);
|
|
||||||
}
|
}
|
||||||
|
// insert according to precedence (sorts from lowest to highest precedence)
|
||||||
|
auto it = newEffects->begin();
|
||||||
|
while (it != newEffects->end() && (*it)->getPrecedence() <= effect->getPrecedence()) {
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
newEffects->insert(it, effect);
|
||||||
|
enabledEffects = newEffects;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OscirenderAudioProcessor::updateEffectPrecedence() {
|
||||||
|
// need to make a new vector because the old one is being iterated over in another thread
|
||||||
|
std::shared_ptr<std::vector<std::shared_ptr<Effect>>> newEffects = std::make_shared<std::vector<std::shared_ptr<Effect>>>();
|
||||||
|
for (auto& e : *enabledEffects) {
|
||||||
|
newEffects->push_back(e);
|
||||||
|
}
|
||||||
|
std::sort(newEffects->begin(), newEffects->end(), [](std::shared_ptr<Effect> a, std::shared_ptr<Effect> b) {
|
||||||
|
return a->getPrecedence() < b->getPrecedence();
|
||||||
|
});
|
||||||
enabledEffects = newEffects;
|
enabledEffects = newEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ public:
|
||||||
void updateAngleDelta();
|
void updateAngleDelta();
|
||||||
void addFrame(std::vector<std::unique_ptr<Shape>> frame) override;
|
void addFrame(std::vector<std::unique_ptr<Shape>> frame) override;
|
||||||
void enableEffect(std::shared_ptr<Effect> effect);
|
void enableEffect(std::shared_ptr<Effect> effect);
|
||||||
|
void updateEffectPrecedence();
|
||||||
private:
|
private:
|
||||||
double theta = 0.0;
|
double theta = 0.0;
|
||||||
double thetaDelta = 0.0;
|
double thetaDelta = 0.0;
|
||||||
|
|
|
@ -56,6 +56,7 @@ void DraggableListBoxItem::hideInsertLines()
|
||||||
{
|
{
|
||||||
insertBefore = false;
|
insertBefore = false;
|
||||||
insertAfter = false;
|
insertAfter = false;
|
||||||
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggableListBoxItem::itemDragEnter(const SourceDetails& dragSourceDetails)
|
void DraggableListBoxItem::itemDragEnter(const SourceDetails& dragSourceDetails)
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "DraggableListBox.h"
|
#include "DraggableListBox.h"
|
||||||
#include <JuceHeader.h>
|
#include <JuceHeader.h>
|
||||||
|
#include "../PluginProcessor.h"
|
||||||
#include "../audio/Effect.h"
|
#include "../audio/Effect.h"
|
||||||
|
|
||||||
// Application-specific data container
|
// Application-specific data container
|
||||||
struct MyListBoxItemData : public DraggableListBoxItemData
|
struct MyListBoxItemData : public DraggableListBoxItemData
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<Effect>> data;
|
std::vector<std::shared_ptr<Effect>> data;
|
||||||
|
OscirenderAudioProcessor& audioProcessor;
|
||||||
|
|
||||||
|
MyListBoxItemData(OscirenderAudioProcessor& p) : audioProcessor(p) {}
|
||||||
|
|
||||||
int getNumItems() override {
|
int getNumItems() override {
|
||||||
return data.size();
|
return data.size();
|
||||||
|
@ -27,13 +31,19 @@ struct MyListBoxItemData : public DraggableListBoxItemData
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveBefore(int indexOfItemToMove, int indexOfItemToPlaceBefore) override {
|
void moveBefore(int indexOfItemToMove, int indexOfItemToPlaceBefore) override {
|
||||||
auto temp = data[indexOfItemToMove];
|
auto effect = data[indexOfItemToMove];
|
||||||
|
|
||||||
if (indexOfItemToMove < indexOfItemToPlaceBefore) {
|
if (indexOfItemToMove < indexOfItemToPlaceBefore) {
|
||||||
move(data, indexOfItemToMove, indexOfItemToPlaceBefore - 1);
|
move(data, indexOfItemToMove, indexOfItemToPlaceBefore - 1);
|
||||||
} else {
|
} else {
|
||||||
move(data, indexOfItemToMove, indexOfItemToPlaceBefore);
|
move(data, indexOfItemToMove, indexOfItemToPlaceBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < data.size(); i++) {
|
||||||
|
data[i]->setPrecedence(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
audioProcessor.updateEffectPrecedence();
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveAfter(int indexOfItemToMove, int indexOfItemToPlaceAfter) override {
|
void moveAfter(int indexOfItemToMove, int indexOfItemToPlaceAfter) override {
|
||||||
|
@ -44,6 +54,12 @@ struct MyListBoxItemData : public DraggableListBoxItemData
|
||||||
} else {
|
} else {
|
||||||
move(data, indexOfItemToMove, indexOfItemToPlaceAfter + 1);
|
move(data, indexOfItemToMove, indexOfItemToPlaceAfter + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < data.size(); i++) {
|
||||||
|
data[i]->setPrecedence(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
audioProcessor.updateEffectPrecedence();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename t> void move(std::vector<t>& v, size_t oldIndex, size_t newIndex) {
|
template <typename t> void move(std::vector<t>& v, size_t oldIndex, size_t newIndex) {
|
||||||
|
|
Ładowanie…
Reference in New Issue