Allow modification of visualiser quality, and improve how it looks

pull/170/head
James Ball 2023-12-21 18:31:18 +00:00
rodzic 972a9840cd
commit 1eec8fc2e1
5 zmienionych plików z 27 dodań i 16 usunięć

Wyświetl plik

@ -4,7 +4,7 @@
class LabelledTextBox : public juce::Component {
public:
LabelledTextBox(juce::String text) {
LabelledTextBox(juce::String text, double min = -999999, double max = 999999, double step = 0.01) : textBox(min, max, step) {
addAndMakeVisible(label);
addAndMakeVisible(textBox);
label.setText(text, juce::dontSendNotification);

Wyświetl plik

@ -3,7 +3,7 @@
juce::StringArray MainMenuBarModel::getMenuBarNames() {
if (editor.processor.wrapperType == juce::AudioProcessor::WrapperType::wrapperType_Standalone) {
return juce::StringArray("File", "Options");
return juce::StringArray("File", "Audio");
} else {
return juce::StringArray("File");
}
@ -20,7 +20,7 @@ juce::PopupMenu MainMenuBarModel::getMenuForIndex(int topLevelMenuIndex, const j
menu.addItem(4, "Create New Project");
}
} else if (topLevelMenuIndex == 1) {
menu.addItem(1, "Audio Settings");
menu.addItem(1, "Settings");
}
return menu;

Wyświetl plik

@ -3,14 +3,12 @@
class SliderTextBox : public juce::Slider {
public:
SliderTextBox() {
double RANGE = 999999;
double step = 0.01;
setRange(-RANGE, RANGE, step);
SliderTextBox(double min, double max, double step) {
setRange(min, max, step);
setTextBoxStyle(juce::Slider::TextBoxAbove, false, 90, getTextBoxHeight());
setSliderStyle(juce::Slider::SliderStyle::IncDecButtons);
setIncDecButtonsMode(juce::Slider::IncDecButtonMode::incDecButtonsDraggable_AutoDirection);
setMouseDragSensitivity(2 * RANGE / step);
setMouseDragSensitivity(2 * (max - min) / step);
setSliderSnapsToMousePosition(false);
setColour(juce::Slider::trackColourId, juce::Colours::transparentBlack);
setSize(60, 20);

Wyświetl plik

@ -5,6 +5,9 @@ VisualiserComponent::VisualiserComponent(int numChannels, OscirenderAudioProcess
resetBuffer();
startTimerHz(60);
startThread();
roughness.textBox.setValue(4);
intensity.textBox.setValue(0.75);
}
VisualiserComponent::~VisualiserComponent() {
@ -15,7 +18,7 @@ VisualiserComponent::~VisualiserComponent() {
void VisualiserComponent::setBuffer(std::vector<float>& newBuffer) {
juce::CriticalSection::ScopedLockType scope(lock);
buffer.clear();
for (int i = 0; i < newBuffer.size(); i += precision * numChannels) {
for (int i = 0; i < newBuffer.size(); i += (int) roughness.textBox.getValue() * numChannels) {
buffer.push_back(newBuffer[i]);
buffer.push_back(newBuffer[i + 1]);
}
@ -81,8 +84,13 @@ void VisualiserComponent::mouseDown(const juce::MouseEvent& event) {
stopThread(1000);
}
repaint();
} else if (event.mods.isRightButtonDown()) {
// TODO: add menu to control colours and precision
} else if (event.mods.isPopupMenu()) {
juce::PopupMenu menu;
menu.addCustomItem(1, roughness, 160, 40, false);
menu.addCustomItem(1, intensity, 160, 40, false);
menu.showMenuAsync(juce::PopupMenu::Options(), [this](int result) {});
}
}
@ -116,15 +124,17 @@ void VisualiserComponent::paintXY(juce::Graphics& g, juce::Rectangle<float> area
double strength = 15;
double widthDivisor = 130;
double lengthIntensityScale = 700;
juce::Colour waveColor = waveformColour;
for (auto& line : lines) {
float normalisedLength = line.getLength() * (sampleRate / DEFAULT_SAMPLE_RATE) / roughness.textBox.getValue();
line.applyTransform(transform);
float normalisedLength = line.getLength() * (sampleRate / DEFAULT_SAMPLE_RATE);
float lengthScale = (normalisedLength + 0.001);
float lengthScaleLog = std::log(strength * (1 / lengthScale) + 1) / std::log(strength + 1);
g.setColour(waveColor.withAlpha(std::max(0.f, std::min(lengthScaleLog, 1.f))).withSaturation(std::pow(lengthScale, 2)));
g.drawLine(line, area.getWidth() * (lengthScaleLog * 0.3 + 0.7) / widthDivisor);
double beamIntensity = intensity.textBox.getValue();
double lengthScale = (lengthIntensityScale * 0.5 + lengthIntensityScale * (1 - beamIntensity)) * (normalisedLength + 0.001);
double lengthScaleLog = std::log(strength * (1 / lengthScale) + 1) / std::log(strength + 1);
g.setColour(waveColor.withAlpha((float) std::max(0.0, std::min(lengthScaleLog * beamIntensity, 1.0))).withSaturation(lengthScale / 4));
g.drawLine(line, area.getWidth() / widthDivisor);
}
}

Wyświetl plik

@ -5,6 +5,7 @@
#include <JuceHeader.h>
#include "../concurrency/BufferConsumer.h"
#include "../PluginProcessor.h"
#include "LabelledTextBox.h"
class VisualiserComponent : public juce::Component, public juce::Timer, public juce::Thread, public juce::MouseListener {
public:
@ -31,6 +32,8 @@ private:
juce::Colour backgroundColour, waveformColour;
OscirenderAudioProcessor& audioProcessor;
int sampleRate = DEFAULT_SAMPLE_RATE;
LabelledTextBox roughness{"Roughness", 1, 8, 1};
LabelledTextBox intensity{"Intensity", 0, 1, 0.01};
std::vector<float> tempBuffer;
int precision = 4;