Skip to content

Commit

Permalink
Fix: Crash due to function being out of scope
Browse files Browse the repository at this point in the history
  • Loading branch information
jalovatt committed Oct 13, 2018
1 parent 641c422 commit 576562e
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions Tracks Properties/Lokasenna_Show only specified tracks.lua
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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


Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
}
]]--
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand All @@ -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
Expand All @@ -364,7 +365,7 @@ end
local function get_settings_to_export()

return table_to_code( get_settings() )

end


Expand All @@ -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


Expand All @@ -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()

Expand All @@ -431,7 +432,7 @@ end
local function btn_export()

GUI.GetUserInputs("Saving settings", {"Name for this preset:"}, {""}, continue_export, 0)

end


Expand Down Expand Up @@ -544,7 +545,7 @@ GUI.New("chk_showopts", "Checklist", {
shadow = true,
swap = nil,
opt_size = 20
})
})

GUI.New("chk_apply", "Checklist", {
z = 11,
Expand Down

0 comments on commit 576562e

Please sign in to comment.