From 9b9e97910f08ed3ce43b97b94ebae41a35790d3b Mon Sep 17 00:00:00 2001 From: Zly Date: Mon, 11 Mar 2024 19:20:27 +0300 Subject: [PATCH] - Fixed `flip_only_on_pitch_change` feature. - Simplified envelope creation code. --- .../VideoAutoFlipper/Zly_VideoAutoFlipper.lua | 94 ++++--------------- 1 file changed, 20 insertions(+), 74 deletions(-) diff --git a/Video/VideoAutoFlipper/Zly_VideoAutoFlipper.lua b/Video/VideoAutoFlipper/Zly_VideoAutoFlipper.lua index 7e6e467..e216ce7 100644 --- a/Video/VideoAutoFlipper/Zly_VideoAutoFlipper.lua +++ b/Video/VideoAutoFlipper/Zly_VideoAutoFlipper.lua @@ -590,13 +590,7 @@ local VAF = { -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- - - local pooled_envelopes = { - flips_h = {}, - flips_v = {}, - opacity = {}, - } - + local flip_index = 0 local prev_pitch = nil for index = 0, items_count - 1 do @@ -620,104 +614,56 @@ local VAF = { local evaluated_flips = found_preset(params.flip_only_on_pitch_change and flip_index or index, item) if env_horiz_flip then - local flip = math.max(evaluated_flips.h, 0)+69 local ai_i = reaper.InsertAutomationItem( env_horiz_flip, - flip, - item_pos, item_len - ) - pooled_envelopes.flips_h[flip] = ai_i - end - - if env_vert_flip then - local flip = math.max(evaluated_flips.v, 0)+69 - local ai_i = reaper.InsertAutomationItem( - env_vert_flip, - flip, - item_pos, item_len - ) - pooled_envelopes.flips_v[flip] = ai_i - end - - if env_opacity then - local item_vol = reaper.GetMediaItemInfo_Value(item, "D_VOL") - local vol_id = math.floor(item_vol*255) - local ai_i = reaper.InsertAutomationItem( - env_opacity, - vol_id, + math.max(evaluated_flips.h, 0)+69, item_pos, item_len ) - pooled_envelopes.opacity[vol_id] = ai_i - end - end - - flip_index = 0 - prev_pitch = nil - -- Process flippings - for index = 0, items_count-1 do - local item = reaper.GetSelectedMediaItem(0, index) - local item_pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION") - - -- Flip only upon pitch change - if params.flip_only_on_pitch_change then - local item_take = reaper.GetActiveTake(item) - local take_pitch = reaper.GetMediaItemTakeInfo_Value(item_take, "D_PITCH") - if take_pitch ~= prev_pitch then - if prev_pitch ~= nil then - flip_index = flip_index + 1 - end - prev_pitch = take_pitch - end - end - - local evaluated_flips = found_preset(params.flip_only_on_pitch_change and flip_index or index, item) - - if env_horiz_flip then reaper.InsertEnvelopePointEx( - -- env env_horiz_flip, - -- autoitem_idx - pooled_envelopes.flips_h[math.max(evaluated_flips.h, 0)+69] or -1, - -- pos, val + ai_i, item_pos, math.max(evaluated_flips.h, 0), - -- shape, tension 1, 1, - -- isSelected, noSort false, false ) end if env_vert_flip then + local ai_i = reaper.InsertAutomationItem( + env_vert_flip, + math.max(evaluated_flips.v, 0)+69, + item_pos, item_len + ) + reaper.InsertEnvelopePointEx( - -- env env_vert_flip, - -- autoitem_idx - pooled_envelopes.flips_v[math.max(evaluated_flips.v, 0)+69] or -1, - -- pos, val + ai_i, item_pos, math.max(evaluated_flips.v, 0), - -- shape, tension 1, 1, - -- isSelected, noSort false, false ) end - -- Volume -> Opacity if env_opacity then - local item_vol = reaper.GetMediaItemInfo_Value(item, "D_VOL") - + local item_vol = reaper.GetMediaItemInfo_Value(item, "D_VOL") + local vol_id = math.floor(item_vol*255) + local ai_i = reaper.InsertAutomationItem( + env_opacity, + vol_id, + item_pos, item_len + ) + reaper.InsertEnvelopePointEx( env_opacity, - pooled_envelopes.opacity[math.floor(item_vol*255)] or -1, + ai_i, item_pos, item_vol, 1, 1, false, false ) end end - - + --if env_horiz_flip then -- reaper.Envelope_SortPoints(env_horiz_flip) --end