PLUG'N SCRIPT
rapid plugin development
Tutorial
DSP
KUIML
How-to
Scripts
  • Tutorial
  • Element Reference
Language basics
  • SKIN
  • DUMMY
  • INCLUDE
  • INCLUDE_ONCE
  • DEFINE
  • UNDEFINE
  • VARIABLE
  • LOCAL_VARIABLE
  • TEMPLATE
  • TEMPLATE_INNER_CONTENT
  • REPEAT
Data model
  • PARAM
  • ACTION
    • Action types
  • ACTION_TRIGGER
  • TIMER
UI Layout and positioning
  • CELL
  • TABLE
UI Widgets
  • CANVAS
    • Graphics API
  • COLOR_SCALE
  • FILE_SELECT_MENU
  • GRID
  • INVISIBLE_PARAM_MENU_BUTTON
  • MENU_ITEM
  • MENU_SEPARATOR
  • POPUP_MENU
  • svg
  • RULER
  • TEXT
  • TEXT_FIELD
  • TEXT_EDIT_BOX
  • XY_PARAM_PAD
  • XY_ZOOM_SELECT_PAD
  • XYZ_PARAM_SCRATCH_PAD
  • XYZ_PARAM_CLICK_PAD
  • XYZ_IMAGE_PARAM_JOYSTICK
UI 3D Objects
  • COLOR_SURFACE_3D
  • GRID_3D
  • GL_OBJECT_3D
Data model commands
  • REQUIRED_OBJECTS
  • EXPOSED_OBJECTS
  • PERSISTENT_OBJECTS
Common attrubutes
  • For all elements
  • Widgets
  • Param Widgets
  • Param Controls
  • Param Info Viewers
  • Text Widgets
  • Surface Viewers
  • Curve Viewers
  • 3D Objects
  • Parameters mapping
  • LetiMix
KUIMLElement ReferenceTIMER
March 25, 2024

TIMER

This element is not an actual data type but simply fires an event on a regular basis, when specified time has elapsed.

Attributes brief detailed show all inherited

Name DescriptionDefault
Exposed: v. 2.0enabledEnables or disables the timer'true'
Exposed: v. 2.0refresh_time_msinterval between two timer events50
Events
Exposed: v. 2.0elapsedFired when specified refresh_time_ms has elapsed, if the event is enabled
Common attributesRead about `common`
idIdentifier of the elementThe id of an element has to be globally unique. Two elements cannot have the same identifierempty
Name Value type Default Description Comment
Exposed: v. 2.0enabledboolean'true'Enables or disables the timer
Exposed: v. 2.0refresh_time_msAny positive integer value50interval between two timer events
Events
Exposed: v. 2.0elapsedref_type_eventFired when specified refresh_time_ms has elapsed, if the event is enabled
Common attributesRead about `common`
ididentifieremptyIdentifier of the elementThe id of an element has to be globally unique. Two elements cannot have the same identifier

More information

Timer can help you do various task: change parameter over time, check for changes that can't be tracked other way, create animation, create delayed action, etc.

Timer hints

Timer parameter refresh_time_ms usually cannot be smaller than 10ms.

Timer speeds on Windows and Mac can be different. 

Timer is affected by SKIN parameter refresh_priority (when it is set to "idle" timers runs slower).

ACTION_TRIGGER with async="true" for a timer tends to crash, use async="false".

Continuous action

  1. <!-- a timer and an action -->
  2. <TIMER id="forever_timer" refresh_time_ms="10" />
  3. <ACTION_TRIGGER event_id="forever_timer.elapsed"
  4. script=" 
  5. demo_param = 0.1+demo_param;
  6. wiggle.h_offset = sin(demo_param)*100;
  7.  " requires="demo_param;wiggle.h_offset" />
  8. <!-- simple param and widget to move -->
  9. <PARAM id="demo_param" default="0" max="$_PARAM_MAX_$"/>
  10. <ROW width="200">
  11. <WIDGET id="wiggle" background_color="#000080" width="10" height="10" />
  12. </ROW>

doc_ref_model_timer_element_example1.png

Action while condition

Timer keeps running but the action is not triggered because condition_formula is false.

  1. <!-- a timer and an action -->
  2. <TIMER id="regular_timer" refresh_time_ms="50" />
  3. <ACTION_TRIGGER event_id="regular_timer.elapsed"
  4. script="demo_param = 1+demo_param;" requires="demo_param"
  5. condition_formula="(demo_param &lt; 30)" />
  6. <!-- demo param -->
  7. <PARAM id="demo_param" default="0" max="$_PARAM_MAX_$"/>
  8. <PARAM_TEXT_CONTROL param_id="demo_param" />

doc_ref_model_timer_element_example1.png

Run and stop

You can enable and disable timer on the fly. The following code creates a timer launched by a button that calls a simple script (using an ACTION_TRIGGER) measuring elapsed time while it is displayed on screen. Once elapsed_time reaches 1000 ms, timer is stopped and a message box is displayed.

  1. <!-- Creates a disabled demo_timer -->
  2. <TIMER id="demo_timer" enabled="false" refresh_time_ms="10" />

  3. <!-- Parameters used by the script-->
  4. <PARAM id="times_clicked" default="0" max="$_PARAM_MAX_$" exposed="true"/>
  5. <PARAM id="times_finished" default="0" max="$_PARAM_MAX_$" exposed="true"/>
  6. <PARAM id="elapsed" default="0" max="2000" exposed="true"/>

  7. <!-- Script action trigger on demo_timer event -->
  8. <ACTION_TRIGGER event_id="demo_timer.elapsed" script=" 
  9. elapsed += demo_timer.refresh_time_ms;
  10. if (elapsed >= 1000) {
  11. demo_timer.enabled = 0;
  12. times_finished = 1+times_finished;
  13. elapsed = 0;
  14. }" async="false" requires="demo_timer.refresh_time_ms;demo_timer.enabled" />

  15. <!-- Simple "click me" button to start the demo_timer -->
  16. <COLUMN margin="5">
  17. <WIDGET background_color="#333333" v_margin="10" h_margin="10">
  18. <TEXT value="Click Here" text_color="#EEEEEE" >
  19. <INVISIBLE_PARAM_BUTTON id="button" width="100%" height="100%" param_id="demo_timer.enabled"/>
  20. <ACTION_TRIGGER event_id="demo_timer.enabled.value_changed" condition_formula="demo_timer.enabled==1" script="times_clicked = 1+times_clicked;" requires="times_clicked" />
  21. </TEXT>
  22. </WIDGET>

  23. <CELL height="10" />

  24. <!-- displaying text data -->
  25. <PARAM_TEXT font_size="15" param_id="elapsed" content="button clicked {value} ms ago" width="300" value_format="0." />
  26. <ROW>
  27. <PARAM_TEXT param_id="times_clicked" content="times clicked: {value} " value_format="0."/>
  28. <PARAM_TEXT param_id="times_finished" content="times finished: {value}" value_format="0."/>
  29. </ROW>
  30. </COLUMN>

doc_ref_model_timer_element_example1.png

2020 - 2025 © Site by LetiMix  |  Plug'n Script and KUIML by Blue Cat Audio