VSTPlugin.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*****************************************************************************
  2. Copyright (C) 2016-2017 by Colin Edwards.
  3. Additional Code Copyright (C) 2016-2017 by c3r1c3 <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. *****************************************************************************/
  15. #ifndef OBS_STUDIO_VSTPLUGIN_H
  16. #define OBS_STUDIO_VSTPLUGIN_H
  17. #define BLOCK_SIZE 512
  18. #include <mutex>
  19. #include <atomic>
  20. #include <string>
  21. #include <QDirIterator>
  22. #include <obs-module.h>
  23. #include "aeffectx.h"
  24. #include "vst-plugin-callbacks.hpp"
  25. #include "EditorWidget.h"
  26. #ifdef __APPLE__
  27. #include <CoreFoundation/CoreFoundation.h>
  28. #endif
  29. class EditorWidget;
  30. class VSTPlugin : public QObject {
  31. Q_OBJECT
  32. /* Because effect is always changed in UI thread, so lockEffect is only necessary for these situations:
  33. 1. access effect object outside of UI thread;
  34. 2. close/delete effect object any where. */
  35. std::recursive_mutex lockEffect;
  36. AEffect *effect = nullptr;
  37. obs_source_t *sourceContext;
  38. std::string pluginPath;
  39. float **inputs = nullptr;
  40. float **outputs = nullptr;
  41. float **channelrefs = nullptr;
  42. size_t numChannels = 0;
  43. void createChannelBuffers(size_t count);
  44. void cleanupChannelBuffers();
  45. EditorWidget *editorWidget = nullptr;
  46. bool editorOpened = false;
  47. AEffect *loadEffect();
  48. std::atomic_bool effectReady = false;
  49. std::string sourceName;
  50. std::string filterName;
  51. char effectName[64];
  52. // Remove below... or comment out
  53. char vendorString[64];
  54. VstTimeInfo mTimeInfo;
  55. #ifdef __APPLE__
  56. CFBundleRef bundle = NULL;
  57. #elif WIN32
  58. HINSTANCE dllHandle = nullptr;
  59. #elif __linux__
  60. void *soHandle = nullptr;
  61. #endif
  62. void unloadLibrary();
  63. static intptr_t hostCallback_static(AEffect *effect, int32_t opcode,
  64. int32_t index, intptr_t value,
  65. void *ptr, float opt);
  66. VstTimeInfo *GetTimeInfo();
  67. float GetSampleRate();
  68. public:
  69. VSTPlugin(obs_source_t *sourceContext);
  70. ~VSTPlugin();
  71. void loadEffectFromPath(const std::string &path);
  72. void unloadEffect();
  73. std::string getEffectPath();
  74. std::string getChunk();
  75. void setChunk(const std::string &data);
  76. void setProgram(const int programNumber);
  77. int getProgram();
  78. void getSourceNames();
  79. obs_audio_data *process(struct obs_audio_data *audio);
  80. bool openInterfaceWhenActive = false;
  81. bool vstLoaded();
  82. bool isEditorOpen();
  83. void onEditorClosed();
  84. public slots:
  85. void openEditor();
  86. void closeEditor();
  87. };
  88. #endif // OBS_STUDIO_VSTPLUGIN_H