osci-render/Source/FrameSettingsComponent.cpp

146 wiersze
5.4 KiB
C++
Czysty Zwykły widok Historia

2024-05-11 22:10:54 +00:00
#include "FrameSettingsComponent.h"
2024-04-15 19:54:25 +00:00
#include "PluginEditor.h"
2024-05-11 22:10:54 +00:00
FrameSettingsComponent::FrameSettingsComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) {
setText("Frame Settings");
2024-04-15 19:54:25 +00:00
addAndMakeVisible(animate);
addAndMakeVisible(sync);
addAndMakeVisible(rateLabel);
2024-04-21 18:07:15 +00:00
addAndMakeVisible(rateBox);
addAndMakeVisible(offsetLabel);
2024-04-21 18:07:15 +00:00
addAndMakeVisible(offsetBox);
2024-05-11 22:10:54 +00:00
addAndMakeVisible(invertImage);
addAndMakeVisible(threshold);
addAndMakeVisible(stride);
2024-05-11 22:10:54 +00:00
animate.setTooltip("Enables animation for files that have multiple frames, such as GIFs or Line Art.");
sync.setTooltip("Synchronises the animation's framerate with the BPM of your DAW.");
offsetLabel.setTooltip("Offsets the animation's start point by a specified number of frames.");
2024-04-27 22:30:42 +00:00
rateLabel.setText("Frames per Second", juce::dontSendNotification);
2024-04-21 18:07:15 +00:00
rateBox.setJustification(juce::Justification::left);
2024-04-15 19:54:25 +00:00
2024-04-27 22:30:42 +00:00
offsetLabel.setText("Start Frame", juce::dontSendNotification);
2024-04-21 18:07:15 +00:00
offsetBox.setJustification(juce::Justification::left);
2024-04-15 19:54:25 +00:00
update();
auto updateAnimation = [this]() {
2024-05-11 22:10:54 +00:00
audioProcessor.animateFrames->setValueNotifyingHost(animate.getToggleState());
2024-04-27 22:30:42 +00:00
audioProcessor.animationSyncBPM->setValueNotifyingHost(sync.getToggleState());
audioProcessor.animationRate->setUnnormalisedValueNotifyingHost(rateBox.getValue());
audioProcessor.animationOffset->setUnnormalisedValueNotifyingHost(offsetBox.getValue());
2024-05-11 22:10:54 +00:00
audioProcessor.invertImage->setValueNotifyingHost(invertImage.getToggleState());
2024-04-15 19:54:25 +00:00
};
animate.onClick = updateAnimation;
sync.onClick = updateAnimation;
rateBox.onFocusLost = updateAnimation;
offsetBox.onFocusLost = updateAnimation;
2024-05-11 22:10:54 +00:00
invertImage.onClick = [this]() {
audioProcessor.invertImage->setValue(invertImage.getToggleState());
};
invertImage.setTooltip("Inverts the image so that dark pixels become light, and vice versa.");
2024-05-11 22:10:54 +00:00
threshold.slider.onValueChange = [this]() {
audioProcessor.imageThreshold->setValue(threshold.slider.getValue());
};
stride.slider.onValueChange = [this]() {
audioProcessor.imageStride->setValue(stride.slider.getValue());
};
audioProcessor.animateFrames->addListener(this);
2024-04-27 22:30:42 +00:00
audioProcessor.animationSyncBPM->addListener(this);
audioProcessor.animationRate->addListener(this);
audioProcessor.animationOffset->addListener(this);
2024-05-11 22:10:54 +00:00
audioProcessor.invertImage->addListener(this);
}
FrameSettingsComponent::~FrameSettingsComponent() {
audioProcessor.invertImage->removeListener(this);
audioProcessor.animationOffset->removeListener(this);
audioProcessor.animationRate->removeListener(this);
audioProcessor.animationSyncBPM->removeListener(this);
audioProcessor.animateFrames->removeListener(this);
2024-04-15 19:54:25 +00:00
}
2024-05-11 22:10:54 +00:00
void FrameSettingsComponent::resized() {
2024-04-15 19:54:25 +00:00
auto area = getLocalBounds().withTrimmedTop(20).reduced(20);
double rowHeight = 20;
if (animated) {
double rowSpace = 10;
auto firstColumn = area.removeFromLeft(220);
auto animateBounds = firstColumn.removeFromTop(rowHeight);
animate.setBounds(animateBounds.removeFromLeft(100));
sync.setBounds(animateBounds.removeFromLeft(100));
firstColumn.removeFromTop(rowSpace);
animateBounds = firstColumn.removeFromTop(rowHeight);
rateLabel.setBounds(animateBounds.removeFromLeft(140));
rateBox.setBounds(animateBounds.removeFromLeft(60));
firstColumn.removeFromTop(rowSpace);
animateBounds = firstColumn.removeFromTop(rowHeight);
offsetLabel.setBounds(animateBounds.removeFromLeft(140));
offsetBox.setBounds(animateBounds.removeFromLeft(60));
}
if (image) {
auto secondColumn = area;
auto invertBounds = secondColumn.removeFromTop(rowHeight);
invertImage.setBounds(invertBounds.removeFromLeft(100));
secondColumn.removeFromTop(5);
rowHeight = 30;
threshold.setBounds(secondColumn.removeFromTop(rowHeight));
stride.setBounds(secondColumn.removeFromTop(rowHeight));
}
2024-04-15 19:54:25 +00:00
}
2024-05-11 22:10:54 +00:00
void FrameSettingsComponent::update() {
rateBox.setValue(audioProcessor.animationRate->getValueUnnormalised(), false, 2);
offsetBox.setValue(audioProcessor.animationOffset->getValueUnnormalised(), false, 2);
2024-05-11 22:10:54 +00:00
animate.setToggleState(audioProcessor.animateFrames->getValue(), false);
2024-04-27 22:30:42 +00:00
sync.setToggleState(audioProcessor.animationSyncBPM->getValue(), false);
2024-05-11 22:10:54 +00:00
invertImage.setToggleState(audioProcessor.invertImage->getValue(), false);
2024-04-27 22:30:42 +00:00
if (sync.getToggleState()) {
rateLabel.setText("Frames per Beat", juce::dontSendNotification);
rateLabel.setTooltip("Set the animation's speed in frames per beat.");
2024-04-27 22:30:42 +00:00
} else {
rateLabel.setText("Frames per Second", juce::dontSendNotification);
rateLabel.setTooltip("Set the animation's speed in frames per second.");
2024-04-27 22:30:42 +00:00
}
}
2024-05-11 22:10:54 +00:00
void FrameSettingsComponent::parameterValueChanged(int parameterIndex, float newValue) {
triggerAsyncUpdate();
}
2024-05-11 22:10:54 +00:00
void FrameSettingsComponent::parameterGestureChanged(int parameterIndex, bool gestureIsStarting) {}
2024-05-11 22:10:54 +00:00
void FrameSettingsComponent::handleAsyncUpdate() {
update();
}
void FrameSettingsComponent::setAnimated(bool animated) {
this->animated = animated;
animate.setVisible(animated);
sync.setVisible(animated);
rateBox.setVisible(animated);
offsetBox.setVisible(animated);
rateLabel.setVisible(animated);
offsetLabel.setVisible(animated);
}
void FrameSettingsComponent::setImage(bool image) {
this->image = image;
invertImage.setVisible(image);
threshold.setVisible(image);
stride.setVisible(image);
}