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.

222 lines
5.3KB

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