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.

CarlaPatchbayUtils.hpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Carla patchbay utils
  3. * Copyright (C) 2011-2014 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. #ifndef CARLA_PATCHBAY_UTILS_HPP_INCLUDED
  18. #define CARLA_PATCHBAY_UTILS_HPP_INCLUDED
  19. #include "LinkedList.hpp"
  20. #define STR_MAX 0xFF
  21. // -----------------------------------------------------------------------
  22. struct GroupNameToId {
  23. uint group;
  24. char name[STR_MAX+1]; // globally unique
  25. void clear() noexcept
  26. {
  27. group = 0;
  28. name[0] = '\0';
  29. }
  30. void setData(const uint g, const char n[]) noexcept
  31. {
  32. group = g;
  33. rename(n);
  34. }
  35. void rename(const char n[]) noexcept
  36. {
  37. std::strncpy(name, n, STR_MAX);
  38. name[STR_MAX] = '\0';
  39. }
  40. bool operator==(const GroupNameToId& groupNameToId) const noexcept
  41. {
  42. if (groupNameToId.group != group)
  43. return false;
  44. if (std::strncmp(groupNameToId.name, name, STR_MAX) != 0)
  45. return false;
  46. return true;
  47. }
  48. bool operator!=(const GroupNameToId& groupNameToId) const noexcept
  49. {
  50. return !operator==(groupNameToId);
  51. }
  52. };
  53. struct PatchbayGroupList {
  54. uint lastId;
  55. LinkedList<GroupNameToId> list;
  56. PatchbayGroupList() noexcept
  57. : lastId(0),
  58. list() {}
  59. void clear() noexcept
  60. {
  61. lastId = 0;
  62. list.clear();
  63. }
  64. uint getGroupId(const char* const groupName) const noexcept;
  65. // always returns valid pointer (non-null)
  66. const char* getGroupName(const uint groupId) const noexcept;
  67. };
  68. // -----------------------------------------------------------------------
  69. struct PortNameToId {
  70. uint group;
  71. uint port;
  72. char name[STR_MAX+1]; // locally unique (within the same group)
  73. char fullName[STR_MAX+1]; // globally unique
  74. void clear() noexcept
  75. {
  76. group = 0;
  77. port = 0;
  78. name[0] = '\0';
  79. fullName[0] = '\0';
  80. }
  81. void setData(const uint g, const uint p, const char n[], const char fn[]) noexcept
  82. {
  83. group = g;
  84. port = p;
  85. rename(n, fn);
  86. }
  87. void setFullName(const char fn[]) noexcept
  88. {
  89. std::strncpy(fullName, fn, STR_MAX);
  90. fullName[STR_MAX] = '\0';
  91. }
  92. void rename(const char n[], const char fn[]) noexcept
  93. {
  94. std::strncpy(name, n, STR_MAX);
  95. name[STR_MAX] = '\0';
  96. std::strncpy(fullName, fn, STR_MAX);
  97. fullName[STR_MAX] = '\0';
  98. }
  99. bool operator==(const PortNameToId& portNameToId) noexcept
  100. {
  101. if (portNameToId.group != group || portNameToId.port != port)
  102. return false;
  103. if (std::strncmp(portNameToId.name, name, STR_MAX) != 0)
  104. return false;
  105. if (std::strncmp(portNameToId.fullName, fullName, STR_MAX) != 0)
  106. return false;
  107. return true;
  108. }
  109. bool operator!=(const PortNameToId& portNameToId) noexcept
  110. {
  111. return !operator==(portNameToId);
  112. }
  113. };
  114. struct PatchbayPortList {
  115. uint lastId;
  116. LinkedList<PortNameToId> list;
  117. PatchbayPortList() noexcept
  118. : lastId(0),
  119. list() {}
  120. void clear() noexcept
  121. {
  122. lastId = 0;
  123. list.clear();
  124. }
  125. // always returns valid pointer (non-null)
  126. const char* getFullPortName(const uint groupId, const uint portId) const noexcept;
  127. const PortNameToId& getPortNameToId(const char* const fullPortName) const noexcept;
  128. };
  129. // -----------------------------------------------------------------------
  130. struct ConnectionToId {
  131. uint id;
  132. uint groupA, portA;
  133. uint groupB, portB;
  134. void clear() noexcept
  135. {
  136. id = 0;
  137. groupA = 0;
  138. portA = 0;
  139. groupB = 0;
  140. portB = 0;
  141. }
  142. void setData(const uint i, const uint gA, const uint pA, const uint gB, const uint pB) noexcept
  143. {
  144. id = i;
  145. groupA = gA;
  146. portA = pA;
  147. groupB = gB;
  148. portB = pB;
  149. }
  150. bool operator==(const ConnectionToId& connectionToId) const noexcept
  151. {
  152. if (connectionToId.id != id)
  153. return false;
  154. if (connectionToId.groupA != groupA || connectionToId.portA != portA)
  155. return false;
  156. if (connectionToId.groupB != groupB || connectionToId.portB != portB)
  157. return false;
  158. return true;
  159. }
  160. bool operator!=(const ConnectionToId& connectionToId) const noexcept
  161. {
  162. return !operator==(connectionToId);
  163. }
  164. };
  165. struct PatchbayConnectionList {
  166. uint lastId;
  167. LinkedList<ConnectionToId> list;
  168. PatchbayConnectionList() noexcept
  169. : lastId(0),
  170. list() {}
  171. void clear() noexcept
  172. {
  173. lastId = 0;
  174. list.clear();
  175. }
  176. };
  177. // -----------------------------------------------------------------------
  178. #endif // CARLA_PATCHBAY_UTILS_HPP_INCLUDED