' TRAN_FRZ.BAS is a QBasic tool to parse project.xml and 'split off' the frame 'transitions'
'
' It is exceedingly complex because transitions take place half on the previous photo, half on this
' = so 'moving' a transition so it takes place on a 'static' photo means adding a new static Vu to
' both the end of the previous Vu and the start of the (transition) Vu
'
' The result is that two new Vu's have to be created for each transition ..
' if every existing raem has a transition, the number of photo's will be tripped
' (the script just points at the existing photos .. it's PS3 that replcates them)
'
'
' The project.xml will have already been parsed to add cr/lf (use Notepad++, replace '>' with '>\r\n' )
' the modded project.xml and all the {n}.jpg's must be in QBASIC\PSTORY3 sub-folder
'
' To run this script, open a DOS box, cd to 'C:\QBASIC\' and type "qbasic /run trans_adj"
'
' The project.xml is first 'scanned' to extract details of the visual units,
' then a second pass extracts the Vu's and does the actual processing
'
' For each vu, if previous Vu has a transition, add leading static (of half previous trans time)
' if this Vu has a transition, add trauining static (of half this vu transition)
'
' On first pass, create array vu(ImgCount, 2), where the 2 entries are leading static time & trailing static time
' 0 = no static (vu display time will be adjusted by lead+trail times)
'
' The first has it's display time modified (reduced by the duration of the 'next' withPrevImage="0" transition)
' and it's (second, next) Transition (withPrevImage="0") entry set to duration="0".
' It's Transition2 is set to type="0" useManualDuration="-1" duration="0" i.e. it's 'turned off'
'
' The second has it's display time set to the original Vu's 'next' (second) transition (withPrevImage="0") entry duration time.
' It's own first transition (withPrevImage="-1") entry is set to duration="0",
' it's second (withPrevImage="0") is left as origionally set, as is it's Transition2 settings.
' Since this 'copy' has to be a 'static' one, both Rect settings are set the same (to the second Rect value)
' and the first RelativeRect set equal to the second (i.e. no movement)
'
' NOTE if the timings are to 'take' then they MUST ALL be set to 'manual'
'
' subroutine to extract a numb from in$ starting near start% (and set the double quote positions)
DECLARE SUB getvalue (in$, start%, numb, q1pos%, q2pos%)
' find val$ in in$. If flag = 0 then adjust by value, else replace val$ with value. If flag is -1, return value instead
DECLARE SUB setvalue (in$, val$, value, flag)
' subroutine to copy a Vu to temp whilst getting the vuTime
DECLARE SUB getVu (in$, vuTime, t2time)
' subroutine to copy a Vu from temp file into main with replacements ...
' note newT2time = 0 emans first copy, non-zero means second
DECLARE SUB outputVu (newVuTime, newT2time)
CLEAR
'
' can't use the double-quote symbol (") in a line of qbasic code, so assign it to a variable
q$ = CHR$(34)
'
OPEN "C:\QBASIC\PSTORY3\project.xml" FOR INPUT AS #1
'
' First pass - discover vu count, create array, discover transitions, record times
'
getVuCt:
LINE INPUT #1, in$
Qpos% = INSTR(in$, "visualUnitCount")
IF Qpos% = 0 THEN GOTO getVuCt:
' get the vucount
CALL setvalue (in$, "visualUnitCount", vucount, -1)
' create the vu array
DIM ttime(vucount,2) AS SINGLE
' initialise the pointer
vunumb = 1
' scan the vu's for the transition times
DO
LINE INPUT #1, in$
IF INSTR(in$, "Transition2") <> 0 THEN
CALL setvalue (in$, "type", t2type, -1)
IF t2type <> 0 THEN CALL setvalue (in$, "duration", dtime, -1) ELSE dtime = 0
' set the prev end static and this static
ttime(vunumb-1,2) = dtime / 2
ttime(vunumb,1) = dtime /2
' up the total image count
vucount = vucount + (2 * SGN(dtime))
' inc the pointer
vunumb = vunumb + 1
END IF
' find next, if any
LOOP UNTIL EOF(1)
'
' OK first pass done, close the file and re-open for the main event
CLOSE
OPEN "C:\QBASIC\PSTORY3\project.xml" FOR INPUT AS #1
OPEN "C:\QBASIC\PSTORY3\new_tran.xml" FOR OUTPUT AS #2
'
' find the visualUnitCount="?" entry
GOTO start1:
start0:
PRINT #2, in$
start1:
LINE INPUT #1, in$
' ignore blank lines
IF in$="" THEN GOTO start1:
Qpos% = INSTR(in$, "visualUnitCount")
IF Qpos% = 0 THEN GOTO start0:
' set the new count val
CALL setvalue (in$, "visualUnitCount", vucount, 1)
PRINT #2, in$
'
' OK, set count for start of processing VisualUnits
vunumb = 0
' inc. to next unit
procNxt:
vunumb = vunumb + 1
proc1:
LINE INPUT #1, in$
' skip blank lines
IF in$="" THEN GOTO proc1:
' check if eof
IF INSTR(in$, "") = 1 THEN GOTO endofinput:
' start of unit ?
IF INSTR(in$, " 0 THEN GOTO proc2:
' no save & go find next unit
PRINT #2, in$
GOTO procNxt:
END IF
PRINT #2, in$
GOTO proc1:
'
proc2:
' OK, a static start or end or both needs to be generated
' start by copying the unit
OPEN "C:\QBASIC\PSTORY3\vunit.xml" FOR OUTPUT AS #3
' now save the whole Vu
DO
PRINT #3, in$
LINE INPUT #1, in$
LOOP UNTIL INSTR(in$, "") = 1
' save last line & close the temp
PRINT #3, in$
CLOSE #3
' OK, now go do the copies ... static start ?
IF ttime(vunumb,1) <> 0 THEN CALL outputVu (ttime(vunumb,1), 1)
' now the main
CALL outputVu (-(ttime(vunumb,1)+ttime(vunumb,2))/2, 0)
' and static end ?
IF ttime(vunumb,2) <> 0 THEN CALL outputVu (ttime(vunumb,2), 2)
'
' OK that's the whole vu done, go for next
GOTO procNxt:
'
' normal exit
endofinput:
PRINT #2, in$
CLOSE
' tell user
beep
beep
PRINT "done"
beep
CLEAR
SYSTEM
' subroutine to copy a Vu from the temp file into main with replacement times etc ...
' if Ncopy is 1 (or 2), then it's a static start (or end), newTime = the duration,
' Ncopy 0 means the main core, newTime is ammount to adjust by
SUB outputVu (newTime, Ncopy)
SHARED q$
' get the vu
OPEN "C:\QBASIC\PSTORY3\vunit.xml" FOR INPUT AS #3
' get first line (had better be the "" THEN PRINT #2, t1in$
IF t2in$ <> "" THEN PRINT #2, t2in$
' OK, now in$ should be the 'image path' line and we need to set useManualDuration="-1"
CALL setvalue (in$, "useManualDuration", -1, 1)
'
PRINT #2, in$
' and now copy all until the first Rect entry is found
LINE INPUT #3, r1in$
DO
PRINT #2, r1in$
LINE INPUT #3, r1in$
LOOP UNTIL INSTR(r1in$, " 1 THEN CALL setvalue (in$, "type", 0, 1)
PRINT #2, in$
' OK, now finish the vu
DO
LINE INPUT #3, in$
PRINT #2, in$
LOOP UNTIL INSTR(in$, "") = 1
'
' OK, done, close temp and exit
CLOSE #3
END SUB
' subroutine to get a number, between two sets of quotes (start looking at Qpos)
SUB getvalue (in$, start%, numb, Q1pos%, Q2pos%)
SHARED q$
' find the first double quote
Q1pos% = INSTR(start% + 1, in$, q$)
' locate the second
Q2pos% = INSTR(Q1pos% + 1, in$, q$)
' extract the value betwn them (may be float)
numb = VAL(MID$(in$, Q1pos% + 1, Q2pos% - Q1pos% - 1))
END SUB
' find val$ in in$. If flag = 0 then adjust by value, else replace val$ with value. If flag is -1, return value instead
SUB setvalue (in$, val$, value, flag)
SHARED q$
' exit if in$ empty
IF LEN(in$)=0 THEN EXIT SUB
' locate the parameter string (start) for value locn.
Qpos% = INSTR(in$, val$)
' abort if we didnd find it
IF Qpos% = 0% THEN EXIT SUB
' get the current value
CALL getvalue (in$, Qpos%, curvalue, Q1pos%, Q2pos%)
' only need to return a value ?
IF flag = -1 THEN
value = curvalue
EXIT SUB
END IF
' adjust or replace ?
IF flag <> 0 THEN curvalue = 0
nval = curval + value
' is the result negative ?
sign = SGN(nval)
' generate a positive string
newval$ = STR$ (ABS(nval))
' strip off any leading space
IF INSTR(newval$, " ") = 1 THEN newval$ = MID$(newval$, 2)
' add a leading 0 if needed
IF INSTR(newval$, ".") = 1 THEN newval$ = "0"+newval$
' add the sign
IF sign = -1 THEN newval$ = "-"+newval$
' now plug it into the string
in$ = left$(in$,Q1pos%) + newval$ + mid$(in$,Q2pos%)
END SUB