--=========================================
local function MODULE(file);
local E,A=pcall(dofile,file);if not(E)then;reaper.ShowConsoleMsg("\n\nError - "..debug.getinfo(1,'S').source:match('.*[/\\](.+)')..'\nMISSING FILE / ОТСУТСТВУЕТ ФАЙЛ!\n'..file:gsub('\\','/'))return;end;
if not A.VersArcFun("3.0.1",file,'')then;A=nil;return;end;return A;
end; local Arc = MODULE((reaper.GetResourcePath()..'/Scripts/Archie-ReaScripts/Functions/Arc_Function_lua.lua'):gsub('\\','/'));
if not Arc then return end;
local ArcFileIni = reaper.GetResourcePath():gsub('\\','/')..'/reaper-Archie.ini';
--=========================================
-------------------------------------------------------
local function copyTake(item,idxTake,destItem,newItem);
--POOL=true;
local retval,str = reaper.GetItemStateChunk(item,'',false);
if idxTake == 0 then;
----
local TK,X;
local STR = '';
for val in string.gmatch(str,".-\n") do;
----
if POOL ~= true then;
val = val:gsub('^%s-POOLEDEVTS%s+%{.+%}','POOLEDEVTS '..reaper.genGuid(''));
end;
val = val:gsub('^%s-GUID%s+%{.+%}','GUID '..reaper.genGuid(''));
----
if val:match('^TAKE%s-\n')or
val:match('^TAKE%s+SEL%s-\n')then;
X = true;
end;
---
if val:match('^TAKE%s+SEL%s-\n')then;TK = 'TAKE\n'break end;
---
if X ~= true then; STR = (STR or '')..val; end;
end;
----
if STR ~= '' and STR ~= str then STR = STR..'\n>\n'; end;
-----
local D;
local STR2 = '';
for val in string.gmatch(STR,".-\n") do;
if D==true then;STR2 = STR2..val;end;
if val:match('^IGUID')then;
D=true;
end;
end;
-----
local retval,str2 = reaper.GetItemStateChunk(destItem,'',false);
local STR3;
if newItem == true then;
local D;
local STR = '';
for val in string.gmatch(str2,".-\n") do;
if val:match('^IGUID')then;
D=true;
end;
STR3 = (STR3 or '')..val;
if D==true then;break;end;
end;
STR3 = STR3..STR2;
else;
TK = TK or 'TAKE SEL\n';
STR2 = TK..STR2;
STR3 = str2:gsub('>%s-\n-%s-$',STR2..'\n%0');
end;
reaper.SetItemStateChunk(destItem,STR3,false);
----
elseif idxTake > 0 then;
----
local STR = '';
local x = 0;
for val in string.gmatch(str,".-\n") do;
if val:match('^TAKE%s-\n')or
val:match('^TAKE%s+SEL%s-\n')then;
x = x+1;
end;
---
if x == idxTake then;
STR = (STR or '')..val;
end;
if x > idxTake then break end;
end;
---
local STR2 = '';
local x = 0;
for val in string.gmatch(STR,".-\n") do;
if val:match('^<')then x=x+1 end;
if val:match('^>')then x=x-1 end;
if x < 0 then val = '' x=0 end;
----
if POOL ~= true then;
val = val:gsub('^%s-POOLEDEVTS%s+%{.+%}','POOLEDEVTS '..reaper.genGuid(''));
end;
val = val:gsub('^%s-GUID%s+%{.+%}','GUID '..reaper.genGuid(''));
----
STR2 = STR2..val;
end;
----
if STR2 and STR2 ~= '' then;
local retval,str = reaper.GetItemStateChunk(destItem,'',false);
local STR3 = '';
if newItem == true then;
----
for val in string.gmatch(str,".-\n") do;
if val:match('^IGUID')then;
break;
end;
STR3 = STR3..val;
end;
STR2 = STR2:gsub('^%s-TAKE%s-[SEL]*%s-\n','');
STR3 = STR3..'\n'..STR2..'\n>';
else;
STR3 = str:gsub('>%s-\n-%s-$',STR2..'\n%0');
end;
reaper.SetItemStateChunk(destItem,STR3,false);
end;
end;
end;
-------------------------------------------------------
local CountSelTrack = reaper.CountSelectedTracks(0);
if CountSelTrack == 0 then no_undo()return end;
for t_idx = 1,CountSelTrack do;
local trackSel = reaper.GetSelectedTrack(0,t_idx-1);
local CountTrItem = reaper.CountTrackMediaItems(trackSel);
if CountTrItem > 0 then;
----
if not UNDO then;
reaper.Undo_BeginBlock();
reaper.PreventUIRefresh(1);
UNDO = true;
end;
----
local numb = reaper.GetMediaTrackInfo_Value(trackSel,'IP_TRACKNUMBER');
local maxtake;
for i = 1,CountTrItem do;
local item = reaper.GetTrackMediaItem(trackSel,i-1);
local counttake = reaper.CountTakes(item);
maxtake = math.max(counttake,(maxtake or 0));
end;
for i = 1,maxtake do;
reaper.InsertTrackAtIndex(i-1+numb,false);
end;
for i = 1,CountTrItem do;
local item = reaper.GetTrackMediaItem(trackSel,i-1);
local take = reaper.GetActiveTake(item);
local nmbTake = reaper.GetMediaItemTakeInfo_Value(take,'IP_TAKENUMBER');
local track = reaper.GetTrack(0,numb+nmbTake);
local pos = reaper.GetMediaItemInfo_Value(item,'D_POSITION');
local len = reaper.GetMediaItemInfo_Value(item,'D_LENGTH');
local itemNew = reaper.CreateNewMIDIItemInProj(track,pos,pos+len,false);
copyTake(item,nmbTake,itemNew,true);
end;
end;
end;
if UNDO then;
reaper.Undo_EndBlock("Copy Take &&&",-1);
reaper.PreventUIRefresh(-1);
else;
no_undo();
end;
reaper.UpdateArrange();