Skip to content

Commit

Permalink
Merge branch 'ReaTeam:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tormyvancool authored Nov 1, 2024
2 parents aef8a0c + f686e0a commit 6a59cec
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
-- @description Split items at timeline grid (with extra options)
-- @author amagalma
-- @version 1.00
-- @donation https://www.paypal.me/amagalma
-- @about
-- Splits selected items at timeline grid. Choice of the exact placement of the split (or of the cross-fade, if any) is offered.
--
-- - Requires ReaImgui and SWS Extensions


package.path = reaper.ImGui_GetBuiltinPath() .. '/?.lua'
local ImGui = require 'imgui' '0.9.3.2'

local ctx = ImGui.CreateContext('amagalma_Split item at specified note durations')
local window_flags = ImGui.WindowFlags_NoCollapse | ImGui.WindowFlags_AlwaysAutoResize

local ext = "amagalma_SplitAtGrid"
local rv, splitautoxfade, restore_autoxfade
local crossfade = reaper.HasExtState( ext, "place" ) and tonumber(reaper.GetExtState( ext, "place" )) or 0
local finetune = reaper.HasExtState( ext, "fine" ) and tonumber(reaper.GetExtState( ext, "fine" )) or 0


local function loop()
local visible, open = ImGui.Begin(ctx, 'Split items at timeline grid', true, window_flags)
if visible then

ImGui.Text(ctx, "Crossfade placement:")
rv,crossfade = ImGui.RadioButtonEx(ctx, 'left', crossfade, 0); ImGui.SameLine(ctx)
rv,crossfade = ImGui.RadioButtonEx(ctx, 'center', crossfade, 1); ImGui.SameLine(ctx)
rv,crossfade = ImGui.RadioButtonEx(ctx, 'right', crossfade, 2); ImGui.SameLine(ctx)
rv,crossfade = ImGui.RadioButtonEx(ctx, 'none', crossfade, 3);

ImGui.Spacing(ctx) ; ImGui.Spacing(ctx) ; ImGui.Separator(ctx) ; ImGui.Spacing(ctx)

ImGui.Text(ctx, "Split placement fine tuning:") ; ImGui.Spacing(ctx)
rv, finetune = ImGui.DragInt(ctx, ' ms', finetune, 0.25)
ImGui.Spacing(ctx) ; ImGui.Spacing(ctx) ; ImGui.Separator(ctx) ; ImGui.Spacing(ctx)

if ImGui.Button(ctx, " Change grid ",0, 0) then
reaper.Main_OnCommand(reaper.NamedCommandLookup('_RS968436cb97d25a22a749f6291f35d4638fe6f0c6'), 0) -- amagalma_Set project grid (via dropdown menu).lua
end

ImGui.SameLine(ctx)

if ImGui.Button(ctx, " Split items ",0, 0) and reaper.CountSelectedMediaItems(0) > 0 then
reaper.PreventUIRefresh(1)
if finetune ~=0 then
reaper.ApplyNudge( 0, 0, 0, 0, finetune, true, 0 )
end
--set crossfade
if crossfade == 3 then
if reaper.GetToggleCommandState( 40912 ) == 1 then
reaper.Main_OnCommand(40928, 0) -- Disable crossfade on split (disregard toolbar auto-crossfade button)
restore_autoxfade = true
end
else
splitautoxfade = tonumber(({reaper.get_config_var_string( "splitautoxfade" )})[2])
local xf_left = splitautoxfade & 131072 ~= 0
local xf_center = splitautoxfade & 262144 ~= 0
local current_crossfade = xf_left and 0 or xf_center and 1 or 2
if crossfade ~= current_crossfade then -- set wanted placement
local set, clear
if crossfade == 0 then
set, clear = 131072, 262144
elseif crossfade == 1 then
set, clear = 262144, 131072
else
clear = 131072 | 262144
end
local splitautoxfade_new = splitautoxfade & ~clear
reaper.SNM_SetIntConfigVar( "splitautoxfade", (set and (splitautoxfade_new | set) or splitautoxfade_new) )
end
end
reaper.Main_OnCommand(40932, 0) -- Split items at timeline grid
-- Recover
if finetune ~=0 then -- bring it back
reaper.ApplyNudge( 0, 0, 0, 0, -finetune, true, 0 )
end
if crossfade ~= current_crossfade then -- set it back
if crossfade ~= 3 then
reaper.SNM_SetIntConfigVar( "splitautoxfade", splitautoxfade )
else
if restore_autoxfade then
reaper.Main_OnCommand(40927, 0) -- Enable crossfade on split (disregard toolbar auto-crossfade button)
end
end
end
reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()
reaper.Undo_OnStateChange("Split items at grid")
end

