Aegisub/automation/demos/k-replacer.rb
pomyk 8d837d6a90 Ruby: key_frames function, improvements in scripts
Originally committed to SVN as r934.
2007-02-08 18:29:50 +00:00

64 lines
1.9 KiB
Ruby

load 'karaoke.rb'
load 'utils.rb'
include Aegisub
$script_name = "k-replacer test"
$script_description = "k-replacer test"
$script_author = "Pomyk"
$script_version = "1"
register_macro("Simple k-replacer", "k-replacer macro", :k_replace_macro, nil)
register_filter("Simple k-replacer", "k-replacer filter", 100, :k_replace_filter, :k_replace_cfg)
def k_replace_macro(subs, sel, act)
cfg = k_replace_cfg(subs, nil)
ok, opt = display_dialog(cfg, nil)
return if not ok # cancelled
write_options(subs, {$script_name => opt})
subs.each do |l|
k_replace(l, opt[:templ], opt[:strip]) if l[:class] == :dialogue && # replace if its dialogue
(opt[:style] =="" || l[:style] == opt[:style]) # and has the right style
end
return subs
end
def k_replace_filter(subs, opt)
subs.each do |l|
k_replace(l, opt[:templ], opt[:strip]) if l[:class] == :dialogue && # replace if its dialogue
opt[:style] =="" || l[:style] == opt[:style] # and has the right style
end
write_options(subs, {$script_name => opt})
return subs
end
def k_replace_cfg(subs, store)
styles = []
subs.each { |l| # read style names
styles << l[:name] if l[:class] == :style
break if l[:class] == :dialogue
}
header_text = <<-head
Expressions are enclosed in % pairs.
Variables:
$start = Start-time of syllable (ms)
$end = End-time of syllable (ms)
$mid = Time midways through the syllable (ms)
$dur = Duration of syllable (cs)
Calculation example:
\\t($start,%$start+$dur*2%,\\fscx110)
\\t(%$start+$dur*2%,$end,\\fscx90)
head
opt = read_options(subs, $script_name)
s_name = $script_name.to_sym
cfg = ScriptCfg.new # helper class for building dialogs
cfg.header header_text, :x => 1, :width => 1
cfg.edit :templ, "template", :text => opt[s_name][:templ]
cfg.dropdown :style, "Style", :items => styles, :value => opt[s_name][:style]
cfg.checkbox :strip, "", :label => "Strip tags?", :value => (opt[s_name][:strip] == "true" ? true : false)
cfg.to_ary # convert to array
end