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.

190 lines
5.6KB

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