ImGui.Spacing(ctx) ;
ImGui.End(ctx)
end
if open then
reaper.defer(loop)
end
end

reaper.atexit(function()
reaper.SetExtState( ext, "place", tostring(crossfade), true )
reaper.SetExtState( ext, "fine", tostring(finetune), true )
end)

reaper.defer(loop)
18 changes: 17 additions & 1 deletion index.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<index version="1" commit="e7af1cdef8363fcdf318889dd0640715f709ff7e" name="ReaTeam Scripts">
<index version="1" commit="60103e6afcf3287bd81140cac24c62a2bb6f96ef" name="ReaTeam Scripts">
<category name="Cursor">
<reapack name="amagalma_Move edit cursor to closest item edge (among the selected items).lua" type="script" desc="Move edit cursor to closest item edge (among the selected items)">
<metadata>
Expand Down Expand Up @@ -5809,6 +5809,22 @@ website
<source main="main" file="amagalma_Split item at mouse cursor position ( Define crossfade and selection settings ).lua">https://github.com/ReaTeam/ReaScripts/raw/998589da431136238f6adae799c8139bb23ef1e2/Items%20Editing/amagalma_Split%20item%20at%20mouse%20cursor%20position%20(%20use%20defined%20crossfade%20and%20selection%20settings%20)/amagalma_Split%20item%20at%20mouse%20cursor%20position%20(%20Define%20crossfade%20and%20selection%20settings%20).lua</source>
</version>
</reapack>
<reapack name="amagalma_Split items at timeline grid (with extra options).lua" type="script" desc="Split items at timeline grid (with extra options)">
<metadata>
<description><![CDATA[{\rtf1\ansi\deff0{\fonttbl{\f0 \fswiss Helvetica;}{\f1 Courier;}}
{\colortbl;\red255\green0\blue0;\red0\green0\blue255;}
\widowctrl\hyphauto

{\pard \ql \f0 \sa180 \li0 \fi0 Splits selected items at timeline grid. Choice of the exact placement of the split (or of the cross-fade, if any) is offered.\par}
{\pard \ql \f0 \sa0 \li360 \fi-360 \bullet \tx360\tab Requires ReaImgui and SWS Extensions\sa180\par}
}
]]></description>
<link rel="donation">https://www.paypal.me/amagalma</link>
</metadata>
<version name="1.00" author="amagalma" time="2024-11-01T09:28:53Z">
<source main="main">https://github.com/ReaTeam/ReaScripts/raw/60103e6afcf3287bd81140cac24c62a2bb6f96ef/Items%20Editing/amagalma_Split%20items%20at%20timeline%20grid%20(with%20extra%20options).lua</source>
</version>
</reapack>
<reapack name="amagalma_Split items under mouse with selection option (selected items get priority over grouped).lua" type="script" desc="Split items under mouse with selection option (selected items get priority over grouped)">
<metadata>
<description><![CDATA[{\rtf1\ansi\deff0{\fonttbl{\f0 \fswiss Helvetica;}{\f1 Courier;}}
Expand Down

0 comments on commit 6a59cec

Please sign in to comment.