123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #pragma once
- #include "openmpt/all/BuildSettings.hpp"
- #ifdef MPT_WITH_VST
- #include "../soundlib/Snd_defs.h"
- #include "../soundlib/plugins/PlugInterface.h"
- #include "../soundlib/Mixer.h"
- #include "plugins/VstDefinitions.h"
- #include "plugins/VstEventQueue.h"
- #if defined(MODPLUG_TRACKER)
- #include "ExceptionHandler.h"
- #endif
- OPENMPT_NAMESPACE_BEGIN
- class CSoundFile;
- struct SNDMIXPLUGIN;
- struct VSTPluginLib;
- class CVstPlugin final : public IMidiPlugin
- {
- protected:
- bool m_maskCrashes;
- HMODULE m_hLibrary;
- Vst::AEffect &m_Effect;
- Vst::ProcessProc m_pProcessFP = nullptr;
- double lastBarStartPos = -1.0;
- uint32 m_nSampleRate;
- bool m_isVst2 : 1;
- bool m_isInstrument : 1;
- bool m_isInitialized : 1;
- bool m_needIdle : 1;
- bool m_positionChanged : 1;
- VstEventQueue vstEvents;
- Vst::VstTimeInfo timeInfo;
- public:
- const bool isBridged : 1;
- private:
- #if defined(MODPLUG_TRACKER)
- ExceptionHandler::Context m_Ectx;
- #endif
- public:
- bool MaskCrashes() noexcept;
- public:
- template <typename Tfn> static DWORD SETryOrError(bool maskCrashes, Tfn fn);
- private:
- template <typename Tfn> DWORD SETryOrError(Tfn fn);
- public:
- CVstPlugin(bool maskCrashes, HMODULE hLibrary, VSTPluginLib &factory, SNDMIXPLUGIN &mixPlugin, Vst::AEffect &effect, CSoundFile &sndFile);
- ~CVstPlugin();
- enum class BridgeMode
- {
- Automatic,
- ForceBridgeWithFallback,
- DetectRequiredBridgeMode,
- };
- static Vst::AEffect *LoadPlugin(bool maskCrashes, VSTPluginLib &plugin, HMODULE &library, BridgeMode bridgeMode);
- protected:
- void Initialize();
- public:
- int32 GetUID() const override;
- int32 GetVersion() const override;
- void Idle() override;
- uint32 GetLatency() const override { return m_Effect.initialDelay; }
-
- bool ProgramsAreChunks() const override { return (m_Effect.flags & Vst::effFlagsProgramChunks) != 0; }
- ChunkData GetChunk(bool isBank) override;
- void SetChunk(const ChunkData &chunk, bool isBank) override;
-
-
-
- bool ShouldProcessSilence() override { return true; }
- int32 GetNumPrograms() const override;
- int32 GetCurrentProgram() override;
- void SetCurrentProgram(int32 nIndex) override;
- PlugParamIndex GetNumParameters() const override;
- PlugParamValue GetParameter(PlugParamIndex nIndex) override;
- void SetParameter(PlugParamIndex nIndex, PlugParamValue fValue) override;
- CString GetCurrentProgramName() override;
- void SetCurrentProgramName(const CString &name) override;
- CString GetProgramName(int32 program) override;
- CString GetParamName(PlugParamIndex param) override;
- CString GetParamLabel(PlugParamIndex param) override { return GetParamPropertyString(param, Vst::effGetParamLabel); };
- CString GetParamDisplay(PlugParamIndex param) override { return GetParamPropertyString(param, Vst::effGetParamDisplay); };
- static intptr_t DispatchSEH(bool maskCrashes, Vst::AEffect *effect, Vst::VstOpcodeToPlugin opCode, int32 index, intptr_t value, void *ptr, float opt, unsigned long &exception);
- intptr_t Dispatch(Vst::VstOpcodeToPlugin opCode, int32 index, intptr_t value, void *ptr, float opt);
- bool HasEditor() const override { return (m_Effect.flags & Vst::effFlagsHasEditor) != 0; }
- CAbstractVstEditor *OpenEditor() override;
- CString GetDefaultEffectName() override;
- void Bypass(bool bypass = true) override;
- bool IsInstrument() const override;
- bool CanRecieveMidiEvents() override;
- void CacheProgramNames(int32 firstProg, int32 lastProg) override;
- void CacheParameterNames(int32 firstParam, int32 lastParam) override;
- public:
- void Release() override;
- void SaveAllParameters() override;
- void RestoreAllParameters(int32 program) override;
- void Process(float *pOutL, float *pOutR, uint32 numFrames) override;
- bool MidiSend(uint32 dwMidiCode) override;
- bool MidiSysexSend(mpt::const_byte_span sysex) override;
- void HardAllNotesOff() override;
- void NotifySongPlaying(bool playing) override;
- void Resume() override;
- void Suspend() override;
- void PositionChanged() override { m_positionChanged = true; }
-
- bool CanAutomateParameter(PlugParamIndex index);
- int GetNumInputChannels() const override { return m_Effect.numInputs; }
- int GetNumOutputChannels() const override { return m_Effect.numOutputs; }
- void BeginSetProgram(int32 program) override;
- void EndSetProgram() override;
- void BeginGetProgram(int32 program) override;
- void EndGetProgram() override;
- protected:
-
- CString GetParamPropertyString(PlugParamIndex param, Vst::VstOpcodeToPlugin opcode);
-
- bool InitializeIOBuffers();
-
- void ProcessVSTEvents();
- void ReceiveVSTEvents(const Vst::VstEvents *events);
- void ReportPlugException(const mpt::ustring &text) const;
- public:
- static intptr_t VSTCALLBACK MasterCallBack(Vst::AEffect *effect, Vst::VstOpcodeToHost opcode, int32 index, intptr_t value, void *ptr, float opt);
- protected:
- intptr_t VstFileSelector(bool destructor, Vst::VstFileSelect &fileSel);
- };
- OPENMPT_NAMESPACE_END
- #endif
|