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.

[solved] Getting master sound value in a script

If you have a question or need help, this is the place to be.
Post Reply
Bicou
Posts: 15
Joined: Tue Sep 12, 2006 2:51 pm

[solved] Getting master sound value in a script

Post by Bicou »

Hello,
First of all, congratulations for that wonderful program !!! I used to use ATI program, which was buggy (crashy) and then Girder which was way too complicated; so thank you very much for your work.
I have configured my EG as I wanted to, but I want to add some OSD stuff, and particularely the sound value, when I inscrease or decrease volume, I'd like to see "Volume: 45%" on the screen, but I have no idea of how to do it.

Thanks
Last edited by Bicou on Tue Sep 12, 2006 4:54 pm, edited 1 time in total.
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster »

SetMasterVolume and ChangeMasterVolume return the current volume level in "eg.result".
http://www.eventghost.org/wiki/Scripting#eg.result

ShowOSD accepts curly-brace syntax to show eg.result.

Example (copy&paste this to your tree):

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="681">
    <Folder Name="Volume Control">
        <Macro Name="Decrease Volume">
            <Event Name="VolumeDown">
            </Event>
            <Action>
                System.ChangeMasterVolumeBy(-2.0)
            </Action>
            <Action>
                EventGhost.ShowOSD(u'Volume: {int(eg.result)}%', u'0;-32;0;0;0;400;0;0;0;0;0;0;0;0;', (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0)
            </Action>
            <Action>
                EventGhost.AutoRepeat(0.59999999999999998, 0.29999999999999999, 0.01, 3.0)
            </Action>
        </Macro>
        <Macro Name="Increase Volume">
            <Event Name="VolumeUp">
            </Event>
            <Action>
                System.ChangeMasterVolumeBy(2.0)
            </Action>
            <Action>
                EventGhost.ShowOSD(u'Volume: {int(eg.result)}%', u'0;-32;0;0;0;400;0;0;0;0;0;0;0;0;', (255, 255, 255), (0, 0, 0), 0, (0, 0), 0, 3.0)
            </Action>
            <Action>
                EventGhost.AutoRepeat(0.59999999999999998, 0.29999999999999999, 0.01, 3.0)
            </Action>
        </Macro>
    </Folder>
</EventGhost>
Bicou
Posts: 15
Joined: Tue Sep 12, 2006 2:51 pm

Post by Bicou »

Thanks a lot! That's really cool :)
I have now another question :p
How can I know if a program has a running instance? I've thought of a Python command testing if mplayerc.exe is running, and right after a conditionnal jump depending on the Python command, is that OK? I just don't know how to make my Python command :s
Thanks
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster »

1. Use a "Find a window" action to find any MPC window (just leave the EXE field enabled, all other can be disabled). Turn off "Stop macro if target is not found"
2. Place a "jump" action after it and don't let it return. If FindWindow has found any MPC windows, it will set eg.result with the list of the windows. "Jump" will regard eg.result with a filled list as "successful" and will jump to the macro you choose. You can let it point to an empty macro, to just interrupt the processing.
3. Place actions to handle the other state after this, like starting MPC.

So this comes down to:
1. Search MPC
2. If found jump to another macro
3. Start MPC.exe
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster »

A bit more advanced:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="714">
    <Folder Name="Start Media Player Classic">
        <Macro Name="Start Media Player Classic">
            <Action>
                Window.FindWindow(u'mplayerc.exe', None, None, None, None, 1, False, 0.0, 2)
            </Action>
            <Action>
                EventGhost.NewJumpIf(XmlIdLink(1355), 0, False)
            </Action>
            <Action>
                System.Execute(u'{eg.PROGRAMFILES}\\Media Player Classic\\mplayerc.exe', u'', 0, False, 2)
            </Action>
        </Macro>
        <Macro Name="Bring to front Media Player Classic" id="1355">
            <Action>
                Window.FindWindow(u'mplayerc.exe', u'{*} - Media Player Classic', u'MediaPlayerClassicW', None, None, 1, False, 0.0, 0)
            </Action>
            <Action>
                Window.BringToFront()
            </Action>
        </Macro>
    </Folder>
</EventGhost>
This will start MPC if not started and bring it to front otherwise.

EDIT:
Small fix so this will also work if a video is loaded (title of MPC window has changed).
Bicou
Posts: 15
Joined: Tue Sep 12, 2006 2:51 pm

Post by Bicou »

Wow, really fast answer, cool :)
Actually I'd like to let Winamp context folder always enabled, except when MPC is turned on. For example if winamp is opened with a playlist, but stopped, and I launch a movie, then I press Play/pause to pause my movie, I don't want winamp to play the playlist!
So I've thought of a macro which triggers on all events in common between MPC and WA (like play/pause, show playlist, stop, jump next file, etc), but this macro must stop process if MPC is running.

My macro is triggered after sending MPC the event :
1. Find Window: MPC
2. If successful, jump to an empty macro (to prevent winamp from getting the event)
But that does not work: if WA and MPC are running at once, say MPC playing and WA stopped, the play/pause button of my remote control will pause MPC and play WA :/

What's wrong?


edit: wow, you're so fast you got time to reply with 2 solutions while I can barely post to explain my problem :p
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster »

Possible pitfall:
You have two matching events for the MPC and WA macro. So even if you don't jump, the other macro will be activated by the event.
Bicou
Posts: 15
Joined: Tue Sep 12, 2006 2:51 pm

Post by Bicou »

Yep that's right.
But how can I do? I tried to disable Winamp folder if MPC is running, but that does not work either (even if MPC's folder is before WA's one in the Context Folder list)
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Post by Bitmonster »

Suggestion:
Use the "Task Create/Switch Events" plugin to get notified if MPC is started and closed. Then disable the WA-Group completely if MPC is started (Task.Created.mplayerc) and enable it again if you get the destroyed event for MPC (Task.Destroyed.mplayerc).
Bicou
Posts: 15
Joined: Tue Sep 12, 2006 2:51 pm

Post by Bicou »

Wow this is just great ! This works perfectly.
Thank you very much for you FAST help! :-)
Post Reply