
function getNumSplitItems()
  title = "Divide selected items Into?"
  num_inputs = 1
  captions_csv = "Split"
  retvals_csv = ""
  retval, retvals_csv = reaper.GetUserInputs(title, num_inputs, captions_csv, retvals_csv)
  if retval == true then
    return tonumber(retvals_csv)
  else

    return  nil
--  retvals_csv = nil
  end
end




mena =  getNumSplitItems()
if mena  == nil then return end
 reaper.Undo_BeginBlock()
--====================================================================== 
local a=0;local I=reaper.CountSelectedMediaItems(a);local e=reaper.GetProjectLength(a);local d=41613 local c=40757 local m="mena split into"local l=200;local function r(e)local t=true;local a=reaper.CountSelectedMediaItems(a);if(a>e)then reaper.ShowMessageBox("over "..tostring(e).." clip num .\nstop process","stop.",0)t=false;end return t end if(r(l)==false)then return end local function p(e)local t=reaper.CountSelectedMediaItems(e);local d=reaper.GetProjectLength(e);local n={}local a={}local o=0;while(o<t)do local t=reaper.GetSelectedMediaItem(e,o);local r=reaper.GetMediaItemTrack(t);local e=reaper.GetMediaTrackInfo_Value(r,"IP_TRACKNUMBER");if(a[e]==nil)then a[e]={}local l=reaper.CountTrackMediaItems(r);local t=0;while(t<l)do local l=reaper.GetTrackMediaItem(r,t)local o=reaper.GetMediaItemInfo_Value(l,"D_POSITION")local n=reaper.GetMediaItemInfo_Value(l,"D_LENGTH")local r={mediaItem=l,startTime=o,length=n,endTime=o+n,mediaItemIdx=reaper.GetMediaItemInfo_Value(l,"IP_ITEMNUMBER"),trackId=e,mediaTrack=r};table.insert(a[e],r);t=t+1;end table.sort(a[e],function(a,e)return(a.startTime>e.startTime);end);end local i=reaper.GetMediaItemInfo_Value(t,"D_POSITION")local l=reaper.GetMediaItemInfo_Value(t,"D_LENGTH")local t={mediaItem=t,startTime=i,length=l,endTime=i+l,mediaItemIdx=reaper.GetMediaItemInfo_Value(t,"IP_ITEMNUMBER"),trackId=e,mediaTrack=r,nextItemStartTime=nil,nextMediaItem=nil};local l=d;local r=nil for a,e in ipairs(a[e])do if(e.mediaItemIdx==t.mediaItemIdx)then t.nextItemStartTime=l;t.nextMediaItem=r;end l=e.startTime;r=e;end if(n[e]==nil)then n[e]={}end table.insert(n[e],t);o=o+1;end return a,n end local r=retvals_csv;if(I>0)then
local t,e=p(a)local n=reaper.GetCursorPosition();for t,e in pairs(e)do for t,e in ipairs(e)do local t=e.length/r;local l=1/128 if(t<l)then return end;local l=e.startTime reaper.SetMediaItemSelected(e.mediaItem,true)for e=1,r do local e=l+t*e reaper.PreventUIRefresh(3)reaper.SetEditCurPos(e,true,false)reaper.Main_OnCommand(c,a)reaper.Main_OnCommand(d,a)reaper.PreventUIRefresh(-1)end end end reaper.SetEditCurPos(n,true,false)reaper.PreventUIRefresh(-1)

  reaper.Undo_EndBlock("Split Items into", -1)
reaper.UpdateArrange()


end