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
Last revisionBoth sides next revision
mozaic_tips_and_tricks [2021/04/12 17:35] – Remove/add array entries (part I) _kimozaic_tips_and_tricks [2021/04/12 17:59] – NoteOn Velocity 0 _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 23: Line 23:
   * [[#Calculate Standard Chords from a Root Note]]   * [[#Calculate Standard Chords from a Root Note]]
   * [[#Include Snippets]]   * [[#Include Snippets]]
 +
 +===== NoteOn Velocity 0 Special Case=====
 +<html><p align = "right"><small><i>From -ki</i></small></p></html>
 +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, an incomming ‚NoteOn Vel 0‘ command will be converted to ‚NoteOff Vel 0‘
 +
  
 ===== Two dimensional Arrays ===== ===== Two dimensional Arrays =====
Line 388: Line 395:
 =====  Remove or add an entry inside an array =====  =====  Remove or add an entry inside an array ===== 
 <html><p align = "right"><small><i>From -ki</i></small></p></html> <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.+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> <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: 2021/07/01 21:41
  • by _ki