Skip to content

Commit

Permalink
initialize drawing with current settings
Browse files Browse the repository at this point in the history
  • Loading branch information
JohT committed May 5, 2022
1 parent 1a9101b commit dc5e514
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/ui/SpecletAnalyzerComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ SpecletAnalyzerComponent::SpecletAnalyzerComponent(SpecletParameters &parameters

//[Constructor] You can add your own custom stuff here..

transformationChanged(parameters.getTransformation());
routingChanged(parameters.getRouting());

//registers itself as listener for parameter-changes
parameters.addListener(this);
DBG("SpecletAnalyzerComponent as parameter listener added");
Expand Down
3 changes: 2 additions & 1 deletion src/ui/SpecletAnalyzerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//[Headers] -- You can add your own extra header files here --
#include "../dsp/transformations/Transformation.h"
#include "../plugin/SpecletParameters.h"
#include "ColourGradients.h"
#include "SpecletDrawer.h"
#include "juce_core/juce_core.h"

Expand Down Expand Up @@ -90,7 +91,7 @@ private :
template<class _Tp>
auto enumOptionIntValue(const _Tp &enumType) const -> int;

SpecletDrawer *specletDrawer = new SpecletDrawer();
SpecletDrawer *specletDrawer = new SpecletDrawer(parameters.getLogFrequency(), parameters.getLogMagnitude(), ColourGradients::forIndex(parameters.getColorMode()));
//[/UserVariables]

//==============================================================================
Expand Down
10 changes: 7 additions & 3 deletions src/ui/SpecletDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const juce::Colour SpecletDrawer::AXIS_COLOR(0xffffffc0);
//[/MiscUserDefs]

//==============================================================================
SpecletDrawer::SpecletDrawer() {
SpecletDrawer::SpecletDrawer(bool logFrequency, bool logMagnitude, const juce::ColourGradient &initialColourGradient)
: settings({logFrequency, logMagnitude}),
renderingHelper(initialColourGradient) {

//[UserPreSize]
//[/UserPreSize]
Expand All @@ -51,6 +53,7 @@ SpecletDrawer::SpecletDrawer() {
TransformationFactory::getSingletonInstance().registerForTransformationResults(this);

startTimer(TIMER);
updateFrequencyAxisImage();
ready = true;
waitForDestruction.signal();
//[/Constructor]
Expand Down Expand Up @@ -159,6 +162,7 @@ void SpecletDrawer::parameterChanged(const juce::String& parameterID, float newV
if (parameterID.equalsIgnoreCase(SpecletParameters::PARAMETER_LOGMAGNITUDE)) {
settings.logMagnitude = (newIndex == static_cast<std::underlying_type_t<SpecletDrawerParameters::Axis>>(SpecletDrawerParameters::Axis::LOGARITHMIC));
}
//TODO (JohT) Add listener to RenderingHelper and move these lines there
if (parameterID.equalsIgnoreCase(SpecletParameters::PARAMETER_COLORMODE)) {
renderingHelper.setColourGradient(ColourGradients::forIndex(newIndex));
}
Expand Down Expand Up @@ -216,14 +220,14 @@ void SpecletDrawer::updateFrequencyAxisImage() {
double maxFrequencyLog = log10(maxSpectralFrequency);
double minFrequencyLog = 1.0;

for (double logFreqDecade = 1; logFreqDecade <= 4; logFreqDecade++) {
for (auto logFreqDecade = 1; logFreqDecade <= 4; logFreqDecade++) {
for (auto i = 0; i < (numberOfSubDivisions - 1); i++) {
double logFreq = logSubDivisionsPerDecade[i] + logFreqDecade;
if (logFreq > maxFrequencyLog) {
break;
}
double posPercent = (logFreq - minFrequencyLog) / (maxFrequencyLog - minFrequencyLog);
int yPos = static_cast<int>(lrint((sizeY - 1) * (1.0f - posPercent)));
auto yPos = static_cast<int>(lrint((sizeY - 1) * (1.0f - posPercent)));
double freqDouble = pow(10, logFreq);
double freqCeil = ceil(freqDouble);
double freqFloor = floor(freqDouble);
Expand Down
14 changes: 7 additions & 7 deletions src/ui/SpecletDrawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//[Headers] -- You can add your own extra header files here --
#include "../dsp/transformations/Transformation.h"
#include "../utilities/RenderingHelper.h"
#include "ColourGradients.h"
#include "juce_core/juce_core.h"

//[/Headers]
Expand All @@ -37,12 +38,12 @@
//[/Comments]
*/
class SpecletDrawer : public juce::Component,
public TransformationListener,
public juce::Timer,
public juce::AudioProcessorValueTreeState::Listener {
public TransformationListener,
public juce::Timer,
public juce::AudioProcessorValueTreeState::Listener {
public:
//==============================================================================
SpecletDrawer();
SpecletDrawer(bool logFrequency = true, bool logMagnitude = true, const juce::ColourGradient & initialColourGradient = ColourGradients::BLUE);
~SpecletDrawer() override;

//==============================================================================
Expand All @@ -56,7 +57,6 @@ class SpecletDrawer : public juce::Component,
void paint(juce::Graphics &g) override;
void resized() override;


//==============================================================================
juce_UseDebuggingNewOperator

Expand All @@ -78,8 +78,8 @@ private :
int sizeY = Constants::SIZE_Y;
double currentTimeResolution = 0;
double currentSamplingFrequency = 0.0;
RenderingHelper::TAnalyzerSettings settings = {};
RenderingHelper renderingHelper = {};
RenderingHelper::TAnalyzerSettings settings;
RenderingHelper renderingHelper;
int currentCursorXPos = 0;
juce::Image spectrumImage = {juce::Image::RGB, sizeX, sizeY, true};
juce::Image axisImage = {juce::Image::PixelFormat::ARGB, sizeX, sizeY, true};
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/RenderingHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "PerformanceLogger.h"
#include <assert.h>

RenderingHelper::RenderingHelper()
: colourGradient(ColourGradients::BLUE) {
RenderingHelper::RenderingHelper(const juce::ColourGradient &initialColourGradient)
: colourGradient(initialColourGradient) {
}

//method for rendering one column of spectral data
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/RenderingHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RenderingHelper {
bool logMagnitude;//false=lin, true=log
};

RenderingHelper();
explicit RenderingHelper(const juce::ColourGradient &initialColourGradient);
~RenderingHelper() = default;

void setColourGradient(const juce::ColourGradient& value) { colourGradient = value; }
Expand Down
5 changes: 3 additions & 2 deletions test/RenderingHelperTest.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "../src/utilities/RenderingHelper.h"
#include "../src/ui/ColourGradients.h"

#include <catch2/catch_test_macros.hpp>

SCENARIO("Rendering Helper") {
GIVEN("pixel to index") {
RenderingHelper renderingHelper;
RenderingHelper renderingHelper(ColourGradients::BLUE);
SpectralDataInfo info(44100, 4096, 4096);
const auto windowHeight = 100;
const bool linearFrequency = false;
Expand Down Expand Up @@ -57,7 +58,7 @@ SCENARIO("Rendering Helper") {
// They are not part of the automated tests.
SCENARIO("Rendering Helper Debugging", "[.debug]") {
GIVEN("pixel to index") {
RenderingHelper renderingHelper;
RenderingHelper renderingHelper(ColourGradients::BLUE);
SpectralDataInfo info(44100, 4096, 4096);
const auto windowHeight = 100;

Expand Down

0 comments on commit dc5e514

Please sign in to comment.