View Full Version : Making your own default values or presets to filters


stickboy
1st September 2003, 04:54
I wrote a simplistic article on avisynth.org about writing wrapper functions (http://www.avisynth.org/oldwiki/index.php?page=Wrapper) to specify your own default values or presets to filters.

Yes, it's nothing new, but I don't think it's conceptually obvious to everyone, especially to novice users.

I know there's already the filter.def (http://forum.doom9.org/showthread.php?s=&threadid=32532) system in use for user-specified default values, but I think that wrapper functions are:
more general (I'm not aware of any filters other than Donald's that use defaults files)
less work for filter authors, since authors don't need to write parsing code
almost as easy for users, especially if users are given cookie-cutter templatesAnyhow, comments and feedback are appreciated. I'm not terribly happy with how complicated the preset examples look.[1]

On a side note, I wish there were a version of Select that operated on strings[2]:
SelectByString(string s, string keyA, itemA [, string keyB, itemB [, ...]])Edit:
[1] After several revisions, I'm happier now. :)
[2] See below.

stickboy
14th September 2003, 07:05
If anyone cares, I wrote my own SelectByString function (http://www.avisynth.org/stickboy/SelectByString.zip), implemented as an AviSynth C (http://forum.doom9.org/showthread.php?s=&threadid=58840) plug-in.

Edit:
No longer an AviSynth C plug-in.

jorel
14th September 2003, 12:08
"....especially to novice users."

thanks stickboy, really cool.
:)

i never knew about it!
:o

Bidoche
15th September 2003, 01:09
Your solution implies creating clips for each path.

Whereas there may be no (reasonable) alternative at the time being, it appears to me that what you really need is a switch construct.

Maybe switch in 3.0 then.

stickboy
15th September 2003, 02:44
Is that a big problem? The same thing would happen with the internal Select function, right? Would it be better if I hacked together a lazy-evaluation system using strings and Eval?

Bidoche
15th September 2003, 11:11
It all depends of the filters used, some may allocate big chunks of memory for buffering or initialize lookup tables or...

Better to avoid creating them for nothing then.
But don't try to avoid it at all costs.
Being aware of the problem may be sufficient.

stickboy
2nd March 2004, 12:57
I'm kind of confused about what's going on with AviSynth C and its transition to the stdcall convention, so I finally got myself access to Visual C++ and compiled an MSVC++ version of my SelectByString plug-in.

SelectByString 0.2.0 (http://www.avisynth.org/stickboy/SelectByString.zip) is now up. I also rewrote the documentation and examples. It's about as basic as an AviSynth plug-in can be, but let me know if there are any bugs, suggestions, or usage questions.

Based on Bidoche's concerns about creating clips for each branch, I've changed my examples to "thunk" values via strings. (Are there any pitfalls to this?)

The other advantage to returning strings is that strings are easily abusable in AviSynth. :D I've updated the Wrapper functions (http://www.avisynth.org/oldwiki/index.php?page=Wrapper) page to demonstrate some of the evil things you can do with strings, linebreaks, and Eval. Here's a snippet:
# We can get Eval to assign multiple variables at once
# by putting linebreaks in our strings. Evil!
s = SelectByString(preset,
\ "default", "r = 4
L = 4
ch = 8
sc = 15
m = 2",
\ "sh0dan-soft", "r = 2
L = 3
ch = 3
sc = 6
m = 2",
\ "sh0dan-medium", "r = 3
L = 5
ch = 5
sc = 10
m = 2",
\ "sh0dan-heavy", "r = 4
L = 8
ch = 8
sc = 10
m = 2")
Eval(s)

hartford
3rd March 2004, 05:23
That's great.

Wish I had a clue.

:confused

stickboy
3rd March 2004, 05:55
Is there anything in particular that's confusing you?