Old 03-21-2020, 06:23 AM   #1
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default Project Time Counter function. (solved)

Hi
Project Time Counter function.
Could you integrate this function from Sexan (unfortunately not active in the forum since January) into the Project Manager?

Thank you

https://www.dropbox.com/sh/mkk741yvo...F7DTTTfOa?dl=0 (counter script and PManager script)


Last edited by Dragonetti; 03-29-2020 at 06:27 AM.
Dragonetti is online now   Reply With Quote
Old 03-25-2020, 01:16 AM   #2
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

Hi there
If "sexan_Project time counter" is running in the background, is it possible to call up the saved times with this code?
The data should be displayed as a string in the corresponding button label of the current project.
(display only days,hours,minutes 00:00:00)

I would be grateful for help (donation)
Dragonetti
Code:
function restore_time() -- restore time values from project
ok,t_sec = reaper.GetProjExtState(0, "time", "s") -- restore seconds  
ok,t_min = reaper.GetProjExtState(0, "time", "m") -- restore minutes
ok,t_hour = reaper.GetProjExtState(0, "time", "h") -- restore hours
ok,t_day = reaper.GetProjExtState(0, "time", "d") -- restore days

  if ok == 0 then -- if no value is stored reset all time values to 0
    t_sec= 0
    t_min = 0
    t_hour = 0
    t_day = 0
  end
  
end
Dragonetti is online now   Reply With Quote
Old 03-25-2020, 08:13 AM   #3
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,500
Default

Something like this for reading the saved time from the project file and convert to dd:hh:mm?
(Thing is though it only works correctly i.e. returns the exact current time spent if you've saved the project before running this, not sure if that's fine?)

Code:
-- only for testing
local function Msg(str)
  reaper.ShowConsoleMsg(tostring(str) .. "\n")
end

-- restore saved time (in sec.) from sexan_Project time counter script
function restore_time() 
  local ret, saved_time_sec = reaper.GetProjExtState(0, "timer", "timer")
  if saved_time_sec ~= "" then
    return saved_time_sec
  else
    return 0
  end
end

-- convert restored time from sec. to dd:hh:mm
function sec_to_ddhhmm(time_sec)
  local days = math.floor(time_sec/(60*60*24))
  local hours = math.floor(time_sec/(60*60)%24)
  local minutes = math.floor(time_sec/60%60)
  return string.format("%02d:%02d:%02d",days,hours,minutes)
end

restored_time_sec = restore_time()
restored_time_ddhhmm =  sec_to_ddhhmm(restored_time_sec)
Msg(restored_time_ddhhmm)
edit:
You seem to be using an older version of Sexan's script (v1.0, from link above), in later versions he changed how the values are stored so my code only works with later versions.
I'd suggest using his latest version from ReaPack (v1.38) then my code should (hopefully) work.

Last edited by nofish; 03-25-2020 at 08:30 AM.
nofish is offline   Reply With Quote
Old 03-26-2020, 04:50 AM   #4
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,737
Default

The code should get the variables from ProjExtState fine.
But this gets the current project that is opened. In order to get all the time for the projects in the list in the project manager, it would have to search for it by parsing the RPP files of each project and extracting the value manually. I'm not sure if it is a good idea.
heda is offline   Reply With Quote
Old 03-26-2020, 04:55 AM   #5
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

@heda
only in the current Project Counter Button, then I can save the time for the current project

@nofish

With your script I only see zeros here.
With this code you can see that.

Now the hard part is probably coming.
The time values should be in this button.
string Days: hours: minutes


Code:
local function Msg(str)
  reaper.ShowConsoleMsg(tostring(str) .. "\n")
end

-- restore saved time (in sec.) from sexan_Project time counter script
function restore_time() -- restore time values from project
ok,t_sec = reaper.GetProjExtState(0, "time", "s") -- restore seconds  
ok,t_min = reaper.GetProjExtState(0, "time", "m") -- restore minutes
ok,t_hour = reaper.GetProjExtState(0, "time", "h") -- restore hours
ok,t_day = reaper.GetProjExtState(0, "time", "d") -- restore days

  if ok == 0 then -- if no value is stored reset all time values to 0
    t_sec= 0
    t_min = 0
    t_hour = 0
    t_day = 0
  end
   
end  

time = restore_time()

Msg(t_day)
Msg(t_hour)
Msg(t_min)
Msg(t_sec)
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 05:15 AM   #6
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,500
Default

Quote:
Originally Posted by Dragonetti View Post
@nofish

With your script I only see zeros here.
With this code you can see that.
see my edit in post #3
It looks like your using sexan's old version with my code?
nofish is offline   Reply With Quote
Old 03-26-2020, 05:41 AM   #7
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

I have version 1.0

Code:
--[[
 * ReaScript Name: Project Time Counter with AFK mode
 * Author: SeXan
 * Licence: GPL v3
 * Forum Thread: LUA : Project Work Timer
 * Forum Thread URI: http://forum.cockos.com/showthread.php?t=167883
 * REAPER: 5.0
 * Extensions: None
 * Version: 1.0
--]]
 
--[[
 * Changelog:
 * v1.0 (2016-01-29)
  + Initial Release
--]]
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 05:48 AM   #8
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,500
Default

Well if you want to use old version and not current one, ok.
nofish is offline   Reply With Quote
Old 03-26-2020, 05:54 AM   #9
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

No
I found it directly at Github
1.38
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 06:00 AM   #10
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,500
Default

It's also in ReaPack:
nofish is offline   Reply With Quote
Old 03-26-2020, 06:08 AM   #11
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

