Your first video plugin

Loading an example

The easiest way to build a new plugin is to start from an example. Drag Lines.amxd from the Examples folder into an empty MIDI track. If Videosync is running, you should see the following pattern:

Lines Output

The following steps will show you how to build an improved version of this plugin.

Making a copy
  • Duplicate the entire Lines folder and rename it to BetterLines. To keep things clear you can also rename the contents of the folder to BetterLines.amxd and BetterLines.fs

The plugin files do not need to have the same name as the folder they are in, but it might be an easy convention.

  • Start with a new Live set and drag BetterLines.amxd onto a MIDI track in Live. The plugin is not yet functional so Videosync should show a purple screen.
  • Open the plugin for editing by pressing the edit button.
  • Switch to presentation mode by pressing the Patching Mode button in the footer bar of the patch window.

Patching Mode

  • Change the content of the message box from Lines to BetterLines.

Changing Name

This message tells the plugin the name of the shader files (.fs and optionally .vs). The two shader files should always share the same name (except for the extension).

  • Save the plugin and close Max. Your new BetterLines plugin should now work like Lines did. Let’s start improving it!
Changing the shader
  • Open BetterLines.fs in a text editor.

You can start editing shaders with a simple editor like TextEdit. Eventually you may want to use a more advanced editor, like Visual Studio Code that supports code highlighting for GLSL files.

  • Let’s start by making the rotations of the lines a bit more interesting. Locate the lines that calculate the red, green and blue pixel colors. For green, add * 2 behind both occasions of radians. For blue, let’s make that * 3. The code should now look like this:

Adapted Rotation

  • As soon as you save the file, the changes are applied. Changing the Rotation parameter in the MFL interface should now now no longer just rotate the lines but move them in respect to each other, overlapping and mixing colors:

Rotated Lines

  • Let’s make this plugin even better by adding an extra parameter!
Setting up a new parameter
  • Open up the Max For Live plugin again by pressing the edit button.
  • Select the three objects that make up the Density parameter, duplicate them (Cmd+D or Alt+drag) and position them to the right.

Duplicated density

  • Change the new prepend object and the comment from density to thickness and connect them like the other parameters.

Connected thickness

  • Right-click the new number box and select Inspector. This opens up a list of properties for this parameter control.
  • Scroll down the list until you find the Long Name and Short Name fields. Change their values to Thickness.

The Long Name field uniquely identifies how this parameter is saved and controlled in Live. The Long Name is also what you will see when selecting this parameter in an automation lane in Live.

  • Also set the following fields: Range/Enum to 0. 1. and Initial Value to 0.5. Your inspector window should now look like this:


  • Finally, switch back to Presentation Mode by clicking the Patching Mode button again. You will see that the new Thickness parameter is not positioned correctly. If you want your interface to look neat in Live, you may want to align it under the other parameters:

Final Interface

  • Close Max and save the plugin, you are now ready to implement the new parameter in the shader.
Implementing the new parameter
  • It’s time to go back to the plugin code in BetterLines.fs. The header contains the definitions of the parameters available to your plugin. Let’s add the thickness parameter here. After the closing bracket of the definition of the density parameter, add a comma: },. Then, on the following line, add the following code:
        "NAME" : "thickness",
        "TYPE" : "float",
        "DEFAULT" : 0.5
  • We can now use the thickness parameter in the calculation of pixel values. The way we have in mind requires two steps:
    • Above the line that calculates the red color, add:
        float offset = thickness * 4 - 2;
    • In each of the lines that calculate a color, add + offset at the end, before the semicolon. Your code should now look like this:

Final Code

  • As soon as you save your code, the Videosync output image should change. If the Thickness parameter in the Max For Live plugin was still set to 1.0 after changing its range in the Inspector, you will now see a white image. Dial down and you should see the lines re-appearing, say at 0.8:

Final Image

  • Your new parameter is done! You can control it with a MIDI controller or automate it in Live’s Session and Arrangement views to create a musical video composition.

This plugin doesn’t use any image input, effectively acting as an instrument. To learn how to make an effect plugin, read on!

« Previous Next »