One of several possible nightmares: During a performance, someone accidentally unplugs the AC from your laptop. After some time your battery is depleted and Windows shuts down. Total mayhem
It would be nice if you had a way to make GP scream at you it is running on battery. Then you could correct the issue before it becomes a problem.
To make this possible I’ve written a small extension (Windows only!):
battery-ext-4.5.8.dll. When you drop that in the 'extensions-folder` of GP and activate it in GP (options->extensions) then you get several extra functions in gpscript available to retrieve things like the state of the AC powerline, the battery percentage, etc. To make GP scream at you is up to you
** To take advantage of these extension you must write a rack-script **. Below an example. I’ve also attached a sample gigfile, which you can check out.
Example of how to use it:
//$<AutoDeclare> //$<AutoDeclare> // DO NOT EDIT THIS SECTION MANUALLY Var Display : Widget ReqBatt : Widget DisplayLifetime : Widget //$</AutoDeclare> // Called when a single widget value has changed On WidgetValueChanged(newValue : double) from ReqBatt var Bpct : int = 0 BChg : boolean = false BDchg : boolean = false BPrsnt : boolean = false BStat : int = 0 BLife : int = 0 disp : string = "" if newValue != 0 then Bpct = BatteryInfo_GetBatteryPercent() BChg = BatteryInfo_GetBatteryCharging() BDchg = BatteryInfo_GetBatteryDischarging() BPrsnt = BatteryInfo_GetBatteryPresent() BStat = BatteryInfo_GetACLineStatus() BLife = BatteryInfo_GetBatteryLifeTime() disp = "Percent " + Bpct + " Charging " + BChg + " Discharging " + BDchg + " Present " + BPrsnt + " State " + BStat Display.SetWidgetLabel(disp ) DisplayLifetime.SetWidgetLabel("Remaining seconds " + BLife ) end End
All functions start with
BatteryInfo_, so using the functions explorer in the gpscript editor you should be able to find them easily.
BatteryInfo-Ext-4.5.8.zip (12.1 KB)
The Gigfile (same one as I attached a little further in this topic):
BatteryInfo Demo.gig (37.6 KB)
For those interested in the source code (and maybe do it better), here is where you can find it: