local timer2 =  reaper.NamedCommandLookup("_SWS_AWTBASETIME")
local timer1 = reaper.GetToggleCommandStateEx(0, timer2)
local rate2 =  reaper.NamedCommandLookup("_SWS_AWTBASEBEATALL")
local rate1 = reaper.GetToggleCommandStateEx(0, rate2)
local beatonly2 =  reaper.NamedCommandLookup("_SWS_AWTBASEBEATPOS")
local beatonly1 = reaper.GetToggleCommandStateEx(0, beatonly2)

if  timer1 == 1 then
timebase = " timebase is time "
elseif  rate1 == 1 then
timebase = " timebase is Beats (position, length, rate) "
elseif  beatonly1 == 1 then
timebase = " timebase is Beats (position only) "
end

Xtrack = reaper.CountTracks(0)
Xitem = reaper.CountMediaItems(0)
Xname  = reaper.GetProjectName(0,0)
Xname2  = reaper.GetProjectName(0,0)
Xpath =   reaper.GetProjectPath(0)
Xtempo=  reaper.GetProjectTimeSignature2(0)
Xsave  = reaper.IsProjectDirty(0)

if not( Xpath == "") then
Xpathn =" Located in "
end

if (Xsave == 1) then
Xsave = "Requires to save "
else
Xsave = ""
end

if Xname  == "" then
Xname  = "UnnamedProject "
end

if ( Xitem == nil) or( Xtrack <2 ) then
pitem = "item "
else
pitem = "items "
end
if ( Xtrack == nil) or( Xtrack <2 ) then
ptrack = "track "
else
ptrack = "tracks "
end
Xex = Xpath .. "\\" .. Xname2
exc = reaper.file_exists(Xex)
if   (exc == true)  then
Xpath = Xpathn .. Xpath
else
Xpath = ""
end
Z  = Xname  .. " has " .. Xtrack.. ptrack.."and ".. Xitem..pitem
Z =Z.. "Project Tempo is " .. Xtempo
R   = reaper.GetProjectLength()
 retval, measures, cml, beat, denom = reaper.TimeMap2_timeToBeats( 0,  R  ) 
Z = Z .. " Time signature is " .. cml  .. "/".. denom  .. timebase


Rz, O = reaper.GetAudioDeviceInfo("IDENT_IN", "")
Rz2, OO = reaper.GetAudioDeviceInfo("IDENT_OUT", "")








local pauser = reaper.GetToggleCommandStateEx(0, 40367)
local stoper = reaper.GetToggleCommandStateEx(0, 1016)
local player = reaper.GetToggleCommandStateEx(0, 1007)
local recording = reaper.GetToggleCommandStateEx(0, 1013)

mono = reaper.GetProjectLength()
--awad =     reaper.GetCursorPosition();
--mono = mena - awad

function SplitFilename(strFilename)
  return string.match(strFilename, "(.-)([^.]-[.-])([^.]+)$")

end


if pauser == 0 then
local OOO1 =  math.floor( 1 * mono  / 60 /60 ) 
local OOO2 =  math.floor( 1 * mono  / 60% 60 ) 
local OOO3 =  math.floor( 100 * (mono % 60 ) ) / 100 


if (tonumber(OOO1) == nil) then
 hour = ""
elseif (tonumber(OOO1) == 0) then
 hour = ""
OOO1 = ""
elseif (tonumber(OOO1) == 1) then
hour = "Hour"
 else
hour = "Hours"
 end
if (tonumber(OOO2) == nil) then
 min = ""
elseif (tonumber(OOO2) == 0) then
 min = ""
OOO2 = ""
elseif (tonumber(OOO2) == 1) then
 min = "Minute"
 else
 min = "Minutes"
 end

if (tonumber(OOO3) == nil)  then
 sec = ""
elseif  (tonumber(OOO3) == 1)  then
 sec = ""
OOO3 = ""
elseif  (tonumber(OOO3) == 1)  then
 sec = "Second"
 else
 sec = "Seconds"
 end
X = "Duration " ..OOO1 .. hour .." " .. OOO2 .. min .. OOO3 .. sec

else
    local Q = reaper.format_timestr_pos(mono,'',1)
 OOO1, OOO2, OOO3 = SplitFilename(Q)

local pp = 1
                local name1 = string.match(string.reverse(OOO1),".+",pp+1)
                if not name1 then name1 = "" end
                local name1 = string.reverse(name1)
local ppp = 2

OOO11 = OOO1 -1
                local name11 = string.match(string.reverse(OOO11),".+",ppp+1)
                if not name11 then name11 = "" end
                local name11 = string.reverse(name11)
local pp = 1

                local name2 = string.match(string.reverse(OOO2),".+",pp+1)
                if not name2 then name1 = "" end
                local name2 = string.reverse(name2)


                local name3 = string.match(string.reverse(OOO3),".+",pp+1)
                if not name3 then name3 = "" end
                local name3 = string.reverse(name3)



if (tonumber(name11) == nil) then
 Bar = ""
elseif (tonumber(name11) == 0) then
Bar = ""
name1 = ""
name11 = ""
elseif (tonumber(name111) == 1) then
Bar = "Bar"
name1 = name11
 else
Bar = "Bars"
name1 = name11






 end
if (tonumber(OOO2) == nil) then
 min = ""
elseif (tonumber(name1) == nil) and (tonumber(OOO2) == 1) then
 min = ""
name2 = ""
elseif not (tonumber(name11) == 0) and (tonumber(OOO2) == 1) then
 min = "Beat"
 else
 min = "Beats"
 end


X = "Duration " ..name1 .. Bar .. name2 .. min.. name3 .."%" 


end

Z = Z .. X.. Xsave.. Xpath
reaper.osara_outputMessage(Z)