4PointCutting: First commit, working but probably not bug-free
This commit is contained in:
parent
83616afb05
commit
2ba98cd1de
144
4PointCutting/4Pcut_execute.lua
Normal file
144
4PointCutting/4Pcut_execute.lua
Normal file
@ -0,0 +1,144 @@
|
||||
local stored_cursorPos = 0
|
||||
local stored_timeSelStart = 0
|
||||
local stored_timeSelEnd = 0
|
||||
local stored_sel_tracks = {}
|
||||
local stored_sel_items = {}
|
||||
local mark_srcin_pos = -1
|
||||
local mark_srcin_id = -1
|
||||
local mark_srcout_pos = -1
|
||||
local mark_srcout_id = -1
|
||||
local mark_dstin_pos = -1
|
||||
local mark_dstin_id = -1
|
||||
local mark_dstout_pos = -1
|
||||
local mark_dstout_id = -1
|
||||
|
||||
-- Send a message to the console
|
||||
function msg(m)
|
||||
reaper.ShowConsoleMsg(tostring(m) .. "\n")
|
||||
end
|
||||
|
||||
function select_src_tracks()
|
||||
local tracks_str = ''
|
||||
local tracks = {}
|
||||
local retval
|
||||
|
||||
retval, tracks_str = reaper.GetProjExtState(0, '4PointCut', 'src_tracks')
|
||||
if retval > 0 then -- variable exists in rpp
|
||||
-- separate GUIDs and populate track table
|
||||
for str in string.gmatch(tracks_str, "([^"..'{'.."]+)") do
|
||||
table.insert(tracks, reaper.BR_GetMediaTrackByGUID(0, '{' .. str))
|
||||
end
|
||||
-- select tracks
|
||||
--reaper.Main_OnCommand(40297, 0) -- Unselect all tracks
|
||||
for _, track in ipairs(tracks) do
|
||||
reaper.SetTrackSelected(track, true)
|
||||
end
|
||||
else
|
||||
-- default to all tracks
|
||||
for i = 0, reaper.CountTracks(0)-1 do
|
||||
reaper.SetTrackSelected(reaper.GetTrack(0, i), true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function select_dst_track_only()
|
||||
local track_str = ''
|
||||
local retval
|
||||
retval, track_str = reaper.GetProjExtState(0, '4PointCut', 'dst_track')
|
||||
if retval > 0 then -- variable exists in rpp
|
||||
reaper.SetOnlyTrackSelected(reaper.BR_GetMediaTrackByGUID(0, track_str))
|
||||
else --default to first track
|
||||
reaper.SetOnlyTrackSelected(reaper.GetTrack(0, 0))
|
||||
end
|
||||
end
|
||||
|
||||
-- START HERE vvvvvvvvvvvvvvvvvvvvvvvvvv
|
||||
-- Store cursor position, time selection, selected tracks, selected items
|
||||
stored_cursorPos = reaper.GetCursorPosition()
|
||||
stored_timeSelStart, stored_timeSelEnd = reaper.GetSet_LoopTimeRange(false, true, 0, 1, false)
|
||||
for i = 0, reaper.CountSelectedTracks(0)-1 do
|
||||
stored_sel_tracks[i+1] = reaper.GetSelectedTrack(0, i)
|
||||
end
|
||||
for i = 0, reaper.CountSelectedMediaItems(0)-1 do
|
||||
stored_sel_items[i+1] = reaper.GetSelectedMediaItem(0, i)
|
||||
end
|
||||
if reaper.CountSelectedMediaItems(0) > 0 then
|
||||
reaper.Main_OnCommand(40289, 0) -- Unselect all items
|
||||
end
|
||||
if reaper.CountSelectedTracks(0) > 0then
|
||||
reaper.Main_OnCommand(40297, 0) -- Unselect all tracks
|
||||
end
|
||||
--reaper.Main_OnCommand(40769, 0)
|
||||
select_src_tracks() -- select tracks specified in rpp (by using 4Pcut_set_src-tracks.lua)
|
||||
|
||||
-- run through all markers and get position of the 4 points
|
||||
local nof_markers = 0
|
||||
_, nof_markers, _ = reaper.CountProjectMarkers(0)
|
||||
for i = 0, nof_markers - 1 do
|
||||
local name = ''
|
||||
local pos = 0
|
||||
local id = 0
|
||||
local isregion = false
|
||||
_, isregion, pos, _, name, id = reaper.EnumProjectMarkers(i)
|
||||
if not isregion then
|
||||
if name == 'SRC-IN_4Pcut' then
|
||||
mark_srcin_pos = pos
|
||||
mark_srcin_id = id
|
||||
elseif name == 'SRC-OUT_4Pcut' then
|
||||
mark_srcout_pos = pos
|
||||
mark_srcout_id = id
|
||||
elseif name == 'DST-IN_4Pcut' then
|
||||
mark_dstin_pos = pos
|
||||
mark_dstin_id = id
|
||||
elseif name == 'DST-OUT_4Pcut' then
|
||||
mark_dstout_pos = pos
|
||||
mark_dstout_id = id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- error messages
|
||||
if mark_srcin_pos < 0 then
|
||||
msg('Please set Source-In Marker first!')
|
||||
return
|
||||
end
|
||||
if mark_srcout_pos < 0 then
|
||||
msg('Please set Source-Out Marker first!')
|
||||
end
|
||||
if mark_dstin_pos < 0 then
|
||||
msg('Please set Destination-In Marker first!')
|
||||
return
|
||||
end
|
||||
|
||||
-- Do stuff before actual edits...
|
||||
reaper.Undo_BeginBlock()
|
||||
|
||||
|
||||
-- Set Source Time selection and Copy Items
|
||||
reaper.GetSet_LoopTimeRange(true, false, mark_srcin_pos, mark_srcout_pos, false)
|
||||
reaper.Main_OnCommand(40718, 0) -- select items on selected tracks under time selection
|
||||
reaper.Main_OnCommand(40060, 0) -- copy selected items under time selection 41383
|
||||
-- reaper.Main_OnCommand( reaper.NamedCommandLookup('_SWS_SMARTCOPY'), 0 )
|
||||
|
||||
|
||||
-- Move edit cursor to Dest-In and Paste
|
||||
--reaper.GoToMarker(0, mark_dstin_id, false)
|
||||
-- reaper.GetSet_LoopTimeRange(true, false, mark_dstin_pos, mark_dstout_pos, false)
|
||||
reaper.MoveEditCursor(mark_dstin_pos - reaper.GetCursorPosition(), false)
|
||||
select_dst_track_only()
|
||||
reaper.Main_OnCommand(40058, 0) -- paste item
|
||||
reaper.SetProjectMarker(mark_dstin_id, false, mark_dstin_pos + (mark_srcout_pos - mark_srcin_pos), 0, 'DST-IN_4Pcut')
|
||||
|
||||
-- Restore cursor position, time selection, selected tracks, selected items
|
||||
reaper.MoveEditCursor(stored_cursorPos - reaper.GetCursorPosition(), false)
|
||||
reaper.Main_OnCommand(40297, 0) -- Unselect all tracks
|
||||
for _, track in ipairs(stored_sel_tracks) do
|
||||
reaper.SetTrackSelected(track, true)
|
||||
end
|
||||
reaper.Main_OnCommand(40289, 0) -- Unselect all items
|
||||
for _, item in ipairs(stored_sel_items) do
|
||||
reaper.SetMediaItemSelected(item, true)
|
||||
end
|
||||
reaper.GetSet_LoopTimeRange(true, true, stored_timeSelStart, stored_timeSelEnd, false)
|
||||
|
||||
reaper.Undo_EndBlock('4 point cut: Execute', 4) -- 4 is a flag for actions concerning items
|
22
4PointCutting/4Pcut_reset_markers.lua
Normal file
22
4PointCutting/4Pcut_reset_markers.lua
Normal file
@ -0,0 +1,22 @@
|
||||
local nof_markers = 0
|
||||
local id = -1
|
||||
local name = ''
|
||||
local isregion = false
|
||||
local ids = {}
|
||||
|
||||
-- check if markers exist
|
||||
_, nof_markers, _ = reaper.CountProjectMarkers(0)
|
||||
for i = 0, nof_markers - 1 do
|
||||
_, isregion, _, _, name, id = reaper.EnumProjectMarkers(i)
|
||||
if not isregion and
|
||||
(name == 'SRC-IN_4Pcut' or
|
||||
name == 'SRC-OUT_4Pcut' or
|
||||
name == 'DST-IN_4Pcut' or
|
||||
name == 'DST-OUT_4Pcut') then
|
||||
table.insert(ids, id)
|
||||
end
|
||||
end
|
||||
-- delete markers
|
||||
for _, id in ipairs(ids) do
|
||||
reaper.DeleteProjectMarker(0, id, false)
|
||||
end
|
2
4PointCutting/4Pcut_reset_src-dest-tracks.lua
Normal file
2
4PointCutting/4Pcut_reset_src-dest-tracks.lua
Normal file
@ -0,0 +1,2 @@
|
||||
reaper.SetProjExtState(0, '4PointCut', 'dst_track', '')
|
||||
reaper.SetProjExtState(0, '4PointCut', 'src_tracks', '')
|
13
4PointCutting/4Pcut_select_dst-track.lua
Normal file
13
4PointCutting/4Pcut_select_dst-track.lua
Normal file
@ -0,0 +1,13 @@
|
||||
-- Send a message to the console
|
||||
function msg(m)
|
||||
reaper.ShowConsoleMsg(tostring(m) .. "\n")
|
||||
end
|
||||
|
||||
-- START HERE vvvvvvvvvvvvvvvvv
|
||||
local track_str = ''
|
||||
local retval
|
||||
|
||||
retval, track_str = reaper.GetProjExtState(0, '4PointCut', 'dst_track')
|
||||
if retval > 0 then -- variable exists in rpp
|
||||
reaper.SetOnlyTrackSelected(reaper.BR_GetMediaTrackByGUID(0, track_str))
|
||||
end
|
22
4PointCutting/4Pcut_select_src-tracks.lua
Normal file
22
4PointCutting/4Pcut_select_src-tracks.lua
Normal file
@ -0,0 +1,22 @@
|
||||
-- Send a message to the console
|
||||
function msg(m)
|
||||
reaper.ShowConsoleMsg(tostring(m) .. "\n")
|
||||
end
|
||||
|
||||
-- START HERE vvvvvvvvvvvvvvvvv
|
||||
local tracks_str = ''
|
||||
local tracks = {}
|
||||
local retval
|
||||
|
||||
retval, tracks_str = reaper.GetProjExtState(0, '4PointCut', 'src_tracks')
|
||||
if retval > 0 then -- variable exists in rpp
|
||||
-- separate GUIDs and populate track table
|
||||
for str in string.gmatch(tracks_str, "([^"..'{'.."]+)") do
|
||||
table.insert(tracks, reaper.BR_GetMediaTrackByGUID(0, '{' .. str))
|
||||
end
|
||||
-- select tracks
|
||||
reaper.Main_OnCommand(40297, 0) -- Unselect all tracks
|
||||
for _, track in ipairs(tracks) do
|
||||
reaper.SetTrackSelected(track, true)
|
||||
end
|
||||
end
|
25
4PointCutting/4Pcut_set_DST-IN.lua
Normal file
25
4PointCutting/4Pcut_set_DST-IN.lua
Normal file
@ -0,0 +1,25 @@
|
||||
local nof_markers = 0
|
||||
local id = -1
|
||||
|
||||
-- check if marker already exists
|
||||
_, nof_markers, _ = reaper.CountProjectMarkers(0)
|
||||
for i = 0, nof_markers - 1 do
|
||||
local name_tmp = ''
|
||||
local isregion_tmp = false
|
||||
local id_tmp = 0
|
||||
_, isregion_tmp, _, _, name_tmp, id_tmp = reaper.EnumProjectMarkers(i)
|
||||
if not isregion then
|
||||
if name_tmp == 'DST-IN_4Pcut' then
|
||||
id = id_tmp
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if id >= 0 then
|
||||
-- edit existing marker
|
||||
reaper.SetProjectMarker(id, false, reaper.GetCursorPosition(), 0, 'DST-IN_4Pcut')
|
||||
else
|
||||
-- create new marker
|
||||
reaper.AddProjectMarker2(0, false, reaper.GetCursorPosition(), 0, 'DST-IN_4Pcut', -1, reaper.ColorToNative(0, 255, 0)|0x1000000)
|
||||
end
|
25
4PointCutting/4Pcut_set_DST-OUT.lua
Normal file
25
4PointCutting/4Pcut_set_DST-OUT.lua
Normal file
@ -0,0 +1,25 @@
|
||||
local nof_markers = 0
|
||||
local id = -1
|
||||
|
||||
-- check if marker already exists
|
||||
_, nof_markers, _ = reaper.CountProjectMarkers(0)
|
||||
for i = 0, nof_markers - 1 do
|
||||
local name_tmp = ''
|
||||
local isregion_tmp = false
|
||||
local id_tmp = 0
|
||||
_, isregion_tmp, _, _, name_tmp, id_tmp = reaper.EnumProjectMarkers(i)
|
||||
if not isregion then
|
||||
if name_tmp == 'DST-OUT_4Pcut' then
|
||||
id = id_tmp
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if id >= 0 then
|
||||
-- edit existing marker
|
||||
reaper.SetProjectMarker(id, false, reaper.GetCursorPosition(), 0, 'DST-OUT_4Pcut')
|
||||
else
|
||||
-- create new marker
|
||||
reaper.AddProjectMarker2(0, false, reaper.GetCursorPosition(), 0, 'DST-OUT_4Pcut', -1, reaper.ColorToNative(0, 255, 0)|0x1000000)
|
||||
end
|
25
4PointCutting/4Pcut_set_SRC-IN.lua
Normal file
25
4PointCutting/4Pcut_set_SRC-IN.lua
Normal file
@ -0,0 +1,25 @@
|
||||
local nof_markers = 0
|
||||
local id = -1
|
||||
|
||||
-- check if marker already exists
|
||||
_, nof_markers, _ = reaper.CountProjectMarkers(0)
|
||||
for i = 0, nof_markers - 1 do
|
||||
local name_tmp = ''
|
||||
local isregion_tmp = false
|
||||
local id_tmp = 0
|
||||
_, isregion_tmp, _, _, name_tmp, id_tmp = reaper.EnumProjectMarkers(i)
|
||||
if not isregion then
|
||||
if name_tmp == 'SRC-IN_4Pcut' then
|
||||
id = id_tmp
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if id >= 0 then
|
||||
-- edit existing marker
|
||||
reaper.SetProjectMarker(id, false, reaper.GetCursorPosition(), 0, 'SRC-IN_4Pcut')
|
||||
else
|
||||
-- create new marker
|
||||
reaper.AddProjectMarker2(0, false, reaper.GetCursorPosition(), 0, 'SRC-IN_4Pcut', -1, reaper.ColorToNative(0, 255, 0)|0x1000000)
|
||||
end
|
25
4PointCutting/4Pcut_set_SRC-OUT.lua
Normal file
25
4PointCutting/4Pcut_set_SRC-OUT.lua
Normal file
@ -0,0 +1,25 @@
|
||||
local nof_markers = 0
|
||||
local id = -1
|
||||
|
||||
-- check if marker already exists
|
||||
_, nof_markers, _ = reaper.CountProjectMarkers(0)
|
||||
for i = 0, nof_markers - 1 do
|
||||
local name_tmp = ''
|
||||
local isregion_tmp = false
|
||||
local id_tmp = 0
|
||||
_, isregion_tmp, _, _, name_tmp, id_tmp = reaper.EnumProjectMarkers(i)
|
||||
if not isregion then
|
||||
if name_tmp == 'SRC-OUT_4Pcut' then
|
||||
id = id_tmp
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if id >= 0 then
|
||||
-- edit existing marker
|
||||
reaper.SetProjectMarker(id, false, reaper.GetCursorPosition(), 0, 'SRC-OUT_4Pcut')
|
||||
else
|
||||
-- create new marker
|
||||
reaper.AddProjectMarker2(0, false, reaper.GetCursorPosition(), 0, 'SRC-OUT_4Pcut', -1, reaper.ColorToNative(0, 255, 0)|0x1000000)
|
||||
end
|
10
4PointCutting/4Pcut_set_dst-track.lua
Normal file
10
4PointCutting/4Pcut_set_dst-track.lua
Normal file
@ -0,0 +1,10 @@
|
||||
-- Send a message to the console
|
||||
function msg(m)
|
||||
reaper.ShowConsoleMsg(tostring(m) .. "\n")
|
||||
end
|
||||
|
||||
-- START HERE vvvvvvv
|
||||
if reaper.CountSelectedTracks(0) > 0 then
|
||||
local first_sel_track = reaper.GetTrackGUID(reaper.GetSelectedTrack(0, 0))
|
||||
reaper.SetProjExtState(0, '4PointCut', 'dst_track', first_sel_track)
|
||||
end
|
14
4PointCutting/4Pcut_set_src-tracks.lua
Normal file
14
4PointCutting/4Pcut_set_src-tracks.lua
Normal file
@ -0,0 +1,14 @@
|
||||
-- Send a message to the console
|
||||
function msg(m)
|
||||
reaper.ShowConsoleMsg(tostring(m) .. "\n")
|
||||
end
|
||||
|
||||
-- START HERE vvvvvvv
|
||||
|
||||
-- get list of selected tracks and make string of GUIDs
|
||||
local sel_tracks = ''
|
||||
for i = 0, reaper.CountSelectedTracks(0)-1 do
|
||||
sel_tracks = sel_tracks .. reaper.GetTrackGUID(reaper.GetSelectedTrack(0, i))
|
||||
end
|
||||
-- store selected tracks to rpp
|
||||
reaper.SetProjExtState(0, '4PointCut', 'src_tracks', sel_tracks)
|
2
4PointCutting/README.md
Normal file
2
4PointCutting/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# 4 Point Cutting (WORK IN PROGRESS)
|
||||
Brings 4 point editing to reaper...
|
Loading…
x
Reference in New Issue
Block a user