Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 08-13-2020, 01:08 AM   #1
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 2,011
Default Version: Script: Lokasenna_Create folder to contain selected tracks.lua

Hi, I made a version of "Script: Lokasenna_Create folder to contain selected tracks.lua" as the script and some others involving folders if the user makes a track selection dividing an existing folderit can get weird ( its late I'm a little tired to explain maybe I edit tommorow hahaha)

but here are some examples

Original States of Tracks



Script of Lokasenna (Last track selected is in the middle of an folder, it causes the next track to it get out of this folder )



My edition over his script




Here is the code of the edition. it is very raw, as I haven't tested it much (and if you wanna help me test it hahaha) I will clean later.
Code:
local firstSel = reaper.GetSelectedTrack(0, 0)
if not firstSel then return end

reaper.Undo_BeginBlock()
reaper.PreventUIRefresh( 1 )

local idx = reaper.GetMediaTrackInfo_Value(firstSel, "IP_TRACKNUMBER") - 1
reaper.InsertTrackAtIndex(idx, true)
local parent = reaper.GetTrack(0, idx)
--[[
  I_FOLDERDEPTH : int * : folder depth change (0=normal, 1=track is a folder parent,
  -1=track is the last in the innermost folder, -2=track is the last in the innermost
  and next-innermost folders, etc
]]--

------reaper.GetSetMediaTrackInfo_String( parent, "P_NAME", parentName, true )
reaper.SetMediaTrackInfo_Value( parent, "I_FOLDERDEPTH", 1, true )

--_FOLDERDEPTH
seltracks_numb = reaper.CountSelectedTracks(0)
lastSel = reaper.GetSelectedTrack(0, seltracks_numb-1)
lastSel_idx = reaper.GetMediaTrackInfo_Value( lastSel,  "IP_TRACKNUMBER" )
 for i = 0, seltracks_numb - 1 do
  selected_track = reaper.GetSelectedTrack(0, i )
  folder_info = reaper.GetMediaTrackInfo_Value( selected_track, "I_FOLDERDEPTH" ) 
  track_idx_first_loop = reaper.GetMediaTrackInfo_Value( selected_track,  "IP_TRACKNUMBER" )
  counter = 0
  if folder_info ~= 0 then counter = counter + folder_info  end 
  i2 = 0
  while counter > 0 do
       i2 = i2 + 1
       track = reaper.GetTrack(0, track_idx_first_loop+i2-1)
       folder_c_info = reaper.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH" )
      if  folder_c_info == 1 then
       counter = counter + 1 
      end
      if folder_c_info < 0  then 
         counter = counter + folder_c_info 
         if  (track_idx_first_loop+i2)>lastSel_idx then
           lastSel = track
           lastSel_idx = reaper.GetMediaTrackInfo_Value( lastSel,  "IP_TRACKNUMBER" )
           max_lastSel_idx = math.max(lastSel_idx)
           lastSel = reaper.GetTrack(0, max_lastSel_idx-1)
         end
      end
  end
end
local curDepth = reaper.GetMediaTrackInfo_Value( lastSel, "I_FOLDERDEPTH" )

reaper.SetMediaTrackInfo_Value( lastSel, "I_FOLDERDEPTH", curDepth-1, true )

reaper.PreventUIRefresh( -1 )

reaper.TrackList_AdjustWindows( false )
reaper.UpdateArrange()

reaper.Undo_EndBlock("Create folder to contain selected tracks", 0)
If you wanna the get user input for naming the track just erase the --


also is ok I post an version of his script? else I can scratch the post....

also where should one use local???? like I know what a local variable is ( I think ) where should I must use it?
daniellumertz is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.