Audio plugin host https://kx.studio/carla
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.

101 lines
2.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wzero-as-null-pointer-constant")
  14. namespace juce
  15. {
  16. template <typename IDType>
  17. class MultiTouchMapper
  18. {
  19. public:
  20. MultiTouchMapper() {}
  21. int getIndexOfTouch (ComponentPeer* peer, IDType touchID)
  22. {
  23. jassert (touchID != 0); // need to rethink this if IDs can be 0!
  24. TouchInfo info {touchID, peer};
  25. int touchIndex = currentTouches.indexOf (info);
  26. if (touchIndex < 0)
  27. {
  28. auto emptyTouchIndex = currentTouches.indexOf ({});
  29. touchIndex = (emptyTouchIndex >= 0 ? emptyTouchIndex : currentTouches.size());
  30. currentTouches.set (touchIndex, info);
  31. }
  32. return touchIndex;
  33. }
  34. void clear()
  35. {
  36. currentTouches.clear();
  37. }
  38. void clearTouch (int index)
  39. {
  40. currentTouches.set (index, {});
  41. }
  42. bool areAnyTouchesActive() const noexcept
  43. {
  44. for (auto& t : currentTouches)
  45. if (t.touchId != 0)
  46. return true;
  47. return false;
  48. }
  49. void deleteAllTouchesForPeer (ComponentPeer* peer)
  50. {
  51. for (auto& t : currentTouches)
  52. if (t.owner == peer)
  53. t.touchId = 0;
  54. }
  55. private:
  56. //==============================================================================
  57. struct TouchInfo
  58. {
  59. TouchInfo() noexcept : touchId (0), owner (nullptr) {}
  60. TouchInfo (IDType idToUse, ComponentPeer* peer) noexcept : touchId (idToUse), owner (peer) {}
  61. TouchInfo (const TouchInfo&) = default;
  62. TouchInfo& operator= (const TouchInfo&) = default;
  63. TouchInfo (TouchInfo&&) noexcept = default;
  64. TouchInfo& operator= (TouchInfo&&) noexcept = default;
  65. IDType touchId;
  66. ComponentPeer* owner;
  67. bool operator== (const TouchInfo& o) const noexcept { return (touchId == o.touchId); }
  68. };
  69. //==============================================================================
  70. Array<TouchInfo> currentTouches;
  71. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MultiTouchMapper)
  72. };
  73. } // namespace juce
  74. JUCE_END_IGNORE_WARNINGS_GCC_LIKE