Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Trigger Event From Volume Level?

If you have a question or need help, this is the place to be.
User avatar
aireca
Posts: 14
Joined: Fri Mar 18, 2011 11:45 am

Trigger Event From Volume Level?

Post by aireca »

Hello

I want to know if there is some way to convert current volume level to an event, i have finded how to print the current volume level ("Change Master Volume: 0.00 %" + "print (int(round(eg.result,1)))") but i dont know how to transform that print to an event, i want to automatically mute the volume when it is at 0% because my system still have sound at 0% and i dont want to manually mute every time anymore :cry:




This is my current volume control:

Code: Select all

    <Folder Name="Volume Control">
        <Macro Name="Mute Volume">
            <Event Name="Lirc.Sony_RM-V210_VCR_Code_8201:SonyVCR.Muting" />
            <Event Name="PS3.Button.L1" />
            <Action>
                System.ToggleMute()
            </Action>
            <Action>
                EventGhost.ShowOSD(u'Mute {("Off", "On")[eg.result]}', u'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;BenguiatGot Bk BT', (0, 255, 0), (0, 0, 0), 5, (0, 35), 0, 3.0, False)
            </Action>
        </Macro>
        <Macro Name="Increase Volume">
            <Event Name="VolumeUp" />
            <Event Name="Lirc.Sony_RM-V210_VCR_Code_8201:SonyVCR.Volume+" />
            <Event Name="PS3.Button.Triangle" />
            <Event Name="Keyboard.LCtrl+RAlt+Oem3" />
            <Action>
                System.MuteOff(0)
            </Action>
            <Action>
                System.ChangeMasterVolumeBy(0.5, 0)
            </Action>
            <Action>
                EventGhost.ShowOSD(u'Volume {int(round(eg.result))}%', u'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;BenguiatGot Bk BT', (0, 255, 0), (0, 0, 0), 5, (0, 35), 0, 3.0, False)
            </Action>
            <Action>
                EventGhost.AutoRepeat(0.0, 0.0, 0.01, 1.0)
            </Action>
        </Macro>
        <Macro Name="Decrease Volume">
            <Event Name="VolumeDown" />
            <Event Name="Lirc.Sony_RM-V210_VCR_Code_8201:SonyVCR.Volume-" />
            <Event Name="PS3.Button.Square" />
            <Event Name="Keyboard.LCtrl+RAlt+P" />
            <Action>
                System.ChangeMasterVolumeBy(-0.5, 0)
            </Action>
            <Action>
                EventGhost.ShowOSD(u'Volume {int(round(eg.result))}%', u'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;BenguiatGot Bk BT', (0, 255, 0), (0, 0, 0), 5, (0, 35), 0, 3.0, False)
            </Action>
            <Action>
                EventGhost.AutoRepeat(0.0, 0.0, 0.01, 0.0)
            </Action>
        </Macro>
    </Folder>

Im into windows 7 x64 latest EventGhost

