Skip to content

Commit

Permalink
ui and seek changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaker committed Jul 6, 2023
1 parent 1c8b4e0 commit 079e9c5
Show file tree
Hide file tree
Showing 10 changed files with 517 additions and 158 deletions.
67 changes: 52 additions & 15 deletions src/cutselectionController.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,25 @@ def splitClipIntoNEqualSections(self):
def addSubclipByTextRange(self):
self.ui.addSubclipByTextRange(self,self.getTotalDuration())

def jumpToSearch(self,searchStr):
def jumpToSearch(self,searchStr,randomjump=False):
searchParts = [x.upper() for x in searchStr.split(' ') if len(x)>0]
nextClipInd = self.files.index(self.currentlyPlayingFileName)+1
foundfile = None
possibles = []
if randomjump:
nextClipInd = 0

for e in self.files[nextClipInd:]:
if all([x in e.upper() for x in searchParts]):
foundfile = e
break
if randomjump:
possibles.append(e)
foundfile = e
else:
foundfile = e
break

if len(possibles) > 0 and randomjump:
foundfile = random.choice(possibles)

if foundfile is None:
for e in self.files[:nextClipInd-1]:
Expand Down Expand Up @@ -387,17 +397,27 @@ def jumpClips(self,offset):
if len(unplayed)==0:
self.randomlyPlayedFiles=set()
unplayed = set(files)
nextRandomFile = random.choice(list(unplayed))
self.playVideoFile(nextRandomFile,0)
self.randomlyPlayedFiles.add(self.currentlyPlayingFileName)
self.randomlyPlayedFiles.add(nextRandomFile)
for _ in range(10):
nextRandomFile = random.choice(list(unplayed))
exists = os.path.isfile(nextRandomFile)
if exists:
self.playVideoFile(nextRandomFile,0)
self.randomlyPlayedFiles.add(self.currentlyPlayingFileName)
self.randomlyPlayedFiles.add(nextRandomFile)
if exists:
break
else:
try:
nextClipInd = self.files.index(self.currentlyPlayingFileName)+offset
nextFile = self.files[nextClipInd%len(self.files)]
self.playVideoFile(nextFile,0)
self.randomlyPlayedFiles.add(self.currentlyPlayingFileName)
self.randomlyPlayedFiles.add(nextFile)
for imult in range(1,10):
nextClipInd = self.files.index(self.currentlyPlayingFileName)+(offset*imult)
nextFile = self.files[nextClipInd%len(self.files)]
exists = os.path.isfile(nextFile)
if exists:
self.playVideoFile(nextFile,0)
self.randomlyPlayedFiles.add(self.currentlyPlayingFileName)
self.randomlyPlayedFiles.add(nextFile)
if exists:
break
except ValueError as e:
logging.error('Exception jumpClips',exc_info=e)

Expand Down Expand Up @@ -517,15 +537,16 @@ def loadFiles(self,fileList,asktoSort=False):
if asktoSort:
pass

self.ui.disableFileWidgets=False
if len(fileList) > 100:
self.ui.disableFileWidgets = False or self.ui.disableFileWidgets
if len(fileList) > 1000:
self.ui.disableFileWidgets=True
elif len(fileList) > 100:
response = self.ui.confirmWithMessage('Disable video listing?','You\'re loading {} files at once, showing these as widgets will affect performance, do you want to disable the file listing widget and just use the "Prev Clip" and "Next Clip" controls?'.format(len(fileList)),icon='warning')
if response=='yes':
self.ui.disableFileWidgets=True

for file in fileList:
if file not in self.files:

file_for_load = file

if self.globalOptions.get('loadRelativeCopyOnFileNotExists',False) and not os.path.exists(file_for_load):
Expand Down Expand Up @@ -628,6 +649,22 @@ def addFullClip(self):
self.videoManager.registerNewSubclip(self.currentlyPlayingFileName,0.0,self.currentTotalDuration)
self.updateProgressStatistics()

def setAB(self,start,end,seekAfter=True):
if start<0:
start=0
if start>self.currentTotalDuration:
start=self.currentTotalDuration

if end<0:
end=0
if end>self.currentTotalDuration:
end=self.currentTotalDuration

self.currentLoop_a = start
self.currentLoop_b = end
self.player.ab_loop_a=start
self.player.ab_loop_b=end

def addNewSubclip(self,start,end,seekAfter=True):
if start<0:
start=0
Expand Down
118 changes: 75 additions & 43 deletions src/cutselectionUi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ def format_timedelta(value, time_format="{days} days, {hours2}:{minutes2}:{secon
'years_total': years_total,
})

placeholderPreviewGrey = None
placeholderPreviewImage = None

class VideoFilePreview(ttk.Frame):
def __init__(self, master, parent, filename, *args, **kwargs):
global placeholderPreviewGrey, placeholderPreviewImage

ttk.Frame.__init__(self, master)

self.filename = filename
Expand All @@ -84,10 +89,15 @@ def __init__(self, master, parent, filename, *args, **kwargs):
self.labelVideoPreviewLabel = ttk.Label(self.frameVideoFileWidget, justify='center', style="previewImg.TLabel")
self.labelVideoPreviewLabel.config(text="No Preview Loaded")

self.previewData = "P5\n200 117\n255\n" + ("0" * 200 * 117)
self.labelVideoPreviewImage = tk.PhotoImage(data=self.previewData)
self.previewData = ""
if placeholderPreviewGrey is None:
self.previewData = "P5\n200 117\n255\n" + ("0" * 200 * 117)
placeholderPreviewGrey = tk.PhotoImage(data=self.previewData)
self.labelVideoPreviewImage = placeholderPreviewGrey
try:
self.labelVideoPreviewImage = tk.PhotoImage(file=".\\resources\\loadingPreview.png")
if placeholderPreviewImage is None:
placeholderPreviewImage = tk.PhotoImage(file=".\\resources\\loadingPreview.png")
self.labelVideoPreviewImage = placeholderPreviewImage
except Exception as e:
print(e)
self.previewRequested = False
Expand Down Expand Up @@ -158,6 +168,14 @@ def remove(self):
self.parent.removeVideoFile(self.filename)


def binseq(upper,lower):
mid = (upper+lower)/2
yield mid
g1,g2 = binseq(lower,mid), binseq(mid,upper)
while 1:
for gen in [g1,g2]:
yield next(gen)

class CutselectionUi(ttk.Frame):
def __init__(self, master=None, controller=None,globalOptions={},*args, **kwargs):
ttk.Frame.__init__(self, master)
Expand Down Expand Up @@ -578,7 +596,14 @@ def __init__(self, master=None, controller=None,globalOptions={},*args, **kwargs
self.frameRate = None
self.disableFileWidgets=False

self.seekpoints = [i/1000 for i in range(1000)]
g = binseq(0,1000)
self.seekpoints = [next(g)/1000 for i in range(1000)]



def searchrandom(self,e):
searchStr = self.searchStringVar.get()
self.controller.jumpToSearch(searchStr,randomjump=True)

def search(self,e):
searchStr = self.searchStringVar.get()
Expand Down Expand Up @@ -709,21 +734,21 @@ def stepForwards(self):

def fastSeek(self,centerAfter=False):
with fastSeekLock:
potential_seekpoints = [x for x in self.seekpoints if abs(x-(self.getCurrentPlaybackPosition()/self.getTotalDuration()))>0.2 ]

if len(potential_seekpoints) == 0:
self.seekpoints = [i/1000 for i in range(1000)]
if len(self.seekpoints) == 0:
g = binseq(0,1000)
self.seekpoints = [next(g)/1000 for i in range(1000)]
print('RESET SEEKPOINTS')

potential_seekpoints = [x for x in self.seekpoints if abs(x-(self.getCurrentPlaybackPosition()/self.getTotalDuration()))>0.2 ]

fn = self.getcurrentFilename()
ranges = self.getRangesForClip(fn)
while 1:
point = random.choice(potential_seekpoints)
self.seekpoints.remove(point)
point = self.seekpoints.pop(0)
clear = True
for s,e in ranges:
if s<=point<=e:
print(point,self.getTotalDuration())
for i,(s,e) in ranges:
print(s,e)
if s<=point*self.getTotalDuration()<=e:
clear = False
break
if clear:
Expand All @@ -747,35 +772,38 @@ def clearVideoMousePress(self):
self.controller.clearVideoRect()

def videomousePress(self,e):
if e.type == tk.EventType.ButtonPress:
logging.debug('video mouse press start')
self.mouseRectDragging=True
self.screenMouseRect[0]=e.x
self.screenMouseRect[1]=e.y
elif e.type in (tk.EventType.Motion,tk.EventType.ButtonRelease) and self.mouseRectDragging:
logging.debug('video mouse press drag')
self.screenMouseRect[2]=e.x
self.screenMouseRect[3]=e.y

vx1,vy1 = self.controller.screenSpaceToVideoSpace(self.screenMouseRect[0],self.screenMouseRect[1])
vx2,vy2 = self.controller.screenSpaceToVideoSpace(self.screenMouseRect[2],self.screenMouseRect[3])

self.controller.setVideoRect(self.screenMouseRect[0],self.screenMouseRect[1],self.screenMouseRect[2],self.screenMouseRect[3],desc='{}x{}'.format(int(abs(vx1-vx2)),int(abs(vy1-vy2))))
if e.type == tk.EventType.ButtonRelease:
logging.debug('video mouse press release')
self.mouseRectDragging=False
if self.screenMouseRect[0] is not None and self.screenMouseRect[2] is not None:
vx1,vy1 = self.controller.screenSpaceToVideoSpace(self.screenMouseRect[0],self.screenMouseRect[1])
vx2,vy2 = self.controller.screenSpaceToVideoSpace(self.screenMouseRect[2],self.screenMouseRect[3])

self.videoMouseRect=[vx1,vy1,vx2,vy2]
self.controller.setVideoRect(self.screenMouseRect[0],self.screenMouseRect[1],self.screenMouseRect[2],self.screenMouseRect[3],desc='{}x{}'.format(int(abs(vx1-vx2)),int(abs(vy1-vy2))))

if self.screenMouseRect[0] is not None and not self.mouseRectDragging and self.screenMouseRect[0]==self.screenMouseRect[2] and self.screenMouseRect[1]==self.screenMouseRect[3]:
logging.debug('video mouse rect clear')
self.screenMouseRect=[None,None,None,None]
self.mouseRectDragging=False
self.controller.clearVideoRect()
try:
if e.type == tk.EventType.ButtonPress:
logging.debug('video mouse press start')
self.mouseRectDragging=True
self.screenMouseRect[0]=e.x
self.screenMouseRect[1]=e.y
elif e.type in (tk.EventType.Motion,tk.EventType.ButtonRelease) and self.mouseRectDragging:
logging.debug('video mouse press drag')
self.screenMouseRect[2]=e.x
self.screenMouseRect[3]=e.y

vx1,vy1 = self.controller.screenSpaceToVideoSpace(self.screenMouseRect[0],self.screenMouseRect[1])
vx2,vy2 = self.controller.screenSpaceToVideoSpace(self.screenMouseRect[2],self.screenMouseRect[3])

self.controller.setVideoRect(self.screenMouseRect[0],self.screenMouseRect[1],self.screenMouseRect[2],self.screenMouseRect[3],desc='{}x{}'.format(int(abs(vx1-vx2)),int(abs(vy1-vy2))))
if e.type == tk.EventType.ButtonRelease:
logging.debug('video mouse press release')
self.mouseRectDragging=False
if self.screenMouseRect[0] is not None and self.screenMouseRect[2] is not None:
vx1,vy1 = self.controller.screenSpaceToVideoSpace(self.screenMouseRect[0],self.screenMouseRect[1])
vx2,vy2 = self.controller.screenSpaceToVideoSpace(self.screenMouseRect[2],self.screenMouseRect[3])

self.videoMouseRect=[vx1,vy1,vx2,vy2]
self.controller.setVideoRect(self.screenMouseRect[0],self.screenMouseRect[1],self.screenMouseRect[2],self.screenMouseRect[3],desc='{}x{}'.format(int(abs(vx1-vx2)),int(abs(vy1-vy2))))

if self.screenMouseRect[0] is not None and not self.mouseRectDragging and self.screenMouseRect[0]==self.screenMouseRect[2] and self.screenMouseRect[1]==self.screenMouseRect[3]:
logging.debug('video mouse rect clear')
self.screenMouseRect=[None,None,None,None]
self.mouseRectDragging=False
self.controller.clearVideoRect()
except Exception as e:
print('Video not loaded',e)

def getCurrentlySelectedRegion(self):
return self.frameTimeLineFrame.getCurrentlySelectedRegion()
Expand Down Expand Up @@ -1077,7 +1105,8 @@ def displayLoopSearchModal(self,useRange=False,rangeStart=None,rangeEnd=None):
def restartForNewFile(self, filename=None):
self.frameRate = None
self.frameTimeLineFrame.resetForNewFile()
self.seekpoints = [i/100 for i in range(100)]
g = binseq(0,1000)
self.seekpoints = [next(g)/1000 for i in range(1000)]
try:
self.frameVideoPlayerlabel.pack_forget()
except:
Expand Down Expand Up @@ -1128,6 +1157,9 @@ def addNewInterestMark(self,point):
def getInterestMarks(self):
return self.controller.getInterestMarks()

def setAB(self, start, end,seekAfter=True):
return self.controller.setAB(start, end, seekAfter=seekAfter)

def addNewSubclip(self, start, end,seekAfter=True):
return self.controller.addNewSubclip(start, end, seekAfter=seekAfter)

Expand Down
8 changes: 5 additions & 3 deletions src/filterSelectionUi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ def refreshtimeLineForNewClip(self):


keyList= self.activeCommandFilterValuePair.getKeyValues()
for timeStamp,value,real in keyList:
for timeStamp,value,real in sorted(keyList):
tx = int((timeStamp/duration)*self.canvasValueTimeline.winfo_width())
ty = heightOffset+(effectiveHeight-(((value-valMin)/valRange)*effectiveHeight))

Expand All @@ -1411,6 +1411,10 @@ def refreshtimeLineForNewClip(self):

lastX,lastY=tx,ty

if lastX is not None and lastY is not None:
self.canvasValueTimeline.create_line(lastX, lastY, self.canvasValueTimeline.winfo_width(), ty,fill="#db6986",tags='KeyValuePoints')


posSeconds = self.controller.getCurrentPlaybackPosition()
for timeStamp,value,real in sorted(keyList,key=lambda lent:abs(lent[0]-posSeconds),reverse=True):
if real:
Expand All @@ -1420,8 +1424,6 @@ def refreshtimeLineForNewClip(self):
self.canvasValueTimeline.create_rectangle(bbox, outline="#69bfdb", fill="#375e6b",tags='ticks')
self.canvasValueTimeline.create_text(tx, 140,text="{:0.2f}".format(value),fill="white",tags='ticks')

if lastX is not None and lastY is not None:
self.canvasValueTimeline.create_line(lastX, lastY, self.canvasValueTimeline.winfo_width(), ty,fill="#db6986",tags='KeyValuePoints')

modeText='No Mode'
if self.activeCommandFilterValuePair.videoSpaceAxis in ('yaw','pitch'):
Expand Down
3 changes: 2 additions & 1 deletion src/filterSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1702,8 +1702,9 @@
{"n": "alpha", "d": 1, "type": "float", "range": None, "inc": 0.1, "_commandVar":['Text-size',[['drawtext@{fn}','alpha']]] }
],
"presets":[
{"preset_name":"Corner Filename White", "bordercolor":"black@0.9", "text":"{!filename}", "x":"20","y":"h-(text_h+20)", "fontsize":"w/10", "fontcolor":"white", "borderw":"5" },
{"preset_name":"Centered Large White", "x":"(w/2)-(text_w/2)","y":"(h/2)-(text_h/2)", "fontsize":"w/7", "fontcolor":"white", "borderw":"10" },
{"preset_name":"Centered Large Violet", "x":"(w/2)-(text_w/2)","y":"(h/2)-(text_h/2)", "fontsize":"w/7", "fontcolor":"violet","borderw":"10" },
{"preset_name":"Centered Large Violet", "x":"(w/2)-(text_w/2)","y":"(h/2)-(text_h/2)", "fontsize":"w/7", "fontcolor":"violet","borderw":"10" },
]
},

Expand Down
12 changes: 9 additions & 3 deletions src/filterValuePair.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,15 @@ def __init__(self, master,controller,param, *args, **kwargs):
self.updateCommandButtonStyles()

def checkCtrl(self,e):
ctrl = e and ((e.state & 0x4) != 0)
shift = e and ((e.state & 0x1) != 0)

ctrl=False
shift=False

try:
ctrl = e and type(e.state) != str and ((e.state & 0x4) != 0)
shift = e and type(e.state) != str and ((e.state & 0x1) != 0)
except Exception as e:
print(e)

if ctrl and not shift:
self.entryFilterValueValue.config(increment=self.originalIncrement*10)
elif shift:
Expand Down
Loading

0 comments on commit 079e9c5

Please sign in to comment.