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.

132 lines
4.8KB

  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. Represents the touch surface of a BLOCKS device.
  19. */
  20. class TouchSurface
  21. {
  22. public:
  23. TouchSurface (Block&);
  24. /** Destructor. */
  25. virtual ~TouchSurface();
  26. //==============================================================================
  27. struct Touch
  28. {
  29. /** A touch index, which will stay constant for each finger as it is tracked. */
  30. int index;
  31. /** The X position of this touch on the device, in logical units starting from 0 (left).
  32. See Block::getWidth() for the maximum X value on the device.
  33. */
  34. float x;
  35. /** An approximation of the velocity at which the X value is changing, measured in
  36. units/second. This is intended as a useful hint to help with gesture detection, but
  37. may be 0 if the device doesn't provide this data.
  38. */
  39. float xVelocity;
  40. /** The Y position of this touch on the device, in logical units starting from 0 (top).
  41. See Block::getHeight() to find the maximum Y on the device.
  42. */
  43. float y;
  44. /** An approximation of the velocity at which the Y value is changing, measured in
  45. units/second. This is intended as a useful hint to help with gesture detection, but
  46. may be 0 if the device doesn't provide this data.
  47. */
  48. float yVelocity;
  49. /** The current pressure of this touch, in the range 0.0 (no pressure) to 1.o (very hard). */
  50. float z;
  51. /** The rate at which pressure is currently changing, measured in units/second. This is
  52. intended as a useful hint to help with gesture detection, but may be 0 if the device
  53. doesn't provide this data.
  54. */
  55. float zVelocity;
  56. /** The timestamp of this event, in milliseconds since the device was booted. */
  57. Block::Timestamp eventTimestamp;
  58. /** True if this is the first event for this finger/index. */
  59. bool isTouchStart;
  60. /** True if this is the final event as this finger/index is lifted off. */
  61. bool isTouchEnd;
  62. /** The ID of the block that generated this touch. */
  63. Block::UID blockUID;
  64. /** The initial X position of the touchStart event corresponding to this finger/index. */
  65. float startX;
  66. /** The initial Y position of the touchStart event corresponding to this finger/index. */
  67. float startY;
  68. };
  69. //==============================================================================
  70. /** Forces a touch-off message for all active touches. */
  71. virtual void cancelAllActiveTouches() noexcept = 0;
  72. /** For the on-screen seaboard view, this will return the number of keys.
  73. For other types of touch-surface, it will return 0. */
  74. virtual int getNumberOfKeywaves() const = 0;
  75. //==============================================================================
  76. /** Receives callbacks when a touch moves or changes pressure. */
  77. struct Listener
  78. {
  79. virtual ~Listener();
  80. virtual void touchChanged (TouchSurface&, const Touch&) = 0;
  81. };
  82. /** Testing feature: this allows you to inject touches onto a touch surface. */
  83. void callListenersTouchChanged (const TouchSurface::Touch& t)
  84. {
  85. listeners.call (&Listener::touchChanged, *this, t);
  86. }
  87. /** Adds a listener to be called when the surface is touched. */
  88. void addListener (Listener*);
  89. /** Removes a previously-registered listener. */
  90. void removeListener (Listener*);
  91. //==============================================================================
  92. /** The block that owns this touch surface. */
  93. Block& block;
  94. protected:
  95. //==============================================================================
  96. juce::ListenerList<Listener> listeners;
  97. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TouchSurface)
  98. };