lynx_test_sc_vst2.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* A minimal VST2 effect with two input and two output pairs (round 188d): tests a host's effect connections (FL's
  2. * wrapper Processing › Connections: inputs as sidechain indexes, "Auto map inputs") without third-party plugins.
  3. * zig cc -shared -O2 -target x86_64-windows-gnu tools/testplugin/lynx_test_sc_vst2.c -o "LYNX Test SC.dll"
  4. * Inputs "Main" (1-2) and "Side" (3-4); outputs "Main" (1-2) = main input, "Side" (3-4) = side input (so a host can
  5. * hear where each input comes from). No parameters, no editor, no state.
  6. */
  7. #ifdef _WIN32
  8. #include <windows.h>
  9. #endif
  10. #include <stdint.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #ifdef _WIN32
  14. #define EXPORT __declspec (dllexport)
  15. #else
  16. #define EXPORT __attribute__ ((visibility ("default")))
  17. #endif
  18. typedef struct Effect Effect;
  19. typedef intptr_t (*HostCallback) (Effect*, int32_t, int32_t, intptr_t, void*, float);
  20. struct Effect
  21. {
  22. int32_t magic;
  23. intptr_t (*dispatcher) (Effect*, int32_t, int32_t, intptr_t, void*, float);
  24. void (*process) (Effect*, float**, float**, int32_t);
  25. void (*setParameter) (Effect*, int32_t, float);
  26. float (*getParameter) (Effect*, int32_t);
  27. int32_t numPrograms, numParams, numInputs, numOutputs, flags;
  28. intptr_t resvd1, resvd2;
  29. int32_t initialDelay, realQualities, offQualities;
  30. float ioRatio;
  31. void* object;
  32. void* user;
  33. int32_t uniqueId, version;
  34. void (*processReplacing) (Effect*, float**, float**, int32_t);
  35. void* processDoubleReplacing;
  36. char future[56];
  37. };
  38. typedef struct
  39. {
  40. char label[64];
  41. int32_t flags, arrangementType;
  42. char shortLabel[8];
  43. char future[48];
  44. } PinProperties;
  45. #ifndef PLUGIN_NAME
  46. #define PLUGIN_NAME "LYNX Test SC"
  47. #endif
  48. #ifndef PLUGIN_ID
  49. #define PLUGIN_ID 0x4C585343 /* 'LXSC' */
  50. #endif
  51. static intptr_t dispatch (Effect* e, int32_t op, int32_t index, intptr_t value, void* ptr, float opt)
  52. {
  53. (void) value, (void) opt;
  54. switch (op)
  55. {
  56. case 1: free (e); return 0; /* close */
  57. #ifdef _WIN32
  58. case 13: /* editGetRect: a plain 240x80 window (FL */
  59. { /* opens no wrapper for an effect without) */
  60. static short rect[4] = { 0, 0, 80, 240 };
  61. *(short**) ptr = rect;
  62. return 1;
  63. }
  64. case 14: /* editOpen */
  65. e->user = CreateWindowExA (0, "STATIC", PLUGIN_NAME, WS_CHILD | WS_VISIBLE | SS_CENTER, 0, 0, 240, 80, (HWND) ptr, 0,
  66. GetModuleHandleA (0), 0);
  67. return e->user != 0;
  68. case 15: /* editClose */
  69. if (e->user != 0) DestroyWindow ((HWND) e->user);
  70. e->user = 0;
  71. return 0;
  72. #endif
  73. case 33: /* getInputProperties */
  74. case 34: /* getOutputProperties */
  75. {
  76. if (index < 0 || index >= 4 || ptr == 0)
  77. return 0;
  78. PinProperties* p = (PinProperties*) ptr;
  79. memset (p, 0, sizeof (*p));
  80. strcpy (p->label, index < 2 ? "Main" : "Side");
  81. strcpy (p->shortLabel, index < 2 ? "Main" : "Side");
  82. p->flags = 1 | ((index & 1) == 0 ? 2 : 0); /* active; the left pin of a stereo pair */
  83. p->arrangementType = 1;
  84. return 1;
  85. }
  86. case 35: return 1; /* getPlugCategory: effect */
  87. case 45: strcpy ((char*) ptr, PLUGIN_NAME); return 1; /* getEffectName */
  88. case 47: strcpy ((char*) ptr, "LYNX"); return 1; /* getVendorString */
  89. case 48: strcpy ((char*) ptr, PLUGIN_NAME); return 1; /* getProductString */
  90. case 58: return 2400; /* getVstVersion */
  91. default: return 0;
  92. }
  93. }
  94. static void setParam (Effect* e, int32_t i, float v) { (void) e, (void) i, (void) v; }
  95. static float getParam (Effect* e, int32_t i) { (void) e, (void) i; return 0.0f; }
  96. static void processReplacing (Effect* e, float** in, float** out, int32_t n)
  97. {
  98. (void) e;
  99. for (int c = 0; c < 4; ++c)
  100. if (out[c] != in[c])
  101. memcpy (out[c], in[c], sizeof (float) * (size_t) n);
  102. }
  103. EXPORT Effect* VSTPluginMain (HostCallback host)
  104. {
  105. Effect* e = (Effect*) calloc (1, sizeof (Effect));
  106. if (e == 0 || host (0, 1, 0, 0, 0, 0.0f) == 0)
  107. return 0;
  108. e->magic = 0x56737450;
  109. e->dispatcher = dispatch;
  110. e->setParameter = setParam;
  111. e->getParameter = getParam;
  112. e->processReplacing = processReplacing;
  113. e->numPrograms = 1;
  114. e->numInputs = 4;
  115. e->numOutputs = 4;
  116. e->flags = 1 << 4; /* replacing */
  117. #ifdef _WIN32
  118. e->flags |= 1; /* has editor */
  119. #endif
  120. e->object = e;
  121. e->uniqueId = PLUGIN_ID;
  122. e->version = 1;
  123. return e;
  124. }