mozaic_tips_and_tricks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revisionBoth sides next revision
mozaic_tips_and_tricks [2020/03/01 22:12] – Minor addition to Knob Double-Tap _kimozaic_tips_and_tricks [2020/07/12 21:46] – Added: Using Inc and Dec in Expressions _ki
Line 14: Line 14:
   * [[#Use a Knob to toggle 16 Pads View to HELP View]]   * [[#Use a Knob to toggle 16 Pads View to HELP View]]
   * [[#Knob double-tap Support]]   * [[#Knob double-tap Support]]
 +  * [[#Using Inc and Dec in Expressions]]
   * [[#Calculate Standard Chords from a Root Note]]   * [[#Calculate Standard Chords from a Root Note]]
  
Line 275: Line 276:
     * //isOn = _val > 64// assigns either 0 or 1 to //isOn// depending on _val     * //isOn = _val > 64// assigns either 0 or 1 to //isOn// depending on _val
  
 +
 +\\ 
 +===== Using Inc and Dec in Expressions ===== 
 +<html><p align = "right"><small><i>From -ki</i></small></p></html>
 +
 +TheOriginalPaulB discovered that Inc and Dec are working as functions. Both Inc and Dec are ‚pre-increment‘ operations like ++var  in C, as the function returns the already incremented value. This allows for several interesting language constructs:
 +
 +In case of a ring buffer index, one could use
 +<code>
 +  index = (Inc index) % 64
 +</code>
 +instead of the longer construct
 +
 +<code>
 +  Inc index
 +  index = index % 64
 +</code>
 +
 +\\ 
 +Sometimes this trick is also applicable in array initialization, but one has to compensate for the pre-increment.
 +<code>
 +  idx = -1
 +  for i = 10 to 19
 +    array[Inc idx] = 2*i
 +  endfor
 +</code>
 +The example fills array[0] to array[9] with the values 20 to 38. To compensate for pre-increment, idx needs to start at -1 since it will be incremented to zero on first usage
 +
 +\\ 
 +It is also possible to construct a post-increment operation by using the inc in the expression itself, but discarding it using multiplication with 0:
 +
 +<code>
 +  idx = 0
 +  for i = 10 to 19
 +    array[idx] = 2*i  + 0*(Inc idx)
 +  endfor
 +</code>
  
 \\  \\ 
  • mozaic_tips_and_tricks.txt
  • Last modified: 2024/04/23 19:07
  • by _ki