From 576562eca8e8add14c7a8286ef95433af35f5ed6 Mon Sep 17 00:00:00 2001 From: Lokasenna Date: Sat, 13 Oct 2018 14:21:19 -0600 Subject: [PATCH] Fix: Crash due to function being out of scope --- .../Lokasenna_Show only specified tracks.lua | 85 ++++++++++--------- 1 file changed, 43 insertions(+), 42 deletions(-) mode change 100755 => 100644 Tracks Properties/Lokasenna_Show only specified tracks.lua diff --git a/Tracks Properties/Lokasenna_Show only specified tracks.lua b/Tracks Properties/Lokasenna_Show only specified tracks.lua old mode 100755 new mode 100644 index 6ac1278a5..8f90a3d39 --- a/Tracks Properties/Lokasenna_Show only specified tracks.lua +++ b/Tracks Properties/Lokasenna_Show only specified tracks.lua @@ -1,10 +1,10 @@ --[[ Description: Show only specified tracks - Version: 1.4.1 + Version: 1.4.2 Author: Lokasenna Donation: https://paypal.me/Lokasenna Changelog: - Fix: Issues with siblings of top-level tracks + Fix: Crash referring to "merge_tables" being nil Links: Lokasenna's Website http://forum.cockos.com/member.php?u=10417 About: @@ -35,19 +35,19 @@ end -- Returns true if the individual words of str_b all appear in str_a local function fuzzy_match(str_a, str_b) - + if not (str_a and str_b) then return end str_a, str_b = string.lower(tostring(str_a)), string.lower(tostring(str_b)) - + --Msg("\nfuzzy match, looking for:\n\t" .. str_b .. "\nin:\n\t" .. str_a .. "\n") - + for word in string.gmatch(str_b, "[^%s]+") do --Msg( tostring(word) .. ": " .. tostring( string.match(str_a, word) ) ) if not string.match(str_a, word) then return end end return true - + end @@ -69,6 +69,25 @@ local function is_match(str, tr_name, tr_idx) end +local function merge_tables(...) + + local tables = {...} + + local ret = {} + for i = #tables, 1, -1 do + if tables[i] then + for k, v in pairs(tables[i]) do + if v then ret[k] = v end + end + end + end + + return ret + +end + + + -- Returns an array of MediaTrack == true for all parents of the given MediaTrack local function recursive_parents(track) if reaper.GetTrackDepth(track) == 0 then @@ -149,7 +168,7 @@ local function get_siblings(tracks) -- siblings to false if reaper.GetTrackDepth( reaper.GetTrack(0, child_idx-1) ) == sibling_depth then siblings[child_idx] = true - end + end end @@ -167,35 +186,17 @@ local function get_siblings(tracks) end -local function merge_tables(...) - - local tables = {...} - - local ret = {} - for i = #tables, 1, -1 do - if tables[i] then - for k, v in pairs(tables[i]) do - if v then ret[k] = v end - end - end - end - - return ret - -end - - local function get_tracks_to_show(settings) --[[ settings = { search = str, - matchmultiple = bool, + matchmultiple = bool, matchonlytop = bool, showchildren = bool, showparents = bool, - mcp = bool, + mcp = bool, tcp = bool } ]]-- @@ -272,16 +273,16 @@ end if script_filename ~= "Lokasenna_Show only specified tracks.lua" then - + local tracks = get_tracks_to_show(settings) if tracks then set_visibility( tracks, settings ) else reaper.MB("Error reading the script's settings. Make sure you haven't edited the script at all.", "Whoops!", 0) end - + return - + end @@ -320,11 +321,11 @@ end local function apply_settings() - + local settings = get_settings() local tracks = get_tracks_to_show(settings) set_visibility(tracks, settings) - + end @@ -349,7 +350,7 @@ local function table_to_code(settings) } for k, v in pairs(settings) do - local param = type(v) == "boolean" and tostring(v) + local param = type(v) == "boolean" and tostring(v) or ('"' .. tostring(v) .. '"') strs[#strs+1] = '\t' .. k .. ' = ' .. param .. ',' end @@ -364,7 +365,7 @@ end local function get_settings_to_export() return table_to_code( get_settings() ) - + end @@ -386,21 +387,21 @@ local function continue_export(alias) return end - local arr, copying = {} + local arr, copying = {} --make sure to add a header tag, "generated by" etc. arr[1] = "-- This script was generated by " .. script_filename .. "\n" arr[2] = "\n" .. get_settings_to_export() .. "\n" for line in file_in:lines() do - + if copying then if string.match(line, "-- END FILE COPY HERE") then break end arr[#arr + 1] = line - elseif string.match(line, "-- BEGIN FILE COPY HERE") then + elseif string.match(line, "-- BEGIN FILE COPY HERE") then copying = true - end - + end + end @@ -412,7 +413,7 @@ local function continue_export(alias) if err then reaper.MB("Error opening output file:\n" .. script_path..name_out .. "\n\n".. tostring(err), "Whoops!", 0) return - end + end file_out:write(table.concat(arr, "\n")) file_out:close() @@ -431,7 +432,7 @@ end local function btn_export() GUI.GetUserInputs("Saving settings", {"Name for this preset:"}, {""}, continue_export, 0) - + end @@ -544,7 +545,7 @@ GUI.New("chk_showopts", "Checklist", { shadow = true, swap = nil, opt_size = 20 -}) +}) GUI.New("chk_apply", "Checklist", { z = 11,