local path = reaper.GetResourcePath()
V1, V2 = reaper.BR_Win32_GetPrivateProfileString("info", "playType", "nil", path .. "\\ini\\dj.ini")
if (tonumber(V2) == 0) then

local nnner2 =  reaper.NamedCommandLookup("_RSa72f75db8e508290c96e25b87e052565de30e5f5")
stats = reaper.Main_OnCommand(nnner2,0)

end
    local function AddItemByNameToSelectedTracks(PATH,
titleUndo);
	   local in_file = io.open(PATH,"r");
	   if in_file then
	   in_file:close();
   do;
		  local CountSelTrack = reaper.CountSelectedTracks(0);
		  if CountSelTrack == 0 then; --no_undo() return end;
			 local CountTrack = reaper.CountTracks(0);
			 if (reaper.CountSelectedTracks(0) == 0) or (CountTrack  ==0) then;
				reaper.InsertTrackAtIndex(CountTrack,false);
				local Track = reaper.GetTrack(0,CountTrack);
				reaper.SetMediaTrackInfo_Value(Track,"I_SELECTED",1);
				CountSelTrack = reaper.CountSelectedTracks(0);
			 end;
		  end;
		  
		  
		  reaper.Undo_BeginBlock();
		  reaper.PreventUIRefresh(1);
	    
		  local CursorPosition = reaper.GetCursorPosition();
		  reaper.SelectAllMediaItems(0,0);
		  
		  local source = reaper.PCM_Source_CreateFromFile(PATH);
		  local NumChannels = reaper.GetMediaSourceNumChannels(source);
		  if NumChannels > 0 then;
			 for i = 1,CountSelTrack do;
				local Track_Sel = reaper.GetSelectedTrack(0,i-1);
				local NewItem = reaper.CreateNewMIDIItemInProj(Track_Sel,CursorPosition,CursorPosition+0.5,false);
				local Take = reaper.GetActiveTake(NewItem);
				local retval,lengthIsQN = reaper.GetMediaSourceLength(source);
				if lengthIsQN then;
				    retval = reaper.TimeMap2_QNToTime(-1,retval);
				end;
				reaper.SetMediaItemInfo_Value(NewItem,'D_LENGTH',retval);
				reaper.GetSetMediaItemTakeInfo_String(Take,"P_NAME",PATH:match(".+[/\\](.+)"),1);
				reaper.SetMediaItemInfo_Value(NewItem,'B_UISEL',1);
				reaper.SetMediaItemTake_Source(Take,source);
				reaper.SetEditCurPos(CursorPosition+retval,true,false);
			 end;
		  end;
		  reaper.Main_OnCommand(40047,0); -- build missing peaks
		  reaper.UpdateArrange();
		  
		  reaper.PreventUIRefresh(-1);
		  reaper.Undo_EndBlock(titleUndo,-1);
	   end;
end
end


function getIniKeysNumber(sectionname, path)
menu1=0
num1, num2 = reaper.BR_Win32_GetPrivateProfileString(sectionname, tostring(menu1 +1), "nil", path)
if (num2  ~= "nil") then
menu1 = menu1 +1
    for i = 0, 100000 do
num1, num2 = reaper.BR_Win32_GetPrivateProfileString(sectionname, tostring(menu1), "nil", path)
if  num2  ~= "nil" then
menu1 = menu1 +1
else
--menu1 = menu1 +1
break
end
end
end
return menu1
end

function SoundPlay(pather)
		  local source = reaper.PCM_Source_CreateFromFile(pather)
idd1 =  reaper.Xen_StartSourcePreview(source,0.80,0 )
local inipath = reaper.GetResourcePath()
local  pathfull =inipath  .. "\\ini\\dj temp.ini"
reaper.BR_Win32_WritePrivateProfileString("0", tostring(getIniKeysNumber("0", pathfull)), idd1, pathfull)
end
local inipath = reaper.GetResourcePath()
local  pathfull =inipath  .. "\\ini\\dj.ini"
finpath=""
num11, num22 = reaper.BR_Win32_GetPrivateProfileString("info", "last3", "", pathfull)
if (tonumber(num22) >0) then
finpath= finpath .. num22  
end
num11, num22 = reaper.BR_Win32_GetPrivateProfileString("info", "last2", "", pathfull)
if (tonumber(num22) >0) then
finpath= finpath .. num22  
end
num1, num2 = reaper.BR_Win32_GetPrivateProfileString("info", "last1", "", pathfull)
num11, num22 = reaper.BR_Win32_GetPrivateProfileString(num2, "7", "", pathfull)
finpath= finpath .. num22  
local path = reaper.GetResourcePath().. "/sounds/" .. finpath .. ".mp3"
local inipath = reaper.GetResourcePath()
local  pathfull =inipath  .. "\\ini\\dj.ini"
num11, num22 = reaper.BR_Win32_GetPrivateProfileString("info", "ActionMode", "", pathfull)
if (num22 == "1") then
AddItemByNameToSelectedTracks(path, 'Add media file(item) by name ("") on track(s)');
else
SoundPlay(path)
end