diff --git a/Fold Source/MB_Fold source media into imploded takes at item length - if multiple takes, explode active take to new track.lua b/Fold Source/MB_Fold source media into imploded takes at item length - if multiple takes, explode active take to new track.lua index 1dfd365..4fe46c2 100644 --- a/Fold Source/MB_Fold source media into imploded takes at item length - if multiple takes, explode active take to new track.lua +++ b/Fold Source/MB_Fold source media into imploded takes at item length - if multiple takes, explode active take to new track.lua @@ -1,7 +1,7 @@ -- @description MB_Fold source media into imploded takes at item length - if multiple takes, explode active take to new track -- @author MonkeyBars --- @version 1.1.2 --- @changelog Fix package +-- @version 1.1.3 +-- @changelog Fix globals -- @provides [main] . -- [nomain] mb-dev-functions.lua -- gnu_license_v3.txt @@ -28,21 +28,25 @@ reaper.Undo_BeginBlock() -local _all_take_info_values, _selected_items, _original_item_length, _item_takes_count, _item_all_takes, _active_take, _active_take_source, _active_take_source_length, _active_take_source_type, _active_take_source_filename, _active_take_num, _active_take_params, _new_takes_before_active_count, _source_length_after_active_take, _new_takes_after_active_count, _new_active_take, _explode_active_takes_to_new_tracks, _api_command_flag, _command_id_deselect_all_items, _command_id_set_item_bounds_to_source, _command_id_delete_active_take, _command_id_duplicate_active_take, _api_take_src_offset_key, _api_item_length_key, _api_item_position_key, _api_takenumber_key, _api_take_name_key, _api_take_guid_key -_all_take_info_values = {"D_STARTOFFS", "D_VOL", "D_PAN", "D_PANLAW", "D_PLAYRATE", "D_PITCH", "B_PPITCH", "I_CHANMODE", "I_PITCHMODE"} -_explode_active_takes_to_new_tracks = reaper.NamedCommandLookup("_RS57edce15d7afa714deecb2ac0541e8cdd3af72cb") -_api_command_flag = 0 -_command_id_deselect_all_items = 40289 -_command_id_set_item_bounds_to_source = 42228 -_command_id_delete_active_take = 40129 -_command_id_duplicate_active_take = 40639 -_api_take_src_offset_key = "D_STARTOFFS" -_api_item_length_key = "D_LENGTH" -_api_item_position_key = "D_POSITION" -_api_takenumber_key = "IP_TAKENUMBER" -_api_take_name_key = "P_NAME" -_api_take_guid_key = "GUID" +local _cmd = { + deselect_all_items = 40289, + set_item_bounds_to_source = 42228, + delete_active_take = 40129, + duplicate_active_take = 40639, + explode_active_takes_to_new_tracks = reaper.NamedCommandLookup("_RS57edce15d7afa714deecb2ac0541e8cdd3af72cb") +} + +local _api = { + command_flag = 0, + take_src_offset_key = "D_STARTOFFS", + item_length_key = "D_LENGTH", + item_position_key = "D_POSITION", + takenumber_key = "IP_TAKENUMBER", + take_name_key = "P_NAME", + msg_type_ok = 0, + all_take_info_values = {"D_STARTOFFS", "D_VOL", "D_PAN", "D_PANLAW", "D_PLAYRATE", "D_PITCH", "B_PPITCH", "I_CHANMODE", "I_PITCHMODE"} +} @@ -69,12 +73,12 @@ function requiredLibsAreInstalled() end if not can_get_sws_version or not sws_version then - reaper.ShowMessageBox("Please install SWS from https://standingwaterstudios.com/ and try again.", "MB_Fold source media requires the SWS plugin extension to work.", _msg_type_ok) + reaper.ShowMessageBox("Please install SWS from https://standingwaterstudios.com/ and try again.", "MB_Fold source media requires the SWS plugin extension to work.", _api.msg_type_ok) return false - elseif not _explode_active_takes_to_new_tracks then - reaper.ShowMessageBox("Please install the ReaTeam scripts from https://github.com/ReaTeam/ReaScripts/raw/master/index.xml and try again.", "MB_Fold source media requires an Amalgama script to work.", _msg_type_ok) + elseif not _cmd.explode_active_takes_to_new_tracks then + reaper.ShowMessageBox("Please install the ReaTeam scripts from https://github.com/ReaTeam/ReaScripts/raw/master/index.xml and try again.", "MB_Fold source media requires an Amalgama script to work.", _api.msg_type_ok) return false end @@ -96,7 +100,7 @@ function getSetSelectedItems(new_selected_items) return getSelectedItems() elseif get_set == "set" then - reaper.Main_OnCommand(_command_id_deselect_all_items, _api_command_flag) + reaper.Main_OnCommand(_cmd.deselect_all_items, _api.command_flag) for i = 1, #new_selected_items do reaper.SetMediaItemSelected(new_selected_items[i], true) @@ -182,7 +186,7 @@ function foldSelectedItems() for i = 1, #_selected_items do this_selected_item = _selected_items[i] - reaper.Main_OnCommand(_command_id_deselect_all_items, _api_command_flag) + reaper.Main_OnCommand(_cmd.deselect_all_items, _api.command_flag) reaper.SetMediaItemSelected(this_selected_item, true) getItemAndTakeValues(this_selected_item) foldItem(this_selected_item) @@ -191,7 +195,7 @@ end function getItemAndTakeValues(item) - _original_item_length = reaper.GetMediaItemInfo_Value(item, _api_item_length_key) + _original_item_length = reaper.GetMediaItemInfo_Value(item, _api.item_length_key) _item_takes_count = reaper.GetMediaItemNumTakes(item) _item_all_takes = {} @@ -215,16 +219,16 @@ end function getMidiTakeValues(item) local original_item_position, original_active_take_offset - original_item_position = reaper.GetMediaItemInfo_Value(item, _api_item_position_key) - original_active_take_offset = reaper.GetMediaItemTakeInfo_Value(_active_take, _api_take_src_offset_key) + original_item_position = reaper.GetMediaItemInfo_Value(item, _api.item_position_key) + original_active_take_offset = reaper.GetMediaItemTakeInfo_Value(_active_take, _api.take_src_offset_key) - reaper.Main_OnCommand(_command_id_set_item_bounds_to_source, _api_command_flag) + reaper.Main_OnCommand(_cmd.set_item_bounds_to_source, _api.command_flag) - _active_take_source_length = reaper.GetMediaItemInfo_Value(item, _api_item_length_key) + _active_take_source_length = reaper.GetMediaItemInfo_Value(item, _api.item_length_key) reaper.SetMediaItemPosition(item, original_item_position, false) reaper.SetMediaItemLength(item, _original_item_length, false) - reaper.SetMediaItemTakeInfo_Value(_active_take, _api_take_src_offset_key, original_active_take_offset) + reaper.SetMediaItemTakeInfo_Value(_active_take, _api.take_src_offset_key, original_active_take_offset) end @@ -242,7 +246,7 @@ end function extractActiveTake(item) if _item_takes_count > 1 then - reaper.Main_OnCommand(_explode_active_takes_to_new_tracks, _api_command_flag) + reaper.Main_OnCommand(_cmd.explode_active_takes_to_new_tracks, _api.command_flag) return true end @@ -294,7 +298,7 @@ end function defineTakeSetup() - _active_take_num = reaper.GetMediaItemTakeInfo_Value(_active_take, _api_takenumber_key) + _active_take_num = reaper.GetMediaItemTakeInfo_Value(_active_take, _api.takenumber_key) _active_take_params = getSetTakeParams(_active_take, "get") _new_takes_before_active_count = math.ceil(_active_take_params.D_STARTOFFS / _original_item_length) _source_length_after_active_take = _active_take_source_length - _original_item_length - _active_take_params.D_STARTOFFS @@ -308,21 +312,21 @@ function getSetTakeParams(take, get_set, new_params) if get_set == "get" then this_take_params = {} - for i = 1, #_all_take_info_values do - this_take_param_name = _all_take_info_values[i] + for i = 1, #_api.all_take_info_values do + this_take_param_name = _api.all_take_info_values[i] this_take_param_value = reaper.GetMediaItemTakeInfo_Value(take, this_take_param_name) this_take_params[this_take_param_name] = this_take_param_value end - retval, this_take_params["name"] = reaper.GetSetMediaItemTakeInfo_String(take, _api_take_name_key, "", false) + retval, this_take_params["name"] = reaper.GetSetMediaItemTakeInfo_String(take, _api.take_name_key, "", false) return this_take_params elseif get_set == "set" then - for i = 1, #_all_take_info_values do - this_take_param_name = _all_take_info_values[i] + for i = 1, #_api.all_take_info_values do + this_take_param_name = _api.all_take_info_values[i] reaper.SetMediaItemTakeInfo_Value(take, this_take_param_name, new_params[this_take_param_name]) end @@ -355,24 +359,24 @@ function addNewTake(item, new_take_idx, new_take_location) new_take_offset = _active_take_params.D_STARTOFFS + round( (_original_item_length * new_take_idx ), 12) end - reaper.Main_OnCommand(_command_id_duplicate_active_take, _api_command_flag) + reaper.Main_OnCommand(_cmd.duplicate_active_take, _api.command_flag) new_take = reaper.GetActiveTake(item) reaper.SetActiveTake(new_take) - reaper.SetMediaItemTakeInfo_Value(new_take, _api_take_src_offset_key, new_take_offset) + reaper.SetMediaItemTakeInfo_Value(new_take, _api.take_src_offset_key, new_take_offset) end function handleActiveTake(item) local new_take - reaper.Main_OnCommand(_command_id_duplicate_active_take, _api_command_flag) + reaper.Main_OnCommand(_cmd.duplicate_active_take, _api.command_flag) new_take = reaper.GetActiveTake(item) _new_active_take = new_take - reaper.SetMediaItemTakeInfo_Value(_new_active_take, _api_take_src_offset_key, _active_take_params.D_STARTOFFS) + reaper.SetMediaItemTakeInfo_Value(_new_active_take, _api.take_src_offset_key, _active_take_params.D_STARTOFFS) end @@ -405,7 +409,7 @@ function renameTake(item, idx, all_takes_count) local this_take, this_take_source_end_point, this_take_indicator, this_is_last_take, new_take_name this_take = reaper.GetTake(item, idx) - this_take_offset = round(reaper.GetMediaItemTakeInfo_Value(this_take, _api_take_src_offset_key), 3) + this_take_offset = round(reaper.GetMediaItemTakeInfo_Value(this_take, _api.take_src_offset_key), 3) this_take_source_end_point = round(this_take_offset + _original_item_length, 3) this_is_last_take = idx == all_takes_count-1 @@ -418,13 +422,13 @@ function renameTake(item, idx, all_takes_count) new_take_name = _active_take_params.name .. " " .. idx .. " of " .. all_takes_count .. " [" .. this_take_offset .. "s to " .. this_take_source_end_point .. "s] " .. this_take_indicator - reaper.GetSetMediaItemTakeInfo_String(this_take, _api_take_name_key, new_take_name, true) + reaper.GetSetMediaItemTakeInfo_String(this_take, _api.take_name_key, new_take_name, true) end function cleanUpFoldSource() reaper.SetActiveTake(_active_take) - reaper.Main_OnCommand(_command_id_delete_active_take, _api_command_flag) + reaper.Main_OnCommand(_cmd.delete_active_take, _api.command_flag) reaper.SetActiveTake(_new_active_take) end