View Full Version : Indented block statements


fvisagie
27th June 2014, 17:03
Hi All,

What is the simplest way of creating indented multi-level block statements, when most levels have quoted strings and the block statements aren't easily moved to a function? Although the example below is from runtime script, I also come across this scenario in other cases.

For example, to this script

ScriptClip(c, """
global MF_activeclips = MF_activeclips + 1
global sequence = sequence + "b" + String(MF_activeclips)
INFO = """" + Eval("MF_source" + String(MF_registeredclips)) + """" + " " + \
String(current_frame) + "=" + MF_Frames2INFO(current_frame + Int(Value("""" + tcoffsetstr + """")), Value("""" + String(fps) + """"))
Eval("global MF_INFO" + String(MF_activeclips) + "=INFO")
MF_show == "Clip" || MF_show == "ClipFast" \
? MF_ShowINFO(INFO) \
: last
""", show=false, after_frame=false)

I need to add another condition level as follows

ScriptClip(c, """
current_frame != MF_clipbefore \
? Eval("
global MF_clipbefore = current_frame
global MF_label = "label"
all_of_the_above
") \
: last
""", show=false, after_frame=false)


However, adding quoted expressions to the Eval() statement as above causes a runtime syntax error, not even to mention quoted expressions in the newly indented level.

Thanks,
Francois

Gavino
27th June 2014, 19:39
What is the simplest way of creating indented multi-level block statements
Are you aware of GScript?

fvisagie
28th June 2014, 14:38
I am, thanks Gavino, but not that it could be of help in cases like this, as your question seems to imply. Would you mind showing how GScript might help here?

Thanks.

StainlessS
28th June 2014, 18:20
This method works ok but initializes GScript at every frame

Function WhatAmI(clip c,int current_frame) {
GSCript("""
c
Txt = "I dont know what I am !"
if(isYUV) {
if(isYV12) {
Txt ="I am YV12"
} Else if(isYUY2) {
Txt="I am YUY2"
} Else if(isYV16) {
Txt="I am YV16"
} Else if(isYV24) {
Txt="I am YV24"
} Else if(isYV411) {
Txt="I am YV411"
} Else if(isY8) {
Txt="I am Y8"
} Else {
Txt="I am some kind of YUV"
}
} Else if (IsRGB) {
if(isRGB24) {
Txt="I am RGB24"
} Else if(isRGB32) {
Txt="I am RGB32"
} Else {
Txt="I am some kind of RGB"
}
}
Subtitle(String(current_frame)+"] "+Txt)
""")
}

c=avisource("D:\avs\test.avi")
c
ConvertToYV24
ScriptClip("WhatAmI(Last,current_frame)", show=false, after_frame=false)
Return ConvertToRGB32() # if v2.6 colorspace


This is a bit more fiddly, but GSCript initialized only once.

FnS="""
Function WhatAmI(clip c,int current_frame) {
c
Txt = "I dont know what I am !"
if(isYUV) {
if(isYV12) {
Txt ="I am YV12"
} Else if(isYUY2) {
Txt="I am YUY2"
} Else if(isYV16) {
Txt="I am YV16"
} Else if(isYV24) {
Txt="I am YV24"
} Else if(isYV411) {
Txt="I am YV411"
} Else if(isY8) {
Txt="I am Y8"
} Else {
Txt="I am some kind of YUV"
}
} Else if (IsRGB) {
if(isRGB24) {
Txt="I am RGB24"
} Else if(isRGB32) {
Txt="I am RGB32"
} Else {
Txt="I am some kind of RGB"
}
}
Subtitle(String(current_frame)+"] "+Txt)
}
Return ScriptClip("WhatAmI(Last,current_Frame)", show=false, after_frame=false)
"""


c=avisource("D:\avs\test.avi")
c
ConvertToYV24
GScript(FnS)
Return ConvertToRGB32() # if v2.6 colorspace


This is a bit like GImport

FnS="""
Function WhatAmI(clip c,int current_frame) {
c
Txt = "I dont know what I am !"
if(isYUV) {
if(isYV12) {
Txt ="I am YV12"
} Else if(isYUY2) {
Txt="I am YUY2"
} Else if(isYV16) {
Txt="I am YV16"
} Else if(isYV24) {
Txt="I am YV24"
} Else if(isYV411) {
Txt="I am YV411"
} Else if(isY8) {
Txt="I am Y8"
} Else {
Txt="I am some kind of YUV"
}
} Else if (IsRGB) {
if(isRGB24) {
Txt="I am RGB24"
} Else if(isRGB32) {
Txt="I am RGB32"
} Else {
Txt="I am some kind of RGB"
}
}
Subtitle(String(current_frame)+"] "+Txt)
}
"""


c=avisource("D:\avs\test.avi")
c
ConvertToYV24
GScript(FnS) # Init Function
ScriptClip("WhatAmI(Last,current_Frame)", show=false, after_frame=false)
Return ConvertToRGB32() # if v2.6 colorspace


I'm sure Gavino has a neater way.

EDIT: And of course the obvious way, which I forgot.

GSCript("""
Function WhatAmI(clip c,int current_frame) {
c
Txt = "I dont know what I am !"
if(isYUV) {
if(isYV12) {
Txt ="I am YV12"
} Else if(isYUY2) {
Txt="I am YUY2"
} Else if(isYV16) {
Txt="I am YV16"
} Else if(isYV24) {
Txt="I am YV24"
} Else if(isYV411) {
Txt="I am YV411"
} Else if(isY8) {
Txt="I am Y8"
} Else {
Txt="I am some kind of YUV"
}
} Else if (IsRGB) {
if(isRGB24) {
Txt="I am RGB24"
} Else if(isRGB32) {
Txt="I am RGB32"
} Else {
Txt="I am some kind of RGB"
}
}
Subtitle(String(current_frame)+"] "+Txt)
}
""")


c=avisource("D:\avs\test.avi")
c
ConvertToYV24
ScriptClip("WhatAmI(Last,current_Frame)", show=false, after_frame=false)
Return ConvertToRGB32() # if v2.6 colorspace

fvisagie
29th June 2014, 09:47
Thanks. I've also managed to come up with something, really crude though ;).