[menu modify]
Modify MIDI content in current MIDI file by a C programming script. This operation requires some understanding of programming scripts in any language.
modification script
This field contains a script code with multiple statements and for/foreach/while loops and conditional if statements to describe which events needs to be changed and how they are changed.
Define variables to remember information (e.g. var n = 0; )
The script may return a result that will be displayed when running successful (e.g. return modifiedcount + " events modified")
Run
Enter modification script and use button run to start the modification.
Debug
Enter modification script and use button debug to display a debugger window that lets step through the statements and stop at breakpoints and error exceptions and lets quick evaluate an expression or enter a debugger command like printvariables or printcallstack.
Syntax errors
errors are displayed in the box below the modification edit box (in English language).
Load
Open a *.dlg text file to load previously stored settings for the dialog
Save
Saves current dialog settings into a .dlg text file for future reuse
Results:
If running script is successful then a successful information and the value returned by the script will be displayed. For syntax errors or error exceptions the error message (sometimes with line, column numbers of the source code position)
OK
closes the dialog and generates a MIDI file opened in GNMIDI which contains the modifications done by the gnscript expressions.
Syntax help
will show this page (also F1 key). Use also gnscript package at https://www.gnmidi.com to learn from script examples.
The gnscript syntax and general available script operators and functions can be found in a sub page of this article.
The MIDI functions and data structure of loaded song can be found in sub page of this article.
Loading of the MIDI file is already done by this operation and saving result will be done using OK button if script runs successful.
Example script: var n = 0;
var fadeinms = 10000;
foreach (var ev in song.events)
{
if (ev.type == EVENTTYPE_NOTE && ev.hasstart && ev.startms < 10000)
{
ev.velocity = (ev.startms * 127/ fadeinms)+1; // valid velocity values are from 1..127
n++;
}
}
return n;
Too difficult
If programming is too difficult for you maybe we could program user tools for your special purpose that can be used directly in GNMIDI.
It can analyse or modify or generate MIDI files.
In fact in most cases we use the gnscript language for implementation.