Skip to content

Commit

Permalink
Trying to fix more failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Aug 4, 2023
1 parent 74750c1 commit 3f54762
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4324)

namespace chowdsp
{
/**
Expand Down Expand Up @@ -78,3 +80,5 @@ class UIToAudioPipeline
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UIToAudioPipeline)
};
} // namespace chowdsp

JUCE_END_IGNORE_WARNINGS_MSVC
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ void BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<! std::is_sam
template <typename SampleType, typename DelayInterpType>
void BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<! std::is_same_v<DelayInterpType, std::nullptr_t>>>::setLatencySamplesInternal (NumericType delaySamples)
{
if (delaySamples == prevDelay)
if (juce::approximatelyEqual (delaySamples, prevDelay))
return;

compDelay.setDelay ((NumericType) delaySamples);

if (delaySamples == 0)
if (juce::approximatelyEqual (delaySamples, (NumericType) 0))
compDelay.reset();

prevDelay = delaySamples;
Expand All @@ -126,7 +126,7 @@ bool BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<! std::is_sam

auto doDelayOp = [] (auto& sampleBuffer, auto& delay, DelayOp op)
{
if (delay.getDelay() == NumericType (0))
if (juce::approximatelyEqual (delay.getDelay(), NumericType (0)))
return;

for (int ch = 0; ch < sampleBuffer.getNumChannels(); ++ch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<std::is_same
/** Converts a parameter handle to a boolean */
static bool toBool (const std::atomic<float>* param)
{
return static_cast<bool> (param->load());
return ! juce::approximatelyEqual (param->load(), 0.0f);
}

/** Allocated required memory, and resets the property */
Expand Down Expand Up @@ -74,7 +74,7 @@ class BypassProcessor<SampleType, DelayInterpType, std::enable_if_t<! std::is_sa
/** Converts a parameter handle to a boolean */
static bool toBool (const std::atomic<float>* param)
{
return static_cast<bool> (param->load());
return ! juce::approximatelyEqual (param->load(), 0.0f);
}

/** Allocated required memory, and resets the property */
Expand Down
5 changes: 4 additions & 1 deletion modules/dsp/chowdsp_dsp_utils/Processors/chowdsp_Gain.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class Gain
[[nodiscard]] double getRampDurationSeconds() const noexcept { return rampDurationSeconds; }

/** Returns true if the current value is currently being interpolated. */
[[nodiscard]] bool isSmoothing() const noexcept { return gain.isSmoothing() || gainTargetLinear != gain.getCurrentValue(); }
[[nodiscard]] bool isSmoothing() const noexcept
{
return gain.isSmoothing() || ! juce::approximatelyEqual (gainTargetLinear, gain.getCurrentValue());
}

//==============================================================================
/** Called before processing starts. */
Expand Down
3 changes: 3 additions & 0 deletions modules/dsp/chowdsp_math/Math/chowdsp_PowApprox.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wstrict-aliasing")

namespace chowdsp
{
/**
Expand Down Expand Up @@ -157,3 +159,4 @@ namespace PowApprox
}
} // namespace PowApprox
} // namespace chowdsp
JUCE_END_IGNORE_WARNINGS_GCC_LIKE
2 changes: 1 addition & 1 deletion modules/gui/chowdsp_foleys/GuiItems/chowdsp_PresetsItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PresetsItem : public foleys::GuiItem

[[nodiscard]] std::vector<foleys::SettableProperty> getSettableProperties() const override
{
std::function<void (juce::ComboBox&)> createAssetFilesMenuLambda = [=] (juce::ComboBox&)
std::function<void (juce::ComboBox&)> createAssetFilesMenuLambda = [this] (juce::ComboBox&)
{
magicBuilder.getMagicState().createAssetFilesMenu();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void InfoComp<ProcType, InfoProvider>::paint (juce::Graphics& g)
auto font = g.getCurrentFont();
auto b = getLocalBounds();

auto drawText = [=, &g, &b] (const juce::String& text)
auto drawText = [&font, &g, &b] (const juce::String& text)
{
auto w = font.getStringWidth (text);
g.drawFittedText (text, b.removeFromLeft (w), juce::Justification::left, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void TitleComp::paint (juce::Graphics& g)
auto curFont = g.getCurrentFont();
auto b = getLocalBounds();

auto drawText = [=, &g, &b] (const juce::String& text)
auto drawText = [&curFont, &g, &b] (const juce::String& text)
{
auto width = curFont.getStringWidth (text);
g.drawFittedText (text, b.removeFromLeft (width), juce::Justification::left, 1);
Expand All @@ -29,7 +29,7 @@ void TitleComp::paint (juce::Graphics& g)

void TitleComp::setStrings (const juce::String& newTitle, const juce::String& newSubtitle, float newFont)
{
font = newFont == 0.0f ? (float) getHeight() : newFont;
font = juce::exactlyEqual (newFont, 0.0f) ? (float) getHeight() : newFont;

title = newTitle;
subtitle = newSubtitle;
Expand Down
16 changes: 8 additions & 8 deletions modules/gui/chowdsp_gui/Presets/chowdsp_PresetsComp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ PresetsComp::PresetsComp (PresetManager& presetManager) : manager (presetManager
presetNameEditor.setMultiLine (false, false);
presetNameEditor.setJustification (juce::Justification::centred);

auto setupNextPrevButton = [=] (juce::DrawableButton& button, bool forward)
auto setupNextPrevButton = [this] (juce::DrawableButton& button, bool forward)
{
addAndMakeVisible (button);
button.setWantsKeyboardFocus (false);
button.setTitle ("Go to " + juce::String (forward ? "next" : "previous") + " preset");
button.setColour (juce::ComboBox::outlineColourId, juce::Colours::transparentBlack);
button.setColour (juce::TextButton::buttonColourId, juce::Colours::transparentBlack);
button.onClick = [=]
button.onClick = [this]
{ goToNextPreset (forward); };
};

Expand Down Expand Up @@ -175,7 +175,7 @@ int PresetsComp::createPresetsMenu (int optionID)

juce::PopupMenu::Item presetItem { preset.getName() };
presetItem.itemID = presetID + 1;
presetItem.action = [=, &preset]
presetItem.action = [this, &preset]
{
updatePresetBoxText();
manager.loadPreset (preset);
Expand Down Expand Up @@ -351,7 +351,7 @@ void PresetsComp::chooseUserPresetFolder (const std::function<void()>& onFinish)
constexpr auto folderChooserFlags = juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories;
fileChooser = std::make_shared<juce::FileChooser> ("Choose User Preset Folder");
{
fileChooser->launchAsync (folderChooserFlags, [=] (const juce::FileChooser& chooser)
fileChooser->launchAsync (folderChooserFlags, [this] (const juce::FileChooser& chooser)
{
manager.setUserPresetPath (chooser.getResult());

Expand All @@ -368,7 +368,7 @@ void PresetsComp::saveUserPreset()
presetNameEditor.grabKeyboardFocus();
presetNameEditor.setHighlightedRegion ({ 0, 100 });

presetNameEditor.onReturnKey = [=]
presetNameEditor.onReturnKey = [this]
{
presetNameEditor.setVisible (false);

Expand All @@ -377,7 +377,7 @@ void PresetsComp::saveUserPreset()
if (presetPath == juce::File() || ! presetPath.isDirectory())
{
presetPath.deleteRecursively();
chooseUserPresetFolder ([=]
chooseUserPresetFolder ([this]
{ savePresetFile (presetName + presetExt); });
}
else
Expand All @@ -386,13 +386,13 @@ void PresetsComp::saveUserPreset()
}
};

presetNameEditor.onEscapeKey = [=]
presetNameEditor.onEscapeKey = [this]
{
presetNameEditor.setVisible (false);
updatePresetBoxText();
};

presetNameEditor.onFocusLost = [=]
presetNameEditor.onFocusLost = [this]
{
presetNameEditor.setVisible (false);
updatePresetBoxText();
Expand Down
2 changes: 1 addition & 1 deletion tests/common_tests/chowdsp_units_test/TimeUnitsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST_CASE ("Time Units Test", "[common][units]")
constexpr auto tt_samples = Time<Samples> { 1000.0f, 1000.0f };
constexpr auto ttt_sec = Time<Seconds> { tt_samples };
constexpr auto ttt_samples = Time<Samples> { ttt_sec, 500.0f };
REQUIRE_MESSAGE (ttt_samples.value() == 500.0f, ttt_samples << " should be equal to " << 500.0f);
REQUIRE_MESSAGE (juce::approximatelyEqual (ttt_samples.value(), 500.0f), ttt_samples << " should be equal to " << 500.0f);
}

SECTION ("Integer Samples")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TEST_CASE ("Repitched Source Test", "[dsp][sources][resampling]")
sineProc.prepare ({ fs, (juce::uint32) blockSize, 1 });
sineProc.sine.setFrequency (sineFreq);
sineProc.setRepitchFactor (repitchFactor);
REQUIRE_MESSAGE (sineProc.getRepitchFactor() == repitchFactor, "Set repitch factor is incorrect!");
REQUIRE_MESSAGE (juce::exactlyEqual (sineProc.getRepitchFactor(), repitchFactor), "Set repitch factor is incorrect!");

chowdsp::TunerProcessor<float> tuner;
tuner.prepare (fs);
Expand Down
4 changes: 2 additions & 2 deletions tests/dsp_tests/chowdsp_dsp_utils_test/GainTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ TEMPLATE_TEST_CASE ("Gain Test", "[dsp][misc]", float, double, xsimd::batch<floa
chowdsp::Gain<T> gain;

gain.setGainLinear ((NumericType) 2);
REQUIRE_MESSAGE (gain.getGainLinear() == (NumericType) 2, "Set linear gain is incorrect!");
REQUIRE_MESSAGE (juce::exactlyEqual (gain.getGainLinear(), (NumericType) 2), "Set linear gain is incorrect!");
REQUIRE_MESSAGE (gain.getGainDecibels() == Catch::Approx ((NumericType) 6).margin (0.03), "Get Decibels gain is incorrect!");

gain.setGainDecibels ((NumericType) -6);
REQUIRE_MESSAGE (gain.getGainDecibels() == Catch::Approx ((NumericType) -6).margin (1.0e-6), "Set Decibels gain is incorrect!");
REQUIRE_MESSAGE (gain.getGainLinear() == Catch::Approx ((NumericType) 0.5).margin (0.02), "Get linear gain is incorrect!");

gain.setRampDurationSeconds (0.05);
REQUIRE_MESSAGE (gain.getRampDurationSeconds() == 0.05, "Set ramp duration is incorrect!");
REQUIRE_MESSAGE (juce::exactlyEqual (gain.getRampDurationSeconds(), 0.05), "Set ramp duration is incorrect!");
}

SECTION ("Smooth Gain Test")
Expand Down
2 changes: 1 addition & 1 deletion tests/dsp_tests/chowdsp_sources_test/SawtoothTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ TEST_CASE ("Sawtooth Test", "[dsp][sources]")
testOsc.setFrequency (0.0f);

for (int i = 0; i < 10; ++i)
REQUIRE_MESSAGE (testOsc.processSample() == 0.0f, "Zero Hz output is non-zero!");
REQUIRE_MESSAGE (juce::approximatelyEqual (testOsc.processSample(), 0.0f), "Zero Hz output is non-zero!");
}
}
2 changes: 1 addition & 1 deletion tests/dsp_tests/chowdsp_sources_test/SquareTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ TEST_CASE ("Square Test", "[dsp][sources]")
testOsc.setFrequency (0.0f);

for (int i = 0; i < 10; ++i)
REQUIRE_MESSAGE (testOsc.processSample() == 0.0f, "Zero Hz output is non-zero!");
REQUIRE_MESSAGE (juce::approximatelyEqual (testOsc.processSample(), 0.0f), "Zero Hz output is non-zero!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ TEST_CASE ("Equalizer Plot Test", "[visualizers][EQ]")
juce::MessageManager::getInstance()->runDispatchLoopUntil (100);

const auto testScreenshot = plotComp.createComponentSnapshot ({ 500, 300 });
// VizTestUtils::saveImage (testScreenshot, "eq_response_plot.png");
// VizTestUtils::saveImage (testScreenshot, "eq_response_plot.png");

const auto refScreenshot = VizTestUtils::loadImage ("eq_response_plot.png");
VizTestUtils::compareImages (testScreenshot, refScreenshot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST_CASE ("Generic Filter Plot Test", "[visualizers]")
};

const auto [freqAxis, magAxis] = plotter.plotFilterMagnitudeResponse();
REQUIRE (freqAxis.size() == (1 << plotter.params.fftOrder) / 2 + 1);
REQUIRE (freqAxis.size() == size_t (1 << plotter.params.fftOrder) / 2 + 1);
REQUIRE (magAxis.size() == freqAxis.size());
for (auto& mag : magAxis)
REQUIRE (juce::approximatelyEqual (mag, 0.0f));
Expand Down Expand Up @@ -58,7 +58,7 @@ TEST_CASE ("Generic Filter Plot Test", "[visualizers]")

TestComponent comp {};
const auto testScreenshot = comp.createComponentSnapshot ({ 500, 300 });
// VizTestUtils::saveImage (testScreenshot, "generic_filter_plot.png");
// VizTestUtils::saveImage (testScreenshot, "generic_filter_plot.png");

const auto refScreenshot = VizTestUtils::loadImage ("generic_filter_plot.png");
VizTestUtils::compareImages (testScreenshot, refScreenshot);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/gui_tests/chowdsp_visualizers_test/Images/waveshaper_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TEST_CASE ("Spectrum Plot Base Test", "[visualizers]")

TestComp comp {};
const auto testScreenshot = comp.createComponentSnapshot ({ 500, 300 });
// VizTestUtils::saveImage (testScreenshot, "freq_grid_plot.png");
// VizTestUtils::saveImage (testScreenshot, "freq_grid_plot.png");

const auto refScreenshot = VizTestUtils::loadImage ("freq_grid_plot.png");
VizTestUtils::compareImages (testScreenshot, refScreenshot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ TEST_CASE ("Plugin Logger Test", "[plugin][utilities]")
{
auto prevNumTopLevelWindows = juce::TopLevelWindow::getNumTopLevelWindows();
chowdsp::PluginLogger logger { logFileSubDir, logFileNameRoot };
juce::MessageManager::getInstance()->runDispatchLoopUntil (100);

auto newNumTopLevelWindows = juce::TopLevelWindow::getNumTopLevelWindows();
REQUIRE_MESSAGE (newNumTopLevelWindows == prevNumTopLevelWindows + 1, "AlertWindow not created!");
Expand Down

0 comments on commit 3f54762

Please sign in to comment.