Script to automatically set Volume to a value (USB-UIRT)

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
archizor
Posts: 1
Joined: Thu Feb 17, 2011 11:08 am

Script to automatically set Volume to a value (USB-UIRT)

Post by archizor » Fri Feb 18, 2011 10:38 am

hello,

I'am starting making some script for eventghost. i would like a little help.

I send from iviewer a broadcast message with a payload value defining the futur new level of my Amplifier.
here is my script, work well.

But i would like to be able to stop this script with an event when i want, actually when i try to send other event they wait the end of the script.

could you help me ?

Code: Select all

eg.event.payload=int(eg.event.payload)
togo =  eg.event.payload
if togo > eg.globals.volume:
        while (eg.globals.volume<togo):
            eg.plugins.USB_UIRT.TransmitIR(u'0000 0067 0000 0010 0061 0018 0031 0018 0031 0018 0019 0018 0019 0018 0031 0018 0019 0018 0019 0018 0019 0018 0019 0018 0019 0018 0019 0018 0031 0018 0031 0018 0019 0018 0019 0376', 2, 10)
            eg.globals.volume += 1
            eg.Wait(0.20000000000000001)
            print "VOLUP",eg.globals.volume
        
else:
        while (togo<eg.globals.volume):
            eg.plugins.USB_UIRT.TransmitIR(u'0000 0067 0000 0010 0061 0018 0019 0018 0031 0018 0019 0018 0019 0018 0031 0018 0019 0018 0019 0018 0019 0018 0019 0018 0019 0018 0019 0018 0031 0018 0031 0018 0019 0018 0019 038F', 2, 10)
            eg.globals.volume -= 1
            eg.Wait(0.20000000000000001)
            print "VOLDOWN",eg.globals.volume
buffer=str(eg.globals.volume)
print buffer
eg.plugins.BroadcastListener.Broadcast(u'NewVolume',buffer, 33333)

hotbuddha
Experienced User
Posts: 99
Joined: Tue Mar 29, 2011 5:14 am

Re: Script to automatically set Volume to a value (USB-UIRT)

Post by hotbuddha » Sun May 29, 2011 4:16 am

If you are running this script via a macro, then it will not be able to receive other events since all macros run under a single thread as triggered by their subscribed events in the order they are received. That is why you see the other event get processed after your script/macro completes, because that other event was waiting in line to get processed by the single thread. If you absolutely had to stop the script with an event you should create a plugin to run this code in it's own thread and have it Bind for the other event.

If you don't want to do all that, you might find success breaking your script apart into more than one script / macro and have each of the sub-macro fire an event at the end to kick off the next sub-macro and passing stuff needed for the next in the payload. Then you create a macro to handle disabling or enabling the macro you need to in order to accomplish your desired result.

I could not see anywhere in your code where you are looking for an event or anything like what you so I assume you did not post that code, other wise I might have been able to figure out exactly what you're trying to do and been more helpful.

Post Reply