kopia lustrzana https://github.com/jameshball/osci-render
add checkbox to effects
rodzic
945acf1df9
commit
fe7b59bc70
|
@ -22,7 +22,6 @@ EffectsComponent::EffectsComponent(OscirenderAudioProcessor& p) : audioProcessor
|
|||
for (int i = 0; i < effects.size(); i++) {
|
||||
auto effect = effects[i];
|
||||
effect->setValue(effect->getValue());
|
||||
audioProcessor.enableEffect(effect);
|
||||
itemData.data.push_back(effect);
|
||||
}
|
||||
|
||||
|
|
|
@ -190,6 +190,23 @@ void OscirenderAudioProcessor::enableEffect(std::shared_ptr<Effect> effect) {
|
|||
enabledEffects = newEffects;
|
||||
}
|
||||
|
||||
void OscirenderAudioProcessor::disableEffect(std::shared_ptr<Effect> effect) {
|
||||
// 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);
|
||||
}
|
||||
// remove any existing effects with the same id
|
||||
for (auto it = newEffects->begin(); it != newEffects->end();) {
|
||||
if ((*it)->getId() == effect->getId()) {
|
||||
it = newEffects->erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
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>>>();
|
||||
|
|
|
@ -81,6 +81,7 @@ public:
|
|||
void updateAngleDelta();
|
||||
void addFrame(std::vector<std::unique_ptr<Shape>> frame) override;
|
||||
void enableEffect(std::shared_ptr<Effect> effect);
|
||||
void disableEffect(std::shared_ptr<Effect> effect);
|
||||
void updateEffectPrecedence();
|
||||
private:
|
||||
double theta = 0.0;
|
||||
|
|
|
@ -5,6 +5,9 @@ VectorCancellingEffect::VectorCancellingEffect() {}
|
|||
VectorCancellingEffect::~VectorCancellingEffect() {}
|
||||
|
||||
Vector2 VectorCancellingEffect::apply(int index, Vector2 input, double value, double frequency, double sampleRate) {
|
||||
if (value < 0.001) {
|
||||
return input;
|
||||
}
|
||||
frequency = 1.0 + 9.0 * value;
|
||||
if (index < lastIndex) {
|
||||
nextInvert = nextInvert - lastIndex + frequency;
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
MyListComponent::MyListComponent(DraggableListBox& lb, MyListBoxItemData& data, int rn) : DraggableListBoxItem(lb, data, rn) {
|
||||
addAndMakeVisible(slider);
|
||||
addAndMakeVisible(label);
|
||||
|
||||
label.setText(data.getText(rn), juce::dontSendNotification);
|
||||
label.attachToComponent(&slider, true);
|
||||
addAndMakeVisible(selected);
|
||||
|
||||
slider.setSliderStyle(juce::Slider::LinearHorizontal);
|
||||
slider.setTextBoxStyle(juce::Slider::TextBoxRight, false, 90, slider.getTextBoxHeight());
|
||||
|
@ -14,6 +11,19 @@ MyListComponent::MyListComponent(DraggableListBox& lb, MyListBoxItemData& data,
|
|||
slider.onValueChange = [this] {
|
||||
((MyListBoxItemData&)modelData).setValue(rowNum, slider.getValue());
|
||||
};
|
||||
|
||||
// check if effect is in audioProcessor enabled effects
|
||||
bool isSelected = false;
|
||||
for (auto effect : *data.audioProcessor.enabledEffects) {
|
||||
if (effect->getId() == data.getId(rn)) {
|
||||
isSelected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
selected.setToggleState(isSelected, juce::dontSendNotification);
|
||||
selected.onClick = [this] {
|
||||
((MyListBoxItemData&)modelData).setSelected(rowNum, selected.getToggleState());
|
||||
};
|
||||
}
|
||||
|
||||
MyListComponent::~MyListComponent() {}
|
||||
|
@ -24,8 +34,9 @@ void MyListComponent::paint (juce::Graphics& g) {
|
|||
}
|
||||
|
||||
void MyListComponent::resized() {
|
||||
auto sliderLeft = 100;
|
||||
slider.setBounds(sliderLeft, 0, getWidth() - 110, getHeight());
|
||||
auto sliderLeft = 150;
|
||||
slider.setBounds(sliderLeft, 0, getWidth() - sliderLeft - 10, getHeight());
|
||||
selected.setBounds(2, 0, 25, getHeight());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@ struct MyListBoxItemData : public DraggableListBoxItemData
|
|||
g.fillAll(juce::Colours::lightgrey);
|
||||
g.setColour(juce::Colours::black);
|
||||
g.drawRect(bounds);
|
||||
bounds.removeFromLeft(30);
|
||||
g.drawText(data[rowNum]->getName(), bounds, juce::Justification::left);
|
||||
}
|
||||
|
||||
void moveBefore(int indexOfItemToMove, int indexOfItemToPlaceBefore) override {
|
||||
|
@ -73,6 +75,14 @@ struct MyListBoxItemData : public DraggableListBoxItemData
|
|||
void setValue(int itemIndex, double value) {
|
||||
data[itemIndex]->setValue(value);
|
||||
}
|
||||
|
||||
void setSelected(int itemIndex, bool selected) {
|
||||
if (selected) {
|
||||
audioProcessor.enableEffect(data[itemIndex]);
|
||||
} else {
|
||||
audioProcessor.disableEffect(data[itemIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
juce::String getText(int itemIndex) {
|
||||
return data[itemIndex]->getName();
|
||||
|
@ -81,6 +91,10 @@ struct MyListBoxItemData : public DraggableListBoxItemData
|
|||
double getValue(int itemIndex) {
|
||||
return data[itemIndex]->getValue();
|
||||
}
|
||||
|
||||
juce::String getId(int itemIndex) {
|
||||
return data[itemIndex]->getId();
|
||||
}
|
||||
};
|
||||
|
||||
// Custom list-item Component (which includes item-delete button)
|
||||
|
@ -97,8 +111,8 @@ protected:
|
|||
juce::Rectangle<int> dataArea;
|
||||
|
||||
juce::Slider slider;
|
||||
juce::Label label;
|
||||
juce::String id;
|
||||
juce::ToggleButton selected;
|
||||
|
||||
private:
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MyListComponent)
|
||||
|
|
Ładowanie…
Reference in New Issue