Audio plugin host https://kx.studio/carla
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.

583 lines
17KB

  1. /*
  2. * Carla Tests
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #undef NDEBUG
  18. #undef DEBUG
  19. #define DEBUG 1
  20. #define RING_BUFFER_SIZE 48
  21. // includes
  22. #include "CarlaDefines.hpp"
  23. #include "CarlaMIDI.h"
  24. #include "ladspa_rdf.hpp"
  25. #include "lv2_rdf.hpp"
  26. // Carla Backend API
  27. #include "CarlaBackend.hpp"
  28. // Carla utils (part 1/4)
  29. #include "CarlaUtils.hpp"
  30. #include "CarlaJuceUtils.hpp"
  31. // Carla utils (part 2/4)
  32. #include "CarlaMutex.hpp"
  33. #include "CarlaRingBuffer.hpp"
  34. #include "CarlaString.hpp"
  35. #include "RtList.hpp"
  36. // Carla utils (part 3/4)
  37. #include "CarlaBackendUtils.hpp"
  38. #include "CarlaBridgeUtils.hpp"
  39. #include "CarlaLadspaUtils.hpp"
  40. #include "CarlaLibUtils.hpp"
  41. // #include "CarlaLv2Utils.hpp"
  42. #include "CarlaOscUtils.hpp"
  43. #include "CarlaShmUtils.hpp"
  44. #include "CarlaStateUtils.hpp"
  45. // #include "CarlaVstUtils.hpp"
  46. // Carla utils (part 4/4)
  47. // #include "Lv2AtomQueue.hpp"
  48. // Carla Native Plugin API
  49. // #include "CarlaNative.h"
  50. // Carla Native Plugin API (C++)
  51. // #include "CarlaNative.hpp"
  52. // Carla Plugin API
  53. // #include "CarlaPlugin.hpp"
  54. // Carla Engine API
  55. // #include "CarlaEngine.hpp"
  56. // Carla Standalone API
  57. // #include "CarlaStandalone.hpp"
  58. // // Carla Plugin
  59. // #include "plugin/CarlaPluginThread.hpp"
  60. // #include "plugin/CarlaPluginInternal.hpp"
  61. // #include "standalone/CarlaStandalone.cpp"
  62. namespace CB = CarlaBackend;
  63. int safe_assert_return_test(bool test)
  64. {
  65. CARLA_SAFE_ASSERT_RETURN(test, 1);
  66. return 0;
  67. }
  68. int main()
  69. {
  70. // ladspa rdf
  71. {
  72. LADSPA_RDF_ScalePoint a;
  73. LADSPA_RDF_Port b;
  74. LADSPA_RDF_Descriptor c;
  75. }
  76. // lv2 rdf
  77. {
  78. LV2_RDF_PortMidiMap a;
  79. LV2_RDF_PortPoints b;
  80. LV2_RDF_PortUnit c;
  81. LV2_RDF_PortScalePoint d;
  82. LV2_RDF_Port e;
  83. LV2_RDF_Preset f;
  84. LV2_RDF_Feature g;
  85. LV2_RDF_UI h;
  86. LV2_RDF_Descriptor i;
  87. }
  88. // Carla Backend API
  89. {
  90. CB::BinaryType a = CB::BINARY_NONE;
  91. CB::PluginType b = CB::PLUGIN_NONE;
  92. CB::PluginCategory c = CB::PLUGIN_CATEGORY_NONE;
  93. CB::ParameterType d = CB::PARAMETER_UNKNOWN;
  94. CB::InternalParametersIndex e = CB::PARAMETER_NULL;
  95. CB::PatchbayIconType f = CB::PATCHBAY_ICON_APPLICATION;
  96. CB::OptionsType g = CB::OPTION_PROCESS_NAME;
  97. CB::CallbackType h = CB::CALLBACK_DEBUG;
  98. CB::ProcessMode i = CB::PROCESS_MODE_SINGLE_CLIENT;
  99. CB::TransportMode j = CB::TRANSPORT_MODE_INTERNAL;
  100. CB::CallbackFunc k = nullptr;
  101. CB::ParameterData l;
  102. CB::ParameterRanges m;
  103. CB::MidiProgramData n;
  104. CB::CustomData o;
  105. a=a;b=b;c=c;d=d;e=e;f=f;g=g;h=h;i=i;j=j;k=k;l=l;m=m;n=n;o=o;
  106. }
  107. #if 0
  108. // Carla Native Plugin API
  109. {
  110. HostHandle a = nullptr;
  111. PluginHandle b = nullptr;
  112. PluginCategory c = PLUGIN_CATEGORY_NONE;
  113. PluginHints d = static_cast<PluginHints>(0x0);
  114. PluginSupports e = static_cast<PluginSupports>(0x0);
  115. ParameterHints f = static_cast<ParameterHints>(0x0);
  116. PluginDispatcherOpcode g = PLUGIN_OPCODE_NULL;
  117. HostDispatcherOpcode h = HOST_OPCODE_NULL;
  118. ParameterScalePoint i;
  119. ParameterRanges j;
  120. Parameter k;
  121. MidiEvent l;
  122. MidiProgram m;
  123. TimeInfoBBT n;
  124. TimeInfo o;
  125. HostDescriptor p;
  126. PluginDescriptor q = { c, d, e,
  127. 0, 0, 0, 0, 0, 0,
  128. nullptr, nullptr, nullptr, nullptr,
  129. nullptr, nullptr,
  130. nullptr, nullptr, nullptr, nullptr,
  131. nullptr, nullptr,
  132. nullptr, nullptr, nullptr,
  133. nullptr, nullptr,
  134. nullptr, nullptr, nullptr,
  135. nullptr, nullptr, nullptr,
  136. nullptr, nullptr,
  137. nullptr };
  138. a=a;b=b;c=c;d=d;e=e;f=f;g=g;h=h;i=i;j=j;k=k;l=l;m=m;n=n;o=o;p=p;
  139. (void)q;
  140. }
  141. #endif
  142. // Carla common utils
  143. {
  144. bool2str(true);
  145. pass();
  146. carla_debug("DEBUG");
  147. carla_stdout("OUT");
  148. carla_stderr("ERR");
  149. carla_stderr2("ERR2");
  150. carla_sleep(1);
  151. carla_msleep(1);
  152. carla_setenv("x", "y");
  153. carla_setprocname("ANSI-Test");
  154. assert(safe_assert_return_test(true) == 0);
  155. assert(safe_assert_return_test(false) == 1);
  156. // carla_strdup
  157. {
  158. const char* s1 = carla_strdup("s1");
  159. const char* s2 = carla_strdup_free(strdup("s2"));
  160. delete[] s1;
  161. delete[] s2;
  162. }
  163. // carla_min
  164. {
  165. assert(carla_min<int>( 1, 2, -1) == 1);
  166. assert(carla_min<int>( 1, 2, 0) == 1);
  167. assert(carla_min<int>( 1, 2, 1) == 1);
  168. assert(carla_min<int>( 1, 2, 2) == 2);
  169. assert(carla_min<int>( 1, 2, 3) == 3);
  170. assert(carla_min<int>( 2, 2, -1) == 2);
  171. assert(carla_min<int>( 1, 2, -1) == 1);
  172. assert(carla_min<int>( 0, 2, -1) == 0);
  173. assert(carla_min<int>(-1, 2, -1) == -1);
  174. assert(carla_min<int>(-2, 2, -1) == -1);
  175. assert(carla_min<int>(-1, 2, 0) == 0);
  176. assert(carla_min<int>(-1, 1, 0) == 0);
  177. assert(carla_min<int>(-1, 0, 0) == 0);
  178. assert(carla_min<int>(-1, -1, 0) == 0);
  179. assert(carla_min<int>(-1, -2, 0) == 0);
  180. unsigned u1 = static_cast<unsigned>(-1);
  181. unsigned u2 = static_cast<unsigned>(-2);
  182. assert(carla_min<unsigned>(u1, u2, 0) == u2);
  183. assert(carla_min<unsigned>(u1, u2, u1) == u1);
  184. assert(carla_min<unsigned>(u1, u2, u2) == u2);
  185. assert(carla_min<unsigned>(u1, 2, 0) == 2);
  186. assert(carla_min<unsigned>( 2, u1, 0) == 2);
  187. assert(carla_min<unsigned>( 2, 2, u1) == u1);
  188. }
  189. // carla_max (same as min)
  190. {
  191. assert(carla_max<int>( 1, 2, -1) == -1);
  192. assert(carla_max<int>( 1, 2, 0) == 0);
  193. assert(carla_max<int>( 1, 2, 1) == 1);
  194. assert(carla_max<int>( 1, 2, 2) == 2);
  195. assert(carla_max<int>( 1, 2, 3) == 2);
  196. assert(carla_max<int>( 2, 2, -1) == -1);
  197. assert(carla_max<int>( 1, 2, -1) == -1);
  198. assert(carla_max<int>( 0, 2, -1) == -1);
  199. assert(carla_max<int>(-1, 2, -1) == -1);
  200. assert(carla_max<int>(-2, 2, -1) == -1);
  201. assert(carla_max<int>(-1, 2, 0) == 0);
  202. assert(carla_max<int>(-1, 1, 0) == 0);
  203. assert(carla_max<int>(-1, 0, 0) == 0);
  204. assert(carla_max<int>(-1, -1, 0) == -1);
  205. assert(carla_max<int>(-1, -2, 0) == -1);
  206. unsigned u1 = static_cast<unsigned>(-1);
  207. unsigned u2 = static_cast<unsigned>(-2);
  208. assert(carla_max<unsigned>(u1, u2, 0) == 0);
  209. assert(carla_max<unsigned>(u1, u2, u1) == u1);
  210. assert(carla_max<unsigned>(u1, u2, u2) == u2);
  211. assert(carla_max<unsigned>(u1, 2, 0) == 0);
  212. assert(carla_max<unsigned>( 2, u1, 0) == 0);
  213. assert(carla_max<unsigned>( 2, 2, u1) == 2);
  214. }
  215. // carla_fixValue (same as min)
  216. {
  217. assert(carla_fixValue<int>( 1, 2, -1) == 1);
  218. assert(carla_fixValue<int>( 1, 2, 0) == 1);
  219. assert(carla_fixValue<int>( 1, 2, 1) == 1);
  220. assert(carla_fixValue<int>( 1, 2, 2) == 2);
  221. assert(carla_fixValue<int>( 1, 2, 3) == 2);
  222. assert(carla_fixValue<int>( 1, 2, -1) == 1);
  223. assert(carla_fixValue<int>( 0, 2, -1) == 0);
  224. assert(carla_fixValue<int>(-1, 2, -1) == -1);
  225. assert(carla_fixValue<int>(-2, 2, -1) == -1);
  226. assert(carla_fixValue<int>(-1, 2, 0) == 0);
  227. assert(carla_fixValue<int>(-1, 1, 0) == 0);
  228. assert(carla_fixValue<int>(-1, 0, 0) == 0);
  229. unsigned u1 = static_cast<unsigned>(-1);
  230. unsigned u2 = static_cast<unsigned>(-2);
  231. assert(carla_fixValue<unsigned>(u2, u1, 0) == u2);
  232. assert(carla_fixValue<unsigned>(u2, u1, u1) == u1);
  233. assert(carla_fixValue<unsigned>(u2, u1, u2) == u2);
  234. }
  235. // carla_add (copy and fill are very similar, so they are ignored here)
  236. {
  237. int a = 0;
  238. int b = 1;
  239. int c = 2;
  240. carla_add<int>(&a, &a, 1);
  241. assert(a == 0);
  242. carla_add<int>(&a, &b, 1);
  243. assert(a == 1);
  244. carla_add<int>(&a, &c, 1);
  245. assert(a == 3);
  246. float d = 10.0f;
  247. float e = 0.11f;
  248. carla_add<float>(&d, &e, 1);
  249. assert(d == 10.11f);
  250. float f[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
  251. float g[5] = { 0.1f, 0.1f, 0.1f, 0.1f, 0.1f };
  252. carla_add<float>(f, g, 5);
  253. assert(f[0] == f[0]);
  254. assert(f[1] == f[1]);
  255. assert(f[2] == f[2]);
  256. assert(f[3] == f[3]);
  257. assert(f[4] == f[4]);
  258. assert(f[0] == g[0]);
  259. assert(f[1] == g[1]);
  260. assert(f[2] == g[2]);
  261. assert(f[3] == g[3]);
  262. assert(f[4] == g[4]);
  263. carla_add<float>(g, f, 1);
  264. carla_add<float>(g, f, 2);
  265. carla_addFloat(g, f, 3);
  266. carla_add(g, f, 4);
  267. carla_add(g, f, 5);
  268. assert(g[0] == f[0]*6);
  269. assert(g[1] == f[1]*5);
  270. assert(g[2] == f[2]*4);
  271. assert(g[3] == f[3]*3);
  272. assert(g[4] == f[4]*2);
  273. carla_stdout("f: %f,%f,%f,%f,%f", f[0], f[1], f[2], f[3], f[4]);
  274. assert(f[0] != g[0]);
  275. assert(f[1] != g[1]);
  276. assert(f[2] != g[2]);
  277. assert(f[3] != g[3]);
  278. assert(f[4] != g[4]);
  279. carla_copy(f, g, 3);
  280. assert(f[0] == g[0]);
  281. assert(f[1] == g[1]);
  282. assert(f[2] == g[2]);
  283. assert(f[3] != g[3]);
  284. assert(f[4] != g[4]);
  285. carla_stdout("f: %f,%f,%f,%f,%f", f[0], f[1], f[2], f[3], f[4]);
  286. }
  287. // memory functions
  288. {
  289. uint64_t a[100];
  290. uint64_t at = 9999;
  291. carla_fill<uint64_t>(a, 100, 1);
  292. assert(a[99] == 1);
  293. assert(at == 9999);
  294. carla_zeroMem(a, sizeof(uint64_t)*100);
  295. assert(a[0] == 0);
  296. assert(a[99] == 0);
  297. assert(at == 9999);
  298. uint64_t b[100];
  299. uint64_t bt = 9999;
  300. carla_fill<uint64_t>(b, 100, 2);
  301. assert(b[99] == 2);
  302. assert(at == 9999);
  303. carla_zeroStruct(b);
  304. assert(b[0] == 0);
  305. assert(b[99] == 0);
  306. assert(bt == 9999);
  307. uint64_t c[100];
  308. uint64_t ct = 9999;
  309. carla_fill<uint64_t>(c, 100, 3);
  310. assert(c[99] == 3);
  311. assert(at == 9999);
  312. carla_zeroStruct(c, 100);
  313. assert(c[0] == 0);
  314. assert(c[99] == 0);
  315. assert(ct == 9999);
  316. struct Test { bool b; void* p; int i; };
  317. Test d, e[11], f[9];
  318. carla_zeroStruct<Test>(d);
  319. carla_zeroStruct<Test>(e, 11);
  320. carla_zeroStruct<Test>(f, 9);
  321. Test* h(new Test);
  322. h->i = 9;
  323. carla_zeroStruct<Test>(h, 1);
  324. assert(h->i == 0);
  325. delete h;
  326. Test* i(new Test[2]);
  327. carla_zeroStruct<Test>(i, 2);
  328. delete[] i;
  329. }
  330. }
  331. // Carla misc utils imported from Juce source code
  332. {
  333. struct Test { char s[24]; void* p; };
  334. ScopedPointer<int> a(new int);
  335. ScopedPointer<long long> b(new long long);
  336. ScopedPointer<Test> c(new Test);
  337. ScopedPointer<Test> d(new Test);
  338. ScopedPointer<Test> e(new Test);
  339. e = nullptr;
  340. delete d.release();
  341. delete e.release();
  342. ScopedPointer<Test> f(nullptr);
  343. }
  344. #if 0
  345. // Carla Native Plugin API (C++)
  346. {
  347. class PluginDescriptorClassTest : public PluginDescriptorClass
  348. {
  349. public:
  350. PluginDescriptorClassTest(const HostDescriptor* const host)
  351. : PluginDescriptorClass(host) {}
  352. protected:
  353. void process(float** const, float** const, const uint32_t, const uint32_t, const MidiEvent* const) {}
  354. PluginDescriptorClassEND(PluginDescriptorClassTest)
  355. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginDescriptorClassTest)
  356. };
  357. const HostDescriptor a = { nullptr, nullptr, nullptr,
  358. nullptr, nullptr, nullptr,
  359. nullptr, nullptr,
  360. nullptr, nullptr, nullptr, nullptr,
  361. nullptr, nullptr,
  362. nullptr };
  363. PluginDescriptor b = { PLUGIN_CATEGORY_NONE, PLUGIN_IS_RTSAFE, PLUGIN_SUPPORTS_EVERYTHING,
  364. 0, 0, 0, 0, 0, 0,
  365. nullptr, nullptr, nullptr, nullptr,
  366. PluginDescriptorFILL(PluginDescriptorClassTest) };
  367. (void)b;
  368. ScopedPointer<PluginDescriptorClassTest> c;
  369. c = new PluginDescriptorClassTest(&a);
  370. }
  371. // Carla Backend utils
  372. {
  373. class TestClass { public: int i; char pad[50]; };
  374. TestClass a, b, c;
  375. uintptr_t ad = CarlaBackend::getAddressFromPointer(&a);
  376. uintptr_t bd = CarlaBackend::getAddressFromPointer(&b);
  377. uintptr_t cd = CarlaBackend::getAddressFromPointer(&c);
  378. assert(bd > ad);
  379. assert(cd > bd);
  380. TestClass* ap = CarlaBackend::getPointerFromAddress<TestClass>(ad);
  381. TestClass* bp = CarlaBackend::getPointerFromAddress<TestClass>(bd);
  382. TestClass* cp = CarlaBackend::getPointerFromAddress<TestClass>(cd);
  383. assert(ap == &a);
  384. assert(bp == &b);
  385. assert(cp == &c);
  386. ap->i = 4;
  387. bp->i = 5;
  388. cp->i = 6;
  389. assert(a.i == 4);
  390. assert(b.i == 5);
  391. assert(c.i == 6);
  392. }
  393. #endif
  394. // Carla Mutex
  395. {
  396. CarlaMutex m;
  397. m.tryLock();
  398. m.unlock();
  399. const CarlaMutex::ScopedLocker sl(m);
  400. }
  401. // RingBuffer
  402. {
  403. RingBuffer buf;
  404. RingBufferControl ctrl(&buf);
  405. assert(! ctrl.dataAvailable());
  406. assert(ctrl.readInt() == 0);
  407. assert(ctrl.readFloat() == 0.0f);
  408. assert(! ctrl.dataAvailable());
  409. ctrl.writeChar('z');
  410. ctrl.commitWrite();
  411. assert(ctrl.dataAvailable());
  412. const char c = ctrl.readChar();
  413. carla_stdout("BufRead c = \"%c\"", c);
  414. assert(c != '\0');
  415. assert(c == 'z');
  416. assert(! ctrl.dataAvailable());
  417. ctrl.writeInt(9999);
  418. ctrl.commitWrite();
  419. const int i = ctrl.readInt();
  420. carla_stdout("BufRead i = \"%i\"", i);
  421. assert(i != 0);
  422. assert(i == 9999);
  423. ctrl.writeLong(-88088);
  424. ctrl.commitWrite();
  425. const long l = ctrl.readLong();
  426. carla_stdout("BufRead l = \"%li\"", l);
  427. assert(l != 0);
  428. assert(l == -88088);
  429. ctrl.writeFloat(5.6789f);
  430. ctrl.commitWrite();
  431. const float f = ctrl.readFloat();
  432. carla_stdout("BufRead f = \"%f\"", f);
  433. assert(f != 0.0f);
  434. assert(f == 5.6789f);
  435. assert(! ctrl.dataAvailable());
  436. for (char i='1'; i <= 'z'; ++i)
  437. {
  438. ctrl.writeChar(char(i));
  439. ctrl.commitWrite();
  440. }
  441. assert(ctrl.dataAvailable());
  442. printf("CHAR DUMP:\n");
  443. while (ctrl.dataAvailable())
  444. printf("%c", ctrl.readChar());
  445. assert(! ctrl.dataAvailable());
  446. printf("\nDUMP FINISHED\n");
  447. }
  448. // RtList
  449. {
  450. class ListTester
  451. {
  452. public:
  453. struct CountObj {
  454. CountObj() : count(0) {}
  455. volatile int count;
  456. };
  457. ListTester()
  458. {
  459. ++getCounter().count;
  460. }
  461. ~ListTester()
  462. {
  463. --getCounter().count;
  464. }
  465. static CountObj& getCounter()
  466. {
  467. static CountObj counter;
  468. return counter;
  469. }
  470. };
  471. ListTester::CountObj& obj = ListTester::getCounter();
  472. assert(obj.count == 0);
  473. NonRtList<ListTester> list;
  474. obj = ListTester::getCounter();
  475. assert(obj.count == 1); // List fRetValue
  476. ListTester t1;
  477. obj = ListTester::getCounter();
  478. assert(obj.count == 2); // List fRetValue + t1
  479. list.append(t1);
  480. list.append(t1);
  481. list.append(t1);
  482. obj = ListTester::getCounter();
  483. assert(obj.count == 5); // List fRetValue + t1 + 3 appends
  484. list.clear();
  485. obj = ListTester::getCounter();
  486. assert(obj.count == 2); // List fRetValue + t1
  487. }
  488. return 0;
  489. }