Tur-Another Idle Volume Adjuster by Turranius

Purpose: Lowers or mutes the master volume after a defined amount of time.

Features: * Set the volume to a percent of the current volume after an amount of time (This is the default).
          * Just mute the audio after an amount of time (Should work for XP)
          * Force the volume to a certain percent at startup.
          * Force the volume to a certain percent when going idle (A definable percent instead of a percent of current volume).
          * Definable FadeOut delay and FadeIn delay.
          * Exceptions. You specify the exe file(s) you want. If one of them is active, it will not go idle.
          * Splashscreen. By default, 2 images are shown when going idle and when it is idle. You can set your own images, turn them off or use message boxes instead.
          * Option to start the volume mixer hidden and never close it. Useful for HyperSpin which would otherwise freeze for half a second while loading the Volume mixer.
          * Definable name for your Volume Mixer window. Works with any language of Windows.
          * Right click it in the traybar for a menu.
          * And a few advanced options.

Reason : Originally ment for HyperSpin to lower/mute the volume after you have not touched anything for some time.
         It is totally stand-alone though, so it should work for anything really.

Usage  : You only need the exe file. The first time you run it, it will create the Settings.ini file and quit.
         Change the Settings.ini file as you want it configured and restart it. All the options are described below.
         If you mess something up in Settings.ini, delete and and a new one will be created on next run.

         -> You may want to disable the sound for "Default Beep" in Windows before running this or if you get a 
            "pling" each time it changes the volume.

Disclamer: You configure the volume in this app. If you blow your eardrums by configuring it to raise the volume
           to 100% or similar, I can not be held responsible. Please read through the options.

Limitation: It actually uses the volume mixer app (SndVol.exe) to change the volumes so it will be started and stopped 
            when the volume needs to be modified. In Debug mode, the volume control will be shown but not otherwise.
            This causes two things to happen.
            1: If you manually open the volume control, it might close on you, depending on timing. Should not be
               a problem as it only happens during idle and resume (and possibly at startup).
            2: When it needs to adjust the volume and the volume control is not started, it will start it causing
               the current active application to loose focus for a second. I give focus back almost instantly though.
               This can be fixed by setting NeverCloseSndVol=True but then you have to open the volume mixer by clicking
               on this application in the traybar instead (Or use media keys or any other way to change the volume).

Compability: Tested on Windows 7 x64 and Windows 8.1 x64. Might work on Vista. It should work on XP, but only to
             totally mute. No fading of the volume is possible. Set Simply_Mute_Audio=True if testing on XP.

             If you do not want HyperSpin to freeze for 1/3 of a second when volume is muted/comes back, set
             NeverCloseSndVol=True. See explanation on that setting below.

Thanks: Thanks to Dime333 for being patient and testing it.

