Old 10-23-2015, 05:05 AM   #1
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default LUA : Project Work Timer

So here is a script that counts working time on the project,it has AFK mode that pauses timer if project is idle(default set to 60 seconds ,you can set any time you want,edit the AFK line at the top of the script).The timer is stored with the project so when saving it and opened next time the timer will be preserved.
Latest version:
https://raw.githubusercontent.com/Go...h_AFK_mode.lua

Last edited by Sexan; 02-25-2017 at 10:44 AM.
Sexan is offline   Reply With Quote
Old 10-23-2015, 06:44 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Nice :P

If you want a GUI, you may consider using this VST =>

HOFA 4U - Free VST, VST3, AU, RTAS, AAX Plugins | HOFA-Plugins

X-Raym is offline   Reply With Quote
Old 10-23-2015, 07:48 AM   #3
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

hahahahahah I've done it ! Its so cute and puny!!


You can see here ,the time stops when you go afk
download:
https://stash.reaper.fm/25511/projecttime.lua
Sexan is offline   Reply With Quote
Old 10-23-2015, 08:18 AM   #4
musicbynumbers
Human being with feelings
 
musicbynumbers's Avatar
 
Join Date: Jun 2009
Location: South, UK
Posts: 14,214
Default

nice work!
__________________
subproject FRs click here
note: don't search for my pseudonym on the web. The "musicbynumbers" you find is not me or the name I use for my own music.
musicbynumbers is offline   Reply With Quote
Old 10-23-2015, 11:42 AM   #5
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

This is nice, thanks.

I like it better than the HOFA one because of the automatic AFK mode.

Would it be possible it could store the time when saving / closing project and continue when reopening the project ?
nofish is offline   Reply With Quote
Old 10-23-2015, 11:59 AM   #6
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Yes I'm working on that that is most important featue
Sexan is offline   Reply With Quote
Old 10-24-2015, 01:49 AM   #7
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

hm...its a little harder than I thought,can someone help?
Sexan is offline   Reply With Quote
Old 10-24-2015, 03:49 AM   #8
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

I think you have to use GetProjExtState() and SetProjExtState().

Quote:
C: int SetProjExtState(ReaProject* proj, const char* extname, const char* key, const char* value)

EEL: int SetProjExtState(ReaProject proj, "extname", "key", "value")

Lua: integer reaper.SetProjExtState(ReaProject proj, string extname, string key, string value)

Python: Int RPR_SetProjExtState(ReaProject proj, String extname, String key, String value)

Save a key/value pair for a specific extension, to be restored the next time this specific project is loaded. Typically extname will be the name of a reascript or extension section. If key is NULL or "", all extended data for that extname will be deleted. If val is NULL or "", the data previously associated with that key will be deleted. Returns the size of the state for this extname. see GetProjExtState, EnumProjExtState.
Haven't looked into this myself closer, but here's for example a script which uses this:

http://forum.cockos.com/showpost.php...&postcount=259
nofish is offline   Reply With Quote
Old 10-24-2015, 04:24 AM   #9
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Yeah I know how to use it ,I've used it before,but don't know how to use in THIS script,it won't store the data dynamically,it just stores one number 1 thats it...
so when the time is for example 2min:04sec it stores only 01sec
Sexan is offline   Reply With Quote
Old 10-24-2015, 04:27 AM   #10
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Maybe something like this (untested)...

You can define a function what Reaper should be doing at exit

Code:
function do_at_exit()
time_at_exit = tostring(day + hour + min + sec) -- convert current time to string
reaper.SetProjExtState(0, "projecttime", "time_at_exit", time_at_exit) -- and store in project file
end
Then call
Code:
reaper.atexit(do_at_exit)
at the end of your script to store current time in project file at script exit.

In the init function you then have to call reaper.GetProjExtState() and convert the string back to day, hour, min, sec and pass it to the main loop.

