diff --git a/Release/Windows/Standalone/Crille Bass Strip.exe b/Release/Windows/Standalone/Crille Bass Strip.exe index 81cdeb4..b5b7d51 100644 Binary files a/Release/Windows/Standalone/Crille Bass Strip.exe and b/Release/Windows/Standalone/Crille Bass Strip.exe differ diff --git a/Release/Windows/VST3/Crille Bass Strip.vst3/Contents/x86_64-win/Crille Bass Strip.vst3 b/Release/Windows/VST3/Crille Bass Strip.vst3/Contents/x86_64-win/Crille Bass Strip.vst3 index 087571a..a671f14 100644 Binary files a/Release/Windows/VST3/Crille Bass Strip.vst3/Contents/x86_64-win/Crille Bass Strip.vst3 and b/Release/Windows/VST3/Crille Bass Strip.vst3/Contents/x86_64-win/Crille Bass Strip.vst3 differ diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index f7d0dae..814b679 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -212,6 +212,135 @@ void CrilleBassStripAudioProcessorEditor::LevelMeter::paint( ); } +CrilleBassStripAudioProcessorEditor::TunerDisplay::TunerDisplay() +{ + setInterceptsMouseClicks(false, false); +} + +void CrilleBassStripAudioProcessorEditor::TunerDisplay::setFrequency( + float newFrequencyHz) +{ + frequencyHz = newFrequencyHz; + repaint(); +} + +void CrilleBassStripAudioProcessorEditor::TunerDisplay::paint( + juce::Graphics& g) +{ + auto bounds = getLocalBounds(); + const bool hasSignal = frequencyHz > 0.0f; + + g.setColour(juce::Colour(0xff777f89)); + g.setFont(juce::Font(10.0f, juce::Font::bold)); + g.drawText( + "INPUT", + bounds.removeFromTop(14), + juce::Justification::centred); + + if (!hasSignal) + { + g.setColour(juce::Colour(0xfff0f1f2)); + g.setFont(juce::Font(26.0f, juce::Font::bold)); + g.drawText("--", 0, 14, getWidth(), 30, juce::Justification::centred); + + g.setColour(juce::Colour(0xffaeb4bc)); + g.setFont(10.0f); + g.drawText("-- Hz", 0, 43, getWidth(), 15, juce::Justification::centred); + + g.setColour(juce::Colour(0xff454a51)); + g.drawLine(18.0f, 70.0f, static_cast(getWidth() - 18), 70.0f, 2.0f); + g.fillEllipse(static_cast(getWidth()) * 0.5f - 4.0f, 66.0f, 8.0f, 8.0f); + + g.setColour(juce::Colour(0xff686e76)); + g.setFont(9.0f); + g.drawText("PLAY A NOTE", 0, 78, getWidth(), 16, juce::Justification::centred); + return; + } + + const float midiNote = + 69.0f + 12.0f * std::log2(frequencyHz / 440.0f); + + const int nearestMidiNote = + static_cast(std::round(midiNote)); + + const float targetFrequency = + 440.0f * std::pow( + 2.0f, + static_cast(nearestMidiNote - 69) / 12.0f); + + const float cents = + 1200.0f * std::log2(frequencyHz / targetFrequency); + + const bool inTune = std::abs(cents) <= 5.0f; + const auto noteName = frequencyToNoteName(targetFrequency); + + g.setColour(inTune + ? juce::Colour(0xff45c95a) + : juce::Colour(0xfff0f1f2)); + g.setFont(juce::Font(26.0f, juce::Font::bold)); + g.drawText(noteName, 0, 14, getWidth(), 30, juce::Justification::centred); + + g.setColour(juce::Colour(0xffaeb4bc)); + g.setFont(10.0f); + g.drawText( + juce::String(frequencyHz, 1) + " Hz", + 0, + 43, + getWidth(), + 15, + juce::Justification::centred); + + const float centreX = static_cast(getWidth()) * 0.5f; + const float indicatorY = 70.0f; + const auto orange = juce::Colour(0xffe5a536); + const auto inactive = juce::Colour(0xff454a51); + const auto green = juce::Colour(0xff45c95a); + + g.setColour(juce::Colour(0xff3c424a)); + g.drawLine(20.0f, indicatorY, static_cast(getWidth() - 20), indicatorY, 2.0f); + + juce::Path leftArrow; + leftArrow.addTriangle( + 12.0f, indicatorY, + 28.0f, indicatorY - 9.0f, + 28.0f, indicatorY + 9.0f); + + juce::Path rightArrow; + rightArrow.addTriangle( + static_cast(getWidth() - 12), indicatorY, + static_cast(getWidth() - 28), indicatorY - 9.0f, + static_cast(getWidth() - 28), indicatorY + 9.0f); + + g.setColour(!inTune && cents > 5.0f ? orange : inactive); + g.fillPath(leftArrow); + + g.setColour(!inTune && cents < -5.0f ? orange : inactive); + g.fillPath(rightArrow); + + g.setColour(inTune ? green : juce::Colour(0xff686e76)); + g.fillEllipse(centreX - 5.0f, indicatorY - 5.0f, 10.0f, 10.0f); + + g.setColour(inTune ? green : orange); + g.setFont(juce::Font(9.0f, juce::Font::bold)); + + juce::String statusText; + + if (inTune) + statusText = "IN TUNE"; + else if (cents < 0.0f) + statusText = "TUNE UP " + juce::String(std::round(std::abs(cents)), 0) + " ct"; + else + statusText = "TUNE DOWN " + juce::String(std::round(std::abs(cents)), 0) + " ct"; + + g.drawText( + statusText, + 0, + 80, + getWidth(), + 16, + juce::Justification::centred); +} + CrilleBassStripAudioProcessorEditor::SectionToggleButton:: SectionToggleButton( const juce::String& sectionName, @@ -295,6 +424,8 @@ CrilleBassStripAudioProcessorEditor( ); addAndMakeVisible(downTuneButton); + addAndMakeVisible(tunerToggleButton); + addAndMakeVisible(tunerDisplay); downTuneAttachment = std::make_unique< @@ -306,6 +437,14 @@ CrilleBassStripAudioProcessorEditor( downTuneButton ); + tunerToggleAttachment = + std::make_unique< + juce::AudioProcessorValueTreeState::ButtonAttachment + >( + processor.apvts, + "tunerOn", + tunerToggleButton); + addAndMakeVisible(gateToggleButton); addAndMakeVisible(compressorToggleButton); addAndMakeVisible(distortionToggleButton); @@ -544,6 +683,11 @@ void CrilleBassStripAudioProcessorEditor::timerCallback() { updateSectionStates(); + const bool tunerEnabled = tunerToggleButton.getToggleState(); + tunerDisplay.setVisible(tunerEnabled); + tunerDisplay.setFrequency( + tunerEnabled ? processor.getDetectedFrequencyHz() : 0.0f); + smoothedGateDb = smoothMeter( smoothedGateDb, @@ -678,136 +822,75 @@ void CrilleBassStripAudioProcessorEditor::paint( 38, juce::Justification::centred); - const float inputFrequency = - processor.getDetectedFrequencyHz(); + const bool tunerEnabled = tunerToggleButton.getToggleState(); - const bool downTuneEnabled = - processor.apvts - .getRawParameterValue("downTuneOn") - ->load() > 0.5f; + if (tunerEnabled) + { + const float inputFrequency = + processor.getDetectedFrequencyHz(); - const float outputFrequency = - downTuneEnabled - ? transposeFrequency( - inputFrequency, - -1 - ) - : inputFrequency; + const bool downTuneEnabled = + processor.apvts + .getRawParameterValue("downTuneOn") + ->load() > 0.5f; - const auto inputNote = - frequencyToNoteName(inputFrequency); + const float outputFrequency = + downTuneEnabled + ? transposeFrequency( + inputFrequency, + -1 + ) + : inputFrequency; - const auto outputNote = - frequencyToNoteName(outputFrequency); + const auto outputNote = + frequencyToNoteName(outputFrequency); - g.setColour(juce::Colour(0xff777f89)); - g.setFont( - juce::Font( - 11.0f, - juce::Font::bold - ) - ); + g.setColour(juce::Colour(0xff777f89)); + g.setFont(juce::Font(11.0f, juce::Font::bold)); - g.drawText( - "INPUT", - 30, - 220, - 150, - 18, - juce::Justification::centred - ); + g.drawText( + "OUTPUT", + 30, + 300, + 150, + 16, + juce::Justification::centred + ); - g.setColour(juce::Colour(0xfff0f1f2)); - g.setFont( - juce::Font( - 28.0f, - juce::Font::bold - ) - ); + g.setColour( + downTuneEnabled + ? juce::Colour(0xffffc247) + : juce::Colour(0xfff0f1f2) + ); - g.drawText( - inputNote, - 30, - 238, - 150, - 36, - juce::Justification::centred - ); + g.setFont(juce::Font(27.0f, juce::Font::bold)); - g.setColour(juce::Colour(0xffaeb4bc)); - g.setFont(11.0f); + g.drawText( + outputNote, + 30, + 315, + 150, + 30, + juce::Justification::centred + ); - const auto inputFrequencyText = - inputFrequency > 0.0f - ? juce::String(inputFrequency, 1) - + " Hz" - : "-- Hz"; + g.setColour(juce::Colour(0xffaeb4bc)); + g.setFont(10.0f); - g.drawText( - inputFrequencyText, - 30, - 270, - 150, - 20, - juce::Justification::centred - ); + const auto outputFrequencyText = + outputFrequency > 0.0f + ? juce::String(outputFrequency, 1) + " Hz" + : "-- Hz"; - g.setColour(juce::Colour(0xff777f89)); - g.setFont( - juce::Font( - 11.0f, - juce::Font::bold - ) - ); - - g.drawText( - "OUTPUT", - 30, - 292, - 150, - 18, - juce::Justification::centred - ); - - g.setColour( - downTuneEnabled - ? juce::Colour(0xffffc247) - : juce::Colour(0xfff0f1f2) - ); - - g.setFont( - juce::Font( - 28.0f, - juce::Font::bold - ) - ); - - g.drawText( - outputNote, - 30, - 310, - 150, - 36, - juce::Justification::centred - ); - - g.setColour(juce::Colour(0xffaeb4bc)); - g.setFont(11.0f); - - const auto outputFrequencyText = - outputFrequency > 0.0f - ? juce::String(outputFrequency, 1) - + " Hz" - : "-- Hz"; - - g.drawText( - outputFrequencyText, - 30, - 342, - 150, - 20, - juce::Justification::centred - ); + g.drawText( + outputFrequencyText, + 30, + 342, + 150, + 16, + juce::Justification::centred + ); + } const auto latencyText = "LATENCY: " @@ -863,11 +946,25 @@ void CrilleBassStripAudioProcessorEditor::resized() downTuneButton.setBounds( 35, - 135, + 120, 140, 50 ); + tunerToggleButton.setBounds( + 50, + 175, + 110, + 30 + ); + + tunerDisplay.setBounds( + 30, + 210, + 150, + 100 + ); + gateInputMeter.setBounds( 215, 125, diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 94336b7..e80ca70 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -54,6 +54,18 @@ private: juce::Colour sectionColour; }; + class TunerDisplay final : public juce::Component + { + public: + TunerDisplay(); + + void setFrequency(float newFrequencyHz); + void paint(juce::Graphics& g) override; + + private: + float frequencyHz = 0.0f; + }; + struct Knob { juce::Slider slider; @@ -74,6 +86,17 @@ private: juce::AudioProcessorValueTreeState::ButtonAttachment> downTuneAttachment; + SectionToggleButton tunerToggleButton { + "TUNER", + juce::Colour(0xffe5a536) + }; + + std::unique_ptr< + juce::AudioProcessorValueTreeState::ButtonAttachment> + tunerToggleAttachment; + + TunerDisplay tunerDisplay; + SectionToggleButton gateToggleButton { "NOISE GATE", juce::Colour(0xffe5a536) diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index bbdb242..9be45d9 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -27,6 +27,11 @@ juce::AudioProcessorValueTreeState::ParameterLayout CrilleBassStripAudioProcesso "DownTune", false)); + p.add(std::make_unique( + pid("tunerOn"), + "Tuner On", + false)); + p.add(std::make_unique( pid("gateOn"), "Gate On", @@ -492,13 +497,25 @@ void CrilleBassStripAudioProcessor::processBlock( const bool eqEnabled = apvts.getRawParameterValue("eqOn")->load() > 0.5f; - if (buffer.getNumChannels() > 0) + const bool tunerEnabled = + apvts.getRawParameterValue("tunerOn")->load() > 0.5f; + + if (tunerEnabled && buffer.getNumChannels() > 0) { updatePitchDetector( buffer.getReadPointer(0), numSamples ); } + else + { + detectedFrequencyHz.store( + 0.0f, + std::memory_order_relaxed); + + pitchSamplesCollected = 0; + pitchAnalysisCounter = 0; + } // Clear output channels that do not contain input data. for (int c = getTotalNumInputChannels();