Changes: 1.0 - 2014-12-15 - First public release.
         1.1 - 2014-12-16 - Should now be better to work with the volume as it can detect current volume and set
                            absolute values to it. Only works on Windows 7 or better now though. Perhaps Vista.
                            If you set it to Simply_Mute_Audio=True, it might work in XP. Not tested.

                            You can now abort the volume fading out when going idle by clicking any key or moving
                            the mouse. 

                            Smoother fade. 1.0 moved the volume 2% at a time. This moves it 1% at a time.

                            Volume can now be set to a percent of current volume, leaving you free to modify the
                            volume at will manually.

                            Changed settings are
                            Add: Set_Volume_at_Idle_to_Percent. Will set the volume to a percent of current volume.
                            Chg: ForceMuteOff. Only worked if Simply_Mute_Audio was True. Now also used if 
                                 Set_Volume_at_Startup is set to False.
                            Chg: Set_Volume_at_Idle. It is now always the value you set it to.
                            Add: QuitKey added. This lets you set your own key to exit the application.
                            Del: ExitWithShiftESC option removed because of the above.
                            Add: ExitWithQuitKey added. If you do not want to quit with the QuitKey, set this to False.
                            Del: KeyPressDelay option removed. No longer used.
                            Add: LoopDelay added.
                            Chg: FadeOut_Delay and FadeIn_Delay can now be set to "False" to instantly change volume
                                 without fading.

         1.2 - 2014-12-17 - Add: [IdleException] added to config. See Readme for explanation. Makes it possible
                                 to skip going idle when, for example, starting a movie or something. Defined by process.

                            Add: MaxDelayIfExceptionFound added to be able to force how long it should wait for the 
                                 excluded process to close if its running. It will then try again. Default is 0 for 
                                 indefinate and you should never have to touch it really, unless it does not resume 
                                 as it should when all the excluded processes closes.

                            Add: Name and version of the program will now be in its tooltip when hovering over it.
                                 It will also show the status (waiting for idle, currently idle, waiting for excluded
                                 process to close etc).

         1.3 - 2014-12-18 - Add: Added the [IdleSplash] section to be able to show a moving message or image on screen
                                 when the volume is muted/faded.

                            Add: Added a check so that only one occurance can be running at a time.

                            Add/Chg: Added VolumeMixerName in [Advanced] where you specify the name of the Volume Mixer window.
                                     It did not work at all if it did not start with "Volume Mixer" before (language dependent).
                                     It will help set this up the first time your run this version.

                            Del: MaxDelayIfExceptionFound removed. There are no max delay anymore as it was not really needed.

       1.3.1 - 2014-12-21   Add: Added NeverCloseSndVol to Settings.ini in [Advanced]

                            Add: Added ShowHiddenSndVolKey to Settings.ini in [Advanced]

         1.4 - 2014-12-23   Add: You can now right click the little icon in the traybar and select some options.
                                 About/Pause       - Shows a little about menu. Will also pause the program as long as its up.
                                 Show Volume Mixer - If you have NeverCloseSndVol=True, you can use this function to
                                                     bring up the hidden volume mixer again.
                                 Hide Volume Mixer - Hide it again.
                                 Edit Settings.ini - Opens notepad.exe with the Settings.ini file.
                                 Reload Settings.ini - Reloads all settings from the ini file so you do not have to restart it.
                                 Check Latest Version - Opens a link to my FTP with all the versions.
                                 Exit - Quits the program.

                            Chg: Cleaned up the code a bit. 

       1.4.1 - 2015-01-08   Del: Deleted ExitWithQuitKey option from Settings.ini. Not really needed. Just set QuitKey= or
                                 QuitKey=False to disable the quitkey instead.

                            Chg: Default setting Debug changed to False on creation of Settings.ini.
                            Chg: Default setting NeverCloseSndVol changed to True on creation of Settings.ini.
                            Chg: ShowHiddenSndVolKey can be set to "" or False to disable it.

                            Chg: Changed how ForceMuteOff=True disables mute on startup. It should no longer actually press keys
                                 to do this. It caused HyperSpin to cancel its intro if they started at the same time.

Settings:

[General Settings]

Time_To_Idle=
Number of seconds before being considered idle. Any keypress or mousemove should reset this timer.
Valid: Any number of seconds.
Default: 360

Debug=
When this is enabled, a traytip will be used to describe what it is doing. If you run into problems or are
interested in what the options you set modify how it works, set this to True.
It will also show the volume control when changing volume.
Note: There are a few more sleep functions while in debug mode to be able to see the messages so it might feel
      a bit sluggish when debug is on. Its detects keypresses and similar faster with debug off.
Valid: True/False
Default: False


[Sounds Options]

Simply_Mute_Audio=
When this is enabled, audio will simply be muted when the idle time kicks in. No fading will occur or similar
just mute or unmute instantly.
When this is enabled, all other options in [Sound Options] are non-valid and do nothing.
Valid: True/False
Default: False

Set_Volume_at_Startup=
Set this volume, in percent, when starting the program. This ensures that the volume is always at the defined level when this
app starts and resuming from idle. Set to False to disable this function.

If set, it should be set higher then "Set_Volume_at_Idle" below, but should work anyway. In fact, if you set it
lower then Set_Volume_at_Idle, this program will work in reverse (Increase volume when idle)!

If this is set to False, your volume is not touched at startup. When recovering from idle mode though, it will go
back to the volume it had before going idle.

