Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions gui/config/plugins/ChorusPlugin/ChorusJUCE/ChorusPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
==============================================================================

This file is part of the JUCE framework examples.
Copyright (c) Raw Material Software Limited

The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

==============================================================================
*/

/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.

BEGIN_JUCE_PIP_METADATA

name: ChorusPlugin
version: 1.0.0
vendor: JUCE
website: oshe.io
description: Chorus audio plugin.

dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
juce_audio_plugin_client, juce_audio_processors,
juce_audio_utils, juce_core, juce_data_structures, juce_dsp,
juce_events, juce_graphics, juce_gui_basics, juce_gui_extra
exporter: Linux Makefile

moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1

type: AudioProcessor
mainClass: ChorusProcessor

useLocalCopy: 1

END_JUCE_PIP_METADATA

*******************************************************************************/

#pragma once


//==============================================================================
class ChorusProcessor final : public juce::AudioProcessor
{
public:

//==============================================================================
ChorusProcessor()
: juce::AudioProcessor (BusesProperties().withInput ("Input", juce::AudioChannelSet::stereo())
.withOutput ("Output", juce::AudioChannelSet::stereo()))
{
addParameter (gainParam = new juce::AudioParameterFloat ({ "gain", 1 }, "Gain", 0.0f, 1.0f, 0.5f));
addParameter (rate = new juce::AudioParameterFloat ({"rate", 1}, "Rate", 0.0f, 10.0f, 2.0f)); // rate is in Hz
addParameter (depth = new juce::AudioParameterFloat ({"depth", 1}, "Depth", 0.0f, 1.0f, 0.2f));
addParameter (delay = new juce::AudioParameterFloat ({ "delay", 1 }, "Delay", 1.0f, 100.0f, 7.0f)); // delay is in milliseconds
addParameter (feedback = new juce::AudioParameterFloat ({ "feedback", 1 }, "Feedback", 0.0f, 1.0f, 0.2f));
addParameter (mix = new juce::AudioParameterFloat ({ "mix", 1 }, "Mix", 0.0f, 1.0f, 0.5f));
}

//==============================================================================
void prepareToPlay (double sampleRate, int samplesPerBlock) override
{
// ProcessSpec is same structure for all JUCE DSP algorithms
juce::dsp::ProcessSpec spec;
spec.maximumBlockSize = samplesPerBlock;
spec.sampleRate = sampleRate;
spec.numChannels = getTotalNumOutputChannels();

// Initializes the chorus and gain processors
chorus.prepare (spec);
gain.prepare (spec);

// Sets values for chorus and gain parameters
gain.setGainLinear (gainParam->get());
chorus.setRate (rate->get());
chorus.setDepth (depth->get());
chorus.setCentreDelay (delay->get());
chorus.setFeedback (feedback->get());
chorus.setMix (mix->get());
}

void releaseResources() override {}

void processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer&) override
{
// Audio buffer converted to audio block for processing
juce::dsp::AudioBlock<float> audioBlock {buffer};

// Processes samples in audio block
chorus.process (juce::dsp::ProcessContextReplacing<float> (audioBlock));
gain.process (juce::dsp::ProcessContextReplacing<float> (audioBlock));
}

//==============================================================================
juce::AudioProcessorEditor* createEditor() override { return new juce::GenericAudioProcessorEditor (*this); }
bool hasEditor() const override { return true; }

//==============================================================================
const juce::String getName() const override { return "Chorus PlugIn"; }
bool acceptsMidi() const override { return false; }
bool producesMidi() const override { return false; }
double getTailLengthSeconds() const override { return 0; }

//==============================================================================
int getNumPrograms() override { return 1; }
int getCurrentProgram() override { return 0; }
void setCurrentProgram (int) override {}
const juce::String getProgramName (int) override { return "None"; }
void changeProgramName (int, const juce::String&) override {}

//==============================================================================
void getStateInformation (juce::MemoryBlock& destData) override
{
juce::MemoryOutputStream (destData, true).writeFloat (*gainParam);
juce::MemoryOutputStream (destData, true).writeFloat (*rate);
juce::MemoryOutputStream (destData, true).writeFloat (*depth);
juce::MemoryOutputStream (destData, true).writeFloat (*delay);
juce::MemoryOutputStream (destData, true).writeFloat (*feedback);
juce::MemoryOutputStream (destData, true).writeFloat (*mix);
}

void setStateInformation (const void* data, int sizeInBytes) override
{
gainParam->setValueNotifyingHost (juce::MemoryInputStream (data, static_cast<size_t> (sizeInBytes), false).readFloat());
rate->setValueNotifyingHost (juce::MemoryInputStream (data, static_cast<size_t> (sizeInBytes), false).readFloat());
depth->setValueNotifyingHost (juce::MemoryInputStream (data, static_cast<size_t> (sizeInBytes), false).readFloat());
delay->setValueNotifyingHost (juce::MemoryInputStream (data, static_cast<size_t> (sizeInBytes), false).readFloat());
feedback->setValueNotifyingHost (juce::MemoryInputStream (data, static_cast<size_t> (sizeInBytes), false).readFloat());
mix->setValueNotifyingHost (juce::MemoryInputStream (data, static_cast<size_t> (sizeInBytes), false).readFloat());
}

//==============================================================================
bool isBusesLayoutSupported (const BusesLayout& layouts) const override
{
const auto& mainInLayout = layouts.getChannelSet (true, 0);
const auto& mainOutLayout = layouts.getChannelSet (false, 0);

return (mainInLayout == mainOutLayout && (! mainInLayout.isDisabled()));
}

private:
//==============================================================================
juce::dsp::Gain<float> gain;
juce::dsp::Chorus<float> chorus;

juce::AudioParameterFloat* gainParam;
juce::AudioParameterFloat* rate;
juce::AudioParameterFloat* depth;
juce::AudioParameterFloat* delay;
juce::AudioParameterFloat* feedback;
juce::AudioParameterFloat* mix;

//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChorusProcessor)
};
Loading