Extension for getting Battery/Powerstate. *Windows Only*

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 :rage:

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 :smiley:

** 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:

   Display : Widget
   ReqBatt : Widget
   DisplayLifetime : Widget

// 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
        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 )

All functions start with BatteryInfo_, so using the functions explorer in the gpscript editor you should be able to find them easily.

SHA256: 2580A691C14E83FDD6C2FC7651AE467073876684E5DE068E482DB5A0D8A521D0

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:


Thanks for this extension.

I’ve created a sample gig file demoing how it should work:

BatteryInfo Demo.gig (37.6 KB)


Excellent! Tested under Win10 22H2, works fine here!
In the past decades it happened a few times to me that the laptop was not on AC during a gig …

With a few cut&paste actions I have tested it in a global rackspace and panel, as this warning and info should be there for all songs, all rackspace, globally:

BatteryInfo Demo Global.gig (38.1 KB)