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.

205 lines
5.9KB

  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. //==============================================================================
  18. /** These can be useful when debugging the topology. */
  19. #ifndef LOG_BLOCKS_CONNECTIVITY
  20. #define LOG_BLOCKS_CONNECTIVITY 0
  21. #endif
  22. #ifndef LOG_BLOCKS_PINGS
  23. #define LOG_BLOCKS_PINGS 0
  24. #endif
  25. #ifndef DUMP_BANDWIDTH_STATS
  26. #define DUMP_BANDWIDTH_STATS 0
  27. #endif
  28. #ifndef DUMP_TOPOLOGY
  29. #define DUMP_TOPOLOGY 0
  30. #endif
  31. #define TOPOLOGY_LOG(text) \
  32. JUCE_BLOCK_WITH_FORCED_SEMICOLON (juce::String buf ("Topology Src: "); \
  33. juce::Logger::outputDebugString (buf << text);)
  34. #if LOG_BLOCKS_CONNECTIVITY
  35. #define LOG_CONNECTIVITY(text) TOPOLOGY_LOG(text)
  36. #else
  37. #define LOG_CONNECTIVITY(text)
  38. #endif
  39. #if LOG_BLOCKS_PINGS
  40. #define LOG_PING(text) TOPOLOGY_LOG(text)
  41. #else
  42. #define LOG_PING(text)
  43. #endif
  44. #if DUMP_BANDWIDTH_STATS
  45. #include "internal/juce_BandwidthStatsLogger.cpp"
  46. #endif
  47. #include "internal/juce_MidiDeviceConnection.cpp"
  48. #include "internal/juce_MIDIDeviceDetector.cpp"
  49. #include "internal/juce_DeviceInfo.cpp"
  50. #include "internal/juce_DepreciatedVersionReader.cpp"
  51. #include "internal/juce_BlockSerialReader.cpp"
  52. #include "internal/juce_ConnectedDeviceGroup.cpp"
  53. #include "internal/juce_BlockImplementation.cpp"
  54. #include "internal/juce_Detector.cpp"
  55. #include "internal/juce_DetectorHolder.cpp"
  56. namespace juce
  57. {
  58. //==============================================================================
  59. PhysicalTopologySource::PhysicalTopologySource (bool startDetached)
  60. {
  61. if (! startDetached)
  62. setActive (true);
  63. }
  64. PhysicalTopologySource::PhysicalTopologySource (DeviceDetector& detectorToUse, bool startDetached)
  65. : customDetector (&detectorToUse)
  66. {
  67. if (! startDetached)
  68. setActive (true);
  69. }
  70. PhysicalTopologySource::~PhysicalTopologySource()
  71. {
  72. setActive (false);
  73. }
  74. void PhysicalTopologySource::setActive (bool shouldBeActive)
  75. {
  76. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
  77. if (isActive() == shouldBeActive)
  78. return;
  79. if (shouldBeActive)
  80. {
  81. if (customDetector == nullptr)
  82. detector = std::make_unique<DetectorHolder>(*this);
  83. else
  84. detector = std::make_unique<DetectorHolder>(*this, *customDetector);
  85. detector->detector->activeTopologySources.add (this);
  86. }
  87. else
  88. {
  89. detector->detector->detach (this);
  90. detector.reset();
  91. }
  92. listeners.call ([] (TopologySource::Listener& l){ l.topologyChanged(); });
  93. }
  94. bool PhysicalTopologySource::isActive() const
  95. {
  96. return detector != nullptr;
  97. }
  98. bool PhysicalTopologySource::isLockedFromOutside() const
  99. {
  100. if (detector != nullptr && detector->detector != nullptr)
  101. return detector->detector->deviceDetector.isLockedFromOutside();
  102. return false;
  103. }
  104. BlockTopology PhysicalTopologySource::getCurrentTopology() const
  105. {
  106. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED // This method must only be called from the message thread!
  107. if (detector != nullptr)
  108. return detector->detector->currentTopology;
  109. return {};
  110. }
  111. void PhysicalTopologySource::cancelAllActiveTouches() noexcept
  112. {
  113. if (detector != nullptr)
  114. detector->detector->cancelAllActiveTouches();
  115. }
  116. bool PhysicalTopologySource::hasOwnServiceTimer() const { return false; }
  117. void PhysicalTopologySource::handleTimerTick()
  118. {
  119. if (detector != nullptr)
  120. detector->handleTimerTick();
  121. }
  122. PhysicalTopologySource::DeviceConnection::DeviceConnection() {}
  123. PhysicalTopologySource::DeviceConnection::~DeviceConnection() {}
  124. PhysicalTopologySource::DeviceDetector::DeviceDetector() {}
  125. PhysicalTopologySource::DeviceDetector::~DeviceDetector() {}
  126. const char* const* PhysicalTopologySource::getStandardLittleFootFunctions() noexcept
  127. {
  128. return BlocksProtocol::ledProgramLittleFootFunctions;
  129. }
  130. template <typename ListType>
  131. static bool collectionsMatch (const ListType& list1, const ListType& list2) noexcept
  132. {
  133. if (list1.size() != list2.size())
  134. return false;
  135. for (auto&& b : list1)
  136. if (! list2.contains (b))
  137. return false;
  138. return true;
  139. }
  140. bool BlockTopology::operator== (const BlockTopology& other) const noexcept
  141. {
  142. return collectionsMatch (connections, other.connections) && collectionsMatch (blocks, other.blocks);
  143. }
  144. bool BlockTopology::operator!= (const BlockTopology& other) const noexcept
  145. {
  146. return ! operator== (other);
  147. }
  148. bool BlockDeviceConnection::operator== (const BlockDeviceConnection& other) const noexcept
  149. {
  150. return (device1 == other.device1 && device2 == other.device2
  151. && connectionPortOnDevice1 == other.connectionPortOnDevice1
  152. && connectionPortOnDevice2 == other.connectionPortOnDevice2)
  153. || (device1 == other.device2 && device2 == other.device1
  154. && connectionPortOnDevice1 == other.connectionPortOnDevice2
  155. && connectionPortOnDevice2 == other.connectionPortOnDevice1);
  156. }
  157. bool BlockDeviceConnection::operator!= (const BlockDeviceConnection& other) const noexcept
  158. {
  159. return ! operator== (other);
  160. }
  161. } // namespace juce