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.

66 lines
3.4KB

  1. /**
  2. @page example_dynamic_parameters Dynamic Parameters
  3. @section dynamic_parameters_introduction Introduction
  4. Learn how to use BLOCKS CODE metadata to interact with your BLOCKS using dynamic parameters.
  5. Launch the BLOCKS CODE application and open the script called @s_file{DynamicParameters.littlefoot}. You can find the script in the Littlefoot-Examples repository, which you can download from GitHub @littlefootgithub{here}. If you don't have the BLOCKS CODE IDE installed on your system, please refer to the section @ref getting_started_with_blocks_code for help.
  6. @section dynamic_parameters_adding_parameters Adding Parameters
  7. Let's start by adding parameters to the side panel of BLOCKS CODE that will appear under the Parameters tab.
  8. These are created using an XML format enclosed between multiline comment blocks and @s_code{\<metadata\>} tags at the top of the file. Variables are created between @s_code{\<variables\>} tags and they can also be grouped using @s_code{\<groups\>} tags as follows:
  9. @code{.xml}
  10. <metadata description="Dynamic Parameters">
  11. <groups>
  12. <group name="pos" displayName="Position" />
  13. <group name="size" displayName="Size" />
  14. <group name="colour" displayName="Colour" />
  15. </groups>
  16. <variables>
  17. <variable group="pos" name="xPos" type="int" min="0" max="15" value="6" />
  18. <variable group="pos" name="yPos" type="int" min="0" max="15" value="6" />
  19. <variable group="size" name="width" type="int" min="1" max="15" value="3" />
  20. <variable group="size" name="height" type="int" min="1" max="15" value="3" />
  21. <variable group="colour" name="alpha" type="float" min="0" max="255" value="255" />
  22. <variable group="colour" name="red" type="int" min="0" max="255" value="255" />
  23. <variable group="colour" name="green" type="int" min="0" max="255" value="0" />
  24. <variable group="colour" name="blue" type="int" min="0" max="255" value="0" />
  25. <variable name="draw" type="bool" value="true" />
  26. </variables>
  27. </metadata>
  28. @endcode
  29. Within the variable declaration, the string given to the "name" attribute becomes the variable name in the subsequent littlefoot code.
  30. Let's now implement the repaint() function of the littlefoot program. This function is called periodically at approximately 25Hz on the device and is used to control the LEDs on a Lightpad.
  31. In the following piece of code, we first call the clearDisplay() function which will reset the screen to a blank state so that any LEDs that were turned on in the previous iteration of the repaint() function are turned off.
  32. @code{.cpp}
  33. void repaint()
  34. {
  35. clearDisplay();
  36. if (draw)
  37. fillRect (makeARGB (int (alpha), red, green, blue), xPos, yPos, width, height);
  38. }
  39. @endcode
  40. Then we use the fillRect() function to draw a rectangle on the screen using the variables defined before, only if the draw button is checked. The fillRect() function takes as argument the colour retrieved by the makeARGB() helper function and the position and size of the rectangle we wish to draw.
  41. @section dynamic_parameters_summary Summary
  42. In this example, we learnt how to add parameters that can be tweaked at runtime to control the behaviour of a program in realtime.
  43. @section dynamic_parameters_see_also See also
  44. - @ref example_colour_pressure_map
  45. - @ref example_tic_tac_toe
  46. - @ref example_music_gen
  47. */