lynx_test_ext.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /* A CLAP effect for LYNX's CLAP extension and timing tests (round 190jg, BUILD-LIST 18):
  2. * Windows: zig cc -shared -O2 -target x86_64-windows-gnu -Ithird_party/clap/include tools/testplugin/lynx_test_ext.c \
  3. * -o "LYNX Test Ext.clap"
  4. * Linux / macOS: cc -shared -fPIC -O2 -Ithird_party/clap/include tools/testplugin/lynx_test_ext.c -lpthread -o "LYNX Test Ext.clap"
  5. * then: LYNX --clapext "LYNX Test Ext.clap" report.txt; LYNX --automationtimingtest "LYNX Test Ext.clap" report.txt
  6. * Sound: it ignores its input and outputs its "Level" parameter (id 7, 0..1) as a constant (DC) on both channels,
  7. * taking each CLAP_EVENT_PARAM_VALUE at its own sample (the event's time): a step of the automation shows in the output
  8. * at the sample the host put it.
  9. * It also uses / offers, and writes down in the file named by the environment variable LYNX_TEST_EXT_LOG:
  10. * thread-pool on its 10th process call it asks the host to run 8 tasks ("pool ok=1 tasks=8 threads=<n>")
  11. * tail 4800 samples; voice-info: 3 voices of 16, overlapping notes
  12. * render the mode the host sets ("render offline" / "render realtime")
  13. * state-context a state saved for a preset / a duplicate / the project ("save context=<n>", "load context=<n>")
  14. * remote-controls one page "Test / Main": Level, Width, then empty knobs
  15. * preset-discovery + preset-load: three presets inside the plugin ("Low" 0.25, "Mid" 0.5, "High" 0.75)
  16. * and the parameter events it received ("P <time> <value> n=<frames>", the first 400), and (round 190sj) the transport's
  17. * tempo each time it changes ("T <tempo> <playing>", "T none <playing>" when the host gives no transport).
  18. * Round 190te (issue #356): the song position the transport says in its first 64 playing process calls ("S <beats> <playing>",
  19. * beats = quarter notes; "S none <playing>" without a position), and LYNX_TEST_EXT_LATENCY=<n> reports n samples of
  20. * latency (its output is a constant, so nothing to delay): LYNX --latency356test.
  21. */
  22. #include <clap/clap.h>
  23. #include <stdatomic.h>
  24. #include <stdint.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #if defined(_WIN32)
  29. #include <windows.h>
  30. #else
  31. #include <pthread.h>
  32. #endif
  33. #define LEVEL_ID 7
  34. #define WIDTH_ID 9
  35. static const char* const features[] = { CLAP_PLUGIN_FEATURE_AUDIO_EFFECT, CLAP_PLUGIN_FEATURE_UTILITY, NULL };
  36. static const clap_plugin_descriptor_t descriptor = {
  37. CLAP_VERSION_INIT, "org.lynx.test-ext", "LYNX Test Ext", "LYNX", "https://github.com/Ka1-S/LYNX-SHARE", "", "", "1.0.0",
  38. "CLAP extension and timing tests", features
  39. };
  40. static FILE* log_file (void)
  41. {
  42. static FILE* f = NULL;
  43. static int opened = 0;
  44. if (! opened)
  45. {
  46. opened = 1;
  47. #if defined(_WIN32)
  48. char path[1024] = { 0 };
  49. if (GetEnvironmentVariableA ("LYNX_TEST_EXT_LOG", path, sizeof (path)) > 0)
  50. f = fopen (path, "a");
  51. #else
  52. const char* path = getenv ("LYNX_TEST_EXT_LOG");
  53. if (path != NULL)
  54. f = fopen (path, "a");
  55. #endif
  56. }
  57. return f;
  58. }
  59. static void say (const char* text)
  60. {
  61. FILE* f = log_file();
  62. if (f != NULL)
  63. {
  64. fputs (text, f);
  65. fflush (f);
  66. }
  67. }
  68. typedef struct
  69. {
  70. clap_plugin_t plugin;
  71. const clap_host_t* host;
  72. double level, width;
  73. double lastTempo; /* round 190sj: the last tempo logged */
  74. int lastPlaying;
  75. int calls, logged;
  76. int positionsLogged; /* round 190te */
  77. atomic_int tasks;
  78. atomic_ullong threadIds[8];
  79. } Ext;
  80. static Ext* self_of (const clap_plugin_t* p) { return (Ext*) p->plugin_data; }
  81. static unsigned long long thread_id (void)
  82. {
  83. #if defined(_WIN32)
  84. return (unsigned long long) GetCurrentThreadId();
  85. #else
  86. return (unsigned long long) (uintptr_t) pthread_self();
  87. #endif
  88. }
  89. /* audio ports */
  90. /* round 190rk: a second port each way (a "Sidechain" input, an "Aux" output), as FabFilter's effects have: the host
  91. * must give process() one buffer per declared port (it gave the main ones only, and they read past the array) */
  92. static uint32_t ports_count (const clap_plugin_t* p, bool in) { (void) p; (void) in; return 2; }
  93. static bool ports_get (const clap_plugin_t* p, uint32_t index, bool in, clap_audio_port_info_t* info)
  94. {
  95. (void) p;
  96. if (index > 1) return false;
  97. memset (info, 0, sizeof (*info));
  98. info->id = (in ? 0 : 1) + 10 * index;
  99. strcpy (info->name, index == 1 ? (in ? "Sidechain" : "Aux") : (in ? "In" : "Out"));
  100. info->flags = index == 0 ? CLAP_AUDIO_PORT_IS_MAIN : 0;
  101. info->channel_count = 2;
  102. info->port_type = CLAP_PORT_STEREO;
  103. info->in_place_pair = CLAP_INVALID_ID;
  104. return true;
  105. }
  106. static const clap_plugin_audio_ports_t audio_ports = { ports_count, ports_get };
  107. /* params */
  108. static uint32_t params_count (const clap_plugin_t* p) { (void) p; return 2; }
  109. static bool params_info (const clap_plugin_t* p, uint32_t index, clap_param_info_t* info)
  110. {
  111. (void) p;
  112. if (index > 1) return false;
  113. memset (info, 0, sizeof (*info));
  114. info->id = index == 0 ? LEVEL_ID : WIDTH_ID;
  115. info->flags = CLAP_PARAM_IS_AUTOMATABLE;
  116. strcpy (info->name, index == 0 ? "Level" : "Width");
  117. info->min_value = 0.0;
  118. info->max_value = 1.0;
  119. info->default_value = 0.5;
  120. return true;
  121. }
  122. static bool params_value (const clap_plugin_t* p, clap_id id, double* value)
  123. {
  124. Ext* e = self_of (p);
  125. if (id == LEVEL_ID) { *value = e->level; return true; }
  126. if (id == WIDTH_ID) { *value = e->width; return true; }
  127. return false;
  128. }
  129. static bool params_to_text (const clap_plugin_t* p, clap_id id, double v, char* out, uint32_t size)
  130. {
  131. (void) p; (void) id;
  132. snprintf (out, size, "%.3f", v);
  133. return true;
  134. }
  135. static bool params_from_text (const clap_plugin_t* p, clap_id id, const char* text, double* v)
  136. {
  137. (void) p; (void) id;
  138. *v = atof (text);
  139. return true;
  140. }
  141. static void apply_event (Ext* e, const clap_event_header_t* h, uint32_t frames)
  142. {
  143. if (h->space_id != CLAP_CORE_EVENT_SPACE_ID || h->type != CLAP_EVENT_PARAM_VALUE) return;
  144. const clap_event_param_value_t* v = (const clap_event_param_value_t*) h;
  145. if (v->param_id == LEVEL_ID)
  146. {
  147. e->level = v->value;
  148. if (e->logged < 400)
  149. {
  150. char line[96];
  151. snprintf (line, sizeof (line), "P %u %.6f n=%u\n", (unsigned) h->time, v->value, (unsigned) frames);
  152. say (line);
  153. ++e->logged;
  154. }
  155. }
  156. else if (v->param_id == WIDTH_ID)
  157. e->width = v->value;
  158. }
  159. static void params_flush (const clap_plugin_t* p, const clap_input_events_t* in, const clap_output_events_t* out)
  160. {
  161. (void) out;
  162. for (uint32_t i = 0; i < in->size (in); ++i)
  163. apply_event (self_of (p), in->get (in, i), 0);
  164. }
  165. static const clap_plugin_params_t params = { params_count, params_info, params_value, params_to_text, params_from_text, params_flush };
  166. /* state + state-context */
  167. static bool write_state (Ext* e, const clap_ostream_t* s, uint32_t context)
  168. {
  169. unsigned char data[12];
  170. float level = (float) e->level, width = (float) e->width;
  171. memcpy (data, "LXE", 3);
  172. data[3] = (unsigned char) context;
  173. memcpy (data + 4, &level, 4);
  174. memcpy (data + 8, &width, 4);
  175. return s->write (s, data, sizeof (data)) == (int64_t) sizeof (data);
  176. }
  177. static bool read_state (Ext* e, const clap_istream_t* s, uint32_t* context)
  178. {
  179. unsigned char data[12];
  180. if (s->read (s, data, sizeof (data)) != (int64_t) sizeof (data) || memcmp (data, "LXE", 3) != 0) return false;
  181. float level, width;
  182. memcpy (&level, data + 4, 4);
  183. memcpy (&width, data + 8, 4);
  184. e->level = level;
  185. e->width = width;
  186. *context = data[3];
  187. return true;
  188. }
  189. static bool state_save (const clap_plugin_t* p, const clap_ostream_t* s) { say ("save context=0\n"); return write_state (self_of (p), s, 0); }
  190. static bool state_load (const clap_plugin_t* p, const clap_istream_t* s)
  191. {
  192. uint32_t saved = 0;
  193. say ("load context=0\n");
  194. return read_state (self_of (p), s, &saved);
  195. }
  196. static const clap_plugin_state_t state = { state_save, state_load };
  197. static bool context_save (const clap_plugin_t* p, const clap_ostream_t* s, uint32_t context)
  198. {
  199. char line[48];
  200. snprintf (line, sizeof (line), "save context=%u\n", (unsigned) context);
  201. say (line);
  202. return write_state (self_of (p), s, context);
  203. }
  204. static bool context_load (const clap_plugin_t* p, const clap_istream_t* s, uint32_t context)
  205. {
  206. uint32_t saved = 0;
  207. char line[64];
  208. const bool ok = read_state (self_of (p), s, &saved);
  209. snprintf (line, sizeof (line), "load context=%u saved_with=%u\n", (unsigned) context, (unsigned) saved);
  210. say (line);
  211. return ok;
  212. }
  213. static const clap_plugin_state_context_t state_context = { context_save, context_load };
  214. /* latency (0, or LYNX_TEST_EXT_LATENCY: round 190te), tail, render, voice info */
  215. static uint32_t latency_get (const clap_plugin_t* p)
  216. {
  217. (void) p;
  218. #if defined(_WIN32)
  219. char text[32] = { 0 };
  220. return GetEnvironmentVariableA ("LYNX_TEST_EXT_LATENCY", text, sizeof (text)) > 0 ? (uint32_t) atoi (text) : 0u;
  221. #else
  222. const char* text = getenv ("LYNX_TEST_EXT_LATENCY");
  223. return text != NULL ? (uint32_t) atoi (text) : 0u;
  224. #endif
  225. }
  226. static const clap_plugin_latency_t latency = { latency_get };
  227. static uint32_t tail_get (const clap_plugin_t* p) { (void) p; return 4800; }
  228. static const clap_plugin_tail_t tail = { tail_get };
  229. static bool render_hard (const clap_plugin_t* p) { (void) p; return false; }
  230. static bool render_set (const clap_plugin_t* p, clap_plugin_render_mode mode)
  231. {
  232. (void) p;
  233. say (mode == CLAP_RENDER_OFFLINE ? "render offline\n" : "render realtime\n");
  234. return true;
  235. }
  236. static const clap_plugin_render_t render = { render_hard, render_set };
  237. static bool voice_get (const clap_plugin_t* p, clap_voice_info_t* info)
  238. {
  239. (void) p;
  240. info->voice_count = 3;
  241. info->voice_capacity = 16;
  242. info->flags = CLAP_VOICE_INFO_SUPPORTS_OVERLAPPING_NOTES;
  243. return true;
  244. }
  245. static const clap_plugin_voice_info_t voice_info = { voice_get };
  246. /* thread pool */
  247. static void pool_exec (const clap_plugin_t* p, uint32_t task)
  248. {
  249. Ext* e = self_of (p);
  250. atomic_fetch_add (&e->tasks, 1);
  251. if (task < 8) atomic_store (&e->threadIds[task], thread_id());
  252. volatile double x = 0.0; /* a little work so the tasks overlap */
  253. for (int i = 0; i < 20000; ++i) x += (double) i * 1e-9;
  254. }
  255. static const clap_plugin_thread_pool_t thread_pool = { pool_exec };
  256. /* remote controls */
  257. static uint32_t remote_count (const clap_plugin_t* p) { (void) p; return 1; }
  258. static bool remote_get (const clap_plugin_t* p, uint32_t index, clap_remote_controls_page_t* page)
  259. {
  260. (void) p;
  261. if (index != 0) return false;
  262. memset (page, 0, sizeof (*page));
  263. strcpy (page->section_name, "Test");
  264. strcpy (page->page_name, "Main");
  265. page->page_id = 1;
  266. for (int k = 0; k < CLAP_REMOTE_CONTROLS_COUNT; ++k) page->param_ids[k] = CLAP_INVALID_ID;
  267. page->param_ids[0] = WIDTH_ID; /* (the page's own order: Width first, then Level) */
  268. page->param_ids[1] = LEVEL_ID;
  269. return true;
  270. }
  271. static const clap_plugin_remote_controls_t remote_controls = { remote_count, remote_get };
  272. /* preset load */
  273. static bool preset_load (const clap_plugin_t* p, uint32_t kind, const char* location, const char* key)
  274. {
  275. Ext* e = self_of (p);
  276. (void) location;
  277. if (kind != CLAP_PRESET_DISCOVERY_LOCATION_PLUGIN || key == NULL) return false;
  278. double v = strcmp (key, "low") == 0 ? 0.25 : strcmp (key, "mid") == 0 ? 0.5 : strcmp (key, "high") == 0 ? 0.75 : -1.0;
  279. if (v < 0.0) return false;
  280. e->level = v;
  281. char line[64];
  282. snprintf (line, sizeof (line), "preset %s level=%.2f\n", key, v);
  283. say (line);
  284. const clap_host_preset_load_t* host = (const clap_host_preset_load_t*) e->host->get_extension (e->host, CLAP_EXT_PRESET_LOAD);
  285. if (host != NULL) host->loaded (e->host, kind, location, key);
  286. return true;
  287. }
  288. static const clap_plugin_preset_load_t preset_load_ext = { preset_load };
  289. /* plugin */
  290. static bool p_init (const clap_plugin_t* p) { (void) p; return true; }
  291. static void p_destroy (const clap_plugin_t* p) { free (self_of (p)); }
  292. 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; }
  293. static void p_deactivate (const clap_plugin_t* p) { (void) p; }
  294. static bool p_start (const clap_plugin_t* p) { (void) p; return true; }
  295. static void p_stop (const clap_plugin_t* p) { (void) p; }
  296. static void p_reset (const clap_plugin_t* p) { (void) p; }
  297. static clap_process_status p_process (const clap_plugin_t* p, const clap_process_t* proc)
  298. {
  299. Ext* e = self_of (p);
  300. const uint32_t n = proc->frames_count;
  301. const uint32_t events = proc->in_events->size (proc->in_events);
  302. uint32_t next = 0;
  303. float* l = proc->audio_outputs_count > 0 && proc->audio_outputs[0].channel_count > 0 ? proc->audio_outputs[0].data32[0] : NULL;
  304. float* r = proc->audio_outputs_count > 0 && proc->audio_outputs[0].channel_count > 1 ? proc->audio_outputs[0].data32[1] : NULL;
  305. for (uint32_t i = 0; i < n; ++i)
  306. {
  307. while (next < events)
  308. {
  309. const clap_event_header_t* h = proc->in_events->get (proc->in_events, next);
  310. if (h->time > i) break;
  311. apply_event (e, h, n);
  312. ++next;
  313. }
  314. if (l != NULL) l[i] = (float) e->level;
  315. if (r != NULL) r[i] = (float) e->level;
  316. }
  317. for (; next < events; ++next)
  318. apply_event (e, proc->in_events->get (proc->in_events, next), n);
  319. /* round 190sj: the tempo the host's transport says, each time it changes ("T <tempo> <playing>"; "T none" without one) */
  320. {
  321. const double tempo = proc->transport != NULL && (proc->transport->flags & CLAP_TRANSPORT_HAS_TEMPO) ? proc->transport->tempo : -1.0;
  322. const int playing = proc->transport != NULL && (proc->transport->flags & CLAP_TRANSPORT_IS_PLAYING) ? 1 : 0;
  323. if (e->calls == 0 || tempo != e->lastTempo || playing != e->lastPlaying)
  324. {
  325. char line[64];
  326. if (tempo < 0.0) snprintf (line, sizeof (line), "T none %d\n", playing);
  327. else snprintf (line, sizeof (line), "T %.3f %d\n", tempo, playing);
  328. say (line);
  329. e->lastTempo = tempo;
  330. e->lastPlaying = playing;
  331. }
  332. }
  333. /* round 190te (issue #356): the song position of the first 64 calls while playing (a host's warm-up runs stopped) */
  334. if (e->positionsLogged < 64 && proc->transport != NULL && (proc->transport->flags & CLAP_TRANSPORT_IS_PLAYING))
  335. {
  336. char line[64];
  337. const int playing = 1;
  338. ++e->positionsLogged;
  339. if (proc->transport->flags & CLAP_TRANSPORT_HAS_BEATS_TIMELINE)
  340. snprintf (line, sizeof (line), "S %.9f %d\n", (double) proc->transport->song_pos_beats / (double) CLAP_BEATTIME_FACTOR, playing);
  341. else
  342. snprintf (line, sizeof (line), "S none %d\n", playing);
  343. say (line);
  344. }
  345. if (e->calls == 4)
  346. {
  347. /* round 190rk: what the host passed (one buffer per port; a transport) */
  348. char line[160];
  349. int writable = proc->audio_outputs_count > 1 && proc->audio_outputs[1].channel_count > 0 && proc->audio_outputs[1].data32 != NULL
  350. && proc->audio_outputs[1].data32[0] != NULL;
  351. if (writable) proc->audio_outputs[1].data32[0][0] = 0.0f;
  352. snprintf (line, sizeof (line), "ports in=%u out=%u side_channels=%u aux_writable=%d transport=%d\n", proc->audio_inputs_count,
  353. proc->audio_outputs_count, proc->audio_inputs_count > 1 ? proc->audio_inputs[1].channel_count : 0u, writable,
  354. proc->transport != NULL ? 1 : 0);
  355. say (line);
  356. }
  357. if (++e->calls == 10)
  358. {
  359. const clap_host_thread_pool_t* pool = (const clap_host_thread_pool_t*) e->host->get_extension (e->host, CLAP_EXT_THREAD_POOL);
  360. atomic_store (&e->tasks, 0);
  361. for (int k = 0; k < 8; ++k) atomic_store (&e->threadIds[k], 0ULL);
  362. const bool ok = pool != NULL && pool->request_exec (e->host, 8);
  363. int threads = 0;
  364. for (int a = 0; a < 8; ++a)
  365. {
  366. const unsigned long long id = atomic_load (&e->threadIds[a]);
  367. int seen = 0;
  368. for (int b = 0; b < a; ++b) seen = seen || atomic_load (&e->threadIds[b]) == id;
  369. if (id != 0 && ! seen) ++threads;
  370. }
  371. char line[96];
  372. snprintf (line, sizeof (line), "pool ok=%d tasks=%d threads=%d\n", ok ? 1 : 0, atomic_load (&e->tasks), threads);
  373. say (line);
  374. }
  375. return CLAP_PROCESS_CONTINUE;
  376. }
  377. static const void* p_extension (const clap_plugin_t* p, const char* id)
  378. {
  379. (void) p;
  380. if (strcmp (id, CLAP_EXT_AUDIO_PORTS) == 0) return &audio_ports;
  381. if (strcmp (id, CLAP_EXT_PARAMS) == 0) return &params;
  382. if (strcmp (id, CLAP_EXT_STATE) == 0) return &state;
  383. if (strcmp (id, CLAP_EXT_STATE_CONTEXT) == 0) return &state_context;
  384. if (strcmp (id, CLAP_EXT_LATENCY) == 0) return &latency;
  385. if (strcmp (id, CLAP_EXT_TAIL) == 0) return &tail;
  386. if (strcmp (id, CLAP_EXT_RENDER) == 0) return &render;
  387. if (strcmp (id, CLAP_EXT_VOICE_INFO) == 0) return &voice_info;
  388. if (strcmp (id, CLAP_EXT_THREAD_POOL) == 0) return &thread_pool;
  389. if (strcmp (id, CLAP_EXT_REMOTE_CONTROLS) == 0) return &remote_controls;
  390. if (strcmp (id, CLAP_EXT_PRESET_LOAD) == 0) return &preset_load_ext;
  391. return NULL;
  392. }
  393. static void p_main_thread (const clap_plugin_t* p) { (void) p; }
  394. static uint32_t f_count (const clap_plugin_factory_t* f) { (void) f; return 1; }
  395. static const clap_plugin_descriptor_t* f_descriptor (const clap_plugin_factory_t* f, uint32_t i) { (void) f; return i == 0 ? &descriptor : NULL; }
  396. static const clap_plugin_t* f_create (const clap_plugin_factory_t* f, const clap_host_t* host, const char* id)
  397. {
  398. (void) f;
  399. if (strcmp (id, descriptor.id) != 0) return NULL;
  400. Ext* e = (Ext*) calloc (1, sizeof (Ext));
  401. e->host = host;
  402. e->level = 0.5;
  403. e->width = 0.5;
  404. clap_plugin_t* p = &e->plugin;
  405. p->desc = &descriptor;
  406. p->plugin_data = e;
  407. p->init = p_init; p->destroy = p_destroy; p->activate = p_activate; p->deactivate = p_deactivate;
  408. p->start_processing = p_start; p->stop_processing = p_stop; p->reset = p_reset; p->process = p_process;
  409. p->get_extension = p_extension; p->on_main_thread = p_main_thread;
  410. return p;
  411. }
  412. static const clap_plugin_factory_t factory = { f_count, f_descriptor, f_create };
  413. /* preset discovery: one provider with three presets inside the plugin */
  414. static const clap_preset_discovery_provider_descriptor_t provider_descriptor = { CLAP_VERSION_INIT, "org.lynx.test-ext.presets", "LYNX Test Ext presets", "LYNX" };
  415. static bool prov_init (const clap_preset_discovery_provider_t* p)
  416. {
  417. const clap_preset_discovery_indexer_t* indexer = (const clap_preset_discovery_indexer_t*) p->provider_data;
  418. const clap_preset_discovery_location_t location = { CLAP_PRESET_DISCOVERY_IS_FACTORY_CONTENT, "Factory", CLAP_PRESET_DISCOVERY_LOCATION_PLUGIN, NULL };
  419. return indexer->declare_location (indexer, &location);
  420. }
  421. static void prov_destroy (const clap_preset_discovery_provider_t* p) { free ((void*) p); }
  422. static bool prov_metadata (const clap_preset_discovery_provider_t* p, uint32_t kind, const char* location, const clap_preset_discovery_metadata_receiver_t* r)
  423. {
  424. (void) p; (void) location;
  425. if (kind != CLAP_PRESET_DISCOVERY_LOCATION_PLUGIN) return false;
  426. static const char* const names[3] = { "Low", "Mid", "High" };
  427. static const char* const keys[3] = { "low", "mid", "high" };
  428. const clap_universal_plugin_id_t id = { "clap", "org.lynx.test-ext" };
  429. for (int i = 0; i < 3; ++i)
  430. if (r->begin_preset (r, names[i], keys[i]))
  431. r->add_plugin_id (r, &id);
  432. return true;
  433. }
  434. static const void* prov_extension (const clap_preset_discovery_provider_t* p, const char* id) { (void) p; (void) id; return NULL; }
  435. static uint32_t d_count (const clap_preset_discovery_factory_t* f) { (void) f; return 1; }
  436. static const clap_preset_discovery_provider_descriptor_t* d_descriptor (const clap_preset_discovery_factory_t* f, uint32_t i)
  437. {
  438. (void) f;
  439. return i == 0 ? &provider_descriptor : NULL;
  440. }
  441. static const clap_preset_discovery_provider_t* d_create (const clap_preset_discovery_factory_t* f, const clap_preset_discovery_indexer_t* indexer, const char* id)
  442. {
  443. (void) f;
  444. if (strcmp (id, provider_descriptor.id) != 0) return NULL;
  445. clap_preset_discovery_provider_t* p = (clap_preset_discovery_provider_t*) calloc (1, sizeof (*p));
  446. p->desc = &provider_descriptor;
  447. p->provider_data = (void*) indexer;
  448. p->init = prov_init;
  449. p->destroy = prov_destroy;
  450. p->get_metadata = prov_metadata;
  451. p->get_extension = prov_extension;
  452. return p;
  453. }
  454. static const clap_preset_discovery_factory_t discovery = { d_count, d_descriptor, d_create };
  455. static bool e_init (const char* path) { (void) path; return true; }
  456. static void e_deinit (void) {}
  457. static const void* e_factory (const char* id)
  458. {
  459. if (strcmp (id, CLAP_PLUGIN_FACTORY_ID) == 0) return &factory;
  460. if (strcmp (id, CLAP_PRESET_DISCOVERY_FACTORY_ID) == 0) return &discovery;
  461. return NULL;
  462. }
  463. CLAP_EXPORT const clap_plugin_entry_t clap_entry = { CLAP_VERSION_INIT, e_init, e_deinit, e_factory };