add lazarus source
This commit is contained in:
@ -10,34 +10,49 @@
|
||||
|
||||
#include "PluginProcessor.h"
|
||||
#include "PluginEditor.h"
|
||||
#include "SoundfontSynthVoice.h"
|
||||
#include "SoundfontSynthSound.h"
|
||||
|
||||
AudioProcessor* JUCE_CALLTYPE createPluginFilter();
|
||||
|
||||
|
||||
//==============================================================================
|
||||
JuicysfpluginAudioProcessor::JuicysfpluginAudioProcessor()
|
||||
#ifndef JucePlugin_PreferredChannelConfigurations
|
||||
: AudioProcessor (BusesProperties()
|
||||
#if ! JucePlugin_IsMidiEffect
|
||||
#if ! JucePlugin_IsSynth
|
||||
.withInput ("Input", AudioChannelSet::stereo(), true)
|
||||
#endif
|
||||
.withOutput ("Output", AudioChannelSet::stereo(), true)
|
||||
#endif
|
||||
)
|
||||
#endif
|
||||
LazarusAudioProcessor::LazarusAudioProcessor()
|
||||
: AudioProcessor (getBusesProperties()),
|
||||
fluidSynthModel(),
|
||||
lastUIWidth(400),
|
||||
lastUIHeight(300)
|
||||
{
|
||||
initialiseSynth();
|
||||
}
|
||||
|
||||
JuicysfpluginAudioProcessor::~JuicysfpluginAudioProcessor()
|
||||
LazarusAudioProcessor::~LazarusAudioProcessor()
|
||||
{
|
||||
// delete fluidSynthModel;
|
||||
}
|
||||
|
||||
void LazarusAudioProcessor::initialiseSynth() {
|
||||
fluidSynthModel.initialise();
|
||||
|
||||
fluidSynth = fluidSynthModel.getSynth();
|
||||
|
||||
const int numVoices = 8;
|
||||
|
||||
// Add some voices...
|
||||
for (int i = numVoices; --i >= 0;)
|
||||
synth.addVoice (new SoundfontSynthVoice(fluidSynthModel.getSynth()));
|
||||
|
||||
// ..and give the synth a sound to play
|
||||
synth.addSound (new SoundfontSynthSound());
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
const String JuicysfpluginAudioProcessor::getName() const
|
||||
const String LazarusAudioProcessor::getName() const
|
||||
{
|
||||
return JucePlugin_Name;
|
||||
}
|
||||
|
||||
bool JuicysfpluginAudioProcessor::acceptsMidi() const
|
||||
bool LazarusAudioProcessor::acceptsMidi() const
|
||||
{
|
||||
#if JucePlugin_WantsMidiInput
|
||||
return true;
|
||||
@ -46,7 +61,7 @@ bool JuicysfpluginAudioProcessor::acceptsMidi() const
|
||||
#endif
|
||||
}
|
||||
|
||||
bool JuicysfpluginAudioProcessor::producesMidi() const
|
||||
bool LazarusAudioProcessor::producesMidi() const
|
||||
{
|
||||
#if JucePlugin_ProducesMidiOutput
|
||||
return true;
|
||||
@ -55,86 +70,87 @@ bool JuicysfpluginAudioProcessor::producesMidi() const
|
||||
#endif
|
||||
}
|
||||
|
||||
bool JuicysfpluginAudioProcessor::isMidiEffect() const
|
||||
{
|
||||
#if JucePlugin_IsMidiEffect
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
double JuicysfpluginAudioProcessor::getTailLengthSeconds() const
|
||||
double LazarusAudioProcessor::getTailLengthSeconds() const
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
int JuicysfpluginAudioProcessor::getNumPrograms()
|
||||
int LazarusAudioProcessor::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 JuicysfpluginAudioProcessor::getCurrentProgram()
|
||||
int LazarusAudioProcessor::getCurrentProgram()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void JuicysfpluginAudioProcessor::setCurrentProgram (int index)
|
||||
void LazarusAudioProcessor::setCurrentProgram (int index)
|
||||
{
|
||||
}
|
||||
|
||||
const String JuicysfpluginAudioProcessor::getProgramName (int index)
|
||||
const String LazarusAudioProcessor::getProgramName (int index)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void JuicysfpluginAudioProcessor::changeProgramName (int index, const String& newName)
|
||||
void LazarusAudioProcessor::changeProgramName (int index, const String& newName)
|
||||
{
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void JuicysfpluginAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
|
||||
void LazarusAudioProcessor::prepareToPlay (double sampleRate, int /*samplesPerBlock*/)
|
||||
{
|
||||
// Use this method as the place to do any pre-playback
|
||||
// initialisation that you need..
|
||||
synth.setCurrentPlaybackSampleRate (sampleRate);
|
||||
keyboardState.reset();
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
void JuicysfpluginAudioProcessor::releaseResources()
|
||||
void LazarusAudioProcessor::releaseResources()
|
||||
{
|
||||
// When playback stops, you can use this as an opportunity to free up any
|
||||
// spare memory, etc.
|
||||
keyboardState.reset();
|
||||
}
|
||||
|
||||
#ifndef JucePlugin_PreferredChannelConfigurations
|
||||
bool JuicysfpluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
|
||||
bool LazarusAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
|
||||
{
|
||||
#if JucePlugin_IsMidiEffect
|
||||
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.
|
||||
if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
|
||||
&& layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
|
||||
// Only mono/stereo and input/output must have same layout
|
||||
const AudioChannelSet& mainOutput = layouts.getMainOutputChannelSet();
|
||||
const AudioChannelSet& mainInput = layouts.getMainInputChannelSet();
|
||||
|
||||
// input and output layout must either be the same or the input must be disabled altogether
|
||||
if (! mainInput.isDisabled() && mainInput != mainOutput)
|
||||
return false;
|
||||
|
||||
// This checks if the input layout matches the output layout
|
||||
#if ! JucePlugin_IsSynth
|
||||
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
|
||||
// do not allow disabling the main buses
|
||||
if (mainOutput.isDisabled())
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
#endif
|
||||
// only allow stereo and mono
|
||||
return mainOutput.size() <= 2;
|
||||
}
|
||||
#endif
|
||||
|
||||
void JuicysfpluginAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
|
||||
{
|
||||
ScopedNoDenormals noDenormals;
|
||||
auto totalNumInputChannels = getTotalNumInputChannels();
|
||||
auto totalNumOutputChannels = getTotalNumOutputChannels();
|
||||
AudioProcessor::BusesProperties LazarusAudioProcessor::getBusesProperties() {
|
||||
return BusesProperties().withInput ("Input", AudioChannelSet::stereo(), true)
|
||||
.withOutput ("Output", AudioChannelSet::stereo(), true);
|
||||
}
|
||||
|
||||
void LazarusAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages) {
|
||||
jassert (!isUsingDoublePrecision());
|
||||
const int numSamples = buffer.getNumSamples();
|
||||
|
||||
// Now pass any incoming midi messages to our keyboard state object, and let it
|
||||
// add messages to the buffer if the user is clicking on the on-screen keys
|
||||
keyboardState.processNextMidiBuffer (midiMessages, 0, numSamples, true);
|
||||
|
||||
// and now get our synth to process these midi events and generate its output.
|
||||
synth.renderNextBlock (buffer, midiMessages, 0, numSamples);
|
||||
fluid_synth_process(fluidSynth, numSamples, 1, nullptr, buffer.getNumChannels(), buffer.getArrayOfWritePointers());
|
||||
|
||||
// In case we have more outputs than inputs, this code clears any output
|
||||
// channels that didn't contain input data, (because these aren't
|
||||
@ -142,51 +158,94 @@ void JuicysfpluginAudioProcessor::processBlock (AudioBuffer<float>& buffer, Midi
|
||||
// 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());
|
||||
|
||||
// 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...
|
||||
}
|
||||
// for (int i = getTotalNumInputChannels(); i < getTotalNumOutputChannels(); ++i)
|
||||
// buffer.clear (i, 0, numSamples);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
bool JuicysfpluginAudioProcessor::hasEditor() const
|
||||
bool LazarusAudioProcessor::hasEditor() const
|
||||
{
|
||||
return true; // (change this to false if you choose to not supply an editor)
|
||||
}
|
||||
|
||||
AudioProcessorEditor* JuicysfpluginAudioProcessor::createEditor()
|
||||
AudioProcessorEditor* LazarusAudioProcessor::createEditor()
|
||||
{
|
||||
return new JuicysfpluginAudioProcessorEditor (*this);
|
||||
return new LazarusAudioProcessorEditor (*this);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void JuicysfpluginAudioProcessor::getStateInformation (MemoryBlock& destData)
|
||||
void LazarusAudioProcessor::getStateInformation (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.
|
||||
|
||||
// Create an outer XML element..
|
||||
XmlElement xml ("MYPLUGINSETTINGS");
|
||||
|
||||
// add some attributes to it..
|
||||
xml.setAttribute ("uiWidth", lastUIWidth);
|
||||
xml.setAttribute ("uiHeight", lastUIHeight);
|
||||
|
||||
// Store the values of all our parameters, using their param ID as the XML attribute
|
||||
for (auto* param : getParameters())
|
||||
if (auto* p = dynamic_cast<AudioProcessorParameterWithID*> (param))
|
||||
xml.setAttribute (p->paramID, p->getValue());
|
||||
|
||||
// then use this helper function to stuff it into the binary blob and return it..
|
||||
copyXmlToBinary (xml, destData);
|
||||
}
|
||||
|
||||
void JuicysfpluginAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
|
||||
void LazarusAudioProcessor::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 getXmlFromBinary() helper function retrieves our XML from the binary blob..
|
||||
ScopedPointer<XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));
|
||||
|
||||
if (xmlState != nullptr)
|
||||
{
|
||||
// make sure that it's actually our type of XML object..
|
||||
if (xmlState->hasTagName ("MYPLUGINSETTINGS"))
|
||||
{
|
||||
// ok, now pull out our last window size..
|
||||
lastUIWidth = jmax (xmlState->getIntAttribute ("uiWidth", lastUIWidth), 400);
|
||||
lastUIHeight = jmax (xmlState->getIntAttribute ("uiHeight", lastUIHeight), 300);
|
||||
|
||||
// Now reload our parameters..
|
||||
for (auto* param : getParameters())
|
||||
if (auto* p = dynamic_cast<AudioProcessorParameterWithID*> (param))
|
||||
p->setValue ((float) xmlState->getDoubleAttribute (p->paramID, p->getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FluidSynth only supports float in its process function, so that's all we can support.
|
||||
bool LazarusAudioProcessor::supportsDoublePrecisionProcessing() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
FluidSynthModel* LazarusAudioProcessor::getFluidSynthModel() {
|
||||
return &fluidSynthModel;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
// This creates new instances of the plugin..
|
||||
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
||||
{
|
||||
return new JuicysfpluginAudioProcessor();
|
||||
return new LazarusAudioProcessor();
|
||||
}
|
||||
|
||||
void LazarusAudioProcessor::setLastUIWidth(int width) {
|
||||
this->lastUIWidth = width;
|
||||
}
|
||||
void LazarusAudioProcessor::setLastUIHeight(int height) {
|
||||
this->lastUIHeight = height;
|
||||
}
|
||||
|
||||
int LazarusAudioProcessor::getLastUIWidth() {
|
||||
return lastUIWidth;
|
||||
}
|
||||
int LazarusAudioProcessor::getLastUIHeight() {
|
||||
return lastUIHeight;
|
||||
}
|
Reference in New Issue
Block a user