/* Introduction This is a reference guide to programming audio-oriented effects for REAPER using JS. JS is a scripting language which is compiled on the fly and allows you to modify and/or generate audio and MIDI, as well as draw custom vector based UI and analysis displays. JS effects are simple text files, which when loaded in REAPER become full featured plug-ins. You can try loading existing JS effects and since they are distributed in source form, you can also edit existing effects to suit your needs (we recommend if editing an existing effect you save it as something with a new name--if you do not you may lose your changes when upgrading REAPER). This guide will offer an outline of the structure of the text file used by JS, the syntax for writing code, as well as a list of all functions and special variables available for use. JSFX file structure JS Effects are text files that are composed of some description lines followed by one or more code sections. The description lines that can be specified are:desc:Effect Description his line should be specified once and only once, and defines the name of the effect which will be displayed to the user. Ideally this line should be the first line of the file, so that it can be quickly identified as a JS file. slider1:5<0,10,1>slider description You can specify multiple of these lines (from 1-64 currently) to specify parameters that the user can control using standard UI controls (typically a fader and text input, but this can vary, see below). These parameters are also automatable from REAPER. In the above example, the first 1 specifies the first parameter, 5 is the default value of the parameter, 0 is the minimum value, 10 is the maximum value, and 1 is the change increment. slider description is what is displayed to the user. There are additional extended slider syntaxes. One is:slider1:0<0,5,1{zerolabel,onelabel,twolabel,threelabel,fourlabel,fivelabel}>some setting This will show this parameter with a list of options from "zerolabel" to "fivelabel". Note that these parameters should be set to start at 0 and have a change increment of 1, as shown above. Another extended syntax is:slider1:/some_path:default_value:slider description In the above example, the /some_path specifies a subdirectory of the REAPER\Data path, which will be scanned for .wav, .txt, .ogg, or .raw files. default_value defines a default filename. If this is used, the script will generally use file_open(slider1) in the @serialize code section to read the contents of the selected file. You can also hide sliders by prefixing their names with "-":slider1:0<0,127,1>-Hidden parameter Such parameters will not be visible in the plug-in UI but still be active, automatable, etc. */ @input omni_midi_out OMNI-MIDI-OUTPUT @input omni_osc_out OMNI-OSC-OUTPUT @input omni_midi OMNI-MIDI @input omni_osc OMNI-OSC @init gfx_init("show input and output", 320,200); function showmsg(type, desc, wp) local(colpos,w,h,str) ( gfx_setfont(1,"Verdana",max(gfx_h/16,10)); gfx_a=1; gfx_mode=0; sprintf(str=#,"%s message: %s\n",type,desc); gfx_measurestr(str,w,h); gfx_x=gfx_w/2-w/2+2; gfx_y=wp - h/2; gfx_r=gfx_g=gfx_b=0; gfx_drawstr(str); gfx_r=0.5+0.5*cos(colpos); gfx_g=0.7+0.3*cos(colpos+$pi/4); gfx_b=0.6+0.4*cos(colpos+$pi/8); colpos+=0.03; gfx_x=gfx_w/2-w/2; gfx_y-=2; gfx_drawstr(str); ); @oscmsg showmsg(msgdev==omni_osc ? "OSC-IN" : "OSC-OUT", oscstr,gfx_h*.4); @midimsg showmsg(msgdev==omni_midi ? "MIDI-IN" : "MIDI-OUT", sprintf(#,"%02x %02x %02x",msg1,msg2,msg3),gfx_h*.6); @timer gfx_clear=-1; gfx_x=gfx_y=0; dx=gfx_w*0.01; dy=gfx_h*0.01; gfx_a=1.0; gfx_blit(-1,0,0.003,dx,dy,gfx_w-2*dx,gfx_h-2*dy,0,0,gfx_w,gfx_h); gfx_a=0.01; gfx_r=gfx_g=gfx_b=0; gfx_rect(0,0,gfx_w,gfx_h);