/**************************************************************************
Copyright (C) 2019 Arnaud Champenois arthelion@free.fr
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#pragma once
#include "../JuceLibraryCode/JuceHeader.h"
#include <vector>
#include "Synth.h"
#include "SynthVoice.h"
#include "GroupParametersLinker.h"
class MolossI;
class PitchParameters;
class VCOParameters;
class LFOParameters;
class TVFParameters;
class TVAParameters;
class TimeVariantParameters;
class SynthParameters;
// #define LOG_FILE
//==============================================================================
/*!
* MolossI audio processor
* This is the plugin top level interface. It relies on a Synth for the sound
* generation. It takes care of presets management, and makes the link between
* the Synth and the parameters that are edited or automated.
*/
class MolossI : public AudioProcessor
{
public:
//==============================================================================
MolossI();
~MolossI();
//==============================================================================
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
#ifndef JucePlugin_PreferredChannelConfigurations
bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
#endif
void processBlock (AudioBuffer<float>&, MidiBuffer&) override;
//==============================================================================
AudioProcessorEditor* createEditor() override;
bool hasEditor() const override;
//==============================================================================
const 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 String getProgramName (int index) override;
void changeProgramName (int index, const String& newName) override;
//==============================================================================
void getStateInformation (MemoryBlock& destData) override;
/*!
* Write state information into buffer
* \param destData Buffer to write to
* \param addPathNode Add a node with current sound file path
*/
void getStateInformation(MemoryBlock& destData, bool addPathNode);
void setStateInformation(const void* data, int sizeInBytes) override;
/*!
* Read state information from buffer
*
* \param data Buffer
* \param sizeInBytes Buffer size
* \param readPathNode Read current sound file path from info or ignore it
*/
void setStateInformation(const void* data, int sizeInBytes, bool readPathNode);
/*!
* Get synth voices (as polyphony count)
*
* \return The SynthVoices array.
*/
const std::vector<SynthVoice*>& getVoices() const { return mVoices; }
/*!
* Get the underlying synth
*
* \return The synth
*/
Synth &getSynth() { return *mSynth; }
VCOParameters* getVCOParameters(int vco) const { return mVCOParametersArray[vco].get(); }
TVFParameters* getTVFParameters(int vco) const { return mTVFParametersArray[vco].get(); }
TVAParameters* getTVAParameters(int vco) const { return mTVAParametersArray[vco].get(); }
PitchParameters* getPitchParameters(int vco) const { return mPitchParametersArray[vco].get(); }
SynthParameters*getSynthParameters() const { return mSynthParameters.get(); }
AudioProcessorValueTreeState& getTreeState() { return *mAudioTreeState; }
void addTreeStateParameter(RangedAudioParameter*param) {
mAudioTreeState->createAndAddParameter(std::unique_ptr <RangedAudioParameter>(param));
}
//==============================================================================
// Preset management section
void loadFromFile();
void saveToFile();
void saveToCurrentFile();
void unsetVoiceLinks(int voice);
void unsetLinks();
void resetSound();
void updateHostDisplayAsync();
void resetVoice(int voiceNumber);
String getCurrentFile();
Array<String> getLoadedFilenames();
bool hasCurrentFile() const {
return mCurrentFile.getFullPathName().isNotEmpty();
}
void parameterChanged() { mParameterChanged = true; updateCurrentFileState(); }
void parameterUnchanged() { mParameterChanged = false; updateCurrentFileState(); }
void updateActivityGUI();
void updateCurrentFileState();
void updateCurrentFiles();
void setTempo(double tempo);
//==============================================================================
// Copy/Paste parameters section
void clearCopiedParameter();
void paste(Moloss1Parameters*parameters,String prefix = String(),String filter = String()) {
parameters->readParameterValues(mCopiedParameters,prefix,filter);
}
void copy(Moloss1Parameters*parameters, String prefix = String()) {
parameters->getParameterValues(mCopiedParameters, prefix);
}
//===========================================================
// Linked parameters section
void addToLinkGroup(Moloss1Parameters*parameters, int group, String prefix);
void removeFromLinkGroup(Moloss1Parameters*parameters, int group, String prefix);
private:
void reloadCurrentFilesList();
//==============================================================================
std::unique_ptr<AudioProcessorValueTreeState> mAudioTreeState;
std::vector<SynthVoice*> mVoices;
std::vector<std::unique_ptr<PitchParameters>> mPitchParametersArray;
std::vector<std::unique_ptr<VCOParameters>> mVCOParametersArray;
std::vector<std::unique_ptr<TVFParameters>> mTVFParametersArray;
std::vector<std::unique_ptr<TVAParameters>> mTVAParametersArray;
std::unique_ptr<SynthParameters> mSynthParameters;
std::vector<LFOParameters*> mLFOParametersArray;
std::vector<TimeVariantParameters*> mADSRParametersArray;
std::unique_ptr <Synth> mSynth;
// Presets management
Array<File> mCurrentFilesList;
File mCurrentFile;
int mCurrentProgram = 0;
std::map <String, float> mCopiedParameters;
bool mParameterChanged = false;
double mTempo = 0.0;
MolossLogger ml;
std::array<GroupParametersLinker,8> mLinkerArray;
CriticalSection lock;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MolossI)
};