From e6a42bdedab1c5875e52fda1e07ca4a531f76371 Mon Sep 17 00:00:00 2001 From: Sneakpeakcss <77424331+Sneakpeakcss@users.noreply.github.com> Date: Tue, 9 Jan 2024 20:37:40 +0100 Subject: [PATCH] [crop] Replace deprecated `vf del` Add remove_last_filter function with additional feedback message --- input.conf | 2 +- scripts/crop.lua | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/input.conf b/input.conf index dad5747..7fb9f1c 100644 --- a/input.conf +++ b/input.conf @@ -6,7 +6,7 @@ alt+c script-message-to crop start-crop soft # delogo mode can be used like so l script-message-to crop start-crop delogo # remove the crop -d vf del -1 +d script-message-to crop remove-crop # or use the ready-made "toggle" binding C script-message-to crop toggle-crop hard diff --git a/scripts/crop.lua b/scripts/crop.lua index adbfaa3..96c1119 100644 --- a/scripts/crop.lua +++ b/scripts/crop.lua @@ -342,6 +342,30 @@ function cancel_crop() active = false end +function remove_last_filter() + local vf_table = mp.get_property_native("vf") + local crop_filter_count = 0 + local remove_last = 0 + + -- count filters + for i = 1, #vf_table do + if vf_table[i].name == "crop" or vf_table[i].name == "delogo" then + crop_filter_count = crop_filter_count + 1 + remove_last = i + removed_filter_name = vf_table[i].name + end + end + + -- remove last filter + if crop_filter_count > 0 then + table.remove(vf_table, remove_last) + mp.set_property_native("vf", vf_table) + mp.osd_message("Removed filter: #" .. tostring(crop_filter_count) .. " " .. removed_filter_name) + else + mp.osd_message("No filters to remove") + end +end + function start_crop(mode) if active then return end if not mp.get_property_native("osd-dimensions") then return end @@ -429,6 +453,6 @@ bindings_repeat[opts.right_fine] = movement_func(opts.fine_movement, 0) bindings_repeat[opts.up_fine] = movement_func(0, -opts.fine_movement) bindings_repeat[opts.down_fine] = movement_func(0, opts.fine_movement) - +mp.add_key_binding(nil, "remove-crop", remove_last_filter) mp.add_key_binding(nil, "start-crop", start_crop) mp.add_key_binding(nil, "toggle-crop", toggle_crop)