function SplitFilename(strFilename)
  return string.match(strFilename, "(.-)([^.]+)$")
end
local CountSelTrack = reaper.CountSelectedTracks(0);
    if CountSelTrack == 0 then  return end;

local midi = 0
local audio = 0
local data = ""
local track =reaper.GetSelectedTrack(0, 0)
		count_items_on_track = reaper.CountTrackMediaItems(track)

	for i = 0,		count_items_on_track-1  do
		item = reaper.GetMediaItem(0, i)
		if item ~= nil then
		take = reaper.GetActiveTake(item)
      if take ~= nil and reaper.TakeIsMIDI(take) then
 midi =midi+ 1
else
audio = audio + 1 
end
end
end
if audio == 1 then
data = " has " .. audio .. " AudioItem "
elseif audio >= 2then
data = " has " .. audio .. " AudioItems "
else
audio = ""
end
if audio ~= "" then
ander = " and "
else
ander = "has "

end
if midi == 1 then
data = data .. ander ..midi .. " MidiItem "
elseif midi >= 2 then
data = data ..  ander  ..midi .. " MidiItems "
end


ZTT =  reaper.GetMediaTrackInfo_Value(reaper.GetSelectedTrack(0, 0), "I_RECINPUT")
fold1  =  reaper.GetMediaTrackInfo_Value(reaper.GetSelectedTrack(0, 0), "I_FOLDERDEPTH");
rtr = reaper.GetParentTrack(reaper.GetSelectedTrack(0, 0))
if rtr then
r,  fold22 =  reaper.GetSetMediaTrackInfo_String(rtr, 'P_NAME', '', 0)
fold33 =  reaper.GetMediaTrackInfo_Value(rtr, "IP_TRACKNUMBER")
fold33, fold333 = SplitFilename(fold33)
fold ="  this track is child of Track".. fold33..fold22
else
fold = ""
end

if (ZTT < 80) then	
ZTT22 = ZTT+1
ZTTCCC = reaper.GetInputChannelName(ZTT)
ZTTCCC2 = reaper.GetInputChannelName(ZTT22)
ZTTCCC= "Input mono From " .. ZTTCCC


elseif (ZTT > 500) and (ZTT < 1000) then
ZTTP =  ZTT-511
 OO1, OO2  = SplitFilename(ZTTP)
pp =1
                local  OOR = string.match(string.reverse(OO1),".+",pp+1)
                local  OORR = string.reverse(OOR)
ZTTCCC= "Input mono reaRoute" ..OO1
elseif (ZTT > 1000) and  (ZTT < 1100) then
ZTT22 = ZTT-1023
ZTT = ZTT-1024
ZTTCCC = reaper.GetInputChannelName(ZTT)
ZTTCCC2 = reaper.GetInputChannelName(ZTT22)
ZTTCCC= "Input Stereo From " .. ZTTCCC .. "/" ..ZTTCCC2
elseif (ZTT > 1500) and  (ZTT < 1700) then
ZTTP =  ZTT-1535
ZTTPP = ZTT-1534
 OO1, OO2  = SplitFilename(ZTTP)
 OOO1, OOO2  = SplitFilename(ZTTPP)
pp = 1
                local  OOR = string.match(string.reverse(OO1),".+",pp+1)
                local  OORR = string.reverse(OOR)
ZTT= "Input stereo reaRoute" ..OORR.. "/" .. OOO1
elseif ZTT > 4096 then

ZTTCCC= "Input Midi"
end


--reaper.osara_outputMessage(ZT)
local ofer = ""
count_FX  = ""
 idxSelFx1  = ""
presetname = ""
fx_name=""
strSpeak = " Empty"


	   local SelTrack8 = reaper.GetSelectedTrack(0, 0);
	   local vol = 20 * math.log(reaper.GetMediaTrackInfo_Value(SelTrack8,"D_VOL"),10);
pana    = reaper.GetMediaTrackInfo_Value(reaper.GetSelectedTrack(0, 0), "D_PAN")
 		track_mode =  reaper.GetMediaTrackInfo_Value(reaper.GetSelectedTrack(0, 0), "I_AUTOMODE")

if  track_mode == 0 then
auto5 = "trim/off"
elseif track_mode  == 1 then
auto5 = "read"
elseif track_mode == 2 then
auto5 =  "touch"
elseif track_mode  == 3 then
auto5 = "write"
elseif track_mode  == 4 then
auto5 = "latch"
elseif track_mode  == 5 then
auto5 = "latch Preview"


