Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
- Changed some logic for helper functions to be more reliable.
- Added two more helpers: "Extend Last Frame to Next" and "Delete Last Frame Fills".
  • Loading branch information
prn.e_lyudchik committed Oct 15, 2024
1 parent dc6b41d commit bd2af75
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 45 deletions.
169 changes: 129 additions & 40 deletions Video/VideoAutoFlipper/Zly_VideoAutoFlipper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,35 @@ local function ImGui_ButtonWithHint(ctx, button_text, alignment, desc)
return rv
end

local DeleteSelectedItemsByName = function(name_to_search)
local item_count = reaper.CountSelectedMediaItems()
if item_count == 0 then
reaper.MB("No Media Items were selected!", "Error", 0)
return
end

reaper.PreventUIRefresh(1)

local items_to_del = {}
for id = 0, item_count - 1 do
local item = reaper.GetSelectedMediaItem(0, id)
local item_take = reaper.GetActiveTake(item)
local track = reaper.GetMediaItemTrack(item)

local retval, stringNeedBig = reaper.GetSetMediaItemTakeInfo_String(item_take, "P_NAME", "", false)

if stringNeedBig == name_to_search then
table.insert(items_to_del, {track = track, item = item})
end
end

for _, item in pairs(items_to_del) do
reaper.DeleteTrackMediaItem(item.track, item.item)
end

reaper.UpdateArrange()
end

--[[===================================================]]--
--[[===================================================]]--
--[[===================================================]]--
Expand Down Expand Up @@ -431,7 +460,7 @@ end
--[[===================================================]]--