Valid: False/0-100  - where 0 is lowest and 100 is max volume.
Default: False

Set_Volume_at_Idle_to_Percent=
Lower the volume by this Percent when going idle. If this is set to 50 and your volume, when going idle, is 80%, your volume
will be set to 40% (50% of 80 is 40).
If you set Set_Volume_at_Startup to False (Do not enforce a volume at startup), you are free to change the volume as you want
and it will always recalculate the percentage when its time to idle.

Valid: False/1-99
Default: 20
Requirement: Set_Volume_at_Idle=False

Set_Volume_at_Idle=
Set this volume when going idle. If you set this to 20, your idle volume will always be 20%, no matter what the normal
volume was. Both this and Set_Volume_at_Idle_to_Percent can not be set at the same time. Set one of them to False.

Valid: 0-100
Default: False
Requirement: Set_Volume_at_Idle_to_Percent=False

FadeOut_Delay=
The delay when fading out. This setting defines how fast the volume is lowered in milliseconds between each
percent of "Volume down".
While 0 delay is quite fast, you can also set it to "False" to instantly change the volume.

NOTE: You CAN abort the fade out process and raise the volume back up by clicking any key or moving the mouse.

Valid: False/0-10000
Default: 450

FadeIn_Delay=
Same as above, but how fast to raise the volume again when you are no longer idle.
Valid: False/0-10000
Default: 20


[IdleException]

This section is only used to define processes that should pause the idle process.
You specify one Exception<#>= per line (basically the .exe file).
Do not remove them all. To disabled, set Exception1=NONE
If it finds one of the processes defined here as running, it will pause until its gone.
Debug=True is good when testing this function as it spells out when and why its pausing.
You can add as many Exception<#> as you want.

Example:
Exception1=notepad.exe
Exception2=calc.exe
Exception3=somethingelse.exe

Valid: Exception<#> entries.
Default: 
Exception1=NONE


[IdleSplash]

This function has two settings. It either shows an image or text. Lets call the modes Image or Text mode from now on.
To enable image mode, put one or two .jpg images in the same folder as the application.
muting.jpg = Shown when the volume is fading down.
muted.jpg  = Shows when the volume is faded/muted. This one moves around.

Please note, some emulators does not allow the image to be shown. It works fine in HyperSpin and MAME for example, but
not in Daphne. It wont break anything, just not show the IdleSplash in those emulators.

EnableIdleFlash=
Enable the Flash/Splash system. This will enable this function.
Settings this to False disables all other values in [IdleSplash] and no indication will be given when going idle (except
if Debug=True of course).
Valid: True/False
Default: True

IdleFlashText=
The text to show when it its idle in text mode. To enable Image mode instead, put a muted.jpg file in the 
same folder as the program itself. To enable Text mode again, rename or remove muted.jpg
Valid: Any text. No quotes needed.
Default: Volume faded. Press any key to resume

IdleFlashTextWinSizeW=
IdleFlashTextWinSizeH=
The width and height of the window showing the IdleFlashText or Image. If you are using an image, it should be
the resolution of the image itself (check properties on it). In Text mode, it also controls the size
of the window.
Valid: Pixels
Default: 400, 291 (for the "muted.jpg" image that comes with the program. If you use the default text, 
         set it to 400, 42.)

IdleFlashTextDuring=
While the audio is fading out, this message is showing, in Text mode. To enable image mode instead 
put a muting.jpg image file in the same folder as the progam itself.
Will be replaced by IdleFlashText when fading is complete.
Valid: Any text. No quotes needed.
Default: Volume is fading. Press any key to abort

