ok, it says new users can’t upload attachments. So, I’ll just paste it here.
PluginEditor.cpp
==============================================================================
This file contains the basic framework code for a JUCE plugin editor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include <JuceHeader.h>
//==============================================================================
VibeSynthAudioProcessorEditor::VibeSynthAudioProcessorEditor (VibeSynthAudioProcessor& p) //VibeSynthAudioProcessor& p
: AudioProcessorEditor (&p)
, audioProcessor (p)
{
//juce::AudioProcessorEditor::AudioProcessorEditor(getAudioProcessor()& )
// Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be.
setSize (400, 300);
//setVisible(true);
}
//mastergain slider stuff
// masterGainSlider.setSliderStyle(juce::Slider::LinearBarVertical);
// masterGainSlider.setTextBoxStyle(juce::Slider::TextBoxBelow, false, 10, 50);
// masterGainSlider.setPopupDisplayEnabled (true, false, this);
// masterGainSlider.setRange(0.0, 1, 0.1);
// masterGainSlider.setValue(1.0);
// addAndMakeVisible(&masterGainSlider);
//}
VibeSynthAudioProcessorEditor::~VibeSynthAudioProcessorEditor()
{
}
//==============================================================================
//void VibeSynthAudioProcessorEditor::paint (juce::Graphics& g)
//{
// // (Our component is opaque, so we must completely fill the background with a solid colour)
// g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));
//
// g.setColour (juce::Colours::white);
// g.setFont (15.0f);
// g.drawFittedText ("Hello World!", getLocalBounds(), juce::Justification::centred, 1);
//}
void VibeSynthAudioProcessorEditor::paint (juce::Graphics& g)
{
// fill the whole window white
g.fillAll (juce::Colours::white);
// set the current drawing colour to black
g.setColour (juce::Colours::black);
// set the font size and draw text to the screen
g.setFont (15.0f);
g.drawFittedText ("Midi Volume", 0, 0, getWidth(), 30, juce::Justification::centred, 1);
}
void VibeSynthAudioProcessorEditor::resized()
{
// This is generally where you'll want to lay out the positions of any
// subcomponents in your editor..
//gets the bounds wen users resize window, bounds updates
// auto bounds = getLocalBounds();
// const int componentSize{100};
masterGainSlider.setBounds(40, 30, 20, getHeight() - 60); //(x,y, width, height)
}
/*
void VibeSynthAudioProcessorEditor::closedButtonPressed()
{
juce::JUCEApplicationBase::getInstance()->systemRequestedQuit();
}
void VibeSynthAudioProcessorEditor::shutdown()
{
mainWindow = nullptr;
}
*/
PluginEditor.h
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin editor.
==============================================================================
*/
#pragma once
#include <JuceHeader.h>
#include "PluginProcessor.h"
//==============================================================================
/**
*/
class VibeSynthAudioProcessorEditor : public juce::AudioProcessorEditor //(name, Colours::white,
//VibeSynthAudioProcessorEditor::allButtons)
{
public:
VibeSynthAudioProcessorEditor (VibeSynthAudioProcessorEditor&);//VibeSynthAudioProcessor&
~VibeSynthAudioProcessorEditor() override;
//==============================================================================
void paint (juce::Graphics&) override;
void resized() override;
/*
void closedButtonPressed();
void shutdown();
*/
private:
// This reference is provided as a quick way for your editor to
// access the processor object that created it.
VibeSynthAudioProcessorEditor& audioProcessor;
std::unique_ptr<VibeSynthAudioProcessorEditor> mainWindow;
juce::Slider masterGainSlider;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VibeSynthAudioProcessorEditor)
};
PluginProcessor.cpp
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
//==============================================================================
VibeSynthAudioProcessor::VibeSynthAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", juce::AudioChannelSet::stereo(), true)
#endif
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)
#endif
)//, apvts(*this, nullptr, "Parameters", createParameters())
#endif
{
synth.addSound(new SynthSound());
synth.addVoice(new SynthVoice());
}
VibeSynthAudioProcessor::~VibeSynthAudioProcessor()
{
}
//==============================================================================
const juce::String VibeSynthAudioProcessor::getName() const
{
return JucePlugin_Name;
}
bool VibeSynthAudioProcessor::acceptsMidi() const
{
#if JucePlugin_WantsMidiInput
return true;
#else
return false;
#endif
}
bool VibeSynthAudioProcessor::producesMidi() const
{
#if JucePlugin_ProducesMidiOutput
return true;
#else
return false;
#endif
}
bool VibeSynthAudioProcessor::isMidiEffect() const
{
#if JucePlugin_IsMidiEffect
return true;
#else
return false;
#endif
}
double VibeSynthAudioProcessor::getTailLengthSeconds() const
{
return 0.0;
}
int VibeSynthAudioProcessor::getNumPrograms()
{
return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
// so this should be at least 1, even if you're not really implementing programs.
}
int VibeSynthAudioProcessor::getCurrentProgram()
{
return 0;
}
void VibeSynthAudioProcessor::setCurrentProgram (int index)
{
}
const juce::String VibeSynthAudioProcessor::getProgramName (int index)
{
return {};
}
void VibeSynthAudioProcessor::changeProgramName (int index, const juce::String& newName)
{
}
//==============================================================================
void VibeSynthAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
// Use this method as the place to do any pre-playback
// initialisation that you need..
synth.setCurrentPlaybackSampleRate(sampleRate); //sets the samplerate
//grabs the total num voices in the synth
for (int i = 0; i < synth.getNumVoices(); i++) {
//dynamic cast converts types, pointers, references to classes up down sideways in their hierarchy
//grabs the synth voices, makes them pointers* and puts them into prep to play function
if (auto voice = dynamic_cast<SynthVoice*>(synth.getVoice(i))) {
voice->prepareToPlay(sampleRate, samplesPerBlock, synth.getNumVoices());
}
}
}
void VibeSynthAudioProcessor::releaseResources()
{
// When playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
#ifndef JucePlugin_PreferredChannelConfigurations
bool VibeSynthAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
#if JucePlugin_IsMidiEffect
juce::ignoreUnused (layouts);
return true;
#else
// This is the place where you check if the layout is supported.
// In this template code we only support mono or stereo.
// Some plugin hosts, such as certain GarageBand versions, will only
// load plugins that support stereo bus layouts.
if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
&& layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
return false;
// This checks if the input layout matches the output layout
#if ! JucePlugin_IsSynth
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
return false;
#endif
return true;
#endif
}
#endif
void VibeSynthAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
// In case we have more outputs than inputs, this code clears any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
// This is here to avoid people getting screaming feedback
// when they first compile a plugin, but obviously you don't need to keep
// this code if your algorithm always overwrites all the output channels.
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
for (int i = 0; i < synth.getNumVoices(); i++) {
if (auto voice = dynamic_cast<juce::SynthesiserVoice*>(synth.getVoice(i))) {
//do stuff with osc, ADSR, LFO, update parameters from value tree
}
}
//basically loads the next block of audio input from midi i guess
//rendernext block is what actually ouputs the sound from the synth
synth.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());
// This is the place where you'd normally do the guts of your plugin's
// audio processing...
// Make sure to reset the state if your inner loop is processing
// the samples and the outer loop is handling the channels.
// Alternatively, you can process the samples with the channels
// interleaved by keeping the same state.
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
auto* channelData = buffer.getWritePointer (channel);
// ..do something to the data...
}
}
//==============================================================================
bool VibeSynthAudioProcessor::hasEditor() const
{
return true; // (change this to false if you choose to not supply an editor)
}
juce::AudioProcessorEditor* VibeSynthAudioProcessor::createEditor()
{
return new VibeSynthAudioProcessorEditor (*this);
}
//==============================================================================
void VibeSynthAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
{
// You should use this method to store your parameters in the memory block.
// You could do that either as raw data, or use the XML or ValueTree classes
// as intermediaries to make it easy to save and load complex data.
}
void VibeSynthAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.
}
//==============================================================================
// This creates new instances of the plugin..
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new VibeSynthAudioProcessor();
}
//Value Tree. this is where you define your osc types, ADSR, etc.
PluginProcessor.h
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin processor.
==============================================================================
*/
#pragma once
#include <JuceHeader.h>
#include "SynthVoice.h"
#include "SynthSound.h"
#include "PluginEditor.h"
//==============================================================================
/**
*/
class VibeSynthAudioProcessor : public juce::AudioProcessor
{
public:
//==============================================================================
VibeSynthAudioProcessor();
~VibeSynthAudioProcessor() override;
//==============================================================================
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
#ifndef JucePlugin_PreferredChannelConfigurations
bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
#endif
void processBlock (juce::AudioBuffer<float>&, juce::MidiBuffer&) override;
//==============================================================================
juce::AudioProcessorEditor* createEditor() override;
bool hasEditor() const override;
//==============================================================================
const juce::String getName() const override;
bool acceptsMidi() const override;
bool producesMidi() const override;
bool isMidiEffect() const override;
double getTailLengthSeconds() const override;
//==============================================================================
int getNumPrograms() override;
int getCurrentProgram() override;
void setCurrentProgram (int index) override;
const juce::String getProgramName (int index) override;
void changeProgramName (int index, const juce::String& newName) override;
//==============================================================================
void getStateInformation (juce::MemoryBlock& destData) override;
void setStateInformation (const void* data, int sizeInBytes) override;
private:
juce::Synthesiser synth;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VibeSynthAudioProcessor)
};