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
UI Layout and positioning
  • CELL
  • TABLE
UI Widgets
  • TEXT
  • TEXT_FIELD
  • TEXT_EDIT_BOX
  • CANVAS
    • Graphics API
  • svg
Common attrubutes
  • For all elements
  • Widgets
  • Param Widgets
  • Param Controls
  • Param Info Viewers
  • Text Widgets
  • Surface Viewers
  • Curve Viewers
  • 3D Objects
  • Parameters mapping
KUIMLElement ReferenceREPEAT
December 19, 2022

REPEAT

This element is a static repeat loop. It can be used to repeat several times the same piece of code, with changes managed by an index variable for each instance. There are several ways to define the index for the loop, either with numbers or with a list of strings.

Attributes brief detailed show all inherited

Name DescriptionDefault
index_namename of the variable used for the index in the loopfor nested repeats it is necessary to define different names for the index variable to avoid conflictsindex
countnumber of repeatsThis is number of repeats for the code contained inside the REPEAT element0
startstart value for the index published in the repeat loopTo be used with the count attributes. Defines the list of values for the index variable0
index_listList of values for the index variable. Also implies the number of repeatsThis attribute overrides the start/count attributesempty
Name Value type Default Description Comment
index_namestringindexname of the variable used for the index in the loopfor nested repeats it is necessary to define different names for the index variable to avoid conflicts
countinteger or a Math Formula using previously defined variables0number of repeatsThis is number of repeats for the code contained inside the REPEAT element
startinteger or Math Formula using previously defined variables0start value for the index published in the repeat loopTo be used with the count attributes. Defines the list of values for the index variable
index_listlist of semi-column separated values (strings)emptyList of values for the index variable. Also implies the number of repeatsThis attribute overrides the start/count attributes

Examples

The following code:

  1. <REPEAT count="2" start="1">
  2. <ELEMENTA attribute_a="$index$"/>
  3. </REPEAT>

Is equivalent to:

  1. <ELEMENTA attribute_a="1"/>
  2. <ELEMENTA attribute_a="2"/>

Similarly, using the index_list attribute instead, the following code:

  1. <REPEAT index_list="A;B">
  2. <ELEMENTA attribute_a="$index$"/>
  3. </REPEAT>

Is equivalent to:

  1. <ELEMENTA attribute_a="A"/>
  2. <ELEMENTA attribute_a="B"/>

And you can modify the index_name attribute for nested loops, so that the following code:

  1. <REPEAT count="2" start="1">
  2. <REPEAT index_name="sub_index" count="2" start="1">
  3. <ELEMENTA attribute_a="$index$-$sub_index$"/>
  4. </REPEAT>
  5. </REPEAT>

Is equivalent to:

  1. <ELEMENTA attribute_a="1-1"/>
  2. <ELEMENTA attribute_a="1-2"/>
  3. <ELEMENTA attribute_a="2-1"/>
  4. <ELEMENTA attribute_a="2-2"/>

A formula can be used to compute the index and start values. For example the following code:

  1. <VARIABLE id="a" value="1">
  2. <VARIABLE id="b" value="0">
  3. <REPEAT count="$a$*2" start="$b$+1">
  4. <ELEMENTA attribute_a="$index$"/>
  5. </REPEAT>

Is equivalent to:

  1. <ELEMENTA attribute_a="2"/>
  2. <ELEMENTA attribute_a="3"/>

Advanced usage

Sometimes you need to increase numeric index as well as loop through the strings in the index_list. You can achieve this using additional VARIABLE with override set to "true". Additionally we can shorten the code using some defines (already defined in LM Skin).

  1. <DEFINE>
  2. <VAR base_type="VARIABLE" override="true" />
  3. <R base_type="REPEAT" />
  4. </DEFINE>

  5. <VAR id="N" value="0" />
  6. <VAR id="list" value="Apples;Peaches;Oranges" />
  7. <VAR id="reversed_list" value="" />

  8. <R index_list="$list$">
  9. <TEXT value="$N$: $index$" />
  10. <VAR id="N" formula="$N$+1" />
  11. <VAR id="reversed_list" value="$index$;$reversed_list$" />
  12. </R>

  13. <TEXT value="$reversed_list$" />

REPEAT as "IF"

Another very useful thing is ability to use formulas in "count" attribute. True = 1, false = 0.

  1. <VAR id="DEBUG_MODE" value="1" />
  2. <R count="$DEBUG_MODE$ != 0">
  3. <TEXT value="Data for DEBUG mode" />
  4. </R>
  5. <R count="$DEBUG_MODE$ == 0">
  6. <TEXT value="Normal mode" />
  7. </R>

However, you can use only numeric and boolean values in formulas. If you need to compare strings, you can use build time scripting possibilities for VARIABLE. Or something! 234

  1. <VAR id="IS_WINDOWS" script="if (&quot;$_SYSTEM_TYPE_$&quot; == &quot;Windows&quot;) return &quot;1&quot;; else return &quot;0&quot;;" />

  2. <R count="$IS_WINDOWS$">
  3. <TEXT value="We're on Windows" />
  4. </R>

  5. <R count="!$IS_WINDOWS$">
  6. <TEXT value="We're on Mac" />
  7. </R>

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