(Maybe there's a better way or it doesn't work like this, I'm just a scripting beginner...)
nofish is offline   Reply With Quote
Old 10-24-2015, 04:59 AM   #11
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

I've got it,now it stores values per project
https://stash.reaper.fm/25515/projecttime.lua
But I can't make atexit to work,its still running in background,and there is a bug,when using SetProjExtState it messes GUI ??? it adds column and moves the whole thing to the left

Last edited by Sexan; 10-24-2015 at 05:26 AM.
Sexan is offline   Reply With Quote
Old 10-24-2015, 05:35 AM   #12
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Yeah, I think atexit() is only triggered when you try to run the script again when it's already running, then Reaper gives a prompt to terminate instance.

When clicking on script GUI close button it's still running in background, I don't know why or how to change this.

Nice that you got it btw., thanks, will test.
nofish is offline   Reply With Quote
Old 10-24-2015, 06:03 AM   #13
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Fixed Gui mess,added d:h:m:s ,cute

https://stash.reaper.fm/25517/projecttime.lua

Last edited by Sexan; 10-24-2015 at 06:11 AM.
Sexan is offline   Reply With Quote
Old 10-24-2015, 07:27 AM   #14
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Hi,

This is how to terminate a script when closing a gfx window:

Code:
local gui = {}

function at_exit()
  reaper.ShowConsoleMsg("Exit")
end

function main()
  c=gfx.getchar() -- if c is -1, the gfx window has been closed
  if c > -1 then  -- defer while gfx window is open
    reaper.defer(main)
  end  
end


function init()
  
  -- Add stuff to "gui" table
  gui.settings = {}                 -- Add "settings" table to "gui" table 
  gui.settings.font_size = 20       -- font size
  gui.settings.docker_id = 0        -- try 0, 1, 257, 513, 1027 etc.
  
  ---------------------------
  -- Initialize gfx window --
  ---------------------------
  
  gfx.init("", 250, 50, gui.settings.docker_id)
  gfx.setfont(1,"Arial", gui.settings.font_size)
  gfx.clear = 3355443  -- matches with "FUSION: Pro&Clean Theme :: BETA 01" http://forum.cockos.com/showthread.php?t=155329
end

reaper.atexit(at_exit)
init() 
main()
spk77 is offline   Reply With Quote
Old 10-24-2015, 08:00 AM   #15
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Great!Thanks!
Then for what is atexit for?
Sexan is offline   Reply With Quote
Old 10-24-2015, 10:34 AM   #16
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Sexan View Post
Great!Thanks!
Then for what is atexit for?
It's useful for storing some variables when the script finishes or is ended by the user:

Code:
local gui = {}

function at_exit()
  --reaper.SetProjExtState(proj "extname", "key", "value")
  --reaper.SetProjExtState(proj "extname", "key2", "value2")
  --etc.
end

function main()
  c=gfx.getchar() -- if c is -1, the gfx window has been closed
  if c > -1 then  -- defer while gfx window is open
    reaper.defer(main)
  end  
end


function init()
  
  -- Add stuff to "gui" table
  gui.settings = {}                 -- Add "settings" table to "gui" table 
  gui.settings.font_size = 20       -- font size
  gui.settings.docker_id = 0        -- try 0, 1, 257, 513, 1027 etc.
  
  ---------------------------
  -- Initialize gfx window --
  ---------------------------
  
  gfx.init("", 250, 50, gui.settings.docker_id)
  gfx.setfont(1,"Arial", gui.settings.font_size)
  gfx.clear = 3355443  -- matches with "FUSION: Pro&Clean Theme :: BETA 01" http://forum.cockos.com/showthread.php?t=155329
end

reaper.atexit(at_exit)
init() 
main()
spk77 is offline   Reply With Quote
Old 10-24-2015, 10:39 AM   #17
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Nice one. I think there have been a couple of attempts at this over the years but they've all fallen short for one reason or another. Looks like yours could be the winner.
IXix is offline   Reply With Quote
Old 10-25-2015, 10:02 AM   #18
Sumalc
Human being with feelings
 
Join Date: Oct 2009
Location: France
Posts: 743
Default

Thank you very much Sexan, more useful (my opinion) than the Hofa one.
Sumalc is offline   Reply With Quote
Old 05-01-2016, 05:02 AM   #19
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Can someone help please,I have rewritten the script (cleaner and better code) but it doesn't store values to project:
https://stash.reaper.fm/27469/TrackingProjectTime.lua
this one is latest rewritten that doesn't store values (don't know why)

and this one is almost the same and it stores value:
https://stash.reaper.fm/27470/Trackin...meORIGINAL.lua

