diff --git a/Items Editing/az_Fade tool (work on context of mouse, razor or time selection).lua b/Items Editing/az_Fade tool (work on context of mouse, razor or time selection).lua index 2b19d38f0..ea2b5e165 100644 --- a/Items Editing/az_Fade tool (work on context of mouse, razor or time selection).lua +++ b/Items Editing/az_Fade tool (work on context of mouse, razor or time selection).lua @@ -1,7 +1,10 @@ -- @description Fade tool (works on context of mouse, razor or time selection) -- @author AZ --- @version 2.2.3 --- @changelog - to avoid simultaneous work of Batch fade tool and changing fade under the mouse - ignore TS if one of it's edges is out of arrange view and the mouse is over an item. +-- @version 2.2.4 +-- @changelog +-- - Improved behavior for batch fades/crossfades options +-- - Added option for immediate applying actual batch settings without dialog +-- - added workaround for some math inaccuracy related to razor area -- @provides -- az_Fade tool (work on context of mouse, razor or time selection)/az_Options window for az_Fade tool.lua -- [main] az_Fade tool (work on context of mouse, razor or time selection)/az_Open options for az_Fade tool.lua @@ -50,10 +53,37 @@ OPEN THE OPTIONS WINDOW BY RUNNING THE SCRIPT WITH MOUSE ON TRANSPORT OR MIXER P ]] --------------------------------- ---------Options functions-------- + --Start load file +function msg(value) + reaper.ShowConsoleMsg(tostring(value)..'\n') +end + +------------------------- + ExtStateName = 'AZ_FadeTool' +CurVers = 2.24 + +SaveLastBatchPrj = reaper.GetExtState(ExtStateName, 'SaveLastBatchPrj') +if SaveLastBatchPrj == 'false' then SaveLastBatchPrj = false +else SaveLastBatchPrj = true +end + +------------------------- + +function copy(tbl) + if type(tbl) ~= "table" then + return tbl + end + local result = {} + for k, v in pairs(tbl) do + result[k] = copy(v) + end + return result +end + +------------------------------ function GetExtStates(OptionsTable) for i, option in ipairs(OptionsTable) do @@ -83,7 +113,7 @@ function GetExtStates(OptionsTable) if wrong == true then reaper.SetExtState(ExtStateName, option[2], tostring(option[3]), true) else - OptionsTable[i][3] = state + option[3] = state end else reaper.SetExtState(ExtStateName, option[2], tostring(option[3]), true) @@ -141,38 +171,9 @@ function OptionsDefaults(NamedTable) text = 'Batch fades/crossfades defaults' table.insert(NamedTable, {text, 'Separator', nil}) - text = 'Fade-in' - table.insert(NamedTable, {text, 'DefaultFadeIn', 30, "%.0f"}) - - text = 'Fade-out' - table.insert(NamedTable, {text, 'DefaultFadeOut', 30, "%.0f"}) - - text = 'Crossfade' - table.insert(NamedTable, {text, 'DefaultCrossFade', 30, "%.0f"}) - - - text = 'Values' - table.insert(NamedTable, {text, 'ValueType', 'milliseconds', { - 'milliseconds', - 'frames' } }) - - text = 'Crossfade type' - table.insert(NamedTable, {text, 'DefCrossType', 'Left', { - 'Left', - 'Centered' } }) - - text = 'Respect existing fades' - table.insert(NamedTable, {text, 'RespectExistingFades', true}) - - text = 'Respect locking' - table.insert(NamedTable, {text, 'RespectLockingBatch', true}) - - text = 'Other options' - table.insert(NamedTable, {text, 'Separator', nil}) - - text = 'Save and use last batch settings in project' - table.insert(NamedTable, {text, 'SaveLastBatchPrj', true}) - + text = "Don't ask values for batch process" + table.insert(NamedTable, {text, 'SilentProcessBatch', false}) + end @@ -185,15 +186,8 @@ function SetOptGlobals(NamedTable, OptionsTable) end end -------------------------- ---End load file -------------------------- - -function msg(value) - reaper.ShowConsoleMsg(tostring(value)..'\n') -end - ------------------------------ + function BatchDefaults(NamedTable) local text @@ -225,13 +219,98 @@ function BatchDefaults(NamedTable) end -------------------------- +----------------------- +function GetSetBatchExtStates(DefT, LastPrjT, getset) -- set == true, get == false + local Mtrack = reaper.GetMasterTrack(0) + local parname = "P_EXT:"..'AZ_Ftool_Batch ' + + if getset == true then -- set + + local GlobOrPrjTable + if SaveLastBatchPrj == true then GlobOrPrjTable = LastPrjT + else GlobOrPrjTable = DefT + end + + if RunBatch == true or SaveLastBatchPrj == true then + for i, option in pairs(GlobOrPrjTable) do + if option[3] ~= nil then + local ret, str = reaper.GetSetMediaTrackInfo_String + ( Mtrack, parname..option[2], tostring(option[3]), getset ) + end + end + end + + if not RunBatch and SaveLastBatchPrj == false then + for i, option in ipairs(DefT) do + if option[3] ~= nil then + reaper.SetExtState(ExtStateName, option[2], tostring(option[3]), true) + end + end + end + + elseif getset == false then -- get + + GetExtStates(DefT) + + for i, option in pairs(LastPrjT) do + if option[3] ~= nil then + local state + local ret, str = reaper.GetSetMediaTrackInfo_String + ( Mtrack, parname..option[2], '', getset ) + if str ~= "" and ret ~= false then + state = str + local stateType = type(option[3]) + if stateType == 'number' then state = tonumber(str) end + if stateType == 'boolean' then + if str == 'true' then state = true else state = false end + end + option[3] = state + else + Opt.SilentProcessBatch = false + option[3] = DefT[i][3] + end + end + end -- for + + end --if getset == false + +end + +-----------START----------- +if reaper.APIExists( 'BR_GetMouseCursorContext' ) ~= true then + reaper.ShowMessageBox('Please, install SWS extension!', 'No SWS extension', 0) + return false +end + +version = tonumber( reaper.GetExtState(ExtStateName, "version") ) +if version ~= CurVers then + if not version or version < 2.0 then + HelloMessage() + else reaper.ShowMessageBox('The script was updated to version '..CurVers ,'Fade tool',0) + end + reaper.SetExtState(ExtStateName, "version", CurVers, true) + reaper.defer(function()end) + return false +end + +OptDefaults = {} +BDefaults = {} +OptionsDefaults(OptDefaults) +BatchDefaults(BDefaults) +BPrjDefaults = copy(BDefaults) +GetExtStates(OptDefaults) + +Opt = {} +SetOptGlobals(Opt, OptDefaults) + +GetSetBatchExtStates(BDefaults, BPrjDefaults, false) +-------------------------- function HelloMessage() local text = 'Hello friend! It seems you have updated script "az_Fade tool".' ..'\n\n'..'The script now has new GUI and more thoughtfull behavior.' - ..'\n'..'Explore all of them including envelope editing, look here: ' + ..'\n'..'Explore all possibilities including envelope editing, look here: ' ..'\n'..'https://forum.cockos.com/showthread.php?t=293335' ..'\n\n'..'Please, check the options if they were changed.' ..'\n'..'Just press assigned hotkey when mouse placed on the transport or mixer area.' @@ -239,9 +318,9 @@ function HelloMessage() reaper.ShowMessageBox(text,'Fade tool - Hello!',0) end ---------------------------------- ------------Work functions-------- ---------------------------------- +------------------------- +--End load file +------------------------- function RazorEditSelectionExists() @@ -810,60 +889,12 @@ end ----------------------- ----------------------- - -function GetSetBatchExtStates(DefT, getset) -- set == true, get == false - local Mtrack = reaper.GetMasterTrack(0) - local parname = "P_EXT:"..'AZ_Ftool_Batch ' - if getset == true then - - for i, option in pairs(DefT) do - if option[3] ~= nil then - local ret, str = reaper.GetSetMediaTrackInfo_String - ( Mtrack, parname..option[2], tostring(option[3]), getset ) - end - end - - elseif getset == false then - - for i, option in pairs(DefT) do - if option[3] ~= nil then - local state - local ret, str = reaper.GetSetMediaTrackInfo_String - ( Mtrack, parname..option[2], '', getset ) - if str ~= "" and ret ~= false and Opt.SaveLastBatchPrj == true then - state = str - local stateType = type(option[3]) - if stateType == 'number' then state = tonumber(str) end - if stateType == 'boolean' then - if str == 'true' then state = true else state = false end - end - DefT[i][3] = state - else - DefT[i][3] = Opt[option[2]] - end - end - - end -- for - - end --if getset == false - -end - ------------------------ ------------------------ -function BatchFadesWindow(razorEdits) - BDefaults = {} - BatchDefaults(BDefaults) - GetSetBatchExtStates(BDefaults, false) - RunBatch = true - RazorEditsBatch = razorEdits - --look for additional file - local script_path = get_script_path() +function BatchFadesWindow() + local script_path = get_script_path() local file = script_path .. 'az_Fade tool (work on context of mouse, razor or time selection)/' ..'az_Options window for az_Fade tool.lua' dofile(file) - OptionsWindow(BDefaults, 'Batch fades/crossfades - Fade Tool') - + OptionsWindow( nil, 'Batch fades/crossfades - Fade Tool', BDefaults, BPrjDefaults) end ----------------------- @@ -874,8 +905,14 @@ function BatchFades() reaper.PreventUIRefresh( 1 ) local AnyEdit BOpt = {} - SetOptGlobals(BOpt, BDefaults) - GetSetBatchExtStates(BDefaults, true) + local GlobOrPrjTable + if SaveLastBatchPrj == true then + GlobOrPrjTable = BPrjDefaults + else + GlobOrPrjTable = BDefaults + end + SetOptGlobals(BOpt, GlobOrPrjTable) + GetSetBatchExtStates(BDefaults, BPrjDefaults, true) if BOpt.RespectLockingBatch == false then RespectLockingBatch = false @@ -883,7 +920,7 @@ function BatchFades() if start_TS ~= end_TS then RazorEditsBatch = GetTSandItems(start_TS, end_TS) else - RazorEditsBatch = GetRazorEdits() + RazorEditsBatch = GetRazorEdits() end end @@ -1365,7 +1402,13 @@ function FadeRazorEdits(razorEdits, needBatch) --get areaMap table and batch fla if needBatch == true then if fulliLock == 0 then - BatchFadesWindow(razorEdits) + RunBatch = true + RazorEditsBatch = razorEdits + if Opt.SilentProcessBatch == false then + BatchFadesWindow() + else + BatchFades() + end end else @@ -1409,9 +1452,9 @@ function FadeRazorEdits(razorEdits, needBatch) --get areaMap table and batch fla local iPos_1 = reaper.GetMediaItemInfo_Value(item_1, "D_POSITION") local itemEndPos_1 = iPos_1+reaper.GetMediaItemInfo_Value(item_1, "D_LENGTH") if (iPos_1 <= areaData.areaStart and itemEndPos_1 < areaData.areaEnd) or - (iPos_1 < areaData.areaStart and itemEndPos_1 <= areaData.areaEnd)then + (iPos_1 < areaData.areaStart and itemEndPos_1 - 0.0002 <= areaData.areaEnd)then Litem = item_1 - elseif (iPos_1 >= areaData.areaStart and itemEndPos_1 > areaData.areaEnd) or + elseif (iPos_1 + 0.0002 >= areaData.areaStart and itemEndPos_1 > areaData.areaEnd) or (iPos_1 > areaData.areaStart and itemEndPos_1 >= areaData.areaEnd)then Ritem = item_1 end @@ -1598,18 +1641,7 @@ function GetTSandItems(start_TS, end_TS) --returns areaMap and needBatch table.insert(areaMap, areaData) end - --[[ - if #SI == 0 then - local areaData = { - areaStart = start_TS, - areaEnd = end_TS, - - track, - items = {}, - } - - table.insert(areaMap, areaData) - end]] + end else --if not 2 items selected SI, needBatch = SaveSelItemsByTracks(start_TS, end_TS) @@ -1627,18 +1659,7 @@ function GetTSandItems(start_TS, end_TS) --returns areaMap and needBatch table.insert(areaMap, areaData) end - --[[ - if #SI == 0 then - local areaData = { - areaStart = start_TS, - areaEnd = end_TS, - - track, - items = {}, - } - - table.insert(areaMap, areaData) - end]] + end return areaMap, needBatch @@ -2308,8 +2329,7 @@ function MovePoint(env, time, item, pointPos) UndoString = 'FadeTool - move point' else UnselectEnvPoints(env, -1) - _, pValue, _, _, _ = reaper.Envelope_Evaluate( env, timeSnap, 192000, 1 ) - --pShape = GetPrefs('defenvs') >> 16 + _, pValue, _, _, _ = reaper.Envelope_Evaluate( env, timeSnap, 192000, 1 ) pShape = tonumber(ExtractDefPointShape(env)) reaper.InsertEnvelopePointEx( env, -1, timeSnap, pValue, pShape, 0, true, false ) UndoString = 'FadeTool - create point' @@ -2509,48 +2529,27 @@ end --------------------------- -----------START----------- -CurVers = 2.23 -version = tonumber( reaper.GetExtState(ExtStateName, "version") ) -if version ~= CurVers then - if not version or version < 2.0 then - HelloMessage() - else reaper.ShowMessageBox('The script was updated to version '..CurVers ,'Fade tool',0) - end - reaper.SetExtState(ExtStateName, "version", CurVers, true) - reaper.defer(function()end) -else - if reaper.APIExists( 'BR_GetMouseCursorContext' ) ~= true then - reaper.ShowMessageBox('Please, install SWS extension!', 'No SWS extension', 0) - return - end - window, segment, details = reaper.BR_GetMouseCursorContext() --msg(window) msg(segment) msg(details) local tcpActIDstr = reaper.GetExtState(ExtStateName, 'TCPaction') local tcpActID - OptDefaults = {} - OptionsDefaults(OptDefaults) - GetExtStates(OptDefaults) - - if window == 'transport' or window == 'mcp' then + if window == 'transport' or window == 'mcp' then --look for additional file - local script_path = get_script_path() + local script_path = get_script_path() local file = script_path .. 'az_Fade tool (work on context of mouse, razor or time selection)/' ..'az_Options window for az_Fade tool.lua' dofile(file) - --ExternalOpen = true - OptionsWindow(OptDefaults, 'Fade Tool Options') + + OptionsWindow(OptDefaults, 'Fade Tool Options', BDefaults, BPrjDefaults) elseif window == 'tcp' and tcpActIDstr ~= '' then if tcpActIDstr:gsub('%d+', '') == '' then - tcpActID = tonumber(tcpActIDstr) + tcpActID = tonumber(tcpActIDstr) elseif tcpActIDstr ~= '' then tcpActID = tonumber(reaper.NamedCommandLookup(tcpActIDstr)) end reaper.Main_OnCommandEx(tcpActID,0,0) else - Opt = {} - SetOptGlobals(Opt, OptDefaults) UndoString = Main() if globalLock == 1 and not RunBatch then @@ -2568,5 +2567,3 @@ else reaper.defer(function()end) end end - -end diff --git a/Items Editing/az_Fade tool (work on context of mouse, razor or time selection)/az_Open options for az_Fade tool.lua b/Items Editing/az_Fade tool (work on context of mouse, razor or time selection)/az_Open options for az_Fade tool.lua index 4c5aac5d7..7b8011398 100644 --- a/Items Editing/az_Fade tool (work on context of mouse, razor or time selection)/az_Open options for az_Fade tool.lua +++ b/Items Editing/az_Fade tool (work on context of mouse, razor or time selection)/az_Open options for az_Fade tool.lua @@ -30,16 +30,12 @@ for line in io.lines(file) do if add == true then scriptPart = scriptPart ..line ..'\n' end if line:match('--End load file') then break end end ---msg(scriptPart) + local func = load(scriptPart) if func then - func() - - OptDefaults = {} - OptionsDefaults(OptDefaults) - GetExtStates(OptDefaults) - - ExternalOpen = true - OptionsWindow(OptDefaults, 'Fade Tool Options') + if func() ~= false then + ExternalOpen = true + OptionsWindow(OptDefaults, 'Fade Tool Options', BDefaults, BPrjDefaults) + end end diff --git a/Items Editing/az_Fade tool (work on context of mouse, razor or time selection)/az_Options window for az_Fade tool.lua b/Items Editing/az_Fade tool (work on context of mouse, razor or time selection)/az_Options window for az_Fade tool.lua index 0b3e6e89f..7eaef8ad0 100644 --- a/Items Editing/az_Fade tool (work on context of mouse, razor or time selection)/az_Options window for az_Fade tool.lua +++ b/Items Editing/az_Fade tool (work on context of mouse, razor or time selection)/az_Options window for az_Fade tool.lua @@ -28,14 +28,14 @@ function rgbToHex(rgba) -- passing a table with percentage like {100, 50, 20, 90 end ------------------------ -function OptionsWindow(OptTable, windowName) +function OptionsWindow(MainTable, windowName, BatchTable, BatchPrjTable) local imgui_path = reaper.GetResourcePath() .. '/Scripts/ReaTeam Extensions/API/imgui.lua' if not reaper.file_exists(imgui_path) then reaper.ShowMessageBox('Please, install ReaImGui from Reapack!', 'No Imgui library', 0) return end dofile(imgui_path) '0.8.7.6' - + local fontSize = 17 local ctx, font, fontSep local H = fontSize @@ -46,7 +46,7 @@ function OptionsWindow(OptTable, windowName) local tcpActIDstr = reaper.GetExtState(ExtStateName, 'TCPaction') local tcpActName = '' local section - + local savedFontSize = tonumber(reaper.GetExtState(ExtStateName, 'FontSize')) if type(savedFontSize) == 'number' then fontSize = savedFontSize end if not savedFontSize then savedFontSize = fontSize end @@ -76,18 +76,13 @@ function OptionsWindow(OptTable, windowName) Background = rgbToHex({11,14,14,95}), Text = rgbToHex({92,92,81.5,100}), activeText = rgbToHex({50,95,80,100}), + ComboBox = { Default = rgbToHex({20,25,30,100}), Hovered = rgbToHex({35,40,45,80}), Active = rgbToHex({42,42,37,100}), }, - --[[ - Input = { - Background = rgbToHex({50,50,50,100}), - Hover = rgbToHex({10,10,90,100}), - Text = rgbToHex({90,90,80,100}), - Label = rgbToHex({90,80,90,100}), - },]] + Button = { Default = rgbToHex({25,30,30,100}), Hovered = rgbToHex({35,40,45,100}), @@ -106,9 +101,7 @@ function OptionsWindow(OptTable, windowName) end -------------- - function frame() - reaper.ImGui_PushFont(ctx, font) - + function populateOptions(OptTable) for i, v in ipairs(OptTable) do local option = v @@ -167,9 +160,41 @@ function OptionsWindow(OptTable, windowName) OptTable[i] = option end -- for + end + + -------------- + function frame() + reaper.ImGui_PushFont(ctx, font) + + if MainTable then + populateOptions(MainTable) + + for i, option in pairs(MainTable) do + if option[2] == 'SilentProcessBatch' and option[3] == true then + SaveLastBatchPrj = true + end + end + end + + reaper.ImGui_NewLine(ctx) reaper.ImGui_SameLine(ctx, fontSize*2) + _, SaveLastBatchPrj = reaper.ImGui_Checkbox(ctx, 'Use last project settings instead of global defaults', SaveLastBatchPrj) + + local batchTextInform = 'Global defaults:' + local GlobOrPrjTable + + if SaveLastBatchPrj == true then + GlobOrPrjTable = BatchPrjTable + batchTextInform = 'Last in-project values:' + else + GlobOrPrjTable = BatchTable + end + + reaper.ImGui_Text(ctx, batchTextInform ) + populateOptions(GlobOrPrjTable) + if RunBatch == nil then - reaper.ImGui_Text(ctx, '' ) --space + reaper.ImGui_Text(ctx, '' ) --space reaper.ImGui_PushItemWidth(ctx, fontSize*5 ) _, tcpActIDstr = reaper.ImGui_InputText (ctx,'TCP context action (paste command ID):\n'..tcpActName, tcpActIDstr) @@ -263,14 +288,13 @@ function OptionsWindow(OptTable, windowName) local window_flags = reaper.ImGui_WindowFlags_MenuBar() reaper.ImGui_SetNextWindowSize(ctx, W, H, reaper.ImGui_Cond_Once()) -- Set the size of the windows. Use in the 4th argument reaper.ImGui_Cond_FirstUseEver() to just apply at the first user run, so ImGUI remembers user resize s2 - reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Text(), gui_colors.White) + reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Text(), gui_colors.White) local visible, open = reaper.ImGui_Begin(ctx, windowName, true, window_flags) reaper.ImGui_PopStyleColor(ctx, 1) if visible then frame() reaper.ImGui_SetWindowSize(ctx, 0, 0, nil ) - --if loopcnt == 0 then reaper.ImGui_SetWindowSize(ctx, 0, 0, nil ) end reaper.ImGui_End(ctx) end @@ -281,21 +305,25 @@ function OptionsWindow(OptTable, windowName) enter = enterMouse or reaper.ImGui_IsKeyReleased(ctx, reaper.ImGui_Key_Enter()) if ExternalOpen == true then - space = spaceMouse or reaper.ImGui_IsKeyReleased(ctx, reaper.ImGui_Key_Space()) + space = spaceMouse or reaper.ImGui_IsKeyReleased(ctx, reaper.ImGui_Key_Space()) if space == true then - SetExtStates(OptTable) + SetExtStates(MainTable) + GetSetBatchExtStates(BatchTable, BatchPrjTable, true) reaper.SetExtState(ExtStateName, 'TCPaction', tcpActIDstr, true) + reaper.SetExtState(ExtStateName, 'SaveLastBatchPrj', tostring(SaveLastBatchPrj), true) end end if open and esc ~= true and enter ~= true then reaper.defer(loop) elseif enter == true then + reaper.SetExtState(ExtStateName, 'SaveLastBatchPrj', tostring(SaveLastBatchPrj), true) if RunBatch == true then reaper.ImGui_DestroyContext(ctx) BatchFades() else - SetExtStates(OptTable) + SetExtStates(MainTable) + GetSetBatchExtStates(BatchTable, BatchPrjTable, true) reaper.SetExtState(ExtStateName, 'TCPaction', tcpActIDstr, true) reaper.ImGui_DestroyContext(ctx) end