From 09d21d5c9007040bc77d448a36b9a14188911d5a Mon Sep 17 00:00:00 2001 From: Archonic Date: Tue, 20 Jun 2023 22:59:03 -0400 Subject: [PATCH] Added 'bend resolution' slider This allows for pitch bend to be quantized into semitones (or smaller increments) for a more 'chipped' feel. --- Source/AdvancedParamsComponent.cpp | 6 +++++- Source/AdvancedParamsComponent.h | 2 ++ Source/PluginEditor.cpp | 2 +- Source/PluginProcessor.cpp | 5 ++++- Source/PulseVoice.h | 2 +- Source/Settings.h | 5 ++++- Source/TonalVoice.cpp | 3 ++- 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Source/AdvancedParamsComponent.cpp b/Source/AdvancedParamsComponent.cpp index a2c27a6..e5eb986 100644 --- a/Source/AdvancedParamsComponent.cpp +++ b/Source/AdvancedParamsComponent.cpp @@ -59,7 +59,10 @@ AdvancedParamsComponent::AdvancedParamsComponent (Magical8bitPlug2AudioProcessor coarseOrFineChoice.reset (new ChoiceComponent (p, "pitchSequenceMode_raw", "Resolution")); addAndMakeVisible (coarseOrFineChoice.get()); coarseOrFineChoice->setName ("Coarse or fine"); - + + bendResolutionSlider.reset(new SliderComponent(p, "bendResolution", "Bend Reso")); + addAndMakeVisible(bendResolutionSlider.get()); + bendResolutionSlider->setName("bend resolution component"); //[UserPreSize] //[/UserPreSize] @@ -109,6 +112,7 @@ void AdvancedParamsComponent::resized() pitchCompo->setBounds (0, 82, getWidth() - 204, 56); dutyCompo->setBounds (0, 138, getWidth() - 160, 56); coarseOrFineChoice->setBounds (getWidth() - 4 - 200, 86, 200, 28); + bendResolutionSlider->setBounds(0, 200, getWidth() - 50, 80); //[UserResized] Add your own custom resize handling here.. //[/UserResized] } diff --git a/Source/AdvancedParamsComponent.h b/Source/AdvancedParamsComponent.h index 3d7e7e1..b655f0f 100644 --- a/Source/AdvancedParamsComponent.h +++ b/Source/AdvancedParamsComponent.h @@ -23,6 +23,7 @@ #include "../JuceLibraryCode/JuceHeader.h" #include "CustomEnvelopeComponent.h" #include "ChoiceComponent.h" +#include "SliderComponent.h" //[/Headers] @@ -62,6 +63,7 @@ private: std::unique_ptr pitchCompo; std::unique_ptr dutyCompo; std::unique_ptr coarseOrFineChoice; + std::unique_ptr bendResolutionSlider; //============================================================================== diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index dfc759e..17fed26 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -156,7 +156,7 @@ struct + genericControlHeight * 4; const int advCompoHeight = componentMargin * 2 + indexHeight - + customEnvelopeHeight * 3; + + customEnvelopeHeight * 4; const int totalHeight (bool isAdvOptOn, bool isMono) { int retHeight = topMargin diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index dca5428..01e7a21 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -121,7 +121,10 @@ Magical8bitPlug2AudioProcessor::Magical8bitPlug2AudioProcessor() std::make_unique ("isVolumeSequenceEnabled_raw", "Enabled", false), std::make_unique ("isPitchSequenceEnabled_raw", "Enabled", false), std::make_unique ("isDutySequenceEnabled_raw", "Enabled", false), - std::make_unique ("pitchSequenceMode_raw", "Mode", StringArray ({"Coarse", "Fine"}), 0) + std::make_unique ("pitchSequenceMode_raw", "Mode", StringArray ({"Coarse", "Fine"}), 0), + //Pitch steps + //0 is max resolution, 1 will cause pitch bend to only work in semitones + std::make_unique ("bendResolution", "Bend Resolution", 0.0f, 1.0f, 1.0f) } ) , settingRefs (¶meters) diff --git a/Source/PulseVoice.h b/Source/PulseVoice.h index 97c5340..4f845a2 100644 --- a/Source/PulseVoice.h +++ b/Source/PulseVoice.h @@ -7,7 +7,7 @@ ============================================================================== */ - + #pragma once #include "TonalVoice.h" diff --git a/Source/Settings.h b/Source/Settings.h index 5afbd4d..d132e8b 100644 --- a/Source/Settings.h +++ b/Source/Settings.h @@ -146,6 +146,8 @@ struct SettingRefs float* isPitchSequenceEnabled_raw = nullptr; float* isDutySequenceEnabled_raw = nullptr; float* pitchSequenceMode_raw = nullptr; + //pitch resolution + float* bendResolution = nullptr; FrameSequence volumeSequence; FrameSequence pitchSequence; @@ -223,6 +225,7 @@ struct SettingRefs isPitchSequenceEnabled_raw = (float*) parameters->getRawParameterValue ("isPitchSequenceEnabled_raw"); isDutySequenceEnabled_raw = (float*) parameters->getRawParameterValue ("isDutySequenceEnabled_raw"); pitchSequenceMode_raw = (float*) parameters->getRawParameterValue ("pitchSequenceMode_raw"); - + //Pitch resolution + bendResolution = (float*) parameters->getRawParameterValue("bendResolution"); } }; diff --git a/Source/TonalVoice.cpp b/Source/TonalVoice.cpp index e98e3a9..13b438d 100644 --- a/Source/TonalVoice.cpp +++ b/Source/TonalVoice.cpp @@ -79,7 +79,6 @@ void TonalVoice::calculateAngleDelta() + currentAutoBendAmount + vibratoAmount + finePitchInSeq; - auto cyclesPerSecond = noteNoToHeltzDouble (noteNoInDouble); auto cyclesPerSample = cyclesPerSecond / getSampleRate(); @@ -203,6 +202,8 @@ void TonalVoice::shiftNoteBuffer(int index) { double TonalVoice::noteNoToHeltzDouble (double noteNoInDouble, const double frequencyOfA) { + double resolution = 1.0 - (*settingRefs->bendResolution); //in the equation, 0 is max res and 1 is 1 semitone + noteNoInDouble = floor(noteNoInDouble/resolution)*resolution; return frequencyOfA * std::pow (2.0, (noteNoInDouble - 69) / 12.0); }