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.

85 lines
2.9KB

  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. #include "CarlaPatchbayUtils.hpp"
  18. static const GroupNameToId kGroupNameToIdFallback = { 0, { '\0' } };
  19. static const PortNameToId kPortNameToIdFallback = { 0, 0, { '\0' }, { '\0' } };
  20. uint PatchbayGroupList::getGroupId(const char* const groupName) const noexcept
  21. {
  22. CARLA_SAFE_ASSERT_RETURN(groupName != nullptr && groupName[0] != '\0', 0);
  23. for (LinkedList<GroupNameToId>::Itenerator it = list.begin(); it.valid(); it.next())
  24. {
  25. const GroupNameToId& groupNameToId(it.getValue(kGroupNameToIdFallback));
  26. CARLA_SAFE_ASSERT_CONTINUE(groupNameToId.group != 0);
  27. if (std::strncmp(groupNameToId.name, groupName, STR_MAX) == 0)
  28. return groupNameToId.group;
  29. }
  30. return 0;
  31. }
  32. const char* PatchbayGroupList::getGroupName(const uint groupId) const noexcept
  33. {
  34. static const char fallback[] = { '\0' };
  35. for (LinkedList<GroupNameToId>::Itenerator it = list.begin(); it.valid(); it.next())
  36. {
  37. const GroupNameToId& groupNameToId(it.getValue(kGroupNameToIdFallback));
  38. CARLA_SAFE_ASSERT_CONTINUE(groupNameToId.group != 0);
  39. if (groupNameToId.group == groupId)
  40. return groupNameToId.name;
  41. }
  42. return fallback;
  43. }
  44. const char* PatchbayPortList::getFullPortName(const uint groupId, const uint portId) const noexcept
  45. {
  46. static const char fallback[] = { '\0' };
  47. for (LinkedList<PortNameToId>::Itenerator it = list.begin(); it.valid(); it.next())
  48. {
  49. const PortNameToId& portNameToId(it.getValue(kPortNameToIdFallback));
  50. CARLA_SAFE_ASSERT_CONTINUE(portNameToId.group != 0);
  51. if (portNameToId.group == groupId && portNameToId.port == portId)
  52. return portNameToId.fullName;
  53. }
  54. return fallback;
  55. }
  56. const PortNameToId& PatchbayPortList::getPortNameToId(const char* const fullPortName) const noexcept
  57. {
  58. CARLA_SAFE_ASSERT_RETURN(fullPortName != nullptr && fullPortName[0] != '\0', kPortNameToIdFallback);
  59. for (LinkedList<PortNameToId>::Itenerator it = list.begin(); it.valid(); it.next())
  60. {
  61. const PortNameToId& portNameToId(it.getValue(kPortNameToIdFallback));
  62. CARLA_SAFE_ASSERT_CONTINUE(portNameToId.group != 0);
  63. if (std::strncmp(portNameToId.fullName, fullPortName, STR_MAX) == 0)
  64. return portNameToId;
  65. }
  66. return kPortNameToIdFallback;
  67. }