Make DAW parameters update when GUI changes and vice versa and fix several bugs

pull/241/head
James Ball 2024-04-26 20:34:50 +01:00 zatwierdzone przez James H Ball
rodzic d8bb084cac
commit 23bfcaee7d
6 zmienionych plików z 54 dodań i 18 usunięć

Wyświetl plik

@ -4,7 +4,6 @@
LineArtComponent::LineArtComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) {
setText("Line Art Settings");
addAndMakeVisible(animate);
addAndMakeVisible(sync);
addAndMakeVisible(rateLabel);
@ -12,11 +11,11 @@ LineArtComponent::LineArtComponent(OscirenderAudioProcessor& p, OscirenderAudioP
addAndMakeVisible(offsetLabel);
addAndMakeVisible(offsetBox);
rateLabel.setText("Framerate: ", juce::dontSendNotification);
rateLabel.setText("Framerate", juce::dontSendNotification);
rateBox.setValue(audioProcessor.animationRate->getValueUnnormalised(), false, 2);
rateBox.setJustification(juce::Justification::left);
offsetLabel.setText(" Offset: ", juce::dontSendNotification);
offsetLabel.setText("Offset", juce::dontSendNotification);
offsetBox.setValue(audioProcessor.animationOffset->getValueUnnormalised(), false, 2);
offsetBox.setJustification(juce::Justification::left);
@ -24,16 +23,28 @@ LineArtComponent::LineArtComponent(OscirenderAudioProcessor& p, OscirenderAudioP
update();
auto updateAnimation = [this]() {
audioProcessor.animateLineArt->setValue(animate.getToggleState());
audioProcessor.syncMIDIAnimation->setValue(sync.getToggleState());
audioProcessor.animationRate->setValueUnnormalised(rateBox.getValue());
audioProcessor.animationOffset->setValueUnnormalised(offsetBox.getValue());
audioProcessor.animateLineArt->setValueNotifyingHost(animate.getToggleState());
audioProcessor.syncMIDIAnimation->setValueNotifyingHost(sync.getToggleState());
audioProcessor.animationRate->setUnnormalisedValueNotifyingHost(rateBox.getValue());
audioProcessor.animationOffset->setUnnormalisedValueNotifyingHost(offsetBox.getValue());
};
animate.onClick = updateAnimation;
sync.onClick = updateAnimation;
rateBox.onFocusLost = updateAnimation;
offsetBox.onFocusLost = updateAnimation;
rateBox.onTextChange = updateAnimation;
offsetBox.onTextChange = updateAnimation;
audioProcessor.animateLineArt->addListener(this);
audioProcessor.syncMIDIAnimation->addListener(this);
audioProcessor.animationRate->addListener(this);
audioProcessor.animationOffset->addListener(this);
}
LineArtComponent::~LineArtComponent() {
audioProcessor.animationOffset->removeListener(this);
audioProcessor.animationRate->removeListener(this);
audioProcessor.syncMIDIAnimation->removeListener(this);
audioProcessor.animateLineArt->removeListener(this);
}
void LineArtComponent::resized() {
@ -65,3 +76,13 @@ void LineArtComponent::update() {
animate.setToggleState(audioProcessor.animateLineArt->getValue(), true);
sync.setToggleState(audioProcessor.syncMIDIAnimation->getValue(), true);
}
void LineArtComponent::parameterValueChanged(int parameterIndex, float newValue) {
triggerAsyncUpdate();
}
void LineArtComponent::parameterGestureChanged(int parameterIndex, bool gestureIsStarting) {}
void LineArtComponent::handleAsyncUpdate() {
update();
}

Wyświetl plik

@ -5,11 +5,15 @@
#include "components/DoubleTextBox.h"
class OscirenderAudioProcessorEditor;
class LineArtComponent : public juce::GroupComponent, public juce::MouseListener {
class LineArtComponent : public juce::GroupComponent, public juce::AudioProcessorParameter::Listener, juce::AsyncUpdater {
public:
LineArtComponent(OscirenderAudioProcessor&, OscirenderAudioProcessorEditor&);
~LineArtComponent();
void resized() override;
void parameterValueChanged(int parameterIndex, float newValue) override;
void parameterGestureChanged(int parameterIndex, bool gestureIsStarting) override;
void handleAsyncUpdate() override;
void update();
private:
OscirenderAudioProcessor& audioProcessor;
@ -20,7 +24,7 @@ private:
juce::Label rateLabel{ "Framerate","Framerate"};
juce::Label offsetLabel{ "Offset","Offset" };
DoubleTextBox rateBox{ -256, 256 };
DoubleTextBox offsetBox{ -8192,8192 };
DoubleTextBox offsetBox{ -8192, 8192 };
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LineArtComponent)
};

Wyświetl plik

@ -662,7 +662,10 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
}
if ((currentFile >= 0) ? (sounds[currentFile]->parser->isAnimatable) : false) {
int animFrame = (int)(animationTime * animationRate->getValueUnnormalised() + animationOffset->getValueUnnormalised());
sounds[currentFile]->parser->getLineArt()->setFrame(animFrame);
auto lineArt = sounds[currentFile]->parser->getLineArt();
if (lineArt != nullptr) {
lineArt->setFrame(animFrame);
}
}
}

Wyświetl plik

@ -36,7 +36,7 @@ public:
// only keep negative sign at beginning
if (text.contains("-")) {
juce::String remainder = text.substring(1);
remainder = remainder.retainCharacters("0123456789");
remainder = remainder.retainCharacters("0123456789.");
text = text.substring(0, 1) + remainder;
}

Wyświetl plik

@ -83,7 +83,9 @@ void LineArtParser::parseJsonFrames(juce::String jsonStr) {
}
void LineArtParser::setFrame(int fNum) {
frameNumber = fNum % numFrames;
// Ensure that the frame number is within the bounds of the number of frames
// This weird modulo trick is to handle negative numbers
frameNumber = (numFrames + (fNum % numFrames)) % numFrames;
}
std::vector<std::unique_ptr<Shape>> LineArtParser::draw() {

Wyświetl plik

@ -16,6 +16,7 @@ import bmesh
import socket
import json
import atexit
from bpy.props import StringProperty
from bpy.app.handlers import persistent
from bpy_extras.io_utils import ImportHelper
@ -67,21 +68,26 @@ class osci_render_save(bpy.types.Operator, ImportHelper):
bl_label = "Save Line Art"
bl_idname = "render.osci_render_save"
bl_description = "Save line art to the chosen file"
filter_glob: bpy.props.StringProperty(
filename_ext = ".gpla"
filter_glob: StringProperty(
default="*.gpla",
options={"HIDDEN"}
)
def execute(self,context):
def execute(self, context):
FilePath = self.filepath
filename, extension = os.path.splitext(self.filepath)
if (extension != ".gpla"):
if extension != ".gpla":
extension = ".gpla"
FilePath = FilePath + ".gpla"
self.report({"INFO"}, FilePath)
if filename is not None and extension is not None:
fin = save_scene_to_file(bpy.context.scene, FilePath)
if (fin == 0):
if fin == 0:
self.report({"INFO"}, "File write successful!")
return {"FINISHED"}
else: