from pyfbsdk import *
from pyfbsdk_additions import *
from sys import *
import os.path
import traceback
global lFp
lFp = FBFilePopup()
def BrowseCallback(control, event):
lFp.Caption = "Select the audio track definition file:"
lFp.Style = FBFilePopupStyle.kFBFilePopupOpen
lFp.Filter = "*.txt"
if os.path.isdir(os.path.splitext(traceback.extract_stack()[-1][0])[0]):
lFp.Path = os.path.normpath(os.path.splitext(traceback.extract_stack()[-1][0])[0])
else:
lFp.Path = os.path.normpath(os.path.dirname(traceback.extract_stack()[-1][0]))
lRes = lFp.Execute()
if lRes:
eButt.Text = os.path.join(lFp.Path,lFp.FileName)
def SetupCallback(control, event):
try:
f=open(os.path.join(lFp.Path,lFp.FileName), 'r')
shotInfoFile = f.readlines()
f.close()
lTrackAudio = FBStoryTrack(FBStoryTrackType.kFBStoryTrackAudio)
shotCnt = len(shotInfoFile)
counter = 1
lastClipEnd = 0
for shotInfo in shotInfoFile:
shots = shotInfo.split()
shotName = shots[0]
shotStart = shots[1]
shotEnd = shots[2]
iShotStart = int(shotStart)
iShotEnd = int(shotEnd)
if counter < 10:
audioPath = os.path.join(lFp.Path,"Audio_Clip_0" + str(counter) + ".wav")
else:
audioPath = os.path.join(lFp.Path,"Audio_Clip_" + str(counter) + ".wav")
lAudio = FBAudioClip(audioPath)
lClip = FBStoryClip (lAudio, lTrackAudio, FBTime(0,0,0,iShotStart))
if lastClipEnd<iShotEnd: lastClipEnd=iShotEnd
counter = counter + 1
FBPlayerControl().LoopStop=FBTime(0,0,0,lastClipEnd,0)
except IOError:
FBMessageBox( "Cannot Continue", "Unable to read the audio track definition file you selected or you have not selected one.", "OK", None, None )
exit
def CloseCallback(control, event):
DestroyTool(t)
def PopulateLayout(mainLyt):
l = FBLabel()
l.Caption = "Select the audio track definition file to use:"
l.Style = FBTextStyle.kFBTextStyleBold
l.WordWrap = True
x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
y = FBAddRegionParam(5,FBAttachType.kFBAttachTop,"")
w = FBAddRegionParam(300,FBAttachType.kFBAttachNone,"")
h = FBAddRegionParam(20,FBAttachType.kFBAttachNone,"")
mainLyt.AddRegion("lab","lab", x, y, w, h)
mainLyt.SetControl("lab",l)
e = FBEdit()
e.ReadOnly = True
e.Text = ""
x2 = FBAddRegionParam(5,FBAttachType.kFBAttachLeft,"")
y2 = FBAddRegionParam(5,FBAttachType.kFBAttachBottom,"lab")
w2 = FBAddRegionParam(220,FBAttachType.kFBAttachNone,"")
h2 = FBAddRegionParam(20,FBAttachType.kFBAttachNone,"")
mainLyt.AddRegion("path","path", x2, y2, w2, h2)
mainLyt.SetControl("path",e)
b2 = FBButton()
b2.Caption = "Browse..."
b2.Justify = FBTextJustify.kFBTextJustifyCenter
x3 = FBAddRegionParam(225,FBAttachType.kFBAttachLeft,"path")
y3 = FBAddRegionParam(5,FBAttachType.kFBAttachBottom,"lab")
w3 = FBAddRegionParam(57,FBAttachType.kFBAttachNone,"")
h3 = FBAddRegionParam(20,FBAttachType.kFBAttachNone,"")
mainLyt.AddRegion("but","but", x3, y3, w3, h3)
mainLyt.SetControl("but",b2)
global eButt
eButt = e
b2.OnClick.Add(BrowseCallback)
b3 = FBButton()
b3.Caption = "Setup Audio"
b3.Justify = FBTextJustify.kFBTextJustifyCenter
x4 = FBAddRegionParam(40,FBAttachType.kFBAttachLeft,"")
y4 = FBAddRegionParam(12,FBAttachType.kFBAttachBottom,"path")
w4 = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
h4 = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
mainLyt.AddRegion("audio","audio", x4, y4, w4, h4)
mainLyt.SetControl("audio",b3)
b3.OnClick.Add(SetupCallback)
b4 = FBButton()
b4.Caption = "Close"
b4.Justify = FBTextJustify.kFBTextJustifyCenter
x5 = FBAddRegionParam(20,FBAttachType.kFBAttachRight,"audio")
y5 = FBAddRegionParam(12,FBAttachType.kFBAttachBottom,"path")
w5 = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
h5 = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
mainLyt.AddRegion("close","close", x5, y5, w5, h5)
mainLyt.SetControl("close",b4)
b4.OnClick.Add(CloseCallback)
def CreateTool():
global t
t = CreateUniqueTool("Audio Track Setup Tool")
t.StartSizeX = 300
t.StartSizeY = 123
PopulateLayout(t)
ShowTool(t)
CreateTool()