Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A collection of avisynth functions to help people animate and position DS screens in an approximate widescreen space.
- # It's designed with the idea of working with a 1280x768 area, as this is 5 DS screens wide and 4 DS screens tall,
- # allowing you to fit them in in a variety of patterns.
- # It's designed to work with the output from DeSmuME, with the 2 256x192 stacked on top of each other
- # This was initially thrown together for the something awful forums by forums user Mastigophoran
- # Done: Have some way to have frame A drawn before frame B, should be pretty easy to do with an eval/default values
- # TODO: Probably add some more examples?
- # Done: Make a function to set the variables yourself and then call functions to perform them
- # Done: Make some functions that make it easier to perform eg Fades/Dissolves without desyncing the two videos
- # Revision 2
- global LastFrame = 0
- global DrawBFirst = false
- global AFC = 30 #animation frame count
- global AnimResizeFilter = "PointResize"
- global basesizeX = 256
- global basesizeY = 192
- global MaxX = 1280
- global MaxY = 768
- global SzX = 1024
- global SzY = 768
- global QSzX = 256
- global QSzY = 192
- global SBSX = 512
- global SBSY = 384
- # These values are used to keep track of where we last put the video, and where we want to put it next
- global LastTopPosX = 0
- global LastTopPosY = 0
- global LastTopSizeX = 256
- global LastTopSizeY = 192
- global LastBotPosX = 0
- global LastBotPosY = 192
- global LastBotSizeX = 256
- global LastBotSizeY = 192
- global newTSX = 0
- global newTSY = 0
- global newBSX = 256
- global newBSY = 192
- global newTPX = 0
- global newTPY = 192
- global newBPX = 256
- global newBPY = 192
- #And this just makes our video return something if we accidently view it
- BlankClip(length=240, width=640, height=480, pixel_type="RGB32", fps=24, fps_denominator=1, audio_rate=44100, stereo=False, sixteen_bit=True, color=$000000)
- Subtitle("This is MastiDS.avs! Import this script into your AVS!")
- Subtitle("Also, load your avi after you import, because this clip returned by the import line!",y = 50)
- function MDS_SetAFC(int newAFC)
- {
- global AFC = newAFC
- }
- function MDS_SetParams(int "pMaxX", int "pMaxY", int "pSzX", int "pSzY", int "pQSzX", int "pQSzY", int "pSBSX", int "pSBSY")
- {
- global MaxX = Default(pMaxX,MaxX)
- global MaxY = Default(pMaxY,MaxY)
- global SzX = Default(pSzX,SzX)
- global SzY = Default(pSzY,SzY)
- global QSzX = Default(pQSzX,floor(SzX / 4))
- global QSzY = Default(pQSzY,floor(SzY / 4))
- global SBSX = Default(pSBSX,floor(SzX / 2))
- global SBSY = Default(pSBSY,floor(SzY / 2))
- }
- function MDS_ResetLastframe()
- {
- global LastFrame = 0
- }
- function MDS_ChangeResizeFilter(string FilterName)
- {
- global AnimResizeFilter = FilterName
- }
- function MDS_TopOnTop(bool Bfirst)
- {
- global DrawBFirst = Bfirst
- }
- function intMDS_SBS()
- {
- global newTSX = SBSX
- global newTSY = SBSY
- global newBSX = SBSX
- global newBSY = SBSY
- global newTPX = floor((SzX + QSzX) / 2) - SBSX# - 4
- global newTPY = floor((SzY - SBSY) / 2)
- global newBPX = floor((SzX + QSzX) / 2)# + 4
- global newBPY = floor((SzY - SBSY) / 2)
- }
- function MDS_SBS(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_SBS()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function MDS_SBS(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_SBS(trim(raw,frame,0))
- }
- function MDS_SBSA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_SBS()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_SBSA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_SBSA(trim(raw,frame,0))
- }
- function intMDS_SBSL()
- {
- global newTSX = SBSX + basesizeX
- global newTSY = SBSY + basesizeY
- global newBSX = SBSX
- global newBSY = SBSY
- global newTPX = 0
- global newTPY = floor((SzY - SBSY - basesizeY) / 2)
- global newBPX = SBSX + basesizeX
- global newBPY = floor((SzY - SBSY) / 2)
- }
- function MDS_SBSL(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_SBSL()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function MDS_SBSL(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_SBSL(trim(raw,frame,0))
- }
- function MDS_SBSLA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_SBSL()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_SBSLA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_SBSLA(trim(raw,frame,0))
- }
- function intMDS_SBSR()
- {
- global newTSX = SBSX
- global newTSY = SBSY
- global newBSX = SBSX + basesizeX
- global newBSY = SBSY + basesizeY
- global newTPX = 0
- global newTPY = floor((SzY - SBSY) / 2)
- global newBPX = SBSX
- global newBPY = floor((SzY - SBSY - basesizeY) / 2)
- }
- function MDS_SBSR(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_SBSR()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function MDS_SBSR(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_SBSR(trim(raw,frame,0))
- }
- function MDS_SBSRA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_SBSR()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_SBSRA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_SBSRA(trim(raw,frame,0))
- }
- function intMDS_Top()
- {
- global newTSX = SzX
- global newTSY = SzY
- global newBSX = QSzX
- global newBSY = QSzY
- global newTPX = 0
- global newTPY = 0
- global newBPX = SzX
- global newBPY = SzY - QSzY
- }
- function MDS_Top(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_Top()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function Top(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_Top(trim(raw,frame,0))
- }
- function MDS_TopA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_Top()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_TopA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_TopA(trim(raw,frame,0))
- }
- function intMDS_TopO()
- {
- global newTSX = SzX
- global newTSY = SzY
- global newBSX = QSzX
- global newBSY = QSzY
- global newTPX = floor(QSzX / 2)
- global newTPY = 0
- global newBPX = SzX + QSzX
- global newBPY = SzY - QSzY
- }
- function MDS_TopO(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_TopO()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function TopO(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_TopO(trim(raw,frame,0))
- }
- function MDS_TopOA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_TopO()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_TopOA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_TopOA(trim(raw,frame,0))
- }
- function intMDS_BotO()
- {
- global newTSX = QSzX
- global newTSY = QSzY
- global newBSX = SzX
- global newBSY = SzY
- global newTPX = -QSzX
- global newTPY = 0
- global newBPX = floor(QSzX / 2)
- global newBPY = 0
- }
- function MDS_BotO(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_BotO()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function TopO(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_BotO(trim(raw,frame,0))
- }
- function MDS_BotOA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_BotO()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_TopOA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_BotOA(trim(raw,frame,0))
- }
- function intMDS_Bot()
- {
- global newTSX = QSzX
- global newTSY = QSzY
- global newBSX = SzX
- global newBSY = SzY
- global newTPX = 0
- global newTPY = 0
- global newBPX = QSzX
- global newBPY = 0
- }
- function MDS_Bot(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_Bot()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function MDS_Bot(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_Bot(trim(raw,frame,0))
- }
- function MDS_BotA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_Bot()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_BotA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_BotA(trim(raw,frame,0))
- }
- function intMDS_TopHSlide()
- {
- global newTSX = SzX
- global newTSY = SzY
- global newBSX = SzX
- global newBSY = SzY
- global newTPX = floor(QSzX / 2)
- global newTPY = 0
- global newBPX = SzX + floor(QSzX / 2)
- global newBPY = 0
- }
- function MDS_TopHSlide(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_TopHSlide()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function MDS_TopHSlide(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_TopHSlide(trim(raw,frame,0))
- }
- function MDS_TopHSlideA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_TopHSlide()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_TopHSlideA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_TopHSlideA(trim(raw,frame,0))
- }
- function intMDS_BotHSlide()
- {
- global newTSX = SzX
- global newTSY = SzY
- global newBSX = SzX
- global newBSY = SzY
- global newTPX = -SzX + floor(QSzX / 2)
- global newTPY = 0
- global newBPX = floor(QSzX / 2)
- global newBPY = 0
- }
- function MDS_BotHSlide(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_BotHSlide()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function MDS_BotHSlide(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_BotHSlide(trim(raw,frame,0))
- }
- function MDS_BotHSlideA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_BotHSlide()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_BotHSlideA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_BotHSlideA(trim(raw,frame,0))
- }
- function intMDS_TopVSlide()
- {
- global newTSX = SzX
- global newTSY = SzY
- global newBSX = SzX
- global newBSY = SzY
- global newTPX = floor(QSzX / 2)
- global newTPY = 0
- global newBPX = floor(QSzX / 2)
- global newBPY = SzY
- }
- function MDS_TopVSlide(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_TopVSlide()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function MDS_TopVSlide(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_TopVSlide(trim(raw,frame,0))
- }
- function MDS_TopVSlideA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_TopVSlide()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_TopVSlideA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_TopVSlideA(trim(raw,frame,0))
- }
- function intMDS_BotVSlide()
- {
- global newTSX = SzX
- global newTSY = SzY
- global newBSX = SzX
- global newBSY = SzY
- global newTPX = floor(QSzX / 2)
- global newTPY = -SzY
- global newBPX = floor(QSzX / 2)
- global newBPY = 0
- }
- function MDS_BotVSlide(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_BotVSlide()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function MDS_BotVSlide(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_BotVSlide(trim(raw,frame,0))
- }
- function MDS_BotVSlideA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_BotVSlide()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_BotVSlideA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_BotVSlideA(trim(raw,frame,0))
- }
- function intMDS_VertStack()
- {
- global newTSX = SBSX
- global newTSY = SBSY
- global newBSX = SBSX
- global newBSY = SBSY
- global newTPX = floor ((SzX + QSzX - SBSX) / 2)
- global newTPY = 0
- global newBPX = floor ((SzX + QSzX - SBSX) / 2)
- global newBPY = SBSY
- }
- function MDS_VertStack(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_VertStack()
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function MDS_VertStack(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_VertStack(trim(raw,frame,0))
- }
- function MDS_VertStackA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- intMDS_VertStack()
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_VertStackA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_VertStackA(trim(raw,frame,0))
- }
- function MDS_Dissolve(clip c, clip raw, int frame, string layout)
- {
- MDS_ExceptionCheck(raw,frame)
- try {
- r = Eval(layout + "(raw)")
- }
- catch (err_msg) {
- Assert(0 == 1, """Couldn't perform provided layout function! (probably)
- """ + err_msg)
- }
- l = Dissolve(trim(c,frame,frame + AFC), trim(r,frame +1,0),AFC).AudioDub(trim(raw,frame,0))
- Trim(c,0,frame - 1) + l
- }
- function MDS_DissolveToBot(clip c, clip raw, int frame, string "layout")
- {
- layout = Default(layout, "MDS_BotHSlide")
- MDS_Dissolve(c, raw, frame, layout)
- }
- function MDS_DissolveToTop(clip c, clip raw, int frame, string "layout")
- {
- layout = Default(layout, "MDS_TopHSlide")
- MDS_Dissolve(c, raw, frame, layout)
- }
- function MDS_Fade(clip c, clip raw, int frame, string layout, bool "fadeaudio")
- {
- MDS_ExceptionCheck(raw,frame)
- fadeaudio = Default(fadeaudio, false)
- try {
- r = Eval(layout + "(raw)")
- }
- catch (err_msg) {
- Assert(0 == 1, """Couldn't perform provided layout function! (probably)
- """ + err_msg)
- }
- k = floor(AFC/2)
- l = FadeOut(trim(c,frame,frame + k),k) + FadeIn(trim(r,frame + k + 3,0),k)
- l = fadeaudio == false ? Eval("""
- l.AudioDub(trim(raw,frame,0))
- """) : l
- Trim(c,0,frame - 1) + l
- }
- function MDS_FadeToBot(clip c, clip raw, int frame, string "layout", bool "fadeaudio")
- {
- layout = Default(layout, "MDS_BotHSlide")
- fadeaudio = Default(fadeaudio, false)
- MDS_Fade(c,raw,frame,layout,fadeaudio)
- }
- function MDS_FadeToTop(clip c, clip raw, int frame, string "layout", bool "fadeaudio")
- {
- layout = Default(layout, "MDS_TopHSlide")
- fadeaudio = Default(fadeaudio, false)
- MDS_Fade(c,raw,frame,layout,fadeaudio)
- }
- function MDS_Custom_TargetData(int TSX,int TSY,int BSX, int BSY, int TPX, int TPY, int BPX, int BPY)
- {
- global newTSX = TSX
- global newTSY = TSY
- global newBSX = BSX
- global newBSY = BSY
- global newTPX = TPX
- global newTPY = TPY
- global newBPX = BPX
- global newBPY = BPY
- }
- function MDS_Custom(clip raw)
- {
- MDS_ExceptionCheck(raw)
- UpdateGlobals()
- DoDSImmediate(raw)
- }
- function MDS_Custom(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_Custom(trim(raw,frame,0))
- }
- function MDS_CustomA(clip raw)
- {
- MDS_ExceptionCheck(raw)
- final = DoDSAnimate(raw)
- UpdateGlobals()
- return final
- }
- function MDS_CustomA(clip c, clip raw, int frame)
- {
- MDS_ExceptionCheck(raw,frame)
- Trim(c,0,frame - 1) + MDS_CustomA(trim(raw,frame,0))
- }
- # Worker functions:
- function DoDSImmediate(clip c)
- {
- a = c.crop(0,0,0,192).PointResize(newTSX,newTSY)
- b = c.crop(0,192,0,0).PointResize(newBSX,newBSY)
- BlankClip(a,width = MaxX,height=MaxY).AudioDub(c)
- final = DrawBFirst == false ? Eval("""
- layer(a,"ADD",256,newTPX,newTPY)
- layer(b,"ADD",256,newBPX,newBPY)
- """) : Eval("""
- layer(b,"ADD",256,newBPX,newBPY)
- layer(a,"ADD",256,newTPX,newTPY)
- """)
- return final
- }
- function DoDSAnimate(clip c)
- {
- a = c.crop(0,0,0,192)
- b = c.crop(0,192,0,0)
- BASE = BlankClip(a,width = MaxX,height=MaxY).AudioDub(c)
- q = a.Animate(0,AFC,"AnimResize",LastTopSizeX,LastTopSizeY,AnimResizeFilter,newTSX,newTSY,AnimResizeFilter).trim(0,AFC)
- q = q + a.trim(AFC + 1,0).AnimResize(newTSX,newTSY,"PointResize")
- r = b.Animate(0,AFC,"AnimResize",LastBotSizeX,LastBotSizeY,AnimResizeFilter,newBSX,newBSY,AnimResizeFilter).trim(0,AFC)
- r = r + b.trim(AFC + 1,0).AnimResize(newBSX,newBSY,"PointResize")
- final = DrawBFirst == false ? Eval("""
- BASE.Animate(0,AFC,"layer",q,"ADD",256,LastTopPosX,LastTopPosY,q,"ADD",256,newTPX,newTPY).Animate(0,AFC,"layer",r,"ADD",256,LastBotPosX,LastBotPosY,r,"ADD",256,newBPX,newBPY)
- """) : Eval("""
- BASE.Animate(0,AFC,"layer",r,"ADD",256,LastBotPosX,LastBotPosY,r,"ADD",256,newBPX,newBPY).Animate(0,AFC,"layer",q,"ADD",256,LastTopPosX,LastTopPosY,q,"ADD",256,newTPX,newTPY)
- """)
- return final
- }
- function UpdateGlobals()
- {
- global LastTopSizeX = newTSX
- global LastTopSizeY = newTSY
- global LastBotSizeX = newBSX
- global LastBotSizeY = newBSY
- global LastTopPosX = newTPX
- global LastTopPosY = newTPY
- global LastBotPosX = newBPX
- global LastBotPosY = newBPY
- }
- Function AnimResize(clip c, int x, int y,string "method")
- {
- blank = BlankClip(c,width = SzX,height = SzY)
- f = Default(method,"PointResize")
- q = Eval("c." + f + "(x,y)")
- Layer(blank,q)
- }
- Function MDS_ExceptionCheck(clip raw)
- {
- Assert(width(raw) == 256, "MDS Error: Raw clip not 256 pixels wide")
- Assert(height(raw) == 384, "MDS Error: Raw clip not 384 pixels high")
- }
- Function MDS_ExceptionCheck(clip raw, int frame)
- {
- MDS_ExceptionCheck(raw)
- Assert(frame >= LastFrame, "MDS Error: Frame " + string(frame) + " is smaller than lastframe+AFC (" + string(LastFrame) + ") - call MDS_ResetLastframe() if not an error")
- global LastFrame = frame + AFC
- }
- Function intMDS_DrawDebug(clip c)
- {
- # Note that this is kind of useless, since it will be applied to all frames regardless of the state things are at the time.
- c
- Subtitle("Last: TopS (" + string(LastTopSizeX) + "," + string(LastTopSizeY) + ") BotS (" + \
- string(LastBotSizeX) + "," + string(LastBotSizeY) + ") TopP (" + string(LastTopPosX) + "," + \
- string(LastTopPosY) + ") BotP (" + string(LastBotPosX) + "," + \
- string(LastBotPosY) + ")")
- Subtitle("New: TopS (" + string(newTSX) + "," + string(newTSY) + ") BotS (" + \
- string(newBSX) + "," + string(newBSY) + ") TopP (" + string(newTPX) + "," + \
- string(newTPY) + ") BotP (" + string(newBPX) + "," + \
- string(newBPY) + ")", y = 100)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement