Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark & Review: cp.apple.finalcut.main.Viewer.isPlaying #1445

Closed
latenitefilms opened this issue Aug 18, 2018 · 3 comments
Closed

Benchmark & Review: cp.apple.finalcut.main.Viewer.isPlaying #1445

latenitefilms opened this issue Aug 18, 2018 · 3 comments
Assignees
Labels
Milestone

Comments

@latenitefilms
Copy link
Contributor

No description provided.

@latenitefilms
Copy link
Contributor Author

Currently I'm using hs.timer.delayed - which is probably the wrong idea. We should see if cp.deferred is more appropriate.

@latenitefilms
Copy link
Contributor Author

@randomeizer - As discussed on Messenger...

Currently, cp.apple.finalcut.main.Viewer.isPlaying is a cp.prop that's updated by the following code:

    local checker
    checker = delayedTimer.new(0.2, function()
        if self.isPlaying:update() then
            -----------------------------------------------------------------------
            -- It hasn't actually finished yet, so keep running:
            -----------------------------------------------------------------------
            checker:start()
        end
    end)

    -----------------------------------------------------------------------
    -- Watch the `timecode` field and update `isPlaying`:
    -----------------------------------------------------------------------
    self.timecode:watch(function()
        if not checker:running() then
            -----------------------------------------------------------------------
            -- Update the first time:
            -----------------------------------------------------------------------
            self.isPlaying:update()
        end
        checker:start()
    end)

cp.apple.finalcutpro.main.Viewer.timecode is a cp.prop that's a mutation of cp.apple.finalcutpro.main.Viewer.timecodeText - specifically:

--- cp.apple.finalcutpro.main.Viewer.timecode <cp.prop: string; live>
--- Field
--- The current timecode value, with the format "hh:mm:ss:ff". Setting also supports "hh:mm:ss;ff".
--- The property can be watched to get notifications of changes.
function Viewer.lazy.prop:timecode()
    return self:timecodeText().value:mutate(

cp.apple.finalcutpro.main.Viewer.timecodeText is a cp.ui.StaticText object - specifically:

function Viewer.lazy.method:timecodeText()
    return StaticText(self, self.bottomToolbarUI:mutate(function(original)
        local ui = original()
        return ui and childFromLeft(childrenWithRole(ui, "AXStaticText"), 1)
    end))
end

cp.ui.StaticText.value uses the following code:

--- cp.ui.StaticText.value <cp.prop: anything>
--- Field
--- The current value of the text field.
function StaticText.lazy.prop:value()
    local value = self.UI:mutate(
        function(original)
            local ui = original()
            local value = ui and ui:attributeValue("AXValue") or nil
            if value and self._convertFn then
                value = self._convertFn(value)
            end
            return value
        end,
        function(value, original)
            local ui = original()
            if ui then
                value = tostring(value)
                local focused = ui:attributeValue("AXFocused")
                ui:setAttributeValue("AXFocused", true)
                ui:setAttributeValue("AXValue", value)
                ui:performAction("AXConfirm")
                ui:setAttributeValue("AXFocused", focused)
            end
        end
    )

    -----------------------------------------------------------------------
    -- Reduce the amount of AX notifications when timecode is updated:
    -----------------------------------------------------------------------
    local timecodeUpdater
    timecodeUpdater = delayedTimer.new(0.001, function()
        value:update()
    end)

    -- wire up a notifier to watch for value changes.
    value:preWatch(function()
        self:notifier():watchFor("AXValueChanged", function()
            timecodeUpdater:start()
        end):start()
    end)

    return value
end

This should all be reviewed, to make sure it's the best way we should be handling things.

@latenitefilms latenitefilms changed the title Benchmark & Review cp.apple.finalcut.main.Viewer.isPlaying Benchmark & Review: cp.apple.finalcut.main.Viewer.isPlaying Jan 19, 2019
@latenitefilms
Copy link
Contributor Author

I don't think we're ever going to have time to go back and "review" stuff, so I'm just going to close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants