Registration covers presenting your Automation 4 Lua script to Aegisub, providing information about it and registering what features it provides.
One of the primary concepts in Automation 4 is the feature. A feature is something a script makes available for Aegisub to call back in response to a user action.
A feature is not a plain callback. Rather, it's usually a set of several callback functions as well as some information on how they should be presented to the user in the GUI.
One feature is the macro. A macro is presented as an item in the Automation menu. A macro has a name (the title show in the menu), a description (the text shown on the status bar when hovering over the menu item), a processing function (the function called when the user selects the menu item) and an optional validation function (determines whether the macro can even do any work in the current state.)
Another feature is the export filter. The export filter is presented in the Export dialogue and can be applied during an export operation. Export filters also have a name, description, processing function and then an optional configuration panel provider. The configuration panel provider is a function that returns a configuration dialogue definition structure which will be displayed in the Export dialogue when the export filter is enabled. The settings filled into the configuration panel are passed to the processing function when it is run.
A script can set a few global variables to provide metadata about the script to Aegisub. The information given with these variables are displayed in the Automation Manager dialogue and the Script Info dialogue.
All of these are optional; a script does not have to provide any of these. If no script name is given, the file name is used instead for display purposes.
The registration functions are the functions provided by Automation 4 Lua you can call to make a feature available to Aegisub. You will usually call these in the top level, at the very bottom of your script.
Synopsis: aegisub.register_macro(name, description, processing_function, validation_function, is_active_function)
Register a macro feature.
If forward slashes (/) are included in the name, the name will be split on the slash, with the portion before the slash used as the name of the submenu to place the macro in. For example, if you register a macro named "Foo/Bar" and a macro named "Foo/Baz", the automation menu will have a submenu named "Foo" with "Bar" and "Baz" entries.
Menus can be nested to whatever depth is supported by the OS, but nesting more than one level deep is unlikely to be a good idea. * description (string) - The description displayed on the status bar when the user hovers the mouse over the menu item. This should be a concise description of what the macro does. Try to keep it at most 60 characters. * processing_function (function) - The function that is called when the user selects the menu item. This must be a function with the macro processing function API. * validation_function (function, optional) - This function is called to determine whether the menu item should be available to the user or not. (Grayed out or not.) If no validation function is provided the macro is always available. This function must follow the macro validation function API. * is_active_function (function, optional) - This function is called to determine whether the menu item should be shown with a check mark next to it. If no function is provided the macro is never checked. This function uses the same API as validation functions, and all of the same caveats apply.
Synopsis: aegisub.register_filter(name, description, priority, processing_function, configuration_panel_provider)
Register an export filter feature.
priority (number) - Determines the initial ordering of export filter application. Filters with higher priority are applied earlier than filters with lower priority. The user can change the filter application order in the Export dialogue. Priorities of the Aegisub built in export filters:
Transform Framerate = 1000 (karaoke effects should have higher priority than this)
Fix Styles = -5000 (should almost always run last)
processing_function (function) - The function that is called when the user initiates the export operation. This must be a function with the export filter processing function API.
These are the callback functions you provide to the registration functions.
Signature: process_macro(subtitles, selected_lines, active_line)
Macro processing functions passed to
aegisub.register_macro
must have this signature. The name process_macro
is a placeholder for your
own function name.
dialogue
class lines can ever be selected.Return value:
The macro processing function can return up to two values: a new
selected_lines
table containing indices of the lines to select after the
macro returns, and an index of the line to make the new active_line
. If
set, the new active line index must be one of the lines in the new
selected_lines
table.
Signature: validate_macro(subtitles, selected_lines, active_line)
Macro validation functions passed to
aegisub.register_macro
must have this signature. The name validate_macro
is a placeholder for
your own function name.
Important, execution time: Validation functions should always run very
fast. Do as little work as possible inside this function, because it is run
every time the user pulls open the Automation menu, and every millisecond
you spend in validate_macro
is one millisecond delay in opening the menu.
Consider that the user might have very large files open. Don't block the UI.
dialogue
class lines can ever be selected.Return value:
Boolean, true
if the macro can run given the current
state of subtitles, selected_lines and active_line, false
if it can
not.
In addition to the primary return value, the validation function can return a string. If it does, the description of the macro is set to the string. This is intended for reporting information to the user about why the macro cannot be run, but there may be more uses for it.
Signature: process_filter(subtitles, settings)
Export filter processing functions passed to
aegisub.register_filter
must have this signature. The name process_filter
is a placeholder for
your own function name.
You do not have to worry about undo issues with export filters. You always work on a copy of the subtitle file.
Return value: Nothing.
Signature: get_filter_configuration_panel(subtitles, old_settings)
Export filter configuration panel providers passed to
aegisub.register_filter
must have this signature. The name get_filter_configuration_panel
is a
placeholder for your own function name.
Important, execution time: This function is called automatically when the user opens the Export dialogue, and Aegisub blocks until it returns with a configuration panel. Consider that the user might have a very large file open, and that every millisecond spent creating your configuration dialogue is one more millisecond the user has to wait for the Export dialogue to open. Don't block the UI.
Return value: A configuration dialogue table. See the page on configuration dialogues for more information on the format of this table.
Overview: | Automation Manager • Running macros • Using export filters • Standard macros |
---|---|
Karaoke Templater reference: | Declaring
templates • Execution
order • Modifiers • Inline-variables ($-variables)
Code lines and blocks • Execution envirionment |
Lua API reference: | Registration • Subtitles object • Progress reporting • Dialogs • Misc. APIs |
Lua Modules: | karaskel.lua • util • unicode • cleantags.lua • clipboard • re |
Karaskel concepts: | Style tables • Dialogue line tables • Syllable tables • Inline effects • Furigana |