-
Notifications
You must be signed in to change notification settings - Fork 171
Release Cycle Fade Shape (Mousewheel) v1.0 #1604
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
Open
grayson-solis
wants to merge
1
commit into
ReaTeam:master
Choose a base branch
from
grayson-solis:reapack.com_upload-1751599861765
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
Items Editing/graysonsolis_Cycle Fade Shape (Mousewheel).lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| -- @description Cycle Fade Shape (Mousewheel) | ||
| -- @author Grayson Solis | ||
| -- @version 1.0 | ||
| -- @about | ||
| -- -- cycles through fade shapes on an item when hovering over fade curves | ||
| -- -- works for both wheel up and down | ||
|
|
||
| -- mousewheel fade shape editor | ||
| -- cycles through fade shapes when hovering over fade curves | ||
| -- works for both wheel up and down | ||
|
|
||
| function main() | ||
| -- get mouse position | ||
| local mouse_x, mouse_y = reaper.GetMousePosition() | ||
|
|
||
| -- find item under mouse | ||
| local item, take = reaper.GetItemFromPoint(mouse_x, mouse_y, true) | ||
| if not item then return end | ||
|
|
||
| -- get item position and length | ||
| local item_pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION") | ||
| local item_len = reaper.GetMediaItemInfo_Value(item, "D_LENGTH") | ||
| local item_end = item_pos + item_len | ||
|
|
||
| -- convert mouse X to project time | ||
| local start_time, end_time = reaper.GetSet_ArrangeView2(0, false, 0, 0) | ||
| local arrange_left = 0 | ||
| local arrange_width = 1000 | ||
|
|
||
| -- get the arrange view dimensions | ||
| local hwnd = reaper.GetMainHwnd() | ||
| local arrange_hwnd = reaper.JS_Window_FindChildByID(hwnd, 1000) | ||
| if arrange_hwnd then | ||
| local retval, left, top, right, bottom = reaper.JS_Window_GetRect(arrange_hwnd) | ||
| arrange_width = right - left | ||
| arrange_left = left | ||
| end | ||
|
|
||
| -- calculate time from mouse position | ||
| local relative_x = mouse_x - arrange_left | ||
| local time_per_pixel = (end_time - start_time) / arrange_width | ||
| local project_time = start_time + (relative_x * time_per_pixel) | ||
|
|
||
| -- get fade info | ||
| local fadein_len = reaper.GetMediaItemInfo_Value(item, "D_FADEINLEN") | ||
| local fadeout_len = reaper.GetMediaItemInfo_Value(item, "D_FADEOUTLEN") | ||
| local fadein_shape = reaper.GetMediaItemInfo_Value(item, "C_FADEINSHAPE") | ||
| local fadeout_shape = reaper.GetMediaItemInfo_Value(item, "C_FADEOUTSHAPE") | ||
|
|
||
| -- check if over fade areas | ||
| local is_over_fadein = (project_time >= item_pos and project_time <= item_pos + fadein_len and fadein_len > 0) | ||
| local is_over_fadeout = (project_time >= item_end - fadeout_len and project_time <= item_end and fadeout_len > 0) | ||
|
|
||
| if not (is_over_fadein or is_over_fadeout) then return end | ||
|
|
||
| -- detect wheel direction from recent input | ||
| local wheel_dir = 0 | ||
| local is_new, name, midi_val = reaper.MIDI_GetRecentInputEvent(0) | ||
|
|
||
| if is_new then | ||
| if midi_val == 1 then -- wheel up | ||
| wheel_dir = 1 | ||
| elseif midi_val == 127 then -- wheel down | ||
| wheel_dir = -1 | ||
| end | ||
| end | ||
|
|
||
| -- alternative method using get_action_context | ||
| if wheel_dir == 0 then | ||
| local is_new, name, sectionID, cmdID, mode, resolution, val = reaper.get_action_context() | ||
| if val > 0 then | ||
| wheel_dir = 1 -- wheel up | ||
| elseif val < 0 then | ||
| wheel_dir = -1 -- wheel down | ||
|
Comment on lines
+72
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Up/down is inverted: scrolling up selects the previous fade & vice versa (ignore if it's the intended behavior). |
||
| end | ||
| end | ||
|
|
||
| if wheel_dir == 0 then return end | ||
|
|
||
| -- Cycle through shapes | ||
| local function cycle_shape(current_shape, direction) | ||
| local new_shape = current_shape + direction | ||
| if new_shape > 6 then new_shape = 0 end | ||
| if new_shape < 0 then new_shape = 6 end | ||
| return new_shape | ||
| end | ||
|
|
||
| reaper.Undo_BeginBlock() | ||
|
|
||
| if is_over_fadein then | ||
| local new_shape = cycle_shape(fadein_shape, wheel_dir) | ||
| reaper.SetMediaItemInfo_Value(item, "C_FADEINSHAPE", new_shape) | ||
| reaper.Undo_EndBlock("Change fade in shape", -1) | ||
| elseif is_over_fadeout then | ||
| local new_shape = cycle_shape(fadeout_shape, wheel_dir) | ||
| reaper.SetMediaItemInfo_Value(item, "C_FADEOUTSHAPE", new_shape) | ||
| reaper.Undo_EndBlock("Change fade out shape", -1) | ||
| end | ||
|
|
||
| reaper.UpdateArrange() | ||
| end | ||
|
|
||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be bogus? The third return value of
MIDI_GetRecentInputEventis "timestamp in samples relative to the current position".