News:

There is now a ChangeLog page on the wiki
New developments are added at the bottom of the page.

Main Menu

Long Delays without voxcommando freezing

Started by xtermin8r, March 21, 2013, 03:25:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

xtermin8r

Hi James

A much needed feature VC.Pause without voxcommando freezing, my creativity takes a serious blow :bonk when it comes to not having a VC.Pause without the VC freeze.
VC.TriggerEvent is a no no :(.
Neural Net Based Artificial Intelligence.

jitterjames

#1
It is not going to happen.

What do you mean VC.TriggerEvent is a no no?

edit:  OK, I should not say that it absolutely won't happen, but it is sticky business and I'm not keen to get gummed up in it!  It involves running each command in it's own thread, which by itself is not such a big deal, but as soon as that command starts to touch other parts of the program, there is a great potential for crash-tastic results.

jitterjames

maybe your needs can be met using the new python plugin.  Multithreading is supported so you could launch a new thread that pauses for a certain amount of time before triggering other actions and events?

jitterjames

here's an example to get you started:

import threading
import datetime
import time       

class ThreadClass(threading.Thread):
    def run(self):
        time.sleep(1)
        osd("it has been 1 second")
        time.sleep(1)
        osd("it has now been 2 seconds")
        time.sleep(3)
        osd("it has now been 5 seconds")

def osd(msg="test"):   
    #show text at top for 1.5 seconds
    vc.callAction("OSD.ShowText",msg+"&&1000&&-30", None)


osd("let's go...")
t = ThreadClass()
t.start()

xtermin8r

Neural Net Based Artificial Intelligence.

jitterjames

#5
You can try this. Use the contents of the attached to update an existing install of VC by overwriting the old files.

This is a test release that allows for mult-ithreaded commands.  Use this at your own risk!

How it works...

by default all commands should still operate normally, meaning that a VC.Pause action will freeze VC and no other commands can start until the current command finishes.  This should be OK for the majority of cases.  But if you absolutely must have it...

Name of your commands so they begin with ++ (see the example xml below).  Any commands whose name starts with ++ will be run in it's own thread.  Be careful with this and only use it if you really need to.  If weird stuff starts to happen, don't be too surprised.  Be particularly careful with commands that read and write {LastResult}.  Since commands may be running simultaneously, you might not get what you expect!

<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="thread test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="27" name="++test this thread 1" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.TellVox</cmdType>
      <cmdString>test this thread 2</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>2500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>AAA 1</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>2500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>AAA 2</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>2500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>AAA 3</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>test this thread 1</phrase>
  </command>
  <command id="39" name="++test this thread 2" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>BBB 1</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>1700</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>BBB 2</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.Pause</cmdType>
      <cmdString>2500</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>BBB 3</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>test this thread 2</phrase>
  </command>
  <command id="56" name="do something else" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <cmdString>OK.</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>do something else</phrase>
  </command>
</commandGroup>


You should be able to say "test this thread 1", and then while it is running (it will also call yet another command on another thread by using tellvox), you can say "do something else".  You will have 3 commands running at once.

If time starts to run backwards or things start falling upwards, don't say you weren't warned...  :biglaugh

[Attachment deleted. This is now standard in VC. Preface your command name with ++ to have the command run in its own thread. Note: if you don't understand what we mean by this then use with caution or not at all. Do not overdo it, regardless.]

xtermin8r

#6
hi James

Problem wiih the osd example,  I'm using vc 0.986.
Once the python script finishes, the osd remains on the screen until i restart voxcommando, any idea why ?

[attachment=1]
Neural Net Based Artificial Intelligence.

jitterjames

Yes it is a side effect of multithreading.  But the update should solve it.

xtermin8r

#8
I'll try the update, thanks again.
Neural Net Based Artificial Intelligence.

xtermin8r

Neural Net Based Artificial Intelligence.