Created
November 8, 2017 07:20
-
-
Save lv7777/df9c6cda5f1087dff44fee4e39d8b135 to your computer and use it in GitHub Desktop.
gometh兄貴の音MAD特有の左右反転するやつに16分音符付け足したやつ (ver1.2).aviutl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--check0:演奏モード,1 | |
--dialog:楽譜,score="dbdb";BPM,bpm=120;通常時エフェクト,o_effect={};反転時エフェクト,p_effect={{"反転","左右反転",1}};反転軸,mirror_param={"x","rz"};再生速度ストレッチ/chk,play_st=false;移動速度ストレッチ/chk,move_st=false;ストレッチ基準F,st_frame=60; | |
-- 通常通りaviutlの中に放り込んだら音MADミラー.anmを上書きして終わり!閉廷! -- | |
-- 初期化 -- | |
--local hash = obj.rand(1,2147483647,1,1) -- オブジェクト毎にグローバル変数を保持したいが為の苦肉のハッシュ関数 | |
local hash = obj.layer | |
if not otomad_mirror_score then otomad_mirror_score = {} end | |
if not otomad_mirror_score_raw then otomad_mirror_score_raw = {} end | |
if not obj.check0 then | |
if otomad_mirror_file_state then -- 専用の動画用カスタムオブジェクトがある場合 | |
local anchor = otomad_mirror_movie_offset[otomad_mirror_f1(obj.time)] -- := { (所属中間点の)開始時刻 , 動画位置 , 再生速度 } | |
obj.load("movie",otomad_mirror_file_state[1],anchor[2]+anchor[3]*(obj.time-anchor[1]),otomad_mirror_file_state[2]) | |
end | |
otomad_mirror_file_state = nil | |
return | |
end | |
-- 楽譜の変更があったら更新(毎フレーム再計算するのは非効率)-- | |
if otomad_mirror_score_raw[hash] ~= score then | |
otomad_mirror_score_raw[hash] = score | |
local note={b={2,-1},c={8,-1},d={2,1},o={8,1},p={1,-1},q={1,1},r={1,0},s={2,0},_={8,0},f={0.5,-1},h={0.5,1},t={0.25,-1},y={0.25,1}} | |
otomad_mirror_score[hash]={} | |
if string.sub(score,1,3)=="BMS" then -- BMSモード | |
local i,j,l,b=0,1,0,0 | |
for bar in string.gmatch(string.gsub(score,"[^tyfhbcdo-s_%-%s]","").." _ ","%s*([tyfhbcdo-s_%-]+)%s+") do -- 1小節分の文字列の読み込み | |
local t=0 | |
for k=1,#bar do | |
local w = string.sub(bar,k,k) | |
if w~="-" then | |
i=i+1 | |
l=note[w][1] | |
otomad_mirror_score[hash][i] = {t,note[w][2]} | |
end | |
t=t+l | |
end | |
for k=j,i do otomad_mirror_score[hash][k][1] = b+otomad_mirror_score[hash][k][1]*8/t end | |
j=i+1 | |
b=b+8 | |
end | |
else -- いままでどおり | |
local i,t=1,0 | |
for w in string.gmatch(string.gsub(score,"[^tyfhbcdo-s_%-]","").."_","[tyfhbcdo-s_]%-*") do -- 音符"d b s q p r o c _ -"の読み込み | |
otomad_mirror_score[hash][i] = {t,note[string.sub(w,1,1)][2]} | |
t=t+note[string.sub(w,1,1)][1]*#w | |
i=i+1 | |
end | |
end | |
end | |
-- 現時点が楽譜のどの部分なのかを計算 -- | |
local lookup = obj.time*bpm/30 -- 4分音符の長さを2としているのでbpmを30で除算 | |
local key_t,key_b = 1,#otomad_mirror_score[hash] -- 二分木探索 | |
while key_t<key_b do | |
local key = math.floor((key_t+key_b)/2) | |
if otomad_mirror_score[hash][key+1][1]<=lookup then key_t = key+1 | |
elseif otomad_mirror_score[hash][key][1]>lookup then key_b = key-1 | |
else key_t,key_b=key,key end | |
end | |
local target = otomad_mirror_score[hash][key_t] -- := { 演奏開始拍 , 反転フラグ } ※演奏終了拍 = [key_t+1]の演奏開始拍 | |
-- 反転フラグが0(休符)ならオブジェクトを非表示にして終了 -- | |
if target[2]==0 then | |
obj.setoption("draw_state",true) | |
otomad_mirror_file_state = nil | |
return | |
end | |
-- 当時の動画再生位置と座標を計算 -- | |
local note_length = (otomad_mirror_score[hash][key_t+1][1]-target[1])*30/bpm | |
local play_stretch, move_stretch = (play_st==1 and st_frame/(obj.framerate*note_length) or 1), (move_st==1 and st_frame/(obj.framerate*note_length) or 1) | |
local local_time = obj.time - target[1]*30/bpm | |
local mirror = {x=1,y=1,z=1,rx=1,ry=1,rz=1,zoom=1,alpha=1,time=1} | |
for i=1,#mirror_param do mirror[mirror_param[i]]=-1 end | |
local zoom_correct = mirror["zoom"]==-1 and obj.getvalue("zoom",(move_st==1 and st_frame/obj.framerate or note_length))/100 or 1 | |
local alpha_correct = mirror["alpha"]==-1 and obj.getvalue("alpha",(move_st==1 and st_frame/obj.framerate or note_length))/100 or 1 | |
if otomad_mirror_file_state then -- 専用の動画用カスタムオブジェクトがある場合 | |
local movie_time = (mirror["time"]==-1 and target[2]==-1) and (note_length-local_time)*play_stretch or local_time*play_stretch | |
local anchor = otomad_mirror_movie_offset[otomad_mirror_f1(movie_time)] -- := { (所属中間点の)開始時刻 , 動画位置 , 再生速度 } | |
obj.load("movie",otomad_mirror_file_state[1],anchor[2]+anchor[3]*(movie_time-anchor[1]),otomad_mirror_file_state[2]) | |
end | |
if target[2]==1 then | |
for i=1,#o_effect do | |
obj.effect(unpack(o_effect[i])) | |
end | |
obj.ox = obj.ox-obj.x+obj.getvalue("x",local_time*move_stretch) | |
obj.oy = obj.oy-obj.y+obj.getvalue("y",local_time*move_stretch) | |
obj.oz = obj.oz-obj.z+obj.getvalue("z",local_time*move_stretch) | |
obj.rx = obj.rx-obj.getvalue("rx")+obj.getvalue("rx",local_time*move_stretch) | |
obj.ry = obj.ry-obj.getvalue("ry")+obj.getvalue("ry",local_time*move_stretch) | |
obj.rz = obj.rz-obj.getvalue("rz")+obj.getvalue("rz",local_time*move_stretch) | |
obj.zoom = obj.zoom*obj.getvalue("zoom",local_time*move_stretch)/obj.getvalue("zoom") | |
obj.alpha = obj.alpha*obj.getvalue("alpha",local_time*move_stretch)/obj.getvalue("alpha") | |
elseif target[2]==-1 then | |
for i=1,#p_effect do | |
obj.effect(unpack(p_effect[i])) | |
end | |
obj.ox = obj.ox-obj.x+obj.getvalue("x",local_time*move_stretch)*mirror["x"] | |
obj.oy = obj.oy-obj.y+obj.getvalue("y",local_time*move_stretch)*mirror["y"] | |
obj.oz = obj.oz-obj.z+obj.getvalue("z",local_time*move_stretch)*mirror["z"] | |
obj.rx = obj.rx-obj.getvalue("rx")+obj.getvalue("rx",local_time*move_stretch)*mirror["rx"] | |
obj.ry = obj.ry-obj.getvalue("ry")+obj.getvalue("ry",local_time*move_stretch)*mirror["ry"] | |
obj.rz = obj.rz-obj.getvalue("rz")+obj.getvalue("rz",local_time*move_stretch)*mirror["rz"] | |
obj.zoom = obj.zoom*(obj.getvalue("zoom",local_time*move_stretch)/100)^mirror["zoom"]*100/obj.getvalue("zoom")*zoom_correct | |
obj.alpha = obj.alpha*(obj.getvalue("alpha",local_time*move_stretch)/100)^mirror["alpha"]*100/obj.getvalue("alpha")*alpha_correct | |
end | |
otomad_mirror_file_state = nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment