HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Page 5, Avisynth registration and Filter Creation:-
Code:
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// The stuff below is to connect and make available the plugin to Avisynth.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// This is the function that creates an instance of the filter class when the filter is used in Avisynth.
// In this case, the function is called 'Create_INTERNALNAME', but it could have been called anything,
// the Avisynth Plugin registration Function 'AvisynthPluginInit2()' (below) told Avisynth which
// function to call to create an instance of the filter. You will only be wanting to edit the name of this
// function, the arguments and calling convention should remain fixed.
// This function can be used for simple parameter checking, so it is possible to create different filters,
// based on the arguments received, for further, see filter sources.
AVSValue __cdecl Create_INTERNALNAME(AVSValue args, void* user_data, IScriptEnvironment* env) {
// Calls the filter class constructor with the arguments provided.
// The arguments to 'new' MUST match those in the class declaration for the constructor.
// BEWARE the 'n' in args[n] must also be set correctly. (incremental from zero)
// Can use types eg, AsClip(), AsInt(), AsFloat(), AsString(), AsBool() and can supply a default argument.
int default_intarg = 42; // could set this default, from eg a settings file.
OutputDebugString(AVISYNTHNAME ": Creating Filter instance - Calling Constructor\n");
return new INTERNALNAME( // Arguments to the Filter class Constructor of INTERNALNAME class.
args[0].AsClip(), // _child, (Not optional no default specified)
args[1].AsInt(default_intarg), // _intarg, with default set to 'default_intarg'.
args[2].AsBool(true), // _version, with default to true if not supplied.
args[3].AsBool(true), // _show, with default to true if not supplied.
args[4].AsInt(-1), // _bounce, with default -1 (auto select bounce step)
env // Supplies constructor with environment, env is often used for raising an error in the constructor.
);
// The above 'new' is sort of like a malloc to get a block of memory for the
// class structure, followed by calling the constructor for the class on that memory block,
// which creates an instance of the filter class and returns it to Avisynth as an AVSValue.
// AVSValue, a type of variant holding a value of any type. The args function argument above is an
// AVSValue which happens to be an array of AVSValues, and eg args[0].AsClip() was used to get
// the first argument as a Clip without a default value.
// An optional clip would eg use a default of 'NULL' (zero) which should be detected as invalid/not-used
// by a filter class constructor, and obviously should not be accessed as a clip, as an alternative, you might call
// a different constructor for the filter which does not take the optional clip arg. (a class can have multiple
// constructors).
}
// ------------------------------------------
// The standard Avisynth Plugin registration Function
// The following function is the function that actually registers the filter in AviSynth
// It is called automatically, when the plugin is loaded to see which functions this filter contains.
// It does not actually create an instance of the filter, but it does tell Avisynth which function to call
// to do that, if the filter is used within a script.
// The name, the argument, and calling convention is fixed.
#ifdef AVISYNTH_PLUGIN_25
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env){
OutputDebugString(AVISYNTHNAME ": AvisynthPluginInit2 Calling env->AddFunction\n");
#else
/* New 2.6 requirement!!! */
// Declare and initialise server pointers static storage.
const AVS_Linkage *AVS_linkage = 0;
/* New 2.6 requirement!!! */
// DLL entry point called from LoadPlugin() to setup a user plugin.
extern "C" __declspec(dllexport) const char* __stdcall
AvisynthPluginInit3(IScriptEnvironment* env, const AVS_Linkage* const vectors) {
/* New 2.6 requirment!!! */
// Save the server pointers.
AVS_linkage = vectors;
OutputDebugString(AVISYNTHNAME ": AvisynthPluginInit3 Calling env->AddFunction\n");
#endif
// The code below, registers the plugin with avisynth and tells it how to construct/create
// the filter, the argument types it accepts and whether they are optional/named arguments.
// AddFunction has the following paramters:
// AddFunction(FilterName , Arguments, Function-to-call,0);
env->AddFunction(
AVISYNTHNAME, // The name of the filter in Avisynth (as a string).
"c[intarg]i[version]b[show]b[bounce]i", // Arguments, THIS MUST BE EDITED TO SUIT THE FILTER ARGUMENTS.
Create_INTERNALNAME, // The function Avisynth will call to create an instance of the filter.
0 // Zero. (possibly 'user_data' arg in Create_INTERNALNAME, never seen used).
);
// This particular registration, says:
// The name of the filter in Avisynth is AVISYNTHNAME().
// First filter arg 'c' is an un-named compulsory clip ('[name]' means 'name' is optional),
// Second filter arg '[intarg]i' is an optional arg of type int.
// Third filter arg '[version]b' is an optional arg of type bool.
// Forth filter arg '[show]b' is an optional arg of type bool.
// Fifth filter arg '[bounce]i' is an optional arg of type int.
// In this case the filter is similar to an Avisynth script definition of
// AVISYNTHNAME(clip,int "intarg",bool "version",bool "show", int "bounce").
// Of course, this must match what it uses in the above Avisynth Filter Creation function,
// and is almost always what the class constructor accepts.
// Arguments is a string that defines the types and optional names of the arguments for your filter.
// The names of optional arguments are enclosed in '[]' as in [name] and followed by the type string specifier.
// An argument list of eg "cc" would indicate a filter requiring two compulsory un-named clips.
// An arg list of eg "c[]c" would indicate a filter accepting a compulsory un-named clip and an
// optional un-named clip, without the '[]' in the arg list string, Avisynth would NOT allow you to call
// the filter without both clips even if you gave a default value in the 'Create_INTERNALNAME' filter creator
// (previous function above).
// Argument type specifier strings.
// c - Video Clip
// i - Integer number
// f - Float number
// s - String
// b - boolean
// . - Any type (dot)
// Array Specifiers
// i* - Integer Array, zero or more
// i+ - Integer Array, one or more
// .* - Any type Array, zero or more
// .+ - Any type Array, one or more
// Etc
#ifdef AVISYNTH_PLUGIN_25
OutputDebugString(AVISYNTHNAME ": AvisynthPluginInit2 returning to Avisynth\n");
#else
OutputDebugString(AVISYNTHNAME ": AvisynthPluginInit3 returning to Avisynth\n");
#endif
// return "'Example' Example plugin";
return ("'" AVISYNTHNAME "' " AVISYNTHNAME " plugin");
// A freeform name of the plugin. Dont think this returned string is actually used for anything in Avisynth.
}
Last edited by StainlessS; 31st March 2015 at 19:26.
Reason: Update
|