Thanks in advance :D
./)_/). o O ( ? )
( O.o')
( > < )
^^^^^
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Trigger Event From Volume Level?

Post by Pako »

You can use either Snarl or Growl.
For example, in Snarl is integrated extension that is called AudioMon.
Using EventGhost style you can redirect the notification also to EventGhost ...

Pako
Attachments
Snarl.Audiomon.0.png
Snarl.Audiomon.0.png (3.64 KiB) Viewed 8818 times
User avatar
aireca
Posts: 14
Joined: Fri Mar 18, 2011 11:45 am

Re: Trigger Event From Volume Level?

Post by aireca »

Thanks but that means a new process, i already have 12 system control processes, cant be done just with eventghost code? :|

there is no way to convert the "print (int(round(eg.result,1)))" to an event?
./)_/). o O ( ? )
( O.o')
( > < )
^^^^^
kalia
Experienced User
Posts: 109
Joined: Wed Aug 12, 2009 1:10 am

Re: Trigger Event From Volume Level?

Post by kalia »

Try the following Python script:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1544">
    <Action Name="Trigger Event based on if">
        EventGhost.PythonScript(u'if eg.result < 1:\n    eg.TriggerEvent("Button.L1", payload=None, prefix="PS3", source=eg)')
    </Action>
</EventGhost>
User avatar
aireca
Posts: 14
Joined: Fri Mar 18, 2011 11:45 am

Re: Trigger Event From Volume Level?

Post by aireca »

kalia wrote:Try the following Python script:
Thanks a lot, i finally have the volume like i want

Here is my final code:

Code: Select all

    <Folder Name="Volume Control Samsung">
        <Macro Name="Mute Volume">
            <Event Name="Lirc.Samsung_BN59-00861A:Sam.Mute" />
            <Action>
                System.ToggleMute()
            </Action>
            <Action id="505">
                EventGhost.ShowOSD(u'Mute {("Off", "On")[eg.result]}', u'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;BenguiatGot Bk BT', (0, 255, 0), (0, 0, 0), 5, (0, 35), 0, 3.0, False)
            </Action>
        </Macro>
        <Macro Name="Increase Volume">
            <Event Name="Lirc.Samsung_BN59-00861A:Sam.Vol+" />
            <Action>
                System.MuteOff(0)
            </Action>
            <Action>
                System.ChangeMasterVolumeBy(0.5, 0)
            </Action>
            <Action id="510">
                EventGhost.ShowOSD(u'Volume {int(round(eg.result))}%', u'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;BenguiatGot Bk BT', (0, 255, 0), (0, 0, 0), 5, (0, 35), 0, 3.0, False)
            </Action>
            <Action>
                EventGhost.AutoRepeat(0.0, 0.20000000000000001, 0.0, 0.59999999999999998)
            </Action>
        </Macro>
        <Macro Name="Decrease Volume">
            <Event Name="Lirc.Samsung_BN59-00861A:Sam.Vol-" />
            <Action>
                System.ChangeMasterVolumeBy(-0.5, 0)
            </Action>
            <Action>
                EventGhost.PythonCommand(u'print (int(round(eg.result,1)))')
            </Action>
            <Action Name="Trigger Event based on if">
                EventGhost.PythonScript(u'if eg.result < 1:\n    eg.TriggerEvent("AutoMute", payload=None, prefix="Volume", source=eg)')
            </Action>
            <Action id="515">
                EventGhost.ShowOSD(u'Volume {int(round(eg.result))}%', u'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;BenguiatGot Bk BT', (0, 255, 0), (0, 0, 0), 5, (0, 35), 0, 3.0, False)
            </Action>
            <Action>
                EventGhost.AutoRepeat(0.0, 0.20000000000000001, 0.0, 0.59999999999999998)
            </Action>
        </Macro>
        <Macro Name="AutoMute">
            <Event Name="Volume.AutoMute" />
            <Action>
                System.MuteOn(0)
            </Action>
            <Action>
                EventGhost.FlushEvents()
            </Action>
        </Macro>
    </Folder>
Thanks a lot again kalia
:D :D :D :D :D
./)_/). o O ( ? )
( O.o')
( > < )
^^^^^
hotbuddha
Experienced User
Posts: 99
Joined: Tue Mar 29, 2011 5:14 am

Re: Trigger Event From Volume Level?

Post by hotbuddha »

UPDATE: Please use the files in the zip file below.

Here you go, real OS level event driven volume events for EG (on vista/7/above, no XP sorry). Put both these files into eventghost\plugins\system (the file __init__.py replaces the old one in system), and rename the file VistaVolEvents.py to VistaVolEvents.pyd (Forum does not allow posting .pyd so I had to rename to post). Restart EG of course.

I posted a version of this the other night but I found out quickly it was unstable, this one I hammered away at for over five minutes and could not cause a problem. I'll go update that one now too. Enjoy and please give feedback, if this tests well I will submit to the base on the next build.
Last edited by hotbuddha on Sat Feb 18, 2012 5:02 pm, edited 1 time in total.
User avatar
aireca
Posts: 14
Joined: Fri Mar 18, 2011 11:45 am

Re: Trigger Event From Volume Level?

Post by aireca »

Thanks but
Its not working:

Code: Select all


Traceback (most recent call last) (1544):
  File "C:\Program Files (x86)\Utilidades\EventGhost\eg\Classes\ActionThread.py", line 33, in StartSession
    pluginInfo.instance.__start__()
  File "C:\Program Files (x86)\Utilidades\EventGhost\plugins\System\__init__.py", line 238, in __start__
    import VistaVolEvents as vistaVolumeDll
ImportError: DLL load failed: No se puede encontrar el m├│dulo especificado.

i have renamed VistaVolEvents.py to VistaVolEvents.pyd & placed on eventghost\plugins\system like you explained

i have EventGhost 0.4.1.r1544, Oct 31 2011, Windows 7 x64 SP1

Anything special i need to make/delete/change?, VistaVolume.dll is there, i have also tryed a clean EventGhost 0.4.1.r1544 installation too

:?
./)_/). o O ( ? )
( O.o')
( > < )
^^^^^
hotbuddha
Experienced User
Posts: 99
Joined: Tue Mar 29, 2011 5:14 am

Re: Trigger Event From Volume Level?

Post by hotbuddha »

No it sounds like you did the right thing. Maybe if I give you everything as a zip it will work so try the stuff in this file.
Last edited by hotbuddha on Mon Feb 20, 2012 12:34 am, edited 1 time in total.
User avatar
aireca
Posts: 14
Joined: Fri Mar 18, 2011 11:45 am

Re: Trigger Event From Volume Level?

Post by aireca »

Nope, looks like there is files refered to your hdd inside VistaVolEvents.pyd or something like that...

Im pretty sure i have it, but needs net framework or VisualStudio?

Code: Select all

Traceback (most recent call last) (1544):
  File "C:\Program Files (x86)\Utilidades\EventGhost\eg\Classes\ActionThread.py", line 33, in StartSession
    pluginInfo.instance.__start__()
  File "C:\Program Files (x86)\Utilidades\EventGhost\plugins\System\__init__.py", line 238, in __start__
    import VistaVolEvents as vistaVolumeDll
ImportError: DLL load failed: No se puede encontrar el m├│dulo especificado.
./)_/). o O ( ? )
( O.o')
( > < )
^^^^^
hotbuddha
Experienced User
Posts: 99
Joined: Tue Mar 29, 2011 5:14 am

Re: Trigger Event From Volume Level?

Post by hotbuddha »

I needed to compile for VS2008 instead of 10, and remove some defaults libs etc etc. I tested this one on my wife's netbook running 7 32 bit, and one other machine running 7 64 bit. Pretty sure this one will work now ;)

UPDATE: Find updated files on page two of thread...
Last edited by hotbuddha on Tue Feb 21, 2012 11:48 pm, edited 1 time in total.
User avatar
aireca
Posts: 14
Joined: Fri Mar 18, 2011 11:45 am

Re: Trigger Event From Volume Level?

Post by aireca »

Now its working thank you very much, but there is 2 problems

- Events Just works when you use the volume panel, so does not detect volume changes done by eventghost itself

- OSD & print isnt show anymore, Show OSD: Volume {int(round(eg.result))}% need new code?

OSD:

Code: Select all

Lirc.Samsung_BN59-00861A:Sam.Vol+
   Increase Volume
      Turn Mute Off
      Change Master Volume: 0.50 %
      Show OSD: Volume {int(round(eg.result))}%
         Error in Action: "Show OSD: Volume {int(round(eg.result))}%"
         Traceback (most recent call last) (1544):
           File "C:\Program Files (x86)\Utilidades\EventGhost\eg\Classes\ActionBase.py", line 170, in CallWrapper
             return self(*args)
           File "C:\Program Files (x86)\Utilidades\EventGhost\plugins\EventGhost\ShowOSD.py", line 385, in __call__
             osdText = eg.ParseString(osdText)
           File "C:\Program Files (x86)\Utilidades\EventGhost\eg\Utils.py", line 204, in ParseString
             res = eval(word, {}, eg.globals.__dict__)
           File "<string>", line 1, in <module>
         TypeError: a float is required
      Autorepeat current macro: 0.0


Print:

Code: Select all

   Decrease Volume
      Change Master Volume: -0.50 %
      print (int(round(eg.result,1)))
         Error in Action: "print (int(round(eg.result,1)))"
         Traceback (most recent call last) (1544):
           File "<string>", line 1, in <module>
         TypeError: a float is required
Thanks in advance
./)_/). o O ( ? )
( O.o')
( > < )
^^^^^
hotbuddha
Experienced User
Posts: 99
Joined: Tue Mar 29, 2011 5:14 am

Re: Trigger Event From Volume Level?

Post by hotbuddha »

Yes I wrote it on purpose so that it does not show events when EG does the volume change. This seemed useful since you don't want to have events when you set volume, you know you set volume. In something like a plugin being bound to volume events it would create a circular effect possibly. If you have some serious need for it to throw events when eg sets volume etc please explain and if it makes sense I will maybe do something like put an action where you can set it like an option to enable/disable events when EG sets volume.

As for the script, the set volume functions themselves are using float but for the events I have it thrown with the volume already in int. Also the value you want is in the payload of the event, so...

print (int(round(eg.result,1)))

CHANGE TO:
print eg.event.payload
User avatar
aireca
Posts: 14
Joined: Fri Mar 18, 2011 11:45 am

Re: Trigger Event From Volume Level?

Post by aireca »

Returns "None"

How i get that volume 0 event that i need, with your plugin?,
remember, im using lirc+eventghost to change volume

or at least make the next value from 0% volume be "mute", what i really need its to make the volume mute after reaches 0%, because i still have sound coming out from the speakers at 0%

it was achieved on the stock volume plugin with this code:

Code: Select all


        <Macro Name="Decrease Volume">
            <Event Name="Lirc.Samsung_BN59-00861A:Sam.Vol-" />
            <Action>
                System.ChangeMasterVolumeBy(-0.5, 0)
            </Action>
            <Action>
                EventGhost.PythonCommand(u'print (int(round(eg.result,1)))')
            </Action>
            <Action Name="Trigger Event based on if">
                EventGhost.PythonScript(u'if eg.result < 1:\n    eg.TriggerEvent("AutoMute", payload=None, prefix="Volume", source=eg)')
            </Action>
            <Action id="515">
                EventGhost.ShowOSD(u'Volume {int(round(eg.result))}%', u'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;BenguiatGot Bk BT', (0, 255, 0), (0, 0, 0), 5, (0, 35), 0, 3.0, False)
            </Action>
            <Action>
                EventGhost.AutoRepeat(0.0, 0.20000000000000001, 0.0, 0.59999999999999998)
            </Action>
        </Macro>
        <Macro Name="AutoMute">
            <Event Name="Volume.AutoMute" />
            <Action>
                System.MuteOn(0)
            </Action>
            <Action>
                EventGhost.FlushEvents()
            </Action>
        </Macro>

what is the new value to get the OSD?
./)_/). o O ( ? )
( O.o')
( > < )
^^^^^
hotbuddha
Experienced User
Posts: 99
Joined: Tue Mar 29, 2011 5:14 am

Re: Trigger Event From Volume Level?

Post by hotbuddha »

Here is a version where I changed the event to be in float like the rest of the volume methods, and I also let events be generated even if EG triggered them.

UPDATE" Find updated zip file on page two of this thread...
Last edited by hotbuddha on Tue Feb 21, 2012 11:49 pm, edited 2 times in total.
hotbuddha
Experienced User
Posts: 99
Joined: Tue Mar 29, 2011 5:14 am

Re: Trigger Event From Volume Level?

Post by hotbuddha »

Maybe something like this, I did not test, you may have to make changes. I assume you have an event called Increase volume which you will also want to remove the action for showing the OSD from, since that is now handled via the macros built on the new System Volume/Mute events. Doing it this way, does not matter if the volume is changed by your Lirc remote, the keyboard or whatever else, the OSD will display...

Code: Select all

        <Macro Name="Decrease Volume">
            <Event Name="Lirc.Samsung_BN59-00861A:Sam.Vol-" />
            <Action>
                System.ChangeMasterVolumeBy(-0.5, 0)
            </Action>
            <Action>
                EventGhost.PythonCommand(u'print (int(round(eg.result,1)))')
            </Action>
            <Action>
                EventGhost.AutoRepeat(0.0, 0.20000000000000001, 0.0, 0.59999999999999998)
            </Action>
        </Macro>
        <Macro Name="Show OSD with AutoMute">
            <Event Name="System.Volume" />
            <Action Name="Trigger Event based on if">
                EventGhost.PythonScript(u'if eg.event.payload < 1:\n    System.MuteOn(0)\n    eg.StopMacro()')
            </Action>
            <Action>
                EventGhost.ShowOSD(u'Volume {int(round(eg.event.payload))}%', u'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;BenguiatGot Bk BT', (0, 255, 0), (0, 0, 0), 5, (0, 35), 0, 3.0, False)
            </Action>
        </Macro>
        <Macro Name="Show OSD for Mute">
            <Event Name="System.Mute" />
            <Action>
                EventGhost.ShowOSD(u'Mute On', u'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;BenguiatGot Bk BT', (0, 255, 0), (0, 0, 0), 5, (0, 35), 0, 3.0, False)
            </Action>
        </Macro>
        <Macro Name="Show OSD for UnMute">
            <Event Name="System.UnMute" />
            <Action>
                EventGhost.ShowOSD(u'Mute Off', u'0;-32;0;0;0;700;0;0;0;0;3;2;1;34;BenguiatGot Bk BT', (0, 255, 0), (0, 0, 0), 5, (0, 35), 0, 3.0, False)
            </Action>
        </Macro>
Post Reply