end
local fin5 = "volume is " .. vol.. " pan is " .. pana*100 ..ZTTCCC .. " automation mode is " .. auto5

-- Function: Speak the time of the end of the last item on the first selected track 
-- Created November 2020 by Chessel 


    
    local countSelTrack = reaper.CountSelectedTracks(0);


    
    local Tr;
    local LastTouchedTrack = reaper.GetLastTouchedTrack();
    if LastTouchedTrack and reaper.GetMediaTrackInfo_Value(LastTouchedTrack,"I_SELECTED")==1 then;
        Tr = LastTouchedTrack else Tr = reaper.GetSelectedTrack(0,0);
    end;
    count_FX = reaper.TrackFX_GetCount(LastTouchedTrack)    
if    count_FX > 0 then
ofer = " of "
    local retval,str = reaper.GetTrackStateChunk(Tr,"",false);
    local idxSelFx = tonumber(string.match(str,"LASTSEL (%d+)"));
idxSelFx1 = idxSelFx+1 
			retval, fx_name = reaper.TrackFX_GetFXName(LastTouchedTrack , idxSelFx, "")
            if fx_name  == "" then fx_name = "No fx" end;

			fx_name = fx_name:gsub("DX: ", "")
			fx_name = fx_name:gsub(" %(.-%)", "")
			fx_name = fx_name:gsub("DXi: ", "")
			fx_name = fx_name:gsub(" %(.-%)", "")
			fx_name = fx_name:gsub("VST: ", "")
			fx_name = fx_name:gsub(" %(.-%)", "")
			fx_name = fx_name:gsub("VSTi: ", "")
			fx_name = fx_name:gsub(" %(.-%)", "")
			fx_name = fx_name:gsub("VST3: ", "")
			fx_name = fx_name:gsub(" %(.-%)", "")
			fx_name = fx_name:gsub("VST3i: ", "")
						fx_name = fx_name:gsub(" %(.-%)", "")
			fx_name = fx_name:gsub("JS: ", "")
						fx_name = fx_name:gsub(" %(.-%)", "")
			fx_name = fx_name:gsub("ReWire: ", "")
						fx_name = fx_name:gsub(" %(.-%)", "")

			retval, presetname = reaper.TrackFX_GetPreset(LastTouchedTrack, idxSelFx, "")
            if presetname == "" then presetname = "No preset" end;



end
            if presetname == nil then presetname = "" end;
if ( count_FX   == nil) or  ( count_FX   == 0) then
count_FX  = ""
 idxSelFx1  = ""
ofer = "No FX"
end
fin5 = fin5.. " " ..  fx_name  .. " " .. idxSelFx1 ..ofer  .. count_FX .. " " .. presetname



function nothing()
end

sel_t_cnt = reaper.CountSelectedTracks(0)

if sel_t_cnt >= 0 then
  t = reaper.GetSelectedTrack(0, 0)
  t_send_cnt = reaper.GetTrackNumSends(t, -1)
N =     t_send_cnt
  if t_send_cnt >= 0 then

    script_title = "show selected track receives fx window"
    reaper.Undo_BeginBlock()
Z = ""    
    for x = 0, t_send_cnt-1 do
      t_send = reaper.BR_GetMediaTrackSendInfo_Track(t, -1, x, 0) -- get x recieve of sel track
local Omena = ""
local Numberer = reaper.GetMediaTrackInfo_Value(t_send,"IP_TRACKNUMBER")
 Numberer1,  Numberer2=  SplitFilename(Numberer)
pp = 1
                local  Numberer1 = string.match(string.reverse( Numberer1),".+",pp+1)
                local  Numberer1 = string.reverse( Numberer1)

Z = Z .. Numberer1 .. " "

    end



if N == 1 then
NN = " Recieve "
else
NN = " Recieves "
end

if Z == "" then
YY = " No Receive "
else
YY = " has " ..N .. NN .. " from " ..Z
end


--     reaper.osara_outputMessage(Y)
    reaper.Undo_EndBlock(script_title, -1)
    
  else
    reaper.defer(nothing)
  end
else
  reaper.defer(nothing)
end
function SplitFilename(strFilename)
  return string.match(strFilename, "(.-)([^.]+)$")
