diff --git a/ReaClassical/ReaClassical_Prepare Takes.lua b/ReaClassical/ReaClassical_Prepare Takes.lua index 76c4f9c0..1d632cf6 100644 --- a/ReaClassical/ReaClassical_Prepare Takes.lua +++ b/ReaClassical/ReaClassical_Prepare Takes.lua @@ -23,8 +23,8 @@ along with this program. If not, see . for key in pairs(reaper) do _G[key] = reaper[key] end local main, shift, horizontal_color, vertical_color_razor, horizontal_group -local vertical_group, horizontal, vertical, copy_track_items, get_color_table -local tracks_per_folder, xfade_check, empty_items_check, get_path, folder_check +local vertical_group, horizontal, vertical, get_color_table +local xfade_check, empty_items_check, get_path, folder_check local trackname_check --------------------------------------------------------------------- @@ -45,6 +45,16 @@ function main() if group_state ~= 1 then Main_OnCommand(1156, 0) -- Enable item grouping end + + local num_pre_selected = CountSelectedTracks(0) + local pre_selected = {} + if num_pre_selected > 0 then + for i = 0, num_pre_selected - 1, 1 do + local track = GetSelectedTrack(0, i) + table.insert(pre_selected, track) + end + end + local cur_pos = (GetPlayState() == 0) and GetCursorPosition() or GetPlayPosition() local start_time, end_time = GetSet_ArrangeView2(0, false, 0, 0, 0, 0) local num_of_project_items = CountMediaItems(0) @@ -70,25 +80,7 @@ function main() end Main_OnCommand(40769, 0) -- Unselect (clear selection of) all tracks/items/envelope points - local folders, tracks_per_group = folder_check() - local total_tracks = folders * tracks_per_group - local empty = false - for i = 0, total_tracks - 1, 1 do - local track = GetTrack(0, i) - if GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH") == 1.0 then - local items = CountTrackMediaItems(track) - if items == 0 then - for j = i + 1, i + 1 + tracks_per_group, 1 do - local child_track = GetTrack(0, j) - local child_items = CountTrackMediaItems(child_track) - if child_items > 0 then - empty = true - break - end - end - end - end - end + local folders = folder_check() local first_item = GetMediaItem(0, 0) local position = GetMediaItemInfo_Value(first_item, "D_POSITION") @@ -96,11 +88,6 @@ function main() shift() end - if empty then - local folder_size = tracks_per_folder() - copy_track_items(folder_size, total_tracks) - end - local _, input = GetProjExtState(0, "ReaClassical", "Preferences") local colors = 0 if input ~= "" then @@ -121,12 +108,18 @@ function main() local scroll_up = NamedCommandLookup("_XENAKIOS_TVPAGEHOME") Main_OnCommand(scroll_up, 0) - if empty then - MB( - "Some folder tracks are empty. If the folders are not completely empty, items " .. - "from first child tracks were copied to folder tracks and muted to act as guide tracks." - , "Guide Tracks Created", 0) + if num_pre_selected > 0 then + Main_OnCommand(40297, 0) --unselect_all + SetOnlyTrackSelected(pre_selected[1]) + for _, track in ipairs(pre_selected) do + if pcall(IsTrackSelected, track) then SetTrackSelected(track, 1) end + end end + + MB("Project takes have been prepared! " .. + "You can run again if you import or record more material..." + , "ReaClassical", 0) + Undo_EndBlock('Prepare Takes', 0) PreventUIRefresh(-1) UpdateArrange() @@ -345,47 +338,6 @@ end --------------------------------------------------------------------- -function copy_track_items(folder_size, total_tracks) - local pos = 0; - for i = 1, total_tracks - 1, folder_size do - local track = GetTrack(0, i) - local previous_track = GetTrack(0, i - 1) - local count_items = CountTrackMediaItems(previous_track) - if count_items > 0 then goto continue end -- guard clause for populated folder - SetOnlyTrackSelected(track) - local num_of_items = CountTrackMediaItems(track) - if num_of_items == 0 then goto continue end -- guard clause for empty first child - for j = 0, num_of_items - 1 do - local item = GetTrackMediaItem(track, j) - if j == 0 then - pos = GetMediaItemInfo_Value(item, "D_POSITION") - end - SetMediaItemSelected(item, 1) - end - Main_OnCommand(40698, 0) -- Edit: Copy items - SetOnlyTrackSelected(previous_track) - SetEditCurPos(pos, false, false) - Main_OnCommand(42398, 0) -- Item: Paste items/tracks - Main_OnCommand(40719, 0) -- Item properties: Mute - Main_OnCommand(40769, 0) -- Unselect (clear selection of) all tracks/items/envelope points - ::continue:: - end -end - ---------------------------------------------------------------------- - -function tracks_per_folder() - local first_track = GetTrack(0, 0) - SetOnlyTrackSelected(first_track) - local select_children = NamedCommandLookup("_SWS_SELCHILDREN2") - Main_OnCommand(select_children, 0) -- SWS: Select children of selected folder track(s) - local selected_tracks = CountSelectedTracks(0) - Main_OnCommand(40297, 0) -- Track: Unselect (clear selection of) all tracks - return selected_tracks -end - ---------------------------------------------------------------------- - function xfade_check() local first_track = GetTrack(0, 0) local num_of_items = CountTrackMediaItems(first_track)