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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 rename(const char n[], const char fn[]) noexcept
  88. {
  89. std::strncpy(name, n, STR_MAX);
  90. name[STR_MAX] = '\0';
  91. std::strncpy(fullName, fn, STR_MAX);
  92. fullName[STR_MAX] = '\0';
  93. }
  94. bool operator==(const PortNameToId& portNameToId) noexcept
  95. {
  96. if (portNameToId.group != group || portNameToId.port != port)
  97. return false;
  98. if (std::strncmp(portNameToId.name, name, STR_MAX) != 0)
  99. return false;
  100. if (std::strncmp(portNameToId.fullName, fullName, STR_MAX) != 0)
  101. return false;
  102. return true;
  103. }
  104. bool operator!=(const PortNameToId& portNameToId) noexcept
  105. {
  106. return !operator==(portNameToId);
  107. }
  108. };
  109. struct PatchbayPortList {
  110. uint lastId;
  111. LinkedList<PortNameToId> list;
  112. PatchbayPortList() noexcept
  113. : lastId(0),
  114. list() {}
  115. void clear() noexcept
  116. {
  117. lastId = 0;
  118. list.clear();
  119. }
  120. // always returns valid pointer (non-null)
  121. const char* getFullPortName(const uint groupId, const uint portId) const noexcept;
  122. const PortNameToId& getPortNameToId(const char* const fullPortName) const noexcept;
  123. };
  124. // -----------------------------------------------------------------------
  125. struct ConnectionToId {
  126. uint id;
  127. uint groupA, portA;
  128. uint groupB, portB;
  129. void clear() noexcept
  130. {
  131. id = 0;
  132. groupA = 0;
  133. portA = 0;
  134. groupB = 0;
  135. portB = 0;
  136. }
  137. void setData(const uint i, const uint gA, const uint pA, const uint gB, const uint pB) noexcept
  138. {
  139. id = i;
  140. groupA = gA;
  141. portA = pA;
  142. groupB = gB;
  143. portB = pB;
  144. }
  145. bool operator==(const ConnectionToId& connectionToId) const noexcept
  146. {
  147. if (connectionToId.id != id)
  148. return false;
  149. if (connectionToId.groupA != groupA || connectionToId.portA != portA)
  150. return false;
  151. if (connectionToId.groupB != groupB || connectionToId.portB != portB)
  152. return false;
  153. return true;
  154. }
  155. bool operator!=(const ConnectionToId& connectionToId) const noexcept
  156. {
  157. return !operator==(connectionToId);
  158. }
  159. };
  160. struct PatchbayConnectionList {
  161. uint lastId;
  162. LinkedList<ConnectionToId> list;
  163. PatchbayConnectionList() noexcept
  164. : lastId(0),
  165. list() {}
  166. void clear() noexcept
  167. {
  168. lastId = 0;
  169. list.clear();
  170. }
  171. };
  172. // -----------------------------------------------------------------------
  173. #endif // CARLA_PATCHBAY_UTILS_HPP_INCLUDED