Skip to content

videofilt_vdxframe_addingscriptsupport

shekh edited this page Apr 15, 2018 · 1 revision

VirtualDub Plugin SDK 1.2

Adding script support

Adding script support to a VDXFrame-based filter is also simplified.

Declaring the script object and script methods

To declare the script object, use the VDXVF_DECLARE_SCRIPT_METHODS macro within the filter class definition:

public:
    virtual void Run();
    
    // ...
    
    VDXVF_DECLARE_SCRIPT_METHODS();
    
protected:

Note that this must be done publicly as the script object needs to be accessible to the VDXVideoFilterDefinition template.

Next, define the script method table and the methods themselves:

VDXVF_BEGIN_SCRIPT_METHODS(MyFilter)
VDXVF_DEFINE_SCRIPT_METHOD(MyFilter, ScriptConfig, "ii")
VDXVF_DEFINE_SCRIPT_METHOD2(MyFilter, ScriptConfig2, "iii")
VDXVF_END_SCRIPT_METHODS()

This creates overloads of the Config() script function. Use VDXVF_DEFINE_SCRIPT_METHOD for the first overload and VDXVF_DEFINE_SCRIPT_METHOD2 for the subsequent ones. The third argument is the signature string. Note that unlike the raw definition, the string used here does not include the return value, which is always declared as 0 (void).

Now the script methods themselves can be implemented:

void MyFilter::ScriptConfig(IVDXScriptInterpreter *isi, const VDXScriptValue *argv, int argc) {
    mConfig.mBrightness = argv[0].asInt();
    mConfig.mContrast = 100;
}

void MyFilter::ScriptConfig2(IVDXScriptInterpreter *isi, const VDXScriptValue *argv, int argc) {
    mConfig.mBrightness = argv[0].asInt();
    mConfig.mContrast = argv[1].asInt();
}

As usual, VDXFrame marshals the this pointer, so these are declared as non-static methods.

Writing the script string

Finally, implement GetScriptString() to generate the Config() call in script. This is done the same as GetSettingsString().

void MyFilter::GetSettingString(char *buf, int maxlen) {
    SafePrintf(buf, maxlen, "Config(%d,%d)"
            , mConfig.mBrightness
            , mConfig.mContrast
            );
}

Copyright (C) 2007-2012 Avery Lee.

Clone this wiki locally