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

Slight cleanup to pull click actions into own fns #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GavinRay97
Copy link

Just makes it so that the core code of main() is the barebones logic and the details are hidden behind functions that have names describing their conditions

function main()
    reaper.Undo_BeginBlock()
    window, segment, details = reaper.BR_GetMouseCursorContext()
    patternClipHover = hovering_over_pattern()

    -- If the user is hovering over a pattern clip
    if segment == "track" and patternClipHover then
        handle_pattern_left_click()
    elseif window == "unknown" then
        handle_unknown_window_click()
    elseif reaper.JS_Mouse_GetState(1) == 0 and patternLeftClick then
        handle_release_pattern_left_drag()
    elseif reaper.JS_Mouse_GetState(-1) >= 4 then
        -- if the user drags onto the tcp
        reaper.JS_WindowMessage_ReleaseAll()
    elseif window == "tcp" then
        handle_drag_to_tcp()
    elseif segment == "track" then
        handle_cursor_on_track()
    elseif segment ~= "track" then
        reaper.JS_WindowMessage_ReleaseAll()
    end

    -----------------------------------
    --[			Defer Mngmt			 ]--
    -----------------------------------
    if reaper.JS_VKeys_GetState(-1):byte(27) == 1 then
        reaper.atexit(on_exit)
        return
    else
        reaper.defer(main)
    end
end

Just makes it so that the core code of `main()` is the barebones logic and the details are hidden behind functions that have names describing their conditions:

```lua
    if segment == "track" and patternClipHover then
        handle_pattern_left_click()
    elseif window == "unknown" then
        handle_unknown_window_click()
    elseif reaper.JS_Mouse_GetState(1) == 0 and patternLeftClick then
        handle_release_pattern_left_drag()
    elseif reaper.JS_Mouse_GetState(-1) >= 4 then
        -- if the user drags onto the tcp
        reaper.JS_WindowMessage_ReleaseAll()
    elseif window == "tcp" then
        handle_drag_to_tcp()
    elseif segment == "track" then
        handle_cursor_on_track()
    elseif segment ~= "track" then
        reaper.JS_WindowMessage_ReleaseAll()
    end
```
@GavinRay97
Copy link
Author

GavinRay97 commented Jan 24, 2021

Also sorry about the sloppy Git diff -- most of it is just useless formatting changes from IDE's auto-format-on-save feature

Actual content changes are basically just this:
https://github.com/GavinRay97/lemerchand/blob/patch-1/SERA/SERA%20-%20Draw%20Tool.lua#L222-L446

```lua
    elseif reaper.GetToggleCommandState(cmd_ID) == 0 then
        -- If the toggle state of the command is "OFF", don't run, call atexit
        -- (This check is needed for Auto-Arm functionality to be able to work right)
        reaper.atexit(on_exit)
        return
    else
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant