| 
UID2积分8682帖子2905主题199论坛币13044 威望16 EP值2349 MP值15 阅读权限200注册时间2011-8-3在线时间2597 小时最后登录2024-8-28
 
   
 | 
| Predefined Function Interfaces 
 The predefined functions if any are executed by TCAX in order, there are in total four interfaces:
 
 tcaxPy_Init
 
 Usually, it does some initialization, and will be executed only once before any other predefined functions of the tcaxPy script.
 
 Implementation example:
 tcaxPy_Main复制代码def tcaxPy_Init():
    # some common pre-defined global values
    global fontSize    # as name implies
    global resX        # horizontal resolution
    global resY        # vertical resolution
    global marginX     # horizontal margin
    global marginY     # vertical margin
    global spacing     # space between texts
    global frameDur    # milliseconds per frame
    global lineNum     # number of lines
    global textNum     # textNum[i], number of texts in ith line
    global start       # start[i], start time of a line
    global end         # end[i], end time of a line
    global kar         # kar[i][j], karaoke time of a syllable
    global elapKar     # elapKar[i][j], elapsed karaoke time before reaching a certain syllable
    global text        # text[i][j], as name implies
    global textLength  # textLength[i], total width of a line
    global width       # width[i][j], width of a text
    global height      # height[i][j], height of a text
    global advance     # advance[i][j], advance of a text, usually larger than width
    global advDiff     # advDiff[i][j], distance between the current text to the first text of the line
    fontSize     = GetVal(val_FontSize)
    resX         = GetVal(val_ResolutionX)
    resY         = GetVal(val_ResolutionY)
    marginX      = GetVal(val_OffsetX)
    marginY      = GetVal(val_OffsetY)
    spacing      = GetVal(val_Spacing)
    frameDur     = 1000 / GetVal(val_FXFPS)
    lineNum      = GetVal(val_nLines)
    textNum      = GetVal(val_nTexts)
    start        = GetVal(val_BegTime)
    end          = GetVal(val_EndTime)
    kar          = GetVal(val_KarTime)
    elapKar      = GetVal(val_KarTimeDiff)
    text         = GetVal(val_Text)
    textLength   = GetVal(val_TextLength)
    width        = GetVal(val_TextWidth)
    height       = GetVal(val_TextHeight)
    advance      = GetVal(val_TextAdvance)
    advDiff      = GetVal(val_TextAdvanceDiff)
    # some user-defined global values
    global font
    global fontBord
    font     = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), fontSize, GetVal(val_Spacing), GetVal(val_SpaceScale), MakeRGB(255, 255, 255), 0, 0)
    fontBord = InitFont(GetVal(val_FontFileName), GetVal(val_FaceID), fontSize, GetVal(val_Spacing), GetVal(val_SpaceScale), MakeRGB(0, 0, 0), 2, 1)
 It provides some easy to use information through the parameters, and the function will be executed many times, which is decided by the number of syllables or texts.
 
 Description of parameters:
 # _i          the current line being handled whose index is _i
 # _j          the current text being handled whose index is _j in the current line
 # _n          number of texts in the current line
 # _start      start time of the current line
 # _end        end time of the current line
 # _elapk      elapsed time from the first text of the line to the current text
 # _k          the karaoke time of the current text
 # _x          the horizontal position of the current text (an5)
 # _y          the vertical position of the current text (an5)
 # _a          the advance of the current text
 # _txt        the content of the current text
 
 Note:
 1. the existing time of the current text is from _start + _elapk to _start + _elapk + _k
 2. you can replace the parameter names with whatever you preferred.
 
 Implementation example:
 tcaxPy_User复制代码def tcaxPy_Main(_i, _j, _n, _start, _end, _elapk, _k, _x, _y, _a, _txt):
    ASS_BUF  = []        # used for saving ASS FX lines
    TCAS_BUF = []        # used for saving TCAS FX raw data
    #############################
    # TODO: write your codes here #
    ass_main(ASS_BUF, SubL(_start, _end), pos(_x, _y) + K(_elapk) + K(_k), _txt)
    #############################
    return (ASS_BUF, TCAS_BUF)
 It will be executed only once and if this function is used, tcaxPy_Main function will be ignored. The difference between tcaxPy_User function and tcaxPy_Main function is that tcaxPy_User function leaves all the work to be done by the user, while tcaxPy_Main function leaves the I/O task to TCAX. The structure of tcaxPy_Main function is somewhat dull, not as flexible as tcaxPy_User function. However, you can make your own script template by implementing the tcaxPy_User interface.
 
 Implementation example:
 tcaxPy_Fin复制代码def tcaxPy_User():
    ASS = CreateAssFile(GetVal(val_OutFile) + '.ass', GetVal(val_AssHeader))
    for i in range(lineNum):
        initPosX = (resX - textLength[i]) / 2 + marginX        # if marginX = 0, then it's just on the middle
        initPosY = marginY
        for j in range(textNum[i]):
            ASS_BUF = []    # you can put the BUF anywhere according to your usage
            if text[i][j] == '' or text[i][j] == ' ' or text[i][j] == ' ':
                continue
            posX = initPosX + advDiff[i][j] + advance[i][j] / 2
            posY = initPosY
            ass_main(ASS_BUF, SubL(start[i], end[i]), an(8) + pos(posX, posY) + K(elapKar[i][j]) + K(kar[i][j]), text[i][j])
            WriteAssFile(ASS, ASS_BUF)
            Progress(i, j)
    FinAssFile(ASS)
 Usually, it does some finalization, and it will be executed only once after any other predefined functions of the tcaxPy script.
 
 Implementation example:
 TCC Options to Enable/Disable the Interfaces复制代码def tcaxPy_Fin():
    FinFont(font)
    FinFont(fontBord)
    Pause()
 You can change the options about whether to use these functions through the TCC file:
 
 < tcaxpy init = true >
 true - will use tcaxPy_Init function, and you should implement the tcaxPy_Init interface in your tcaxPy scripts.
 
 < tcaxpy user = false >
 false - will use tcaxPy_Main function instead, and you should implement the tcaxPy_Main interface in your tcaxPy scripts.
 
 < tcaxpy fin = false >
 false - will not use tcaxPy_Fin function, so you do not have to implement it.
 
 you can change the settings according to your usage.
 
 
 Miscellaneous
 
 Python is a powerful scripting language, you can break the limitations of TCAX,  and enhance it by using external modules and co-operate with your own tcaxPy script template, which can be achieved by using your own implementation of the predefined tcaxPy_User interface. Though such task is never easy, and requires your better understanding of Python programming and the concepts of TCAX.
 
 Here is an example of implementing a new tcaxPy_User function.
 http://www.tcax.org/forum.php?mod=viewthread&tid=278
 
 
 
 | 
 |