end



    
    
    local function RetNumbTable(T);local x=0;for key,val in pairs(T)do;x=x+1;end;return x;end;
    
    
    
    --========================================================================
    local CountSelTrack = reaper.CountSelectedTracks(0);

    
    
    local T         = {};
    local selTrackT = {};
    local totalT    = {};
    local nameSetT  = {};
    local Undo;
    local NAME_Coincides;
    
    
    for i = 1, CountSelTrack do;
        local SendTrack = reaper.GetSelectedTrack(0,i-1);
        local GUID = reaper.GetTrackGUID(SendTrack);
        local _,stringNeedBig = reaper.GetSetMediaTrackInfo_String(SendTrack,"P_NAME",0,0);
        selTrackT[GUID]=SendTrack
        nameSetT[stringNeedBig]=stringNeedBig;  
    end;
    
    
    
    for i = 1, CountSelTrack do;
    
        local TrackSel = reaper.GetSelectedTrack(0,i-1);
        ----
        local NumSends = reaper.GetTrackNumSends(TrackSel,0);
if  NumSends  == nil then
XX = ""
else
XX = NumSends 
end
        for i = 1, NumSends do;
            local SendTrack = reaper.BR_GetMediaTrackSendInfo_Track(TrackSel,0,i-1,1);
            local GUID = reaper.GetTrackGUID(SendTrack);
            T[GUID] = SendTrack;
        end;

        
        ----------------------------
        ::ToLookFurther::;
        local x = RetNumbTable(T);

        for key, val in pairs(T) do;
            local NumSends = reaper.GetTrackNumSends(val,0);
            for i = 1, NumSends do;
                local SendTrack = reaper.BR_GetMediaTrackSendInfo_Track(val,0,i-1,1);
                local GUID = reaper.GetTrackGUID(SendTrack);
                T[GUID] = SendTrack;
            end;
        end
        
        if x ~= RetNumbTable(T) then goto ToLookFurther end;
        ----------------------------
        
        
        for key, val in pairs(T) do;
            totalT[key] = val;
        end;
        
        T = {};
    end;
    --========================================================================
    
    
    

 if RetNumbTable(totalT) > 0 then;
        local CountTracks = reaper.CountTracks(0);
local Omena =""

        for i = 1, CountTracks do;
            local Track = reaper.GetTrack(0,i-1);
            local GUID = reaper.GetTrackGUID(Track);
local Numberer = reaper.GetMediaTrackInfo_Value(Track, "IP_TRACKNUMBER")

            if  totalT[GUID] and not selTrackT[GUID] then;
--                local show = reaper.GetMediaTrackInfo_Value(Track,"B_SHOWINTCP");
 Numberer1,  Numberer2=  SplitFilename(Numberer)
pp = 1
                local  Numberer1 = string.match(string.reverse( Numberer1),".+",pp+1)
                local  Numberer1 = string.reverse( Numberer1)

Omena = Omena .. Numberer1 .. " "








            end;
        end;

if XX == 1 then
 sender = " Send "
else
 sender = " Sends "
end

if XX == "" then
ZZ = "No Send "
else


ZZ =" has " ..  XX.. sender  .." to " .. Omena
end

end
if ZZ == nil then
ZZ = " No send "
end

function main()
local retval, measures, cml, beat, denom 


local track = reaper.GetSelectedTrack(0,0) -- Get the first selected track in the active project 
if track then
local numitems = reaper.GetTrackNumMediaItems( track )
if numitems > 0   then 
strSpeak = " its time "  
local item = reaper.GetTrackMediaItem( track, numitems-1 )
local itempos = reaper.GetMediaItemInfo_Value( item, "D_POSITION" )
local itemlen = reaper.GetMediaItemInfo_Value( item, "D_LENGTH" )
local trackend = itempos + itemlen

-- retval, measures, cml, beat, denom = reaper.TimeMap2_timeToBeats( 0,  trackend  ) 
-- Speak( "Track stats are " .. measures .. ", " .. cml .. ", " .. beat .. ", " .. denom )  


-- Calculate minutes and seconds 
local minutes =  math.floor( 1 * trackend  / 60 ) 
local seconds =  math.floor( 100 * (trackend % 60 ) ) / 100 

-- Construct what to say
if minutes == 1 then
strSpeak =strSpeak.. "1 minute" 
elseif minutes > 1 then
strSpeak =strSpeak .. minutes .. " minutes"
end 

if seconds == 1 then 
strSpeak = strSpeak .. "1 second"
elseif seconds > 0 then
strSpeak =strSpeak .. seconds .. " seconds"
end 

-- Now say it 


end -- if there are items on the track
end -- if there is a selected track 
end
main()
ZT =  data..strSpeak.." " .. fin5..ZZ..YY ..fold
reaper.osara_outputMessage(ZT)