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.

108 lines
3.1KB

  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. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wzero-as-null-pointer-constant")
  19. namespace juce
  20. {
  21. template <typename IDType>
  22. class MultiTouchMapper
  23. {
  24. public:
  25. MultiTouchMapper() {}
  26. int getIndexOfTouch (ComponentPeer* peer, IDType touchID)
  27. {
  28. jassert (touchID != 0); // need to rethink this if IDs can be 0!
  29. TouchInfo info {touchID, peer};
  30. int touchIndex = currentTouches.indexOf (info);
  31. if (touchIndex < 0)
  32. {
  33. auto emptyTouchIndex = currentTouches.indexOf ({});
  34. touchIndex = (emptyTouchIndex >= 0 ? emptyTouchIndex : currentTouches.size());
  35. currentTouches.set (touchIndex, info);
  36. }
  37. return touchIndex;
  38. }
  39. void clear()
  40. {
  41. currentTouches.clear();
  42. }
  43. void clearTouch (int index)
  44. {
  45. currentTouches.set (index, {});
  46. }
  47. bool areAnyTouchesActive() const noexcept
  48. {
  49. for (auto& t : currentTouches)
  50. if (t.touchId != 0)
  51. return true;
  52. return false;
  53. }
  54. void deleteAllTouchesForPeer (ComponentPeer* peer)
  55. {
  56. for (auto& t : currentTouches)
  57. if (t.owner == peer)
  58. t.touchId = 0;
  59. }
  60. private:
  61. //==============================================================================
  62. struct TouchInfo
  63. {
  64. TouchInfo() noexcept : touchId (0), owner (nullptr) {}
  65. TouchInfo (IDType idToUse, ComponentPeer* peer) noexcept : touchId (idToUse), owner (peer) {}
  66. TouchInfo (const TouchInfo&) = default;
  67. TouchInfo& operator= (const TouchInfo&) = default;
  68. TouchInfo (TouchInfo&&) noexcept = default;
  69. TouchInfo& operator= (TouchInfo&&) noexcept = default;
  70. IDType touchId;
  71. ComponentPeer* owner;
  72. bool operator== (const TouchInfo& o) const noexcept { return (touchId == o.touchId); }
  73. };
  74. //==============================================================================
  75. Array<TouchInfo> currentTouches;
  76. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MultiTouchMapper)
  77. };
  78. } // namespace juce
  79. JUCE_END_IGNORE_WARNINGS_GCC_LIKE