You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
6.4KB

  1. // vst_eureka_standalone_test.cpp : Defines the entry point for the console application.
  2. //
  3. #define DLL_PATH "../../vst2_bin/veeseevstrack_effect.dll"
  4. // #define SO_PATH "../../vst2_bin/veeseevstrack_effect.so"
  5. #define SO_PATH "../vst2_lglw_debug_plugin/debug_lglw.so"
  6. #include <yac.h>
  7. #ifdef YAC_WIN32
  8. #include "stdafx.h"
  9. #include <windows.h>
  10. #else
  11. #include <dlfcn.h>
  12. #include <unistd.h>
  13. #include <X11/Xlib.h>
  14. #include <X11/Xutil.h>
  15. #include <X11/Xos.h>
  16. #include <X11/Xatom.h>
  17. #endif
  18. #include <aeffect.h>
  19. #include <aeffectx.h>
  20. typedef AEffect* (*PluginEntryProc) (audioMasterCallback audioMaster);
  21. #ifndef YAC_WIN32
  22. // https://github.com/Ardour/ardour/blob/master/gtk2_ardour/linux_vst_gui_support.cc
  23. long getXWindowProperty(Display* display, Window window, Atom atom)
  24. {
  25. long result = 0;
  26. int userSize;
  27. unsigned long bytes;
  28. unsigned long userCount;
  29. unsigned char *data;
  30. Atom userType;
  31. // LXVST_xerror = false;
  32. /*Use our own Xerror handler while we're in here - in an
  33. attempt to stop the brain dead default Xerror behaviour of
  34. qutting the entire application because of e.g. an invalid
  35. window ID*/
  36. // XErrorHandler olderrorhandler = XSetErrorHandler(TempErrorHandler);
  37. XGetWindowProperty(display,
  38. window,
  39. atom,
  40. 0,
  41. 2,
  42. false,
  43. AnyPropertyType,
  44. &userType,
  45. &userSize,
  46. &userCount,
  47. &bytes,
  48. &data);
  49. if(userCount == 1)
  50. result = *(long*)data;
  51. // XSetErrorHandler(olderrorhandler);
  52. /*Hopefully this will return zero if the property is not set*/
  53. return result;
  54. }
  55. #endif
  56. static VstIntPtr VSTCALLBACK HostCallback(AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt) {
  57. static VstInt32 lastOpcode = -1;
  58. static VstIntPtr lastTimeMask = ~0;
  59. VstIntPtr result = 0;
  60. lastOpcode = opcode;
  61. (void)lastOpcode;
  62. (void)lastTimeMask;
  63. return result;
  64. }
  65. float *inputBuffers[48];
  66. float *outputBuffers[48];
  67. void open_and_close(void) {
  68. #ifdef YAC_WIN32
  69. HINSTANCE dllHandle = ::LoadLibraryA(DLL_PATH);
  70. #else
  71. void *dllHandle = ::dlopen(SO_PATH, RTLD_NOW);
  72. if(NULL == dllHandle)
  73. {
  74. printf("Failed to load library %s: %s", SO_PATH, dlerror());
  75. return;
  76. }
  77. #endif
  78. #ifndef YAC_WIN32
  79. Display *d;
  80. Window w;
  81. int s;
  82. d = XOpenDisplay(NULL);
  83. s = DefaultScreen(d);
  84. #endif
  85. for(int i = 0; i < 48; i++)
  86. {
  87. inputBuffers[i] = new float[4096];
  88. outputBuffers[i] = new float[4096];
  89. }
  90. if(NULL != dllHandle)
  91. {
  92. #ifdef YAC_WIN32
  93. PluginEntryProc mainProc = (PluginEntryProc) ::GetProcAddress((HMODULE)dllHandle, "VSTPluginMain");
  94. if(NULL == mainProc)
  95. {
  96. mainProc = (PluginEntryProc) ::GetProcAddress((HMODULE)dllHandle, "main");
  97. }
  98. #else
  99. PluginEntryProc mainProc = (PluginEntryProc) ::dlsym(dllHandle, "VSTPluginMain");
  100. if(NULL == mainProc)
  101. {
  102. mainProc = (PluginEntryProc) ::dlsym(dllHandle, "main");
  103. }
  104. #endif
  105. if(NULL != mainProc)
  106. {
  107. AEffect *effect;
  108. printf("xxx calling mainProc\n");
  109. effect = mainProc(HostCallback);
  110. printf("xxx mainProc returned effect=%p\n", effect);
  111. if(NULL != effect)
  112. {
  113. #ifndef YAC_WIN32
  114. w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1,
  115. BlackPixel(d, s), WhitePixel(d, s));
  116. XSelectInput(d, w, ExposureMask | KeyPressMask);
  117. XMapRaised(d, w);
  118. XFlush(d);
  119. #endif
  120. printf("xxx calling effect->dispatcher<effOpen>\n");
  121. effect->dispatcher(effect, effOpen, 0, 0, NULL, 0.0f);
  122. printf("xxx effect->dispatcher<effOpen> returned\n");
  123. #ifdef YAC_WIN32
  124. VstIntPtr ip = effect->dispatcher(effect, effEditOpen, 0, 0, NULL/*hWnd*/, 0.0f);
  125. #else
  126. VstIntPtr ip = effect->dispatcher(effect, effEditOpen, 0, 0, (void*)(w)/*hWnd*/, 0.0f);
  127. #endif
  128. (void)ip;
  129. sleep(2);
  130. #ifndef YAC_WIN32
  131. long result = getXWindowProperty(d, w, XInternAtom(d, "_XEventProc", false));
  132. if(result == 0)
  133. {
  134. printf("xxx no XEventProc found\n");
  135. }
  136. else
  137. {
  138. printf("xxx XEventProc found... calling\n");
  139. void (* eventProc) (void * event);
  140. eventProc = (void (*) (void* event))result;
  141. eventProc(NULL);
  142. }
  143. #endif
  144. printf("xxx calling effect->dispatcher<effEditIdle>\n");
  145. effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
  146. sleep(1);
  147. printf("xxx calling effect->dispatcher<effEditIdle>\n");
  148. effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
  149. sleep(1);
  150. printf("xxx calling effect->dispatcher<effEditClose>\n");
  151. effect->dispatcher(effect, effEditClose, 0, 0, NULL, 0.0f);
  152. sleep(1);
  153. printf("xxx calling effect->dispatcher<effEditOpen> again\n");
  154. #ifdef YAC_WIN32
  155. effect->dispatcher(effect, effEditOpen, 0, 0, NULL/*hWnd*/, 0.0f);
  156. #else
  157. effect->dispatcher(effect, effEditOpen, 0, 0, (void*)(w)/*hWnd*/, 0.0f);
  158. #endif
  159. sleep(1);
  160. printf("xxx calling effect->dispatcher<effEditIdle>\n");
  161. effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
  162. sleep(1);
  163. printf("xxx call processreplacing\n");
  164. for(int i = 0; i < 1024; i++)
  165. {
  166. effect->processReplacing(effect, inputBuffers, outputBuffers, (VstInt32)64);
  167. }
  168. printf("xxx calling effect->dispatcher<effEditClose>\n");
  169. effect->dispatcher(effect, effEditClose, 0, 0, NULL, 0.0f);
  170. sleep(1);
  171. printf("xxx calling effect->dispatcher<effClose>\n");
  172. effect->dispatcher(effect, effClose, 0, 0, NULL, 0.0f);
  173. sleep(1);
  174. #ifndef YAC_WIN32
  175. XDestroyWindow(d, w);
  176. #endif
  177. }
  178. }
  179. else
  180. {
  181. printf("[---] failed to find mainProc\n");
  182. }
  183. #ifdef YAC_WIN32
  184. ::FreeLibrary(dllHandle);
  185. #else
  186. ::dlclose(dllHandle);
  187. #endif
  188. }
  189. for(int i = 0; i < 48; i++)
  190. {
  191. delete [] inputBuffers[i];
  192. delete [] outputBuffers[i];
  193. }
  194. #ifndef YAC_WIN32
  195. XCloseDisplay(d);
  196. #endif
  197. }
  198. int main() {
  199. for(int i = 0; i < 5; i++)
  200. {
  201. open_and_close();
  202. }
  203. return 0;
  204. }