local GUI = {
version = "1.1.2",
version = "1.2.0",
name = "Video Auto-Flipper",

timer = 0.0,
Expand Down Expand Up @@ -1294,16 +1323,72 @@ function GUI:TAB_Helpers()
ImGui.SeparatorText(self.ctx, "Media Items")
--------------------------------------------------------------------------------------------------------------------

if ImGui_ButtonWithHint(self.ctx, "Extend Last Frame to Next", 0.5,
"Extends selected Media Items last frames to their next adjacent Media Items."
) then
UndoWrap("[VAF] Extend Last Frame to Next", function()
local item_count = reaper.CountSelectedMediaItems()
if item_count == 0 then return end

local selected_items = {}
for id = 0, item_count-1 do
local item = reaper.GetSelectedMediaItem(0, id)
if item then
table.insert(selected_items, item)
end
end

if #selected_items == 0 then
return
end

reaper.PreventUIRefresh(1)
for id = 1, #selected_items-1 do
local item = selected_items[id]
local next_item = selected_items[id + 1]

local item_start = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local item_duration = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
local next_item_start = reaper.GetMediaItemInfo_Value(next_item, "D_POSITION")

local cut_position = item_start + item_duration * 0.99
local new_cut_item = reaper.SplitMediaItem(item, cut_position)

if new_cut_item then
local target_duration = next_item_start - cut_position

reaper.GetSetMediaItemTakeInfo_String(reaper.GetActiveTake(new_cut_item), "P_NAME", "VAF_LAST_FRAME_EXTEND", true)
reaper.SetMediaItemTakeInfo_Value(reaper.GetActiveTake(new_cut_item), "D_PLAYRATE", 0)
reaper.SetMediaItemLength(new_cut_item, target_duration, false)
end
end
reaper.UpdateArrange()
end)
end

if ImGui_ButtonWithHint(self.ctx, "Extend to Next", 0.5,
"Extends selected Media Items to their next adjacent Media Items."
) then
UndoWrap("[VAF] Extend to Next", function()
local item_count = reaper.CountSelectedMediaItems()
if item_count == 0 then return end

for id = 0, item_count - 2 do
local item = reaper.GetSelectedMediaItem(0, id)
local next_item = reaper.GetSelectedMediaItem(0, id+1)
local selected_items = {}
for id = 0, item_count-1 do
local item = reaper.GetSelectedMediaItem(0, id)
if item then
table.insert(selected_items, item)
end
end

if #selected_items == 0 then
return
end

reaper.PreventUIRefresh(1)
for id = 1, #selected_items - 1 do
local item = selected_items[id]
local next_item = selected_items[id + 1]

local item_start = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local next_item_start = reaper.GetMediaItemInfo_Value(next_item, "D_POSITION")
Expand All @@ -1324,11 +1409,23 @@ function GUI:TAB_Helpers()
UndoWrap("[VAF] Silent Fill to Next", function()
local item_count = reaper.CountSelectedMediaItems()
if item_count == 0 then return end

local selected_items = {}
for id = 0, item_count-1 do
local item = reaper.GetSelectedMediaItem(0, id)
if item then
table.insert(selected_items, item)
end
end

if #selected_items == 0 then
return
end

local prev_split = nil
for id = 0, item_count - 2 do
local item = reaper.GetSelectedMediaItem(0, id)
local next_item = reaper.GetSelectedMediaItem(0, id+1)
for id = 1, #selected_items - 1 do
local item = selected_items[id]
local next_item = selected_items[id + 1]

local item_start = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local item_len = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
Expand All @@ -1353,16 +1450,25 @@ function GUI:TAB_Helpers()
then
UndoWrap("[VAF] Stretch to Next", function()
local item_count = reaper.CountSelectedMediaItems()
if item_count == 0 then
reaper.MB("No Media Items were selected!", "Error", 0)
if item_count == 0 then return end

local selected_items = {}
for id = 0, item_count-1 do
local item = reaper.GetSelectedMediaItem(0, id)
if item then
table.insert(selected_items, item)
end
end

if #selected_items == 0 then
return
end

reaper.PreventUIRefresh(1)

for id = 0, item_count - 2 do
local item = reaper.GetSelectedMediaItem(0, id)
local next_item = reaper.GetSelectedMediaItem(0, id+1)
for id = 1, #selected_items - 1 do
local item = selected_items[id]
local next_item = selected_items[id + 1]

local item_start = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local item_duration = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
Expand All @@ -1385,40 +1491,23 @@ function GUI:TAB_Helpers()
--------------------------------------------------------------------------------------------------------------------
ImGui.SeparatorText(self.ctx, "Media Items")
--------------------------------------------------------------------------------------------------------------------

if ImGui_ButtonWithHint(self.ctx, "Delete Silent Fills", 0.5,
"Deletes selected items that has name \"VAF_SILENT_FILL\" in it, those are generated by \"Silent Extend to Next\"."
) then
UndoWrap("[VAF] Delete Silent Fills", function()
local item_count = reaper.CountSelectedMediaItems()
if item_count == 0 then
reaper.MB("No Media Items were selected!", "Error", 0)
return
end

reaper.PreventUIRefresh(1)

local items_to_del = {}
for id = 0, item_count - 1 do
local item = reaper.GetSelectedMediaItem(0, id)
local item_take = reaper.GetActiveTake(item)
local track = reaper.GetMediaItemTrack(item)

local retval, stringNeedBig = reaper.GetSetMediaItemTakeInfo_String(item_take, "P_NAME", "", false)

if stringNeedBig == "VAF_SILENT_FILL" then
table.insert(items_to_del, {track = track, item = item})
end
end

for _, item in pairs(items_to_del) do
reaper.DeleteTrackMediaItem(item.track, item.item)
end

reaper.UpdateArrange()
DeleteSelectedItemsByName("VAF_SILENT_FILL")
end)
end


if ImGui_ButtonWithHint(self.ctx, "Delete Last Frame Fills", 0.5,
"Deletes selected items that has name \"VAF_LAST_FRAME_EXTEND\" in it, those are generated by \"Extend Last Frame to Next\"."
) then
UndoWrap("[VAF] Delete Last Frame Fills", function()
DeleteSelectedItemsByName("VAF_LAST_FRAME_EXTEND")
end)
end

ImGui.EndChild(self.ctx)
end
end
Expand Down
8 changes: 3 additions & 5 deletions Video/meta_VideoAutoFlipper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@metapackage
@description Video Auto-Flipper [YTPMV]
@author Zly
@version 1.1.2
@version 1.2.0
@provides
[main] .\VideoAutoFlipper\Zly_VideoAutoFlipper.lua
.\VideoAutoFlipper\images\*.png
Expand All @@ -22,8 +22,6 @@
- Has a tab for Helper functions to assist with video animation and such.
- Has some brief FAQ page, just in case.
@changelog
- Changed VFX Effects add behavior: Chroma-Key is being added, if none existed already, when applying any of the VFX effects.
- Opacity now adds after Chroma-key, so no more weird unexpected color behavior because of the wrong effects order.
- Changed `Scale` effect to have filtering off by default.
- Some additional FAQ pages.
- Changed some logic for helper functions to be more reliable.
- Added two more helpers: "Extend Last Frame to Next" and "Delete Last Frame Fills".
--]]

0 comments on commit bd2af75

Please sign in to comment.