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.

248 lines
6.6KB

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