Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
mozaic_tips_and_tricks [2020/11/17 02:15] – Formatting _ki | mozaic_tips_and_tricks [2021/07/01 21:41] (current) – Added „ About State-Saving“ section _ki | ||
---|---|---|---|
Line 4: | Line 4: | ||
This wiki page contains programming tips & tricks for [[mozaic_plugin_engine|Mozaic]] | This wiki page contains programming tips & tricks for [[mozaic_plugin_engine|Mozaic]] | ||
+ | * [[#NoteOn Velocity 0 Special Case]] | ||
* [[#Two dimensional Arrays]] | * [[#Two dimensional Arrays]] | ||
* [[#Multi dimensional Arrays]] | * [[#Multi dimensional Arrays]] | ||
Line 11: | Line 11: | ||
* [[#Output Fixed Point Values in Labels]] | * [[#Output Fixed Point Values in Labels]] | ||
* [[#Some Best Practice Tips]] | * [[#Some Best Practice Tips]] | ||
+ | * [[#About State-Saving]] | ||
* [[#Detect Long or Short Pad Taps]] | * [[#Detect Long or Short Pad Taps]] | ||
* [[#Detect Long or Short SHIFT Button Taps]] | * [[#Detect Long or Short SHIFT Button Taps]] | ||
Line 18: | Line 19: | ||
* [[#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]] | ||
* [[# | * [[# | ||
* [[#Include Snippets]] | * [[#Include Snippets]] | ||
+ | |||
+ | ===== NoteOn Velocity 0 Special Case===== | ||
+ | < | ||
+ | The Midi Spec allows to use a NoteOn command with velocity zero instead of a NoteOff command. If this combination is received by Mozaic, this midi command is automatically converted to
NoteOff vel 0 - even for the @OnMidiInput event and when checking MidiByte1. | ||
+ | |||
+ | Therefore scripts don‘t need to check for this ‚NoteOn Vel 0‘ case, as that special case is handled by Mozaic. Even when using MidiThrough, | ||
+ | |||
===== Two dimensional Arrays ===== | ===== Two dimensional Arrays ===== | ||
Line 84: | Line 93: | ||
varB = 124 // allowed range 0 .. ~16000 | varB = 124 // allowed range 0 .. ~16000 | ||
| | ||
- | combinedValue = valA + valB * maxA | + | combinedValue = valA + (valB * maxA) |
</ | </ | ||
+ | |||
+ | 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 145: | Line 156: | ||
f = Div n, 10 | f = Div n, 10 | ||
r = (n-f*10) % 10 | r = (n-f*10) % 10 | ||
- | if number>=0 | + | if value >=0 |
LabelKnob 1, {N: +},f,{.},r | LabelKnob 1, {N: +},f,{.},r | ||
else | else | ||
- | LabelKnob 1, {N: +},f,{.},r | + | LabelKnob 1, {N: },f,{.},r |
endif | endif | ||
</ | </ | ||
Line 178: | Line 189: | ||
@End | @End | ||
</ | </ | ||
+ | |||
+ | \\ | ||
+ | ===== About State-Saving ===== | ||
+ | < | ||
+ | All assigned variables of a script are automatically included in a saved preset and restored when reloading. To not overwrite them, use the | ||
+ | < | ||
+ | if Unassigned channel | ||
+ | channel = 10 | ||
+ | bank = 1 | ||
+ | .... | ||
+ | endif | ||
+ | </ | ||
+ | construct in the scripts **OnLoad** that only set the default value if a script is freshly run using ‚Upload‘. If reloaded (and therefor some value is already assigned to ‚channel‘ ) the initialization block is skipped. | ||
+ | |||
+ | |||
+ | Mozaic stores some more more information in the presets/ | ||
+ | * Layout | ||
+ | * Pad labels, color, latch-state | ||
+ | * Knob labels and position | ||
+ | * XY position | ||
+ | * Title label above pads, knobs, XY | ||
+ | * Rootnote and scale | ||
+ | |||
+ | Things **not** restored during session reload: | ||
+ | * ShortName | ||
+ | * Timer state and settings | ||
+ | * LFO settings | ||
Line 382: | Line 420: | ||
+ | \\ | ||
+ | ===== Remove or add an entry inside an array ===== | ||
+ | < | ||
+ | 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: | ||
+ | |||
+ | < | ||
\\ | \\ | ||
+ | === Remove an entry of an array (shift left) === | ||
+ | |||
+ | < | ||
+ | @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 | ||
+ | @End | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | === 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: | ||
+ | |||
+ | < | ||
+ | @OnLoad | ||
+ | for i=0 to 6 | ||
+ | a[i] = i | ||
+ | endfor | ||
+ | Log {Before | ||
+ | |||
+ | // Insert a new a[2] | ||
+ | CopyArray a[2], _tmp, 6 | ||
+ | CopyArray _tmp, a[3], 6 | ||
+ | a[2] = 9 | ||
+ | | ||
+ | Log {After | ||
+ | @End | ||
+ | </ | ||
===== Using Logic Operators in Expressions instead of IF cases ===== | ===== Using Logic Operators in Expressions instead of IF cases ===== | ||
< | < |