IdleFlashTextWinSizeDuringW=
IdleFlashTextWinSizeDuringH=
The width and height of the above window. In Image mode, it should match the size of muting.jpg.
Valid: Pixels
Default: 170, 170 (for the "muting.jpg" image that comes with the program. 400, 42 for the default text.

IdleFlashLoopsToMove=
The IdleFlashText (or image) can jump around on screen, like a screensaver.
How many loops of the program do you want to wait before it moves?
The default looptime is 1 second (Controlled by LoopDelay in [Advanced]), so setting this to 5 means that it will wait 5
seconds before moving the window.
Valid=0-infinite. Set 0 to keep it centered at all time.
Default: 1

IdleFlashTextFontName=
The name of the font to use. Set "default" to use the system font. This is only used in Text mode.
Valid: Any (?!) installed font name. No quotes needed. When looking at your fonts, select properties on the one you want. Check the
       "Title" name. That is the name to use.
Default: default

IdleFlashTextFontSize=
The size of the font. default is 12. This is only used in Text mode.
Valid: 6 8 9 10 11 12 14 16 18 20 22 24 26 28 36 48 72
Default: default

IdleFlashTextFontWeight=
The weight of the font from 1-900. This is only used in Text mode.
Normal is 400 so under it will make the font thinner. Over 400 will make it bolder.
Valid: 0-900 where 0 is the default weight for the selected font.
Default: default

IdleFlashDebug=
Set this to True if you want to test your flashes. It will switch between them every 4 seconds, showing your result.
Exit the program to quit the demo.
Valid: True/False
Default: False



[Advanced]
Advanced settings in here. Should not need to use them really.

ForceMuteOff=
Only used if Simply_Mute_Audio is set to True or Set_Volume_at_Startup is set to False. If this setting is True, it 
will ensure that mute is not on when starting the program by lowering the volume one step and raising it once again.
Otherwise, if mute is on when you start the program and when idle time kicks in, it can get confused.
Valid: True/False
Default: True

QuitKey=
The key to use to quit the program. The default is +{ESC} which means Shift-ESC.
You can read this page for usage: https://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm
To disable it, leave it empty or set it to False
Valid: False / Any Autoit3 key from URL above.
Default: +{ESC}

AbortIdleUsingFadeIn_Delay=
If you abort the fade out process when its lowering the volume, do you want to instantly
raise the volume back up or fade it back in using the FadeIn_Delay value?
Valid: True/False
Default: True

LoopDelay=
This program is basically one big loop where it checks idle time and volume. The default is 1000 ms meaning that 
it does its thing every second. If you want it to be more responsive, you can lower this value. If it eats all
your CPU (no, it wont), you can raise it.
Be careful with this option. Setting it to low will most likely cause problems. Setting it too high will cause
it to miss when you are no longer idle.
Valid: 0-infinte (Do not set 0 though).
Default: 1000 (one second).

VolumeMixerName=
What is the Volume Mixer called? The first time you run this program, when it sets up the Settings.ini, it will
try to detect it and autoset it for you.
It matches from the start of the text, so if your Volume Mixer window is called
"Volume Mixer - Speakers (2- Realtek High Definition Audio)"
it is enough if you just define it as
"Volume mixer - ".
Try to be as precise as you can though, so it does not start manipulating the volume in the wrong window.

You can also set it to AUTO (case sensitive). It will then try to autodetect it every start, but since this is timing
dependent, it is better to have it hardcoded.

Valid: AUTO / The name of your Volume Mixer window.
Default: None. It will be autodetected at first startup.

NeverCloseSndVol=
By default, this is True. That means that the first time it runs SndVol.exe (The volume mixer), it will not close it again.
Since its running hidden, you will not be able to open it with the little speaker icon in the traybar. Nothing will happen.
Why have it this way? When it needs to modify the volume, it starts SndVol.exe. For a split second, it takes focus. If you 
are running HyperSpin, HyperSpin will pause for a split second when it loses focus. We do not want that so we leave SndVol.exe
running and hidden with this setting set to True. You CAN still use media keys to change the volume or by any other means.
You may also right click the TAIVA icon in the traybar to display/hide the volume mixer again.

Also, if you get weird theme errors in HyperSpin after the volume has gone all the way down and back up again, set this to True.
Valid: True/False
Default: True

ShowHiddenSndVolKey=
This is a keycombination to show the Volume Mixer. Useful if NeverCloseSndVol=True. 
Valid: Any command acceptable. See QuitKey above. Same as with that one.
Set it empty or to False to disable the key combination.
Default: +!v (meaning Shift-Alt-V)
