Skip to content

Commit

Permalink
Issue 228 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyBars3k committed Mar 2, 2022
1 parent 479250b commit f1e5191
Showing 1 changed file with 56 additions and 52 deletions.
108 changes: 56 additions & 52 deletions Superglue/MB_Superglue-Utils.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- @description MB_Superglue-Utils: Codebase for MB_Superglue scripts' functionality
-- @author MonkeyBars
-- @version 1.784
-- @changelog Remove from Pool doesn't recolor item if enabled (https://github.com/MonkeyBars3k/ReaScripts/issues/228)
-- @version 1.785
-- @changelog Issue 228 fix
-- @provides [nomain] .
-- serpent.lua
-- rtk.lua
Expand Down Expand Up @@ -1725,6 +1725,10 @@ function handleSuperitemPostGlue(superitem, superitem_init_name, pool_id, select
_active_instance_length_has_changed = _pool_parent_last_glue_length ~= selected_items_length
end

if not this_is_reglue then
setSuperitemColor()
end

setSuperitemName(superitem, superitem_init_name)
addRemoveItemImage(superitem, "superitem")
storeRetrieveSuperitemParams(pool_id, _postglue_action_step, superitem)
Expand All @@ -1735,42 +1739,6 @@ function handleSuperitemPostGlue(superitem, superitem_init_name, pool_id, select
end


function setSuperitemName(item, superitem_name_ending)
local take, new_superitem_name

take = reaper.GetActiveTake(item)
new_superitem_name = _superitem_name_prefix .. superitem_name_ending

reaper.GetSetMediaItemTakeInfo_String(take, _api_take_name_key, new_superitem_name, true)
end


function storeRetrieveSuperitemParams(pool_id, action_step, superitem)
local retrieve, store, superitem_params_key_label, retval, superitem_params

retrieve = not superitem
store = superitem
superitem_params_key_label = _pool_key_prefix .. pool_id .. _separator .. action_step .. _superitem_params_suffix

if retrieve then
retval, superitem_params = storeRetrieveProjectData(superitem_params_key_label)
retval, superitem_params = serpent.load(superitem_params)

if superitem_params then
superitem_params.track = reaper.BR_GetMediaTrackByGUID(_api_current_project, superitem_params.track_guid)
end

return superitem_params

elseif store then
superitem_params = getSetItemParams(superitem)
superitem_params = serpent.dump(superitem_params)

storeRetrieveProjectData(superitem_params_key_label, superitem_params)
end
end


function getSetItemParams(item, params)
local get, set, track, retval, track_guid, active_take, active_take_num, item_params

Expand Down Expand Up @@ -1811,6 +1779,16 @@ function getSetItemParams(item, params)
end


function setSuperitemName(item, superitem_name_ending)
local take, new_superitem_name

take = reaper.GetActiveTake(item)
new_superitem_name = _superitem_name_prefix .. superitem_name_ending

reaper.GetSetMediaItemTakeInfo_String(take, _api_take_name_key, new_superitem_name, true)
end


function addRemoveItemImage(item, type_or_remove)
local item_images_are_enabled = reaper.GetExtState(_global_options_section, _global_option_toggle_item_images_key) == "true"

Expand Down Expand Up @@ -1839,6 +1817,46 @@ function addRemoveItemImage(item, type_or_remove)
end


function storeRetrieveSuperitemParams(pool_id, action_step, superitem)
local retrieve, store, superitem_params_key_label, retval, superitem_params

retrieve = not superitem
store = superitem
superitem_params_key_label = _pool_key_prefix .. pool_id .. _separator .. action_step .. _superitem_params_suffix

if retrieve then
retval, superitem_params = storeRetrieveProjectData(superitem_params_key_label)
retval, superitem_params = serpent.load(superitem_params)

if superitem_params then
superitem_params.track = reaper.BR_GetMediaTrackByGUID(_api_current_project, superitem_params.track_guid)
end

return superitem_params

elseif store then
superitem_params = getSetItemParams(superitem)
superitem_params = serpent.dump(superitem_params)

storeRetrieveProjectData(superitem_params_key_label, superitem_params)
end
end


function setSuperitemColor()
local global_option_toggle_new_superglue_random_color = reaper.GetExtState(_global_options_section, _global_option_toggle_new_superglue_random_color_key)

if global_option_toggle_new_superglue_random_color == "true" then
setItemToRandomColor()
end
end


function setItemToRandomColor()
reaper.Main_OnCommand(40706, _api_command_flag)
end


function handleDescendantPoolReferences(pool_id, child_instances_pool_ids)
local this_pool_descendants, i, this_child_pool_id, this_child_pool_descendant_pool_ids_key, retval, this_child_pool_descendant_pool_ids, j, descendant_pool_ids_key, this_pool_descendants_string

Expand Down Expand Up @@ -3502,20 +3520,6 @@ function handleDePoolPostGlue(superitem, target_item_state, target_item_params)
end


function setSuperitemColor()
local global_option_toggle_new_superglue_random_color = reaper.GetExtState(_global_options_section, _global_option_toggle_new_superglue_random_color_key)

if global_option_toggle_new_superglue_random_color == "true" then
setItemToRandomColor()
end
end


function setItemToRandomColor()
reaper.Main_OnCommand(40706, _api_command_flag)
end


function setAllSuperitemsColor()
local current_window, retval, color, all_items_count, i, this_item, this_item_instance_pool_id

Expand Down

0 comments on commit f1e5191

Please sign in to comment.