Version: 1.44
The last link in the corresponding thread same Date
https://forum.cockos.com/showthread.php?t=167883
Code:
--[[
 * ReaScript Name: Multi project time counter
 * About: Script shows 3 timers: Windows time, how long project has been opened and third timer has AFK mode that that counts time only while you work in the project
 * Author: SeXan
 * Licence: GPL v3
 * REAPER: 5.0
 * Extensions: None
 * Version: 1.44
--]]
 
--[[
 * Changelog:
 * v1.44 (2017-08-14)
  + simplifed code
--]]
---------------------------------------
local afk = 60 -- set afk treshold HERE
---------------------------------------
local threshold = afk
local last_time = 0
local last_action_time = 0
local last_proj_change_count = reaper.GetProjectStateChangeCount(0)
local last_proj, last_proj_name =  reaper.EnumProjects( -1 , 0) 
local dock_pos = reaper.GetExtState("timer", "dock")

local timer,timer2

local function store_time() -- store time values to project
  reaper.SetProjExtState(0, "timer", "timer", timer) -- store seconds
  reaper.SetProjExtState(0, "timer", "timer2", timer2) -- store seconds
end

local function restore_time() -- restore time values from project
  local ret, load_timer = reaper.GetProjExtState(0, "timer", "timer") -- restore seconds
  local ret, load_timer2 = reaper.GetProjExtState(0, "timer", "timer2") -- restore seconds
    if load_timer ~= "" and load_timer2 ~= "" then
      timer = tonumber(load_timer)
      timer2 = tonumber(load_timer2)
    else
      timer = 0
      timer2 = 0
    end
end

local function count_time()
  if afk < threshold then
    if os.time() - last_action_time > 0 then -- interval of 1 second      
      afk = afk + 1
      timer = timer + 1
      last_action_time = os.time() 
    end
  end
  
  if os.time() - last_time > 0 then
    timer2 = timer2 + 1
    last_time = os.time()    
  end
    
  store_time()
end

local function time(x)
  local days = math.floor(x/(60*60*24))
  local hours  = math.floor(x/(60*60)%24)
  local minutes = math.floor(x/60%60)
  local seconds = math.floor(x%60)
      
  local time = string.format("%02d:%02d:%02d:%02d",days,hours,minutes,seconds)
  return time
end

local function main()
  local proj, proj_name =  reaper.EnumProjects( -1 , 0) 
  local proj_change_count = reaper.GetProjectStateChangeCount(0)
  
  if last_proj ~= proj then
    restore_time()
    last_proj = proj
  end
  
  if proj_change_count > last_proj_change_count or reaper.GetPlayState() ~= 0 then
    afk = 0
    last_proj_change_count = proj_change_count
  end 
  
  count_time()
  
  local project_time, afk_time = time(timer2), time(timer)
  local w_time = os.date("%X")
  
  gfx.x, gfx.y = 2, 8
  gfx.printf("     ")
  gfx.printf(w_time)
  gfx.printf(" - T")
  gfx.x, gfx.y = 2, 38
  gfx.printf(project_time)
  gfx.printf(" - P")
  gfx.x, gfx.y = 2, 68
  gfx.printf(afk_time)
  gfx.printf(" - A")
  gfx.update()

  if gfx.getchar() > -1 then  -- defer while gfx window is open
     reaper.defer(main)
  end
end

local function store_settings()
  reaper.SetExtState("timer", "dock", gfx.dock(-1), true)
  store_time()
end

local function init()
  dock_pos = dock_pos or 513  
  gfx.init("", 155, 100, dock_pos)
  gfx.setfont(1,"Arial", 24)
  gfx.clear = 3355443 
  main()   
end
restore_time()
init()
reaper.atexit(store_settings)
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 06:15 AM   #12
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

Let us take the 1.38
The 1.44 is a special version with 2 timers
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 06:22 AM   #13
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

Can you still take the seconds?
This is better for testing. Afterwards they come away again.
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 09:57 AM   #14
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

@nofish
Sorry
Your script works perfectly.
Unfortunately Sexans Counter continues to write when I load a new project.
Dragonetti is online now   Reply With Quote
Old 03-26-2020, 02:50 PM   #15
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

When opening a project, Sexan's counter script would have to be closed and then opened again with the new project.
I already did this with the SWS Extension, but it didn't work.
I think it's related to the GUI, I actually don't need a GUI.
I only need the entry in the project manager, please.
Thanks
Dragonetti is online now   Reply With Quote
Old 03-27-2020, 12:27 PM   #16
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

Hi
Before I bother lb0 all the time, he has enough to do with the LBX_Stripper.
Here is the question for the community.
How do I get the found entries of the current project in the line of the current project?

https://www.dropbox.com/sh/mkk741yvo...F7DTTTfOa?dl=0

Dragonetti is online now   Reply With Quote
Old 03-28-2020, 02:20 PM   #17
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

Hi
with "Archie_Info; Counter time project" it works wonderfully.
In this case sexan counter does not work. I updated the link.

But I don't get the values in the right "current project" line.
HELP !!!!
Dragonetti is online now   Reply With Quote
Old 03-29-2020, 06:27 AM   #18
Dragonetti
Human being with feelings
 
Join Date: Feb 2017
Location: Kiel
Posts: 206
Default

I solved the problem in Post # 16 myself.
Dragonetti is online now   Reply With Quote
Old 03-29-2020, 10:33 AM   #19
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 3,369
Default

Awesome, congratulations!
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.