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.

593 lines
22KB

  1. //=============================== HEAP =========================================
  2. /** Reads and returns the value of a single byte from the heap.
  3. @param byteIndex the index (in bytes) of the byte to read
  4. @returns the value of the byte
  5. */
  6. int getHeapByte (int byteIndex);
  7. /** Reads 4 bytes from the heap and returns the value as an integer.
  8. @param byteIndex the index (in bytes) of the start of the 4 bytes to read
  9. @returns the value of the 4 bytes as an integer
  10. */
  11. int getHeapInt (int byteIndex);
  12. /** Reads a sequence of bits from the heap and returns the value as an integer.
  13. @param startBitIndex the index (in bits) of the start of the sequence of bits to read
  14. @param numBits how many bits to read
  15. @returns the value of the sequence of bits as an integer
  16. */
  17. int getHeapBits (int startBitIndex, int numBits);
  18. /** Writes a single byte to the heap.
  19. @param byteIndex the index (in bytes) of the byte to set
  20. @param newValue the new value to set this byte to
  21. */
  22. void setHeapByte (int byteIndex, int newValue);
  23. /** Writes 4 bytes to the heap.
  24. @param byteIndex the index (in bytes) of the start of the 4 bytes to set
  25. @param newValue the new value to set the 4 bytes to
  26. */
  27. void setHeapInt (int byteIndex, int newValue);
  28. //=============================== GENERAL/UTILITY ==============================
  29. /** Returns the smaller of two integer values. */
  30. int min (int a, int b);
  31. /** Returns the smaller of two floating point values. */
  32. float min (float a, float b);
  33. /** Returns the larger of two integer values. */
  34. int max (int a, int b);
  35. /** Returns the larger of two floating point values. */
  36. float max (float a, float b);
  37. /** Constrains an integer value to keep it within a given range.
  38. @param lowerLimit the minimum value to return
  39. @param upperLimit the maximum value to return
  40. @param valueToConstrain the value to try to return
  41. @returns the closest value to valueToConstrain which lies between lowerLimit
  42. and upperLimit (inclusive)
  43. */
  44. int clamp (int lowerLimit, int upperLimit, int valueToConstrain);
  45. /** Constrains a floating point value to keep it within a given range.
  46. @param lowerLimit the minimum value to return
  47. @param upperLimit the maximum value to return
  48. @param valueToConstrain the value to try to return
  49. @returns the closest value to valueToConstrain which lies between lowerLimit
  50. and upperLimit (inclusive)
  51. */
  52. float clamp (float lowerLimit, float upperLimit, float valueToConstrain);
  53. /** Returns the absolute value of an integer value. */
  54. int abs (int arg);
  55. /** Returns the absolute value of a floating point value. */
  56. float abs (float arg);
  57. /** Remaps a value from a source range to a target range.
  58. @param value the value within the source range to map
  59. @param sourceMin the minimum value of the source range
  60. @param sourceMax the maximum value of the source range
  61. @param destMin the minumum value of the destination range
  62. @param destMax the maximum value of the destination range
  63. @returns the original value mapped to the destination range
  64. */
  65. float map (float value, float sourceMin, float sourceMax, float destMin, float destMax);
  66. /** Remaps a value from a source range to the range 0 - 1.0.
  67. @param value the value within the source range to map
  68. @param sourceMin the minimum value of the source range
  69. @param sourceMax the maximum value of the source range
  70. @returns the original value mapped to the range 0 - 1.0
  71. */
  72. float map (float value, float sourceMin, float sourceMax);
  73. /** Performs a modulo operation (can cope with the dividend being negative).
  74. The divisor must be greater than zero.
  75. @returns the result of the modulo operation
  76. */
  77. int mod (int dividend, int divisor);
  78. /** Returns a random floating-point number.
  79. @returns a random value in the range 0 (inclusive) to 1.0 (exclusive)
  80. */
  81. float getRandomFloat();
  82. /** Returns a random integer, limited to a given range.
  83. @returns a random integer between 0 (inclusive) and maxValue (exclusive).
  84. */
  85. int getRandomInt (int maxValue);
  86. /** Returns the number of milliseconds since a fixed event (usually system startup).
  87. This returns a monotonically increasing value which is unaffected by changes to the
  88. system clock. It should be accurate to within a few millisecseconds.
  89. */
  90. int getMillisecondCounter();
  91. /** Returns the length of time spent in the current function call in milliseconds. */
  92. int getTimeInCurrentFunctionCall();
  93. /** Logs an integer value to the console. */
  94. void log (int data);
  95. /** Logs a hexadecimal value to the console. */
  96. void logHex (int data);
  97. //=============================== MIDI/MPE =====================================
  98. /** Sends a 1-byte short midi message. */
  99. void sendMIDI (int byte0);
  100. /** Sends a 2-byte short midi message. */
  101. void sendMIDI (int byte0, int byte1);
  102. /** Sends a 3-byte short midi message. */
  103. void sendMIDI (int byte0, int byte1, int byte2);
  104. /** Sends a key-down message.
  105. @param channel the midi channel, in the range 0 to 15
  106. @param noteNumber the key number, in the range 0 to 127
  107. @param velocity the velocity, in the range 0 to 127
  108. */
  109. void sendNoteOn (int channel, int noteNumber, int velocity);
  110. /** Sends a key-up message.
  111. @param channel the midi channel, in the range 0 to 15
  112. @param noteNumber the key number, in the range 0 to 127
  113. @param velocity the velocity, in the range 0 to 127
  114. */
  115. void sendNoteOff (int channel, int noteNumber, int velocity);
  116. /** Sends an aftertouch message.
  117. @param channel the midi channel, in the range 0 to 15
  118. @param noteNumber the key number, in the range 0 to 127
  119. @param level the amount of aftertouch, in the range 0 to 127
  120. */
  121. void sendAftertouch (int channel, int noteNumber, int level);
  122. /** Sends a controller message.
  123. @param channel the midi channel, in the range 0 to 15
  124. @param controller the type of controller
  125. @param value the controller value
  126. */
  127. void sendCC (int channel, int controller, int value);
  128. /** Sends a pitch bend message.
  129. @param channel the midi channel, in the range 0 to 15
  130. @param position the wheel position, in the range 0 to 16383
  131. */
  132. void sendPitchBend (int channel, int position);
  133. /** Sends a channel-pressure change event.
  134. @param channel the midi channel, in the range 0 to 15
  135. @param pressure the pressure, in the range 0 to 127
  136. */
  137. void sendChannelPressure (int channel, int pressure);
  138. /** Sets the MIDI channel range.
  139. @param useMPE
  140. @param lowChannel
  141. @param highChannel
  142. */
  143. void setChannelRange (bool useMPE, int lowChannel, int highChannel);
  144. /** Assigns a MIDI channel to a note number.
  145. @param noteNumber the note number to assign the channel to
  146. @returns the MIDI channel that has been assigned
  147. */
  148. int assignChannel (int noteNumber);
  149. /** Deassigns a channel from a note number.
  150. @param noteNumber the note number to deassign
  151. @param channel the MIDI channel
  152. */
  153. void deassignChannel (int noteNumber, int channel);
  154. /** Returns the channel that is being used for control messages.
  155. If MPE is enabled then this will be the first channel.
  156. */
  157. int getControlChannel();
  158. /** Sets whether duplicate notes should be filtered out when MPE is enabled. */
  159. void useMPEDuplicateFilter (bool active);
  160. //=============================== CALLBACKS ====================================
  161. /** Use this method to draw the display.
  162. The block will call this approximately 25 times per second.
  163. */
  164. void repaint()
  165. /** Called when a button is pushed.
  166. @param index the index of the button that was pushed
  167. */
  168. void handleButtonDown (int index);
  169. /** Called when a button is released.
  170. @param index the index of the button that was released
  171. */
  172. void handleButtonUp (int index);
  173. /** Called when a control block button is pressed.
  174. @param buttonIndex the index of the button
  175. */
  176. void onControlPress (int buttonIndex);
  177. /** Called when a control block button is released.
  178. @param buttonIndex the index of the button
  179. */
  180. void onControlRelease (int buttonIndex);
  181. /** Called when a touch event starts.
  182. @param index the touch index, which will stay constant for each finger as it is tracked
  183. @param x the X position of this touch on the device, in block units starting from 0 (left)
  184. @param y the Y position of this touch on the device, in block units starting from 0 (top)
  185. @param z the current pressure of this touch, in the range 0.0 (no pressure) to 1.0 (very hard)
  186. @param vz the rate at which pressure is currently changing, measured in units/second
  187. */
  188. void touchStart (int index, float x, float y, float z, float vz);
  189. /** Called when a touch event moves.
  190. @param index the touch index, which will stay constant for each finger as it is tracked
  191. @param x the X position of this touch on the device, in block units starting from 0 (left)
  192. @param y the Y position of this touch on the device, in block units starting from 0 (top)
  193. @param z the current pressure of this touch, in the range 0.0 (no pressure) to 1.0 (very hard)
  194. @param vz the rate at which pressure is currently changing, measured in units/second
  195. */
  196. void touchMove (int index, float x, float y, float z, float vz);
  197. /** Called when a touch event ends.
  198. @param index the touch index, which will stay constant for each finger as it is tracked
  199. @param x the X position of this touch on the device, in block units starting from 0 (left)
  200. @param y the Y position of this touch on the device, in block units starting from 0 (top)
  201. @param z the current pressure of this touch, in the range 0.0 (no pressure) to 1.0 (very hard)
  202. @param vz the rate at which pressure is currently changing, measured in units/second
  203. */
  204. void touchEnd (int index, float x, float y, float z, float vz);
  205. /** Called when a program is loaded onto the block and is about to start. Do any setup here. */
  206. void initialise();
  207. /** Called when a block receives a MIDI message. */
  208. void handleMIDI (int byte0, int byte1, int byte2);
  209. /** Called when a block receives a message.
  210. @see sendMessageToBlock
  211. */
  212. void handleMessage (int param1, int param2, int param3);
  213. //=============================== GRAPHICS =====================================
  214. /** Combines a set of 8-bit ARGB values into a 32-bit colour and returns the result. */
  215. int makeARGB (int alpha, int red, int green, int blue);
  216. /** Blends the overlaid ARGB colour onto the base one and returns the new colour. */
  217. int blendARGB (int baseColour, int overlaidColour);
  218. /** Displays an animation indicating the current battery level of this block.
  219. A control block will light up its top LEDs indicating battery level and a lightpad
  220. block will draw the battery level on the display.
  221. */
  222. void displayBatteryLevel();
  223. /** Clears the display and sets all the LEDs to black. */
  224. void clearDisplay();
  225. /** Clears the display and sets all the LEDs to a specified colour.
  226. @param rgb the colour to use (0xff...)
  227. */
  228. void clearDisplay (int rgb);
  229. /** Sets a pixel to a specified colour with full alpha.
  230. @param rgb the colour to use (0xff...)
  231. @param x the x coordinate of the pixel to fill
  232. @param y the y coordinate of the pixel to fill
  233. */
  234. void fillPixel (int rgb, int x, int y);
  235. /** Blends the current pixel colour with a specified colour.
  236. @param argb the colour to use
  237. @param x the x coordinate of the pixel to blend
  238. @param y the y coordinate of the pixel to blend
  239. */
  240. void blendPixel (int argb, int x, int y);
  241. /** Fills a rectangle on the display with a specified colour.
  242. @param rgb the colour to use (0xff...)
  243. @param x the x coordinate of the rectangle to draw
  244. @param y the y coordinate of the rectangle to draw
  245. @param width the width of the rectangle to draw
  246. @param height the height of the rectangle to draw
  247. */
  248. void fillRect (int rgb, int x, int y, int width, int height);
  249. /** Blends a rectangle on the display with a specified colour.
  250. @param argb the colour to use
  251. @param x the x coordinate of the rectangle to blend
  252. @param y the y coordinate of the rectangle to blend
  253. @param width the width of the rectangle to blend
  254. @param height the height of the rectangle to blend
  255. */
  256. void blendRect (int argb, int x, int y, int width, int height);
  257. /** Fills a rectangle on the display with four corner colours blended together.
  258. @param colourNW the colour to use in the north west corner of the rectangle
  259. @param colourNE the colour to use in the north east corner of the rectangle
  260. @param colourSE the colour to use in the south east corner of the rectangle
  261. @param colourSW the colour to use in the south west corner of the rectangle
  262. @param x the x coordinate of the rectangle
  263. @param y the y coordinate of the rectangle
  264. @param width the width of the rectangle
  265. @param height the height of the rectangle
  266. */
  267. void blendGradientRect (int colourNW, int colourNE, int colourSE, int colourSW, int x, int y, int width, int height);
  268. /** Blends a circle on the display with a specified colour.
  269. @param argb the colour to use
  270. @param xCentre the x position of the circle's centre in block units
  271. @param yCentre the y position of the circle's centre in block units
  272. @param radius the radius of the circle in block units
  273. @param fill if true then the circle will be filled, if false the circle will be an outline
  274. */
  275. void blendCircle (int argb, float xCentre, float yCentre, float radius, bool fill);
  276. /** Draws a number on the display.
  277. @param value the number to draw between 0 and 99
  278. @param colour the colour to use
  279. @param x the x coordinate to use
  280. @param y the y coordinate to use
  281. */
  282. void drawNumber (int value, int colour, int x, int y);
  283. //=============================== BLOCK GENERAL =================================
  284. /** Returns the current firmware version of this block. */
  285. int getFirmwareVersion();
  286. /** Returns the battery level of this block, between 0 and 1.0. */
  287. float getBatteryLevel();
  288. /** Returns true if this block's battery is charging. */
  289. bool isBatteryCharging();
  290. /** Sets whether status overlays should be displayed on this block. */
  291. void setStatusOverlayActive (bool active);
  292. /** Sets whether power saving mode should be enabled on this block. */
  293. void setPowerSavingEnabled (bool enabled);
  294. /** Returns the type of the block with a given ID.
  295. @returns an enum indicating the type of block @see Block::Type
  296. */
  297. int getBlockTypeForID (int blockID);
  298. /** Sends a message to the block with the specified ID.
  299. This will be processed in the handleMessage() callback.
  300. @param blockID the ID of the block to send this message to
  301. @param param1 the first chunk of data to send
  302. @param param2 the second chunk of data to send
  303. @param param3 the third chunk of data to send
  304. */
  305. void sendMessageToBlock (int blockID, int param1, int param2, int param3);
  306. /** Sends a message to the host. To receive this the host will need to implement
  307. the Block::ProgramEventListener::handleProgramEvent() method.
  308. @param param1 the first chunk of data to send
  309. @param param2 the second chunk of data to send
  310. @param param3 the third chunk of data to send
  311. */
  312. void sendMessageToHost (int param1, int param2, int param3);
  313. //=============================== LIGHTPAD =====================================
  314. /** Draws a pressure point with a specified colour and pressure.
  315. @param argb the colour to use
  316. @param touchX the x position of the touch in block units
  317. @param touchY the y position of the touch in block units
  318. @param touchZ the pressure value of the touch
  319. */
  320. void addPressurePoint (int argb, float touchX, float touchY, float touchZ);
  321. /** Draws the pressure map on the display. */
  322. void drawPressureMap();
  323. /** Fades the pressure map on the display. */
  324. void fadePressureMap();
  325. //=============================== CONTROL ======================================
  326. /** Links a another block to this control block.
  327. @param blockID the ID of the block to link
  328. */
  329. void linkBlockIDtoController (int blockID);
  330. /** Repaints the control block display. */
  331. void repaintControl();
  332. /** Initialises one of the control block buttons.
  333. @param buttonIndex the index of the button to initialise
  334. @param modeToUse the mode to use for this button @see ControlMode
  335. @param outputType the control type to use @see ControlType
  336. @param val the current value to set this button to
  337. @param min the minimum value for this button
  338. @param max the maximum value for this button
  339. @param index the item index
  340. @param onColourToUse the colour to use when this button is on
  341. @param offColourToUse the colour to use when this button is off
  342. */
  343. void initControl (int buttonIndex, int modeToUse, int outputType, int val, int min, int max,
  344. int index, int onColourToUse, int offColourToUse);
  345. enum ControlType
  346. {
  347. internalConfig = 0,
  348. midiCC,
  349. sysex
  350. };
  351. enum ControlMode
  352. {
  353. toggle = 0,
  354. togglePulse,
  355. gate,
  356. trigger,
  357. cycle,
  358. incDec,
  359. triState
  360. };
  361. //=============================== SEABOARD =====================================
  362. /** Forces a touch event to be handled as seaboard playing.
  363. @param touchIndex the index of the touch event
  364. */
  365. void handleTouchAsSeaboard (int touchIndex);
  366. //=============================== TOPOLOGY AND CLUSTERS ========================
  367. /** Returns the number of blocks in the current topology. */
  368. int getNumBlocksInTopology();
  369. /** Returns the ID of a block at a given index in the topology. */
  370. int getBlockIDForIndex (int index);
  371. /** Returns true if this block is directly connected to the host,
  372. as opposed to only being connected to a different block via a connection port.
  373. */
  374. bool isMasterBlock();
  375. /** Returns true if this block is connected to the host computer, this can be
  376. directly or through connections to other blocks. */
  377. bool isConnectedToHost();
  378. /** Returns the ID of a block connected to a specified port on this block. */
  379. int getBlockIDOnPort (int port);
  380. /** Returns the port number that is connected to the master block. Returns 0xFF if there is
  381. no port connected to master. */
  382. int getPortToMaster();
  383. /** Returns the horizontal distance between this block and the master block in block units. */
  384. int getHorizontalDistFromMaster();
  385. /** Returns the vertical distance between this block and the master block in block units. */
  386. int getVerticalDistFromMaster();
  387. /** Returns the angle of this block relative to the master block in degrees. */
  388. int getAngleFromMaster();
  389. /** Sets whether this block should auto-rotate when its angle relative to the master block changes. */
  390. void setAutoRotate (bool enabled);
  391. /** Returns the index of this block in the current cluster. */
  392. int getClusterIndex();
  393. /** Returns how many blocks wide the current cluster is. */
  394. int getClusterWidth();
  395. /** Returns how many blocks high the current cluster is. */
  396. int getClusterHeight();
  397. /** Returns the x index of this block in the current cluster. */
  398. int getClusterXpos();
  399. /** Returns the y index of this block in the current cluster. */
  400. int getClusterYpos();
  401. /** Returns the number of blocks in the current cluster. */
  402. int getNumBlocksInCurrentCluster();
  403. /** Returns the block ID for a block in the current cluster.
  404. @param index the cluster index of the block to get the ID of
  405. */
  406. int getBlockIdForBlockInCluster (int index);
  407. /** Returns true if the master block is in the current cluster. */
  408. bool isMasterInCurrentCluster();
  409. //=============================== CONFIG =======================================
  410. /** Returns current value of one of the local config items.
  411. @param item the config item to get (see ConfigItemId enum in juce_BlocksProtocolDefinitions.h)
  412. */
  413. int getLocalConfig (int item);
  414. /** Sets the current value of one of the local config items.
  415. @param item the config item to set the value of (see ConfigItemId enum in juce_BlocksProtocolDefinitions.h)
  416. @param value the value to set the config to
  417. */
  418. void setLocalConfig (int item, int value);
  419. /** Sets the local config of a block to the config item of a remote block.
  420. @param longAddress the address of the remote block
  421. @param item the config item (see ConfigItemId enum in juce_BlocksProtocolDefinitions.h)
  422. */
  423. void requestRemoteConfig (int longAddress, int item);
  424. /** Sets the config of a remote block.
  425. @param longAddress the address of the remote block
  426. @param item the config item (see ConfigItemId enum in juce_BlocksProtocolDefinitions.h)
  427. @param value the value to set the config to
  428. */
  429. void setRemoteConfig (int longAddress, int item, int value);
  430. /** Sets the range of one of the local config items.
  431. @param item the config item to set the range of (see ConfigItemId enum in juce_BlocksProtocolDefinitions.h)
  432. @param min the minimum value this config item should use
  433. @param max the maximum value this config item should use
  434. */
  435. void setLocalConfigItemRange (int item, int min, int max);
  436. /** Sets whether a local config item should be active.
  437. @param item the config item to set active (see ConfigItemId enum in juce_BlocksProtocolDefinitions.h)
  438. @param isActive sets whether the config should be active or not
  439. @param saveToFlash if true then this config item will be saved to the flash memory of the block
  440. */
  441. void setLocalConfigActiveState (int item, bool isActive, bool saveToFlash);