BigClockExtra: Added time unit measures/beats. closes #7
This commit is contained in:
		
							parent
							
								
									fa570bbb4b
								
							
						
					
					
						commit
						f41bb72fe5
					
				| @ -10,10 +10,12 @@ | ||||
| -- Basic gui stuff by forum user "spk77": https://forum.cockos.com/showthread.php?t=161557 | ||||
| 
 | ||||
| 
 | ||||
| -- Some adjustable settings: | ||||
| -- Some adjustable settings (startup settings that can be changed in GUI): | ||||
| local timeSinceProject = true -- EITHER this one is true OR one of the next two | ||||
| local timeSinceMarker = false | ||||
| local timeSinceRegion = false | ||||
| local timeUnitHMS = false -- EITHER this one is true OR one of the next one | ||||
| local timeUnitMeasures = true | ||||
| 
 | ||||
| -- Nothing to adjust here anymore... | ||||
| local script_path | ||||
| @ -28,6 +30,13 @@ function msg(m) | ||||
|   reaper.ShowConsoleMsg(tostring(m) .. "\n") | ||||
| end | ||||
| 
 | ||||
| -- Round number | ||||
| function round(num, numDecimalPlaces) | ||||
|   local mult = 10^(numDecimalPlaces or 0) | ||||
|   return math.floor(num * mult + 0.5) / mult | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
| -- Store state to project variables | ||||
| function storeExtState() | ||||
|     if timeSinceProject then | ||||
| @ -48,6 +57,12 @@ function storeExtState() | ||||
|         reaper.SetProjExtState(0, 'bigclock_extra', 'timeSinceRegion', '0') | ||||
|     end | ||||
| 
 | ||||
|     if timeUnitMeasures then | ||||
|       reaper.SetProjExtState(0, 'bigclock_extra', 'timeUnit', 'measures') | ||||
|     else | ||||
|       reaper.SetProjExtState(0, 'bigclock_extra', 'timeUnit', 'hms') | ||||
|     end | ||||
| 
 | ||||
|     reaper.SetProjExtState(0, 'bigclock_extra', 'dockState', gfx.dock(-1)) | ||||
| end | ||||
| 
 | ||||
| @ -89,9 +104,15 @@ function gui_init() | ||||
|   rc_menu:add_item({label = "Time since previous marker", | ||||
|                     toggleable = true, | ||||
|                     selected = timeSinceMarker}) | ||||
|   rc_menu:add_item({label = "Time since previous region", | ||||
|   rc_menu:add_item({label = "Time since previous region|", | ||||
|                     toggleable = true, | ||||
|                     selected = timeSinceRegion})         | ||||
|                     selected = timeSinceRegion}) | ||||
|   rc_menu:add_item({label = "Minutes:Seconds.Milliseconds", | ||||
|                     toggleable = true, | ||||
|                     selected = timeUnitHMS}) | ||||
|   rc_menu:add_item({label = "Measures.Beats", | ||||
|                     toggleable = true, | ||||
|                     selected = timeUnitMeasures})         | ||||
|   rc_menu:add_item({label = "Quit"}) | ||||
| 
 | ||||
|   -- Let's add a command to all created items: | ||||
| @ -134,7 +155,29 @@ function gui_init() | ||||
|                                 end | ||||
|                                 storeExtState() | ||||
|                             end | ||||
|     rc_menu.items[4].command = function() quit = true end | ||||
|     rc_menu.items[4].command = function()  | ||||
|                               if rc_menu.items[4].selected then  | ||||
|                                   timeUnitHMS = true | ||||
|                                   timeUnitMeasures = false | ||||
|                                   rc_menu.items[5].selected = false | ||||
|                               else  | ||||
|                                   --dont let user disable option but force selection of other option | ||||
|                                   rc_menu.items[5].selected = true;  | ||||
|                               end | ||||
|                               storeExtState() | ||||
|                           end | ||||
|     rc_menu.items[5].command = function()  | ||||
|                             if rc_menu.items[5].selected then  | ||||
|                               timeUnitHMS = false | ||||
|                               timeUnitMeasures = true | ||||
|                               rc_menu.items[4].selected = false | ||||
|                             else  | ||||
|                                 --dont let user disable option but force selection of other option | ||||
|                                 rc_menu.items[4].selected = true;  | ||||
|                             end | ||||
|                             storeExtState() | ||||
|                         end | ||||
|     rc_menu.items[6].command = function() quit = true end | ||||
| end | ||||
| 
 | ||||
| -- Draw GUI -- | ||||
| @ -144,6 +187,8 @@ function drawGui() | ||||
|     local timeRaw | ||||
|     local timeDisplay | ||||
|     local timeDisplaySeconds | ||||
|     local timeMeasures | ||||
|     local timeBeats | ||||
|     local markerId | ||||
|     local regionId | ||||
|     local isRegion | ||||
| @ -168,13 +213,20 @@ function drawGui() | ||||
|     end | ||||
|     if retval > 0 then timeRaw = timeRaw - markerRegionPos end | ||||
| 
 | ||||
|     -- construct display string, with leading zeros if neccessary (e.g. 27:08.321) | ||||
|     timeDisplaySeconds = math.floor((timeRaw%60)*1000)/1000 | ||||
|     timeDisplay = math.floor(timeRaw/60) .. ":" | ||||
|     if timeDisplaySeconds < 10 then | ||||
|       timeDisplay = timeDisplay .. "0" | ||||
|     end | ||||
|     timeDisplay = timeDisplay .. timeDisplaySeconds      | ||||
|     -- Construct display string | ||||
|     if timeUnitMeasures then | ||||
|       -- measures and beats: e.g. 07.3.99 | ||||
|      timeBeats, timeMeasures, _, _, _ = reaper.TimeMap2_timeToBeats(0, timeRaw) | ||||
|      timeDisplay = timeMeasures+1 .. '.' .. round(timeBeats+1, 2) | ||||
|     else | ||||
|       -- minutes and seconds: MM:SS.xxx (e.g. 27:08.321) | ||||
|       timeDisplaySeconds = math.floor((timeRaw%60)*1000)/1000 | ||||
|       timeDisplay = math.floor(timeRaw/60) .. ":" | ||||
|       if timeDisplaySeconds < 10 then | ||||
|         timeDisplay = timeDisplay .. "0" | ||||
|       end | ||||
|       timeDisplay = timeDisplay .. timeDisplaySeconds | ||||
|     end          | ||||
| 
 | ||||
|     gfx.clear = 3355443 -- background is dark grey | ||||
| 
 | ||||
| @ -260,6 +312,16 @@ function init() | ||||
|       timeSinceRegion = false | ||||
|     end | ||||
|   end | ||||
|   retval, val = reaper.GetProjExtState(0, 'bigclock_extra', 'timeUnit') | ||||
|   if retval > 0 then | ||||
|     if val == 'measures' then | ||||
|       timeUnitMeasures = true | ||||
|       timeUnitHMS = false | ||||
|     else  | ||||
|       timeUnitMeasures = false | ||||
|       timeUnitHMS = true | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   -- init stuff... | ||||
|   gui_init() | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user