Old 09-21-2023, 05:25 AM   #1
b4s1c
Human being with feelings
 
Join Date: May 2021
Posts: 1
Default Script lua: Real-time Editing Progress Monitor

Hello fellow REAPER users!

I'm excited to introduce a script developed with the assistance of OpenAI that can greatly aid your editing workflow. It’s designed to give you a real-time perspective of your editing progress, letting you know how much of the content you've edited and how much is left.



Features:

1. Displays the time you've already edited (Done).
2. Shows the remaining time to the end of a region named "Timecode" (Remaining).
3. Visual representation of completion percentage (Completion).
4. A progress bar that visually shows how much of the "Timecode" region has been completed.
5. An Elapsed time counter, counting the time since the script was initiated.
6. Ability to pause the Elapsed time using the space key.
7. A blinking (Paused) effect when Elapsed time is paused.
8. Reset the Elapsed time counter using the 'R' key.

How it works:

- The script predominantly revolves around a region named "Timecode". If no such region exists, the script will exit.

- FormatTime function is in charge of converting time (in seconds) into a readable HH:MM:SS format, with an optional ability to add milliseconds.

- The drawProgress function draws a progress bar indicating how far along in the editing process you are relative to the entirety of the "Timecode" region.

Instructions:

1. Run the script.
2. Begin editing within the "Timecode" region.
3. Monitor your progress via the script window.
4. Pause the Elapsed time anytime using the space key or reset it using the 'R' key.

Without further ado, here's the script:

Code:
-- Inicjacja okna gfx
gfx.init("Time Remaining", 230, 130)

function FormatTime(totalSeconds, includeMillis)
    local hours = math.floor(totalSeconds / 3600)
    local mins = math.floor(totalSeconds / 60 - (hours * 60))
    local secs = math.floor(totalSeconds % 60)
    if includeMillis then
        local millis = math.floor((totalSeconds * 1000) % 1000)
        return string.format("%02d:%02d:%02d.%03d", hours, mins, secs, millis)
    else
        return string.format("%02d:%02d:%02d", hours, mins, secs)
    end
end

function drawProgress(completionPercentage)
    local barWidth = 200
    local barHeight = 10
    local filledWidth = barWidth * (completionPercentage / 100)

    gfx.rect(10, 70, barWidth, barHeight, false) -- Outline
    gfx.rect(10, 70, filledWidth, barHeight, true) -- Filled portion
end

local startTime = os.time()
local pausedTime = 0
local lastPauseStart = 0
local elapsedAtPause = 0 -- New variable to store the elapsed time at the moment of pausing
local isPaused = false
local showPaused = true -- Dla efektu migania
local blinkTime = os.time()

function Main()
    local numMarkers = reaper.CountProjectMarkers()
    local timecodeRegionStart = nil
    local timecodeRegionEnd = nil

    for i = 0, numMarkers - 1 do
        local _, isRegion, pos, rgnend, name = reaper.EnumProjectMarkers(i)
        if isRegion and name == "Timecode" then
            timecodeRegionStart = pos
            timecodeRegionEnd = rgnend
            break
        end
    end

    if not timecodeRegionStart then
        gfx.quit()
        return
    end

    local playPosition = reaper.GetPlayPosition()

    -- Oblicz pozostały czas i czas wykonania
    local doneTime = playPosition - timecodeRegionStart
    local remainingTime = timecodeRegionEnd - playPosition
    local totalTime = timecodeRegionEnd - timecodeRegionStart
    local completionPercentage = (doneTime / totalTime) * 100

    gfx.x = 10
    gfx.y = 10
    gfx.drawstr("Done: " .. FormatTime(doneTime, true))

    gfx.x = 10
    gfx.y = 30
    gfx.drawstr("Remaining: " .. FormatTime(remainingTime, true))

    gfx.x = 10
    gfx.y = 50
    gfx.drawstr(string.format("Completion: %.2f%%", completionPercentage))

    drawProgress(completionPercentage)

    -- Handle keyboard inputs
    local char = gfx.getchar()
    
    -- Reset Elapsed time with "R"
    if char == 114 then 
        startTime = os.time()
        pausedTime = 0
        isPaused = false
    end

    -- Pause with Spacebar
    if char == 32 and not lastSpacePressed then  -- Space pressed
        lastSpacePressed = true
        if isPaused then
            isPaused = false
            pausedTime = pausedTime + os.difftime(os.time(), lastPauseStart)
        else
            isPaused = true
            lastPauseStart = os.time()
            showPaused = true
            blinkTime = os.time()
            elapsedAtPause = os.difftime(os.time(), startTime) - pausedTime -- Capture elapsed time at pause moment
        end
    elseif char ~= 32 then
        lastSpacePressed = false
    end

    local elapsed = isPaused and elapsedAtPause or os.difftime(os.time(), startTime) - pausedTime

    -- Blinking logic when paused
    if isPaused and os.difftime(os.time(), blinkTime) >= 1 then
        showPaused = not showPaused
        blinkTime = os.time()
    end

    if showPaused or not isPaused then
        gfx.x = 10
        gfx.y = 90
        gfx.drawstr("Elapsed: " .. FormatTime(elapsed, false))
    end

    if isPaused then
        gfx.x = 10
        gfx.y = 110
        gfx.drawstr("(Paused)")
    end

    -- Refresh window
    gfx.update()

    if char >= 0 then
        reaper.defer(Main)
    end
end

Main()
I'd like to express my gratitude to the community for your continued support and ChatGPT for their immense help in creating this script. I truly hope you find this tool beneficial and would love to hear your thoughts, feedback, and suggestions!

Best,
B4s1c
Attached Images
File Type: png Zrzut ekranu 2023-09-21 o 14.24.43.png (32.6 KB, 66 views)
b4s1c is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.