2
0
Fork 0
OB-Xd/Source/PluginProcessor.h

280 lines
9 KiB
C
Raw Normal View History

2017-01-23 10:15:08 +00:00
/*
==============================================================================
This file is part of Obxd synthesizer.
Copyright © 2013-2014 Filatov Vadim
Contact author via email :
justdat_@_e1.ru
This file may be licensed under the terms of of the
GNU General Public License Version 2 (the ``GPL'').
Software distributed under the License is distributed
on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
express or implied. See the GPL for the specific language
governing rights and limitations.
You should have received a copy of the GPL along with this
program. If not, go to http://www.gnu.org/licenses/gpl.html
or write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
==============================================================================
*/
#ifndef PLUGINPROCESSOR_H_INCLUDED
#define PLUGINPROCESSOR_H_INCLUDED
#include "../JuceLibraryCode/JuceHeader.h"
#include "Engine/SynthEngine.h"
//#include <stack>
#include "Engine/midiMap.h"
#include "Engine/ObxdBank.h"
//==============================================================================
const int fxbVersionNum = 1;
struct fxProgram
{
int32 chunkMagic; // 'CcnK'
int32 byteSize; // of this chunk, excl. magic + byteSize
int32 fxMagic; // 'FxCk'
int32 version;
int32 fxID; // fx unique id
int32 fxVersion;
int32 numParams;
char prgName[28];
float params[1]; // variable no. of parameters
};
struct fxSet
{
int32 chunkMagic; // 'CcnK'
int32 byteSize; // of this chunk, excl. magic + byteSize
int32 fxMagic; // 'FxBk'
int32 version;
int32 fxID; // fx unique id
int32 fxVersion;
int32 numPrograms;
char future[128];
fxProgram programs[1]; // variable no. of programs
};
struct fxChunkSet
{
int32 chunkMagic; // 'CcnK'
int32 byteSize; // of this chunk, excl. magic + byteSize
int32 fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
int32 version;
int32 fxID; // fx unique id
int32 fxVersion;
int32 numPrograms;
char future[128];
int32 chunkSize;
char chunk[8]; // variable
};
struct fxProgramSet
{
int32 chunkMagic; // 'CcnK'
int32 byteSize; // of this chunk, excl. magic + byteSize
int32 fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
int32 version;
int32 fxID; // fx unique id
int32 fxVersion;
int32 numPrograms;
char name[28];
int32 chunkSize;
char chunk[8]; // variable
};
// Compares a magic value in either endianness.
static inline bool compareMagic (int32 magic, const char* name) noexcept
{
return magic == (int32) ByteOrder::littleEndianInt (name)
|| magic == (int32) ByteOrder::bigEndianInt (name);
}
static inline int32 fxbName (const char* name) noexcept { return (int32) ByteOrder::littleEndianInt (name); }
static inline int32 fxbSwap (const int32 x) noexcept { return (int32) ByteOrder::swapIfLittleEndian ((uint32) x); }
static inline float fxbSwapFloat (const float x) noexcept
{
#ifdef JUCE_LITTLE_ENDIAN
union { uint32 asInt; float asFloat; } n;
n.asFloat = x;
n.asInt = ByteOrder::swap (n.asInt);
return n.asFloat;
#else
return x;
#endif
}
enum class Tooltip
{
Disable = 0,
StandardDisplay,
FullDisplay
};
2017-01-23 10:15:08 +00:00
//==============================================================================
/**
*/
class ObxdAudioProcessor : public AudioProcessor,
public AudioProcessorValueTreeState::Listener,
public ChangeBroadcaster
2017-01-23 10:15:08 +00:00
{
public:
//==============================================================================
ObxdAudioProcessor();
~ObxdAudioProcessor();
//==============================================================================
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
void releaseResources() override;
2017-01-23 10:15:08 +00:00
void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) override;
2017-01-23 10:15:08 +00:00
//==============================================================================
AudioProcessorEditor* createEditor() override;
bool hasEditor() const override;
2017-01-23 10:15:08 +00:00
//==============================================================================
void processMidiPerSample (MidiBuffer::Iterator* iter, const int samplePos);
bool getNextEvent (MidiBuffer::Iterator* iter, const int samplePos);
2017-01-23 10:15:08 +00:00
//==============================================================================
void initAllParams();
2021-05-16 16:15:11 +00:00
void initMidi();
const String getInputChannelName (int channelIndex) const override; // WATCH OUT!
const String getOutputChannelName (int channelIndex) const override; // WATCH OUT!
bool isInputChannelStereoPair (int index) const override; // WATCH OUT!
bool isOutputChannelStereoPair (int index) const override; // WATCH OUT!
bool acceptsMidi() const override;
bool producesMidi() const override;
double getTailLengthSeconds() const override;
const String getName() const override;
2017-01-23 10:15:08 +00:00
//==============================================================================
int getNumPrograms() override;
int getCurrentProgram() override;
void setCurrentProgram (int index) override;
2021-05-12 16:47:15 +00:00
void setCurrentProgram (int index, bool updateHost);
const String getProgramName (int index) override;
void changeProgramName (int index, const String& newName) override;
2017-01-23 10:15:08 +00:00
//==============================================================================
void getStateInformation (MemoryBlock& destData) override;
void setStateInformation (const void* data, int sizeInBytes) override;
void setCurrentProgramStateInformation (const void* data,int sizeInBytes) override;
void getCurrentProgramStateInformation (MemoryBlock& destData) override;
2017-01-23 10:15:08 +00:00
//==============================================================================
void scanAndUpdateBanks();
2020-05-10 09:15:47 +00:00
void scanAndUpdateSkins();
2017-01-23 10:15:08 +00:00
const Array<File>& getBankFiles() const;
2020-05-10 09:15:47 +00:00
const Array<File>& getSkinFiles() const;
bool deleteBank();
bool loadPreset(const File& fxpFile);
bool savePreset(const File& fxpFile);
2022-10-04 17:30:58 +00:00
void serializePreset(MemoryBlock& memoryBlock); // Copy the current Preset into a MemoryBlock
void changePresetName(const String &name);
void newPreset(const String &name);
void deletePreset();
2022-10-04 17:30:58 +00:00
bool loadFromFXPFile(const File& fxbFile);
2021-05-19 18:09:59 +00:00
bool loadFromFXBFile(const File& fxbFile);
2022-11-03 17:18:45 +00:00
bool isMemoryBlockAPreset(const MemoryBlock& memoryBlock);
2022-10-04 17:30:58 +00:00
bool loadFromMemoryBlock(MemoryBlock& memoryBlock);
bool saveFXBFile(const File& fxbFile);
bool saveFXPFile(const File& fxpFile);
bool saveBank(const File& fxbFile);
2017-01-23 10:15:08 +00:00
bool restoreProgramSettings(const fxProgram* const prog);
File getCurrentBankFile() const;
2020-07-16 08:14:56 +00:00
MidiMap &getMidiMap(){ return bindings; }
2017-01-23 10:15:08 +00:00
//==============================================================================
const ObxdBank& getPrograms() const { return programs; }
//==============================================================================
File getDocumentFolder() const;
File getSkinFolder() const;
File getPresetsFolder() const;
2017-01-23 10:15:08 +00:00
File getBanksFolder() const;
2021-05-19 18:09:59 +00:00
File getMidiFolder() const;
2017-01-23 10:15:08 +00:00
File getCurrentSkinFolder() const;
void setCurrentSkinFolder(const String& folderName);
2021-09-01 08:38:39 +00:00
void setGuiSize(const int gui_size);
Tooltip getTooltipBehavior() const;
void setTooltipBehavior(const Tooltip tooltip);
//==============================================================================
static String getEngineParameterId (size_t);
2022-02-20 18:53:09 +00:00
static String getTrueParameterValueFromNormalizedRange(size_t, float normalizedValue);
int getParameterIndexFromId (String);
2020-07-16 08:14:56 +00:00
void setEngineParameterValue (int, float, bool notifyToHost= false);
void parameterChanged (const String&, float) override;
AudioProcessorValueTreeState& getPluginState();
2021-04-27 08:17:13 +00:00
bool getShowPresetBar(){
return this->showPresetBar;
}
void setShowPresetBar(bool val){
this->showPresetBar = val;
config->setValue("presetnavigation", this->showPresetBar);
}
2017-01-23 10:15:08 +00:00
private:
//==============================================================================
bool isHostAutomatedChange;
int lastMovedController;
int lastUsedParameter;
MidiMessage* nextMidi;
MidiMessage* midiMsg;
2021-05-19 18:09:59 +00:00
2017-01-23 10:15:08 +00:00
bool midiControlledParamSet;
bool hasMidiMessage;
int midiEventPos;
SynthEngine synth;
ObxdBank programs;
2021-09-01 08:38:39 +00:00
public:
2021-09-01 08:38:39 +00:00
float physicalPixelScaleFactor;
int gui_size;
String currentSkin;
2017-01-23 10:15:08 +00:00
String currentBank;
File currentBankFile;
void saveBank();
2021-05-16 16:15:11 +00:00
String currentMidiPath;
String currentPreset;
File currentPresetFile;
void savePreset();
2021-05-19 18:09:59 +00:00
MidiMap bindings;
2021-04-27 08:17:13 +00:00
bool showPresetBar = false;
2021-05-19 18:09:59 +00:00
void updateConfig();
private:
2017-01-23 10:15:08 +00:00
Array<File> bankFiles;
2020-05-10 09:15:47 +00:00
Array<File> skinFiles;
Tooltip tooltipBehavior;
2017-01-23 10:15:08 +00:00
std::unique_ptr<PropertiesFile> config;
2017-01-23 10:15:08 +00:00
InterProcessLock configLock;
//==============================================================================
AudioProcessorValueTreeState apvtState;
UndoManager undoManager;
2017-01-23 10:15:08 +00:00
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ObxdAudioProcessor)
};
#endif // PLUGINPROCESSOR_H_INCLUDED