Bridge.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Bridge.h
  3. * --------
  4. * Purpose: VST plugin bridge (plugin side)
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include <atomic>
  12. #include "BridgeCommon.h"
  13. OPENMPT_NAMESPACE_BEGIN
  14. class PluginBridge : private BridgeCommon
  15. {
  16. public:
  17. static bool m_fullMemDump;
  18. protected:
  19. enum TimerID : UINT
  20. {
  21. TIMER_IDLE = 1,
  22. };
  23. static PluginBridge *m_latestInstance;
  24. static ATOM m_editorClassAtom;
  25. // Plugin
  26. Vst::AEffect *m_nativeEffect = nullptr;
  27. HMODULE m_library = nullptr;
  28. HWND m_window = nullptr;
  29. int m_windowWidth = 0, m_windowHeight = 0;
  30. std::atomic<bool> m_isProcessing = false;
  31. // Static memory for host-to-plugin pointers
  32. union
  33. {
  34. Vst::VstSpeakerArrangement speakerArrangement;
  35. char name[256];
  36. } m_host2PlugMem;
  37. std::vector<char> m_eventCache; // Cached VST (MIDI) events
  38. std::vector<char> m_fileSelectCache; // Cached VstFileSelect data
  39. // Pointers to sample data
  40. std::vector<void *> m_sampleBuffers;
  41. uint32 m_mixBufSize = 0;
  42. HANDLE m_audioThread = nullptr;
  43. Event m_sigThreadExit; // Signal to kill audio thread
  44. bool m_needIdle = false; // Plugin needs idle time
  45. public:
  46. PluginBridge(const wchar_t *memName, HANDLE otherProcess);
  47. ~PluginBridge();
  48. PluginBridge(const PluginBridge&) = delete;
  49. PluginBridge &operator=(const PluginBridge&) = delete;
  50. static void MainLoop(TCHAR *argv[]);
  51. protected:
  52. void RequestDelete();
  53. bool SendToHost(BridgeMessage &sendMsg);
  54. void UpdateEffectStruct();
  55. void CreateProcessingFile(std::vector<char> &dispatchData);
  56. void ParseNextMessage(int msgID);
  57. void NewInstance(NewInstanceMsg &msg);
  58. void InitBridge(InitMsg &msg);
  59. void DispatchToPlugin(DispatchMsg &msg);
  60. void SetParameter(ParameterMsg &msg);
  61. void GetParameter(ParameterMsg &msg);
  62. void AutomateParameters();
  63. void Process();
  64. void ProcessReplacing();
  65. void ProcessDoubleReplacing();
  66. intptr_t DispatchToHost(Vst::VstOpcodeToHost opcode, int32 index, intptr_t value, void *ptr, float opt);
  67. void SendErrorMessage(const wchar_t *str);
  68. intptr_t Dispatch(Vst::VstOpcodeToPlugin opcode, int32 index, intptr_t value, void *ptr, float opt);
  69. template<typename buf_t>
  70. int32 BuildProcessPointers(buf_t **(&inPointers), buf_t **(&outPointers));
  71. static DWORD WINAPI AudioThread(LPVOID param);
  72. void AudioThread();
  73. static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  74. static void CALLBACK IdleTimerProc(HWND hwnd, UINT message, UINT_PTR idTimer, DWORD dwTime);
  75. static intptr_t VSTCALLBACK MasterCallback(Vst::AEffect *effect, Vst::VstOpcodeToHost, int32 index, intptr_t value, void *ptr, float opt);
  76. };
  77. OPENMPT_NAMESPACE_END