The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

121 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. /** Describes a physical connection between two ports of two block devices.
  20. @tags{Blocks}
  21. */
  22. struct BlockDeviceConnection
  23. {
  24. Block::UID device1, device2;
  25. Block::ConnectionPort connectionPortOnDevice1, connectionPortOnDevice2;
  26. bool operator== (const BlockDeviceConnection&) const noexcept;
  27. bool operator!= (const BlockDeviceConnection&) const noexcept;
  28. };
  29. /** Describes a set of blocks and the connections between them.
  30. @tags{Blocks}
  31. */
  32. struct BlockTopology
  33. {
  34. Block::Array blocks;
  35. Array<BlockDeviceConnection> connections;
  36. bool operator== (const BlockTopology&) const noexcept;
  37. bool operator!= (const BlockTopology&) const noexcept;
  38. Block::Ptr getBlockWithUID (Block::UID deviceID)
  39. {
  40. for (auto&& block : blocks)
  41. if (block->uid == deviceID)
  42. return block;
  43. return {};
  44. }
  45. const Block::Ptr getBlockWithUID (Block::UID deviceID) const
  46. {
  47. for (auto&& block : blocks)
  48. if (block->uid == deviceID)
  49. return block;
  50. return {};
  51. }
  52. Block::Array getDirectlyConnectedBlocks (Block::UID blockUID) const
  53. {
  54. Block::Array connectedBlocks;
  55. for (const auto& connection : connections)
  56. {
  57. auto connectedDeviceUID = Block::UID { 0 };
  58. if (connection.device1 == blockUID)
  59. connectedDeviceUID = connection.device2;
  60. else if (connection.device2 == blockUID)
  61. connectedDeviceUID = connection.device1;
  62. if (connectedDeviceUID != Block::UID { 0 })
  63. if (auto newBlock = getBlockWithUID (connectedDeviceUID))
  64. connectedBlocks.addIfNotAlreadyThere (newBlock);
  65. }
  66. return connectedBlocks;
  67. }
  68. Array<BlockDeviceConnection> getConnectionsBetweenBlocks (Block::UID uid1, Block::UID uid2) const
  69. {
  70. Array<BlockDeviceConnection> blockConnections;
  71. for (const auto& connection : connections)
  72. {
  73. if ((connection.device1 == uid1 && connection.device2 == uid2)
  74. || (connection.device1 == uid2 && connection.device2 == uid1))
  75. {
  76. blockConnections.add (connection);
  77. }
  78. }
  79. return blockConnections;
  80. }
  81. int getNumberOfConnectionsToBlock (Block::UID uid) const
  82. {
  83. int connectionCount = 0;
  84. for (const auto& connection : connections)
  85. if (connection.device1 == uid || connection.device2 == uid)
  86. ++connectionCount;
  87. return connectionCount;
  88. }
  89. };
  90. } // namespace juce