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.

factory.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * travesty, pure C VST3-compatible interface
  3. * Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include "base.h"
  18. /**
  19. * plugin factory v1
  20. */
  21. struct v3_factory_info {
  22. char vendor[64];
  23. char url[256];
  24. char email[128];
  25. int32_t flags; // set to 0x10 (unicode)
  26. };
  27. struct v3_class_info {
  28. v3_tuid class_id;
  29. int32_t cardinality; // set to 0x7FFFFFFF (many instances)
  30. char category[32];
  31. char name[64];
  32. };
  33. struct v3_plugin_factory {
  34. #ifndef __cplusplus
  35. struct v3_funknown;
  36. #endif
  37. v3_result (V3_API *get_factory_info)(void* self, struct v3_factory_info*);
  38. int32_t (V3_API *num_classes)(void* self);
  39. v3_result (V3_API *get_class_info)(void* self, int32_t idx, struct v3_class_info*);
  40. v3_result (V3_API *create_instance)(void* self, const v3_tuid class_id, const v3_tuid iid, void** instance);
  41. };
  42. static constexpr const v3_tuid v3_plugin_factory_iid =
  43. V3_ID(0x7A4D811C, 0x52114A1F, 0xAED9D2EE, 0x0B43BF9F);
  44. /**
  45. * plugin factory v2
  46. */
  47. enum {
  48. V3_DISTRIBUTABLE = 1 << 0,
  49. V3_SIMPLE_MODE = 1 << 1
  50. };
  51. struct v3_class_info_2 {
  52. v3_tuid class_id;
  53. int32_t cardinality; // set to 0x7FFFFFFF
  54. char category[32];
  55. char name[64];
  56. uint32_t class_flags;
  57. char sub_categories[128];
  58. char vendor[64];
  59. char version[64];
  60. char sdk_version[64];
  61. };
  62. struct v3_plugin_factory_2 {
  63. #ifndef __cplusplus
  64. struct v3_plugin_factory;
  65. #endif
  66. v3_result (V3_API *get_class_info_2)(void* self, int32_t idx, struct v3_class_info_2*);
  67. };
  68. static constexpr const v3_tuid v3_plugin_factory_2_iid =
  69. V3_ID(0x0007B650, 0xF24B4C0B, 0xA464EDB9, 0xF00B2ABB);
  70. /**
  71. * plugin factory v3
  72. * (we got it right this time I swear)
  73. *
  74. * same as above, but "unicode" (really just utf-16, thanks microsoft!)
  75. */
  76. struct v3_class_info_3 {
  77. v3_tuid class_id;
  78. int32_t cardinality; // set to 0x7FFFFFFF
  79. char category[32];
  80. int16_t name[64];
  81. uint32_t class_flags;
  82. char sub_categories[128];
  83. int16_t vendor[64];
  84. int16_t version[64];
  85. int16_t sdk_version[64];
  86. };
  87. struct v3_plugin_factory_3 {
  88. #ifndef __cplusplus
  89. struct v3_plugin_factory_2;
  90. #endif
  91. v3_result (V3_API *get_class_info_utf16)(void* self, int32_t idx, struct v3_class_info_3*);
  92. v3_result (V3_API *set_host_context)(void* self, struct v3_funknown** host);
  93. };
  94. static constexpr const v3_tuid v3_plugin_factory_3_iid =
  95. V3_ID(0x4555A2AB, 0xC1234E57, 0x9B122910, 0x36878931);
  96. #ifdef __cplusplus
  97. /**
  98. * C++ variants
  99. */
  100. struct v3_plugin_factory_cpp : v3_funknown {
  101. v3_plugin_factory v1;
  102. v3_plugin_factory_2 v2;
  103. v3_plugin_factory_3 v3;
  104. };
  105. template<> inline
  106. constexpr v3_plugin_factory_2* v3_cpp_obj(v3_plugin_factory_2** obj)
  107. {
  108. /**
  109. * this ugly piece of code is required due to C++ assuming `reinterpret_cast` by default,
  110. * but we need everything to be `static_cast` for it to be `constexpr` compatible.
  111. */
  112. return static_cast<v3_plugin_factory_2*>(
  113. static_cast<void*>(static_cast<uint8_t*>(static_cast<void*>(*obj)) + sizeof(void*)*7));
  114. }
  115. template<> inline
  116. constexpr v3_plugin_factory_3* v3_cpp_obj(v3_plugin_factory_3** obj)
  117. {
  118. /**
  119. * this ugly piece of code is required due to C++ assuming `reinterpret_cast` by default,
  120. * but we need everything to be `static_cast` for it to be `constexpr` compatible.
  121. */
  122. return static_cast<v3_plugin_factory_3*>(
  123. static_cast<void*>(static_cast<uint8_t*>(static_cast<void*>(*obj)) + sizeof(void*)*8));
  124. }
  125. #endif