The only difference between this two is that the latest one (first one) defers "count_time()" function for defined time when action is made

Code:
function count_time()
local currentTime =os.time() -- get reaper time
local timer = currentTime - last_action_time -- start counter from 0 when action is made
 if timer <= afk then -- if last action change happened over a minute -- PAUSE TIMER    
    reaper.defer(count_time) -- defer while timer is lower than afk value
    if timer - t1 == 1 then -- this is interval timer of 1 second needed for counting
       t_sec=t_sec + 1      
       if t_sec == 60 then
          t_min = t_min + 1 
          t_sec = 0            
          if t_min == 60 then
             t_hour = t_hour + 1
             t_min = 0
             if t_hour == 24 then
                t_day = t_day + 1
                t_hour = 0
             end
          end
       end       
       t1 = timer    
    end   
    else
    timer = 0 -- if defer is over reset timer to 0
 end
 store_time() -- call function to store time values
end
Sexan is offline   Reply With Quote
Old 05-01-2016, 08:45 AM   #20
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

figured out the problem but don't know is it a limitation or a bug or this is not supposed to work:

If I call the function defered (as second defered script within main() function) it won't store the value,but if I call the function non defered it stores values normally.

I've called function like this and store is not working
Code:
function main()
If action then
   xxx()
end
end

function xxx()
if A < B then
   reaper.defer(xxx)
end
store()
end
But if I do this without defer it works
Code:
function main()
if A < B then
   xxx()
end
end

function xxx()
some code
store()
end
Here is the latest with fix
https://stash.reaper.fm/27471/Project...%20Counter.lua

and the one defered that does not work (if someone wants to check if I made mistake anywhere)
https://stash.reaper.fm/27469/TrackingProjectTime.lua
Sexan is offline   Reply With Quote
Old 05-01-2016, 10:18 AM   #21
Jae.Thomas
Human being with feelings
 
Join Date: Jun 2006
Posts: 22,567
Default

I wish this could load with every project at startup...
Jae.Thomas is offline   Reply With Quote
Old 05-01-2016, 10:42 AM   #22
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

you can,with sws startup action,but you need to save as template and set that template for new project,I have 5 scripts that auto start with reaper.I've set custom action with 5 scripts and then add that action to sws startup
Sexan is offline   Reply With Quote
Old 05-01-2016, 10:43 AM   #23
Jae.Thomas
Human being with feelings
 
Join Date: Jun 2006
Posts: 22,567
Default

will it stay docked?
Jae.Thomas is offline   Reply With Quote
Old 05-01-2016, 10:44 AM   #24
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Sexan View Post

and the one defered that does not work (if someone wants to check if I made mistake anywhere)
https://stash.reaper.fm/27469/TrackingProjectTime.lua
This one seems to work here.

Quote:
Originally Posted by Jason Brian Merrill View Post
I wish this could load with every project at startup...
There's SWS: Set global startup action
spk77 is offline   Reply With Quote
Old 05-01-2016, 10:51 AM   #25
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Quote:
Originally Posted by spk77 View Post
This one seems to work here.


There's SWS: Set global startup action
it works when you save close and reopen project??

yes it stays docked
Sexan is offline   Reply With Quote
Old 05-01-2016, 11:18 AM   #26
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Sexan View Post
it works when you save close and reopen project??

yes it stays docked
Yes:


Edit: It works also if it's set as a global startup action.
spk77 is offline   Reply With Quote
Old 05-01-2016, 11:34 AM   #27
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

hm....that script wont work for me,don't know why,I'm on latest pre
Sexan is offline   Reply With Quote
Old 05-01-2016, 11:42 AM   #28
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Sexan View Post
hm....that script wont work for me,don't know why,I'm on latest pre
Latest pre here too...

Quote:
Originally Posted by Sexan View Post
you can,with sws startup action,but you need to save as template and set that template for new project,I have 5 scripts that auto start with reaper.I've set custom action with 5 scripts and then add that action to sws startup
Hmm...maybe one of these scripts is overwriting the Project Work Timer extstate?
spk77 is offline   Reply With Quote
Old 05-01-2016, 11:49 AM   #29
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

But the latest working one (non defered) is working just fine with the rest of the scripts.Nope ...test it again and it does not store the values,first save and open does but second save open it resets it to 0 (same as before)
Sexan is offline   Reply With Quote
Old 05-01-2016, 11:53 AM   #30
Jae.Thomas
Human being with feelings
 
Join Date: Jun 2006
Posts: 22,567
Default

I really want this to be in my default template, docked forever. When you guys have it sorted this will be great.

You guys are awesome!!!
Jae.Thomas is offline   Reply With Quote
Old 05-01-2016, 12:11 PM   #31
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

Quote:
Originally Posted by Sexan View Post
But the latest working one (non defered) is working just fine with the rest of the scripts.Nope ...test it again and it does not store the values,first save and open does but second save open it resets it to 0 (same as before)
I tried to save/close/open multiple times and it's still working - don't know why it doesn't work on your computer.

This is the state it's storing:
Code:
  <EXTSTATE
    <TIME
      D 0
      H 0
      M 1.0
      S 1.0
    >
  >
spk77 is offline   Reply With Quote
Old 05-01-2016, 12:14 PM   #32
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

No no the script in the first post is the final working,there is another one that is basically the same but does not work as it should,thats what we are sorting out.
Ok so the startup steps:
1.Go to actions right click on the script and copy action ID
2.Go to extensions Start Up Action - Set Global StartUp action - (if you want it globaly) or Project startup (if you want it in temple)
3.Paste
4.Close and reopen reaper
5.enjoy

btw the default dock position is top right,you can change that at the bottom of the script

And if X-Raym approve this one to be in ReaPack repository I would be happy it has needed header

Last edited by Sexan; 05-01-2016 at 12:20 PM.
Sexan is offline   Reply With Quote
Old 05-09-2016, 11:33 PM   #33
_TIP_
Human being with feelings
 
_TIP_'s Avatar
 
Join Date: Apr 2014
Location: NY
Posts: 175
Default

Thank you very much Sexan, this script is very useful and better than the Hofa freebie in my opinion! Is it possible though to create a new version with just the time counter and not the d:h:m:s?
_TIP_ is offline   Reply With Quote
Old 05-10-2016, 01:10 AM   #34
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

sure no problem :
https://stash.reaper.fm/27543/OnlyTimer.lua
Sexan is offline   Reply With Quote
Old 05-10-2016, 08:36 AM   #35
_TIP_
Human being with feelings
 
_TIP_'s Avatar
 
Join Date: Apr 2014
Location: NY
Posts: 175
Default

Thank you very much Sexan!!!
_TIP_ is offline   Reply With Quote
Old 02-24-2017, 01:33 AM   #36
_TIP_
Human being with feelings
 
_TIP_'s Avatar
 
Join Date: Apr 2014
Location: NY
Posts: 175
Default

Hey Sexan, sorry to ask you again but i'm having a little problem here. Unfortunately every time i open any of my projects or a new project, the timer instead of showing in the top right corner, is hiding bellow the Master channels Mixer in the bottom right corner, so every time i have to drag it and drop it in the right place...
Is it possible to fix that for me please? Here is a Gif showing the problem, thanks again, i really love your script!!!
_TIP_ is offline   Reply With Quote
Old 02-24-2017, 03:09 AM   #37
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

Will see what I can do, probably dock code is bugging
Sexan is offline   Reply With Quote
Old 02-24-2017, 03:16 AM   #38
_TIP_
Human being with feelings
 
_TIP_'s Avatar
 
Join Date: Apr 2014
Location: NY
Posts: 175
Default

Quote:
Originally Posted by Sexan View Post
Will see what I can do, probably dock code is bugging
Thank you very much, I really appreciate it!
_TIP_ is offline   Reply With Quote
Old 02-24-2017, 03:21 AM   #39
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
Default

While I'm at it I will rewrite the code since is really really old (and no dock code is there)
Sexan is offline   Reply With Quote
Old 02-24-2017, 03:25 AM   #40
_TIP_
Human being with feelings
 
_TIP_'s Avatar
 
Join Date: Apr 2014
Location: NY
Posts: 175
Default

Quote:
Originally Posted by Sexan View Post
While I'm at it I will rewrite the code since is really really old (and no dock code is there)
Awesome, sounds great!!!
_TIP_ is offline   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 03:02 AM.


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