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 revision
Previous revision
Next revisionBoth sides next revision
mozaic_tips_and_tricks [2020/07/30 19:01] – [Mozaic: Scripting Tips & Tricks] Added link to ‚Dynamic Letters for Labeling‚ section _kimozaic_tips_and_tricks [2021/04/12 17:43] – [Remove or add an entry inside an array] _ki
Line 9: Line 9:
   * [[#Store two positive Values into a single Variable]]   * [[#Store two positive Values into a single Variable]]
   * [[#Store three unsigned Bytes into a single Variable]]   * [[#Store three unsigned Bytes into a single Variable]]
 +  * [[#Output Fixed Point Values in Labels]]
   * [[#Some Best Practice Tips]]   * [[#Some Best Practice Tips]]
 +  * [[#Detect Long or Short Pad Taps]]
 +  * [[#Detect Long or Short SHIFT Button Taps]]
   * [[#Multi-Line Pad Labels]]   * [[#Multi-Line Pad Labels]]
   * [[#Dynamic Letters for Labeling]]   * [[#Dynamic Letters for Labeling]]
Line 15: Line 18:
   * [[#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]]
 +  * [[#Remove or add an entry inside an array]]
   * [[#Using Logic Operators in Expressions instead of IF cases]]   * [[#Using Logic Operators in Expressions instead of IF cases]]
   * [[#Using Inc and Dec in Expressions]]   * [[#Using Inc and Dec in Expressions]]
Line 81: Line 85:
   varB = 124   // allowed range 0 .. ~16000   varB = 124   // allowed range 0 .. ~16000
      
-  combinedValue = valA + valB * maxA +  combinedValue = valA + (valB * maxA
 </code>  </code> 
 +
 +For single-byte MIDI values, use 128 for maxA
  
 To later extract the values from their packed format use To later extract the values from their packed format use
Line 117: Line 123:
 </code> </code>
  
 +
 +\\ 
 +===== Output Fixed Point Values in Labels =====
 +<html><p align = "right"><small><i>From -ki</i></small></p></html>
 +When outputting floating point values into labels (knobs, pads, titles) Moazic generates either a 4 digit fraction string 
 +like 42.5000 (if a remainder present) or an integer value without fraction.
 +
 +\\ 
 +To always output a positive float with two digits (even when integer), one needs to split the input value and output the computed integer parts individually:
 +<code>
 +  n = Round value * 100
 +  f = Div n, 100
 +  d = n-f*100
 +  r1 = Div d, 10
 +  r2 = d % 10
 +  LabelKnob 0, {B:},f,{.},r1,r2
 +</code>
 +
 +\\ 
 +To always output a negative and positive float with a single digit, the split needs to work on the absolute value
 +and a conditional statement is used to output both variants:
 +<code>
 +  n = Round Abs(value * 10)
 +  f = Div n, 10
 +  r = (n-f*10) % 10
 +  if value >=0
 +    LabelKnob 1, {N: +},f,{.},r
 +  else
 +    LabelKnob 1, {N: },f,{.},r
 +  endif
 +</code>
  
 \\  \\ 
Line 145: Line 182:
 </code> </code>
  
 +
 +\\ 
 +===== Detect Long or Short Pad Taps =====
 +<html><p align = "right"><small><i>From wim</i></small></p></html>
 +
 +<code>
 +@OnLoad
 +  FillArray downStart,0,16
 +  pressTime = 250
 +@End
 +
 +@OnPadDown
 +  downStart[LastPad] = SystemTime
 +@End
 +
 +@OnPadUp
 +  pad = LastPad
 +  if SystemTime - downStart[pad] < pressTime
 +    Log {Short tap pad }, pad
 +  else
 +    Log {Long tap pad }, pad
 +  endif
 +@End
 +</code>
 +
 +\\ 
 +
 +===== Detect Long or Short SHIFT Button Taps =====
 +<html><p align = "right"><small><i>From wim</i></small></p></html>
 +
 +<code>
 +@OnLoad
 +  shiftStart = 0
 +  pressTime  = 250
 +@End
 +
 +@OnShiftDown
 +  shiftStart = SystemTime
 +@End
 +
 +@OnShiftUp
 +  if SystemTime - shiftStart < pressTime
 +    Log {Short tap SHIFT}
 +  else
 +    Log {Long  tap SHIFT}
 +  endif
 +@End
 +</code>
  
 \\  \\ 
Line 181: Line 266:
 </code> </code>
  
 +\\ 
 ===== Use the SHIFT Button to toggle to HELP View ===== ===== Use the SHIFT Button to toggle to HELP View =====
 <html><p align = "right"><small><i>From -ki</i></small></p></html> <html><p align = "right"><small><i>From -ki</i></small></p></html>
Line 299: Line 385:
  
  
 +\\ 
 +=====  Remove or add an entry inside an array ===== 
 +<html><p align = "right"><small><i>From -ki</i></small></p></html>
 +Instead of running through an array with a FOR loop to shift entries to either insert or remove an  intermedeate enry, it is way faster to use the CopyArray Mozaic function:
 +
 +<code> CopyArray source, dest, size</code>
  
 \\  \\ 
 +=== Remove an entry of an array (shift left) ===
 +
 +<code>
 +@OnLoad
 +  for i=0 to 6
 +    a[i] = i
 +  endfor
 +  Log {Before },a[0],{ },a[1],{ },a[2],{ },a[3],{ },a[4],{ },a[5],{ },a[6]
 +
 +  // Remove entry a[2] by left shift of the following entries
 +  CopyArray a[3], a[2], 6
 +  
 +  Log {After  },a[0],{ },a[1],{ },a[2],{ },a[3],{ },a[4],{ },a[5],{ },a[6]
 +@End
 +</code>
 +
 +\\ 
 +=== Insert an entry into array (shift right) ===
 +
 +Due to the inner working of CopyArray, the above trick doesn‘t work for right shifts - but one can use a temporary array to be more efficient than iterating over the array:
 +
 +<code>
 +@OnLoad
 +  for i=0 to 6
 +    a[i] = i
 +  endfor
 +  Log {Before  },a[0],{ },a[1],{ },a[2],{ },a[3],{ },a[4],{ },a[5],{ },a[6]
 +
 +  // Insert a new a[2]
 +  CopyArray a[2], _tmp, 6
 +  CopyArray _tmp, a[3], 6  
 +  a[2] = 9
 +  
 +  Log {After   },a[0],{ },a[1],{ },a[2],{ },a[3],{ },a[4],{ },a[5],{ },a[6]
 +@End
 +</code>
 =====  Using Logic Operators in Expressions instead of IF cases =====  =====  Using Logic Operators in Expressions instead of IF cases ===== 
 <html><p align = "right"><small><i>From -ki</i></small></p></html> <html><p align = "right"><small><i>From -ki</i></small></p></html>
  • mozaic_tips_and_tricks.txt
  • Last modified: 2024/04/23 19:07
  • by _ki