User:Klaus Eiperle/FxScript

FXScript is a programming language for Final Cut Pro and Final Cut Express.
Do you sometimes want to create an effect you have never seen before? Or did you see an effect on TV or in the cinema, and you want to clone it? You can program your own effects and modify or enhance the existing Final Cut Pro FXScripts.

FXBuilder
FXScript is a programming language inside of Final Cut Pro and Final Cut Express. FXBuilder is the scripting utility in which you are able to modify the existing FCP FXScripts or program completely new ones. If you program your own FXScripts, you shouldn't reinvent the wheel. you should use the powerful image processing of Final Cut Pro. For example, when you want to scale an image, you don't need to develop an algorithm for an image scaler. Only two lines are necessary to scale an image from its full size to half size:

''scale(Region, CenterOfScale, 0.5, 0.5); blitrect(ImageBuffer, OrigRegion, Destination-Buffer, Region);''

First the region, which might be a rectangle, is scaled by the statement scale and its parameters. Then the statement blitrect copies a region of an image into a changed region. When the OrigRegion and the new Region have different sizes, Final Cut Pro scales the image to fit into the new region. A Statement is a command that accomplishes a single action. In our example, the statements are scale and blitrect. These software statements are already desbribed in full in the FCP User Manual.

Different FX Groups
Inside Final Cut Pro/Express and FXScript are three types of effects:


 * Video Transitions, which change from one clip to another (for example, the Cross Dissolve). This FXScript type is called transition.
 * Video Filters, which change the picture fo a whole clip (for example, the Color Balance). This FXScript type is called filter.
 * Video Generators, which create new video information and therefore use the actual Sequence Preset (for example, the Custom Gradient). This FXScript type is called generator.

What's possible with FXScript?
To see more effects, look at the demo verisons of the plugin package CGM DVE Ultimate which is completely developed in FXScript by Eiperle CGM. Klaus Eiperle developes FXScripts since the year 2000.

Navigating FXBuilder
In the FXBuilder you can create and test FXScripts. You can have open more than one FXBuilder window. Access FXBuilder from the Tools menu. When FXBuilder is evoked, the new menu item FXBuilder is added to the FCP menus. The FXBuilder menu is only available when a FXBuilder screen is active. With the commands of this menu, you can start and stop the real time running of a FXScript, save the FXScripts as normal or as encoded plugins, and insert FXScript statements.

Structure of a FXScript
A FXScript has two parts:


 * The head state, which contains the script's name, type, and assigned group in the Browser. You can also specify the input controls that are needed.
 * The body, which contains the actual script code.

Normally the flow of the script is from top to bottom. You can take flow control by using loops (for example, For/Next) and conditional branches (for example, If/Else). FXScript also allows you to break scripts up into subroutines that can be called from other parts of the script by using their names.

Create a new FXScript
It's time for you to create your first FXScript. The following code is a complete script with comments.

Open a new FXBuilder window. Type in the following code. Please do not type in the line numbers. End each line with the carriage return (the Return key).


 * 1) transition Cross Dissolve
 * 2) group CGM DVE Transitions
 * 3) wipeCode(0,100)
 * 4) code
 * 5) // Cross Dissolve
 * 6) blend(src1,src2,dest,ratio)

Line 1 states the script's type and name, a transition with the name Cross Dissolve. Line 2 assignes the script to a group in the Browser. The effect Cross Dissolve will appear in the Browser's folder Video Transitions inside the folder CGM DVE Transitions. Line 3 defines the transitions wipe code. It's not really important. Line 4 is the marker between the head and body. Line 5 is a comment and will not be executed. Line 6 blends the two source image buffers (src1 and src2) by using the predefined variable ratio and stores the result in the image buffer dest. The image burffer src1 contains the current image of the outgoing source clip. Image buffer src2 contains the current image of the incoming source clip. You always put the effect's result into the image buffer dest, because this is the buffer for the video output. The variable ratio contains the ratio of current frame location to duration. This is a number between 0 and 1.

Now test the transition's function by pressing Command+K. If you made no mistakes, the script blends from Source 1 to Source 2. Stop the script to save your work. Use the pulldown menu FXBuilder / Create Plugin. Name it Cross Dissolve, as defined in line 1 of the script. Save it into the Final Cut Pro Plugins folder Macintosh HD/Library/Application Support/Final Cut Pro System Support/Plugins.

After restarting Final Cut Pro, your effect Cross Dissolve will appear in the Browser's bin Video Transitions inside the CGM DVE Transitions bin.