lynx_test_gain.c 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* A minimal CLAP effect (stereo pass-through at half gain) for testing LYNX's plugin scan and FL-project plugin
  2. * matching without third-party plugins:
  3. * zig cc -shared -O2 -target x86_64-windows-gnu -Ithird_party/clap/include tools/testplugin/lynx_test_gain.c \
  4. * -o "LYNX Test Gain.clap"
  5. * LYNX.exe --scantest <folder with it> report.txt
  6. */
  7. #include <clap/clap.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. static const char* const features[] = { CLAP_PLUGIN_FEATURE_AUDIO_EFFECT, CLAP_PLUGIN_FEATURE_UTILITY, NULL };
  11. static const clap_plugin_descriptor_t descriptor = {
  12. CLAP_VERSION_INIT, "org.lynx.test-gain", "LYNX Test Gain", "LYNX", "https://github.com/Ka1-S/LYNX-SHARE", "", "", "1.0.0",
  13. "Half-gain pass-through for scan tests", features
  14. };
  15. static uint32_t ports_count (const clap_plugin_t* p, bool in) { (void) p; (void) in; return 1; }
  16. static bool ports_get (const clap_plugin_t* p, uint32_t index, bool in, clap_audio_port_info_t* info)
  17. {
  18. (void) p;
  19. if (index != 0) return false;
  20. memset (info, 0, sizeof (*info));
  21. info->id = in ? 0 : 1;
  22. strcpy (info->name, in ? "In" : "Out");
  23. info->flags = CLAP_AUDIO_PORT_IS_MAIN;
  24. info->channel_count = 2;
  25. info->port_type = CLAP_PORT_STEREO;
  26. info->in_place_pair = CLAP_INVALID_ID;
  27. return true;
  28. }
  29. static const clap_plugin_audio_ports_t audio_ports = { ports_count, ports_get };
  30. static bool p_init (const clap_plugin_t* p) { (void) p; return true; }
  31. static void p_destroy (const clap_plugin_t* p) { free ((void*) p); }
  32. static bool p_activate (const clap_plugin_t* p, double r, uint32_t a, uint32_t b) { (void) p; (void) r; (void) a; (void) b; return true; }
  33. static void p_deactivate (const clap_plugin_t* p) { (void) p; }
  34. static bool p_start (const clap_plugin_t* p) { (void) p; return true; }
  35. static void p_stop (const clap_plugin_t* p) { (void) p; }
  36. static void p_reset (const clap_plugin_t* p) { (void) p; }
  37. static clap_process_status p_process (const clap_plugin_t* p, const clap_process_t* proc)
  38. {
  39. (void) p;
  40. if (proc->audio_inputs_count < 1 || proc->audio_outputs_count < 1) return CLAP_PROCESS_CONTINUE;
  41. for (uint32_t c = 0; c < 2 && c < proc->audio_inputs[0].channel_count && c < proc->audio_outputs[0].channel_count; ++c)
  42. for (uint32_t i = 0; i < proc->frames_count; ++i)
  43. proc->audio_outputs[0].data32[c][i] = 0.5f * proc->audio_inputs[0].data32[c][i];
  44. return CLAP_PROCESS_CONTINUE;
  45. }
  46. static const void* p_extension (const clap_plugin_t* p, const char* id)
  47. {
  48. (void) p;
  49. return strcmp (id, CLAP_EXT_AUDIO_PORTS) == 0 ? &audio_ports : NULL;
  50. }
  51. static void p_main_thread (const clap_plugin_t* p) { (void) p; }
  52. static uint32_t f_count (const clap_plugin_factory_t* f) { (void) f; return 1; }
  53. static const clap_plugin_descriptor_t* f_descriptor (const clap_plugin_factory_t* f, uint32_t i) { (void) f; return i == 0 ? &descriptor : NULL; }
  54. static const clap_plugin_t* f_create (const clap_plugin_factory_t* f, const clap_host_t* host, const char* id)
  55. {
  56. (void) f; (void) host;
  57. if (strcmp (id, descriptor.id) != 0) return NULL;
  58. clap_plugin_t* p = (clap_plugin_t*) calloc (1, sizeof (clap_plugin_t));
  59. p->desc = &descriptor;
  60. p->init = p_init; p->destroy = p_destroy; p->activate = p_activate; p->deactivate = p_deactivate;
  61. p->start_processing = p_start; p->stop_processing = p_stop; p->reset = p_reset; p->process = p_process;
  62. p->get_extension = p_extension; p->on_main_thread = p_main_thread;
  63. return p;
  64. }
  65. static const clap_plugin_factory_t factory = { f_count, f_descriptor, f_create };
  66. static bool e_init (const char* path) { (void) path; return true; }
  67. static void e_deinit (void) {}
  68. static const void* e_factory (const char* id) { return strcmp (id, CLAP_PLUGIN_FACTORY_ID) == 0 ? &factory : NULL; }
  69. CLAP_EXPORT const clap_plugin_entry_t clap_entry = { CLAP_VERSION_INIT, e_init, e_deinit, e_factory };