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.

140 lines
5.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. /**
  24. Represents the touch surface of a BLOCKS device.
  25. */
  26. class TouchSurface
  27. {
  28. public:
  29. TouchSurface (Block&);
  30. /** Destructor. */
  31. virtual ~TouchSurface();
  32. //==============================================================================
  33. struct Touch
  34. {
  35. /** A touch index, which will stay constant for each finger as it is tracked. */
  36. int index;
  37. /** The X position of this touch on the device, in logical units starting from 0 (left).
  38. See Block::getWidth() for the maximum X value on the device.
  39. */
  40. float x;
  41. /** An approximation of the velocity at which the X value is changing, measured in
  42. units/second. This is intended as a useful hint to help with gesture detection, but
  43. may be 0 if the device doesn't provide this data.
  44. */
  45. float xVelocity;
  46. /** The Y position of this touch on the device, in logical units starting from 0 (top).
  47. See Block::getHeight() to find the maximum Y on the device.
  48. */
  49. float y;
  50. /** An approximation of the velocity at which the Y value is changing, measured in
  51. units/second. This is intended as a useful hint to help with gesture detection, but
  52. may be 0 if the device doesn't provide this data.
  53. */
  54. float yVelocity;
  55. /** The current pressure of this touch, in the range 0.0 (no pressure) to 1.o (very hard). */
  56. float z;
  57. /** The rate at which pressure is currently changing, measured in units/second. This is
  58. intended as a useful hint to help with gesture detection, but may be 0 if the device
  59. doesn't provide this data.
  60. */
  61. float zVelocity;
  62. /** The timestamp of this event, in milliseconds since the device was booted. */
  63. Block::Timestamp eventTimestamp;
  64. /** True if this is the first event for this finger/index. */
  65. bool isTouchStart;
  66. /** True if this is the final event as this finger/index is lifted off. */
  67. bool isTouchEnd;
  68. /** The ID of the block that generated this touch. */
  69. Block::UID blockUID;
  70. /** The initial X position of the touchStart event corresponding to this finger/index. */
  71. float startX;
  72. /** The initial Y position of the touchStart event corresponding to this finger/index. */
  73. float startY;
  74. };
  75. //==============================================================================
  76. /** Forces a touch-off message for all active touches. */
  77. virtual void cancelAllActiveTouches() noexcept = 0;
  78. /** For the on-screen seaboard view, this will return the number of keys.
  79. For other types of touch-surface, it will return 0. */
  80. virtual int getNumberOfKeywaves() const = 0;
  81. //==============================================================================
  82. /** Receives callbacks when a touch moves or changes pressure. */
  83. struct Listener
  84. {
  85. virtual ~Listener();
  86. virtual void touchChanged (TouchSurface&, const Touch&) = 0;
  87. };
  88. /** Testing feature: this allows you to inject touches onto a touch surface. */
  89. void callListenersTouchChanged (const TouchSurface::Touch& t)
  90. {
  91. listeners.call (&Listener::touchChanged, *this, t);
  92. }
  93. /** Adds a listener to be called when the surface is touched. */
  94. void addListener (Listener*);
  95. /** Removes a previously-registered listener. */
  96. void removeListener (Listener*);
  97. //==============================================================================
  98. /** The block that owns this touch surface. */
  99. Block& block;
  100. protected:
  101. //==============================================================================
  102. juce::ListenerList<Listener> listeners;
  103. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TouchSurface)
  104. };