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.

203 lines
6.1KB

  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. namespace
  40. {
  41. /** Helper function to create juce::String from BlockStringData */
  42. template <size_t MaxSize>
  43. juce::String asString (juce::BlocksProtocol::BlockStringData<MaxSize> blockString)
  44. {
  45. return { reinterpret_cast<const char*> (blockString.data),
  46. juce::jmin (sizeof (blockString.data), static_cast<size_t> (blockString.length))};
  47. }
  48. }
  49. #include "internal/juce_MidiDeviceConnection.cpp"
  50. #include "internal/juce_MIDIDeviceDetector.cpp"
  51. #include "internal/juce_DeviceInfo.cpp"
  52. #include "internal/juce_DepreciatedVersionReader.cpp"
  53. #include "internal/juce_ConnectedDeviceGroup.cpp"
  54. #include "internal/juce_BlockImplementation.cpp"
  55. #include "internal/juce_Detector.cpp"
  56. #include "internal/juce_DetectorHolder.cpp"
  57. namespace juce
  58. {
  59. //==============================================================================
  60. PhysicalTopologySource::PhysicalTopologySource (bool startDetached)
  61. {
  62. if (! startDetached)
  63. setActive (true);
  64. }
  65. PhysicalTopologySource::PhysicalTopologySource (DeviceDetector& detectorToUse, bool startDetached)
  66. : customDetector (&detectorToUse)
  67. {
  68. if (! startDetached)
  69. setActive (true);
  70. }
  71. PhysicalTopologySource::~PhysicalTopologySource()
  72. {
  73. setActive (false);
  74. }
  75. void PhysicalTopologySource::setActive (bool shouldBeActive)
  76. {
  77. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
  78. if (isActive() == shouldBeActive)
  79. return;
  80. if (shouldBeActive)
  81. {
  82. if (customDetector == nullptr)
  83. detector = std::make_unique<DetectorHolder>(*this);
  84. else
  85. detector = std::make_unique<DetectorHolder>(*this, *customDetector);
  86. detector->detector->activeTopologySources.add (this);
  87. }
  88. else
  89. {
  90. detector->detector->detach (this);
  91. detector.reset();
  92. }
  93. listeners.call ([](TopologySource::Listener& l){ l.topologyChanged(); });
  94. }
  95. bool PhysicalTopologySource::isActive() const
  96. {
  97. return detector != nullptr;
  98. }
  99. bool PhysicalTopologySource::isLockedFromOutside() const
  100. {
  101. if (detector != nullptr && detector->detector != nullptr)
  102. return detector->detector->deviceDetector.isLockedFromOutside();
  103. return false;
  104. }
  105. BlockTopology PhysicalTopologySource::getCurrentTopology() const
  106. {
  107. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED // This method must only be called from the message thread!
  108. if (detector != nullptr)
  109. return detector->detector->currentTopology;
  110. return {};
  111. }
  112. void PhysicalTopologySource::cancelAllActiveTouches() noexcept
  113. {
  114. if (detector != nullptr)
  115. detector->detector->cancelAllActiveTouches();
  116. }
  117. bool PhysicalTopologySource::hasOwnServiceTimer() const { return false; }
  118. void PhysicalTopologySource::handleTimerTick()
  119. {
  120. if (detector != nullptr)
  121. detector->handleTimerTick();
  122. }
  123. PhysicalTopologySource::DeviceConnection::DeviceConnection() {}
  124. PhysicalTopologySource::DeviceConnection::~DeviceConnection() {}
  125. PhysicalTopologySource::DeviceDetector::DeviceDetector() {}
  126. PhysicalTopologySource::DeviceDetector::~DeviceDetector() {}
  127. const char* const* PhysicalTopologySource::getStandardLittleFootFunctions() noexcept
  128. {
  129. return BlocksProtocol::ledProgramLittleFootFunctions;
  130. }
  131. template <typename ListType>
  132. static bool collectionsMatch (const ListType& list1, const ListType& list2) noexcept
  133. {
  134. if (list1.size() != list2.size())
  135. return false;
  136. for (auto&& b : list1)
  137. if (! list2.contains (b))
  138. return false;
  139. return true;
  140. }
  141. bool BlockTopology::operator== (const BlockTopology& other) const noexcept
  142. {
  143. return collectionsMatch (connections, other.connections) && collectionsMatch (blocks, other.blocks);
  144. }
  145. bool BlockTopology::operator!= (const BlockTopology& other) const noexcept
  146. {
  147. return ! operator== (other);
  148. }
  149. bool BlockDeviceConnection::operator== (const BlockDeviceConnection& other) const noexcept
  150. {
  151. return (device1 == other.device1 && device2 == other.device2
  152. && connectionPortOnDevice1 == other.connectionPortOnDevice1
  153. && connectionPortOnDevice2 == other.connectionPortOnDevice2)
  154. || (device1 == other.device2 && device2 == other.device1
  155. && connectionPortOnDevice1 == other.connectionPortOnDevice2
  156. && connectionPortOnDevice2 == other.connectionPortOnDevice1);
  157. }
  158. bool BlockDeviceConnection::operator!= (const BlockDeviceConnection& other) const noexcept
  159. {
  160. return ! operator== (other);
  161. }
  162. } // namespace juce