|
|
|
10-23-2015, 05:05 AM
|
#1
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
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.
|
|
|
10-23-2015, 07:48 AM
|
#3
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
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
|
|
|
10-23-2015, 08:18 AM
|
#4
|
Human being with feelings
Join Date: Jun 2009
Location: South, UK
Posts: 14,214
|
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.
|
|
|
10-23-2015, 11:42 AM
|
#5
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
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 ?
|
|
|
10-23-2015, 11:59 AM
|
#6
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
Yes I'm working on that that is most important featue
|
|
|
10-24-2015, 01:49 AM
|
#7
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
hm...its a little harder than I thought,can someone help?
|
|
|
10-24-2015, 03:49 AM
|
#8
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
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
|
|
|
10-24-2015, 04:24 AM
|
#9
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
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
|
|
|
10-24-2015, 04:27 AM
|
#10
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
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...)
|
|
|
10-24-2015, 04:59 AM
|
#11
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
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.
|
|
|
10-24-2015, 05:35 AM
|
#12
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
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.
|
|
|
10-24-2015, 06:03 AM
|
#13
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
Last edited by Sexan; 10-24-2015 at 06:11 AM.
|
|
|
10-24-2015, 07:27 AM
|
#14
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
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()
|
|
|
10-24-2015, 08:00 AM
|
#15
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
Great!Thanks!
Then for what is atexit for?
|
|
|
10-24-2015, 10:34 AM
|
#16
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Sexan
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()
|
|
|
10-24-2015, 10:39 AM
|
#17
|
Human being with feelings
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
|
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.
|
|
|
10-25-2015, 10:02 AM
|
#18
|
Human being with feelings
Join Date: Oct 2009
Location: France
Posts: 743
|
Thank you very much Sexan, more useful (my opinion) than the Hofa one.
|
|
|
05-01-2016, 05:02 AM
|
#19
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
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
|
|
|
05-01-2016, 08:45 AM
|
#20
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
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
|
|
|
05-01-2016, 10:18 AM
|
#21
|
Human being with feelings
Join Date: Jun 2006
Posts: 22,567
|
I wish this could load with every project at startup...
|
|
|
05-01-2016, 10:42 AM
|
#22
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
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
|
|
|
05-01-2016, 10:43 AM
|
#23
|
Human being with feelings
Join Date: Jun 2006
Posts: 22,567
|
will it stay docked?
|
|
|
05-01-2016, 10:44 AM
|
#24
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Sexan
|
This one seems to work here.
Quote:
Originally Posted by Jason Brian Merrill
I wish this could load with every project at startup...
|
There's SWS: Set global startup action
|
|
|
05-01-2016, 10:51 AM
|
#25
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
Quote:
Originally Posted by spk77
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
|
|
|
05-01-2016, 11:18 AM
|
#26
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Sexan
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.
|
|
|
05-01-2016, 11:34 AM
|
#27
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
hm....that script wont work for me,don't know why,I'm on latest pre
|
|
|
05-01-2016, 11:42 AM
|
#28
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Sexan
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
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?
|
|
|
05-01-2016, 11:49 AM
|
#29
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
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)
|
|
|
05-01-2016, 11:53 AM
|
#30
|
Human being with feelings
Join Date: Jun 2006
Posts: 22,567
|
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!!!
|
|
|
05-01-2016, 12:11 PM
|
#31
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Sexan
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
>
>
|
|
|
05-01-2016, 12:14 PM
|
#32
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
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.
|
|
|
05-09-2016, 11:33 PM
|
#33
|
Human being with feelings
Join Date: Apr 2014
Location: NY
Posts: 175
|
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?
|
|
|
05-10-2016, 01:10 AM
|
#34
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
|
|
|
05-10-2016, 08:36 AM
|
#35
|
Human being with feelings
Join Date: Apr 2014
Location: NY
Posts: 175
|
Thank you very much Sexan!!!
|
|
|
02-24-2017, 01:33 AM
|
#36
|
Human being with feelings
Join Date: Apr 2014
Location: NY
Posts: 175
|
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!!!
|
|
|
02-24-2017, 03:09 AM
|
#37
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
Will see what I can do, probably dock code is bugging
|
|
|
02-24-2017, 03:16 AM
|
#38
|
Human being with feelings
Join Date: Apr 2014
Location: NY
Posts: 175
|
Quote:
Originally Posted by Sexan
Will see what I can do, probably dock code is bugging
|
Thank you very much, I really appreciate it!
|
|
|
02-24-2017, 03:21 AM
|
#39
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,598
|
While I'm at it I will rewrite the code since is really really old (and no dock code is there)
|
|
|
02-24-2017, 03:25 AM
|
#40
|
Human being with feelings
Join Date: Apr 2014
Location: NY
Posts: 175
|
Quote:
Originally Posted by Sexan
While I'm at it I will rewrite the code since is really really old (and no dock code is there)
|
Awesome, sounds great!!!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 03:02 AM.
|