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.

192 lines
5.7KB

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