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.

215 lines
8.2KB

  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 either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. /**
  18. Represents an individual BLOCKS device.
  19. */
  20. class Block : public juce::ReferenceCountedObject
  21. {
  22. public:
  23. //==============================================================================
  24. /** Destructor. */
  25. virtual ~Block();
  26. /** The different block types.
  27. @see Block::getType()
  28. */
  29. enum Type
  30. {
  31. unknown = 0,
  32. lightPadBlock,
  33. liveBlock,
  34. loopBlock,
  35. developerControlBlock
  36. };
  37. /** The Block class is reference-counted, so always use a Block::Ptr when
  38. you are keeping references to them.
  39. */
  40. using Ptr = juce::ReferenceCountedObjectPtr<Block>;
  41. /** The Block class is reference-counted, so Block::Array is useful when
  42. you are storing lists of them.
  43. */
  44. using Array = juce::ReferenceCountedArray<Block>;
  45. /** The Block's serial number. */
  46. const juce::String serialNumber;
  47. using UID = uint64;
  48. /** This Block's UID.
  49. This will be globally unique, and remains constant for a particular device.
  50. */
  51. const UID uid;
  52. //==============================================================================
  53. /** Returns the type of this device.
  54. @see Block::Type
  55. */
  56. virtual Type getType() const = 0;
  57. /** Returns a human-readable description of this device type. */
  58. virtual juce::String getDeviceDescription() const = 0;
  59. /** Returns the battery level in the range 0.0 to 1.0. */
  60. virtual float getBatteryLevel() const = 0;
  61. /** Returns true if the battery is charging. */
  62. virtual bool isBatteryCharging() const = 0;
  63. //==============================================================================
  64. /** Returns true if this block is connected and active. */
  65. virtual bool isConnected() const = 0;
  66. /** Returns true if this block is directly connected to the application,
  67. as opposed to only being connected to a different block via a connection port.
  68. @see ConnectionPort
  69. */
  70. virtual bool isMasterBlock() const = 0;
  71. //==============================================================================
  72. /** Returns the width of the device in logical device units. */
  73. virtual int getWidth() const = 0;
  74. /** Returns the height of the device in logical device units. */
  75. virtual int getHeight() const = 0;
  76. /** Returns true if the device is a physical hardware block (i.e. not a virtual block). */
  77. virtual bool isHardwareBlock() const = 0;
  78. /** Returns the length of one logical device unit as physical millimeters. */
  79. virtual float getMillimetersPerUnit() const = 0;
  80. //==============================================================================
  81. /** If this block has a grid of LEDs, this will return an object to control it.
  82. Note that the pointer that is returned belongs to this object, and the caller must
  83. neither delete it or use it after the lifetime of this Block object has finished.
  84. If there are no LEDs, then this method will return nullptr.
  85. */
  86. virtual LEDGrid* getLEDGrid() const = 0;
  87. /** If this block has a row of LEDs, this will return an object to control it.
  88. Note that the pointer that is returned belongs to this object, and the caller must
  89. neither delete it or use it after the lifetime of this Block object has finished.
  90. If there are no LEDs, then this method will return nullptr.
  91. */
  92. virtual LEDRow* getLEDRow() const = 0;
  93. /** If this block has any status LEDs, this will return an array of objects to control them.
  94. Note that the objects in the array belong to this Block object, and the caller must
  95. neither delete them or use them after the lifetime of this Block object has finished.
  96. */
  97. virtual juce::Array<StatusLight*> getStatusLights() const = 0;
  98. /** If this block has a pressure-sensitive surface, this will return an object to
  99. access its data.
  100. Note that the pointer returned does is owned by this object, and the caller must
  101. neither delete it or use it after the lifetime of this Block object has finished.
  102. If the device is not touch-sensitive, then this method will return nullptr.
  103. */
  104. virtual TouchSurface* getTouchSurface() const = 0;
  105. /** If this block has any control buttons, this will return an array of objects to control them.
  106. Note that the objects in the array belong to this Block object, and the caller must
  107. neither delete them or use them after the lifetime of this Block object has finished.
  108. */
  109. virtual juce::Array<ControlButton*> getButtons() const = 0;
  110. //==============================================================================
  111. /** This returns true if the block supports generating graphics by drawing into a JUCE
  112. Graphics context. This should only be true for virtual on-screen blocks; hardware
  113. blocks will instead use the LED Grid for visuals.
  114. */
  115. virtual bool supportsGraphics() const = 0;
  116. //==============================================================================
  117. /** These are the edge-connectors that a device may have. */
  118. struct ConnectionPort
  119. {
  120. enum class DeviceEdge
  121. {
  122. north,
  123. south,
  124. east,
  125. west
  126. };
  127. /** The side of the device on which this port is located. */
  128. DeviceEdge edge;
  129. /** The index of this port along the device edge.
  130. For north and south edges, index 0 is the left-most port.
  131. For east and west edges, index 0 is the top-most port.
  132. */
  133. int index;
  134. bool operator== (const ConnectionPort&) const noexcept;
  135. bool operator!= (const ConnectionPort&) const noexcept;
  136. };
  137. /** Returns a list of the connectors that this device has. */
  138. virtual juce::Array<ConnectionPort> getPorts() const = 0;
  139. //==============================================================================
  140. /** Interface for objects listening to input data port. */
  141. struct DataInputPortListener
  142. {
  143. virtual ~DataInputPortListener() {}
  144. /** Called whenever a message from a block is received. */
  145. virtual void handleIncomingDataPortMessage (Block& source, const void* messageData, size_t messageSize) = 0;
  146. };
  147. /** Adds a new listener of data input port. */
  148. virtual void addDataInputPortListener (DataInputPortListener*);
  149. /** Removes a listener of data input port. */
  150. virtual void removeDataInputPortListener (DataInputPortListener*);
  151. /** Sends a message to the block. */
  152. virtual void sendMessage (const void* messageData, size_t messageSize) = 0;
  153. //==============================================================================
  154. /** This type is used for timestamping events. It represents a number of milliseconds since the block
  155. device was booted.
  156. */
  157. using Timestamp = uint32;
  158. protected:
  159. //==============================================================================
  160. Block (const juce::String& serialNumberToUse);
  161. juce::ListenerList<DataInputPortListener> dataInputPortListeners;
  162. private:
  163. //==============================================================================
  164. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Block)
  165. };