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/03/01 21:24] – Added tip author _kimozaic_tips_and_tricks [2020/03/01 22:12] – Minor addition to Knob Double-Tap _ki
Line 1: Line 1:
 ====== Mozaic: Scripting Tips & Tricks ====== ====== Mozaic: Scripting Tips & Tricks ======
 +~~NOTOC~~ {{tag>Mozaic midi_scripting}}
  
 This wiki page contains programming tips & tricks for [[mozaic_plugin_engine|Mozaic]] This wiki page contains programming tips & tricks for [[mozaic_plugin_engine|Mozaic]]
Line 12: Line 13:
   * [[#Use the SHIFT Button to toggle to HELP View]]   * [[#Use the SHIFT Button to toggle to HELP View]]
   * [[#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]]
   * [[#Calculate Standard Chords from a Root Note]]   * [[#Calculate Standard Chords from a Root Note]]
  
Line 213: Line 215:
 @End @End
 </code> </code>
-{{tag>Mozaic midi_scripting}} 
  
 +\\ 
 +===== Knob double-tap Support ===== 
 +<html><p align = "right"><small><i>From -ki</i></small></p></html>
 +
 +The value returned from //**GetKnobValue**// is a floating point number, usually it will contain non-zero decimal places when the knob is turned manually. If double tapped the knob-value is set to 64 exactly. 
 +This tip exploits the fact, that is very unlikely to manually dial in exactly 64.0000 - if such a knob value is returned, then the knob has probably been double-tapped.
 +
 +
 +If a knob is only used to toggle between two states like a switch (like the variable //isOn// in the example), the code for double-tap detection would look like:
 +<code>
 +@OnKnobChange
 +  _knob = LastKnob
 +  _val  = GetKnobValue _knob
 +  
 +  if _knob = TOGGLE_KNOB
 +    if _val = 64
 +      isOn = not isOn
 +      SetKnobValue TOGGLE_KNOB,48 + 32*isOn
 +    else
 +      isOn = _val > 64  
 +    endif
 +    
 +    if isOn
 +      LabelKnob TOGGLE_KNOB,  {ON}
 +    else
 +      LabelKnob TOGGLE_KNOB,  {OFF}
 +    endif
 +  endif
 +@End
 +
 +@OnLoad
 +  ShowLayout 2
 +  LabelPads {Knob Double-Tap Demo }
 +  LabelKnobs {Toggle with Double-Tap}
 +  for _knob = 0 to 3
 +    SetKnobValue _knob,0
 +    LabelKnob _knob,  { }
 +  endfor
 +  
 +  if Unassigned isOn
 +    isOn = NO  
 +  endif
 +  
 +  TOGGLE_KNOB = 1
 +  
 +  SetKnobValue TOGGLE_KNOB,48 + 32*isOn
 +  if isOn
 +    LabelKnob TOGGLE_KNOB,  {ON}
 +  else
 +    LabelKnob TOGGLE_KNOB,  {OFF}
 +  endif
 +@End
 +</code>
 +The script snippet also features
 +  * State saving of the toggle variable isOn
 +  * Conditional expressions: 
 +    * //48 + 32*isOn// is either 48 or 80 depending on the state of //isOn//
 +    * //isOn = _val > 64// assigns either 0 or 1 to //isOn// depending on _val
 +
 +
 +\\ 
 ===== Calculate Standard Chords from a Root Note ==== ===== Calculate Standard Chords from a Root Note ====
 <html><p align = "right"><small><i>From wim</i></small></p></html> <html><p align = "right"><small><i>From wim</i></small></p></html>
  • mozaic_tips_and_tricks.txt
  • Last modified: 2024/04/23 19:07
  • by _ki