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.

773 lines
26KB

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