Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Improved multicamMatchFrame() to handle some additional cases.
* Added Playhead:show() actually scrolling to the playhead if it is present.
* Added TimelineContents:playheadClipsUI(…) function to support finding the clips under the playhead, ordered top to bottom.
  • Loading branch information
randomeizer committed Jan 16, 2017
1 parent c4cff39 commit 5af2a67
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 10 deletions.
34 changes: 28 additions & 6 deletions src/hs/fcpxhacks/modules/fcpx10-3.lua
Expand Up @@ -4627,6 +4627,21 @@ end
-- Delete any pre-existing highlights:
--------------------------------------------------------------------------------
deleteAllHighlights()

local contents = fcp:timeline():contents()

--------------------------------------------------------------------------------
-- Store the originally-selected clips
--------------------------------------------------------------------------------
local originalSelection = contents:selectedClipsUI()

--------------------------------------------------------------------------------
-- If nothing is selected, select the top clip under the playhead:
--------------------------------------------------------------------------------
if not originalSelection or #originalSelection == 0 then
local playheadClips = contents:playheadClipsUI(true)
contents:selectClip(playheadClips[1])
end

--------------------------------------------------------------------------------
-- Get Multicam Angle:
Expand Down Expand Up @@ -4654,20 +4669,22 @@ end
if menuBar:isEnabled("Window", "Go To", "Timeline") then
menuBar:selectMenu("Window", "Go To", "Timeline")
else
dialog.displayErrorMessage("Unable to return to timeline.\n\n" .. errorFunction)
dialog.displayErrorMessage("Unable to return to timeline." .. errorFunction)
return
end

--------------------------------------------------------------------------------
-- Ensure the playhead is visible:
--------------------------------------------------------------------------------
contents:playhead():show()

fcp:timeline():contents():selectClipInAngle(multicamAngle)
contents:selectClipInAngle(multicamAngle)

--------------------------------------------------------------------------------
-- Reveal In Browser:
--------------------------------------------------------------------------------
if menuBar:isEnabled("File", "Reveal in Browser") then
menuBar:selectMenu("File", "Reveal in Browser")
else
dialog.displayErrorMessage("No clip is available in the current angle under the playhead." .. errorFunction)
return
end

--------------------------------------------------------------------------------
Expand All @@ -4681,6 +4698,11 @@ end
return
end
end

--------------------------------------------------------------------------------
-- Select the original clips again.
--------------------------------------------------------------------------------
contents:selectClips(originalSelection)

--------------------------------------------------------------------------------
-- Highlight Browser Playhead:
Expand All @@ -4694,7 +4716,7 @@ end
--------------------------------------------------------------------------------
function getMulticamAngleFromSelectedClip()

local errorFunction = " Error occurred in getMulticamAngleFromSelectedClip()."
local errorFunction = "\n\nError occurred in getMulticamAngleFromSelectedClip()."

--------------------------------------------------------------------------------
-- Ninja Pasteboard Copy:
Expand Down
15 changes: 13 additions & 2 deletions src/hs/finalcutpro/main/Playhead.lua
Expand Up @@ -81,9 +81,20 @@ end
function Playhead:show()
local parent = self:parent()
-- show the parent.
if parent:show() then
if parent:show():isShowing() then
-- ensure the playhead is visible
-- TODO
if parent.viewFrame then
local viewFrame = parent:viewFrame()
local position = self:getPosition()
if position < viewFrame.x or position > (viewFrame.x + viewFrame.w) then
-- Need to move the scrollbar
local timelineFrame = parent:timelineFrame()
local scrollWidth = timelineFrame.w - viewFrame.w
local scrollPoint = position - viewFrame.w/2 - timelineFrame.x
local scrollTarget = scrollPoint/scrollWidth
parent:scrollHorizontalTo(scrollTarget)
end
end
end
return self
end
Expand Down
31 changes: 29 additions & 2 deletions src/hs/finalcutpro/main/TimelineContents.lua
Expand Up @@ -237,6 +237,34 @@ function TimelineContents:clipsUI(expandGroups, filterFn)
return nil
end

--- hs.finalcutpro.main.TimelineContents:playheadClipsUI(expandedGroups, filterFn) -> table of axuielements
--- Function
--- Returns a table array containing the list of clips in the Timeline under the playhead, ordered with the
--- highest clips at the beginning of the array.
---
--- If `expandsGroups` is true any AXGroup items will be expanded to the list of contained `AXLayoutItems`.
---
--- If `filterFn` is provided it will be called with a single argument to check if the provided
--- clip should be included in the final table.
---
--- Parameters:
--- * expandGroups - (optional) if true, expand AXGroups to include contained AXLayoutItems
--- * filterFn - (optional) if provided, the function will be called to check each clip
---
--- Returns:
--- * The table of axuielements that match the conditions
---
function TimelineContents:playheadClipsUI(expandGroups, filterFn)
local playheadPosition = self:playhead():getPosition()
local clips = self:clipsUI(expandGroups, function(clip)
local frame = clip:frame()
return frame and playheadPosition >= frame.x and playheadPosition <= (frame.x + frame.w)
and (filterFn == nil or filterFn(clip))
end)
table.sort(clips, function(a, b) return a:position().y < b:position().y end)
return clips
end

function TimelineContents:_filterClips(clips, expandGroups, filterFn)
if expandGroups then
return self:_expandClips(clips, filterFn)
Expand Down Expand Up @@ -277,7 +305,6 @@ function TimelineContents:selectClip(clipUI)
return self:selectClips({clipUI})
end


-----------------------------------------------------------------------
-----------------------------------------------------------------------
--- MULTICAM ANGLE EDITOR
Expand Down Expand Up @@ -319,6 +346,7 @@ function TimelineContents:selectClipInAngle(angleNumber)
local clipsUI = self:anglesUI()
if clipsUI then
local angleUI = clipsUI[angleNumber]

local playheadPosition = self:playhead():getPosition()
local clipUI = axutils.childMatching(angleUI, function(child)
local frame = child:frame()
Expand All @@ -329,7 +357,6 @@ function TimelineContents:selectClipInAngle(angleNumber)
self:monitorVideoInAngle(angleNumber)

if clipUI then
debugMessage("Selecting a clip in angle "..angleNumber..":\n".._inspect(clipUI))
self:selectClip(clipUI)
else
debugMessage("Unable to find the clip under the playhead for angle "..angleNumber..".")
Expand Down

0 comments on commit 5af2a67

Please sign in to comment.