[dasher: 54/217] Added speech cancel command to control box and Win32 implementation.



commit 68a67c767c1f222376578917db38c1a8ded001f9
Author: ipomoena <amajorek google com>
Date:   Sat Oct 10 16:35:28 2015 -0700

    Added speech cancel command to control box and Win32 implementation.
    
    Also eliminated crash at exit with fixing root cause.
    https://github.com/ipomoena/dasher/issues/3

 Src/DasherCore/ControlManager.cpp |   21 +++++++++++++++++----
 Src/Win32/Dasher.cpp              |    5 ++++-
 2 files changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/Src/DasherCore/ControlManager.cpp b/Src/DasherCore/ControlManager.cpp
index 8ba9252..c7342e6 100644
--- a/Src/DasherCore/ControlManager.cpp
+++ b/Src/DasherCore/ControlManager.cpp
@@ -323,8 +323,6 @@ CControlBase::Action *CControlManager::parseAction(const XML_Char *name, const X
 }
 
 CControlManager::~CControlManager() {
-  delete m_pSpeech;
-  delete m_pCopy;
 }
 
 class TextActionHeader : public CDasherInterfaceBase::TextAction, public CControlBase::NodeTemplate {
@@ -341,13 +339,28 @@ private:
   CControlBase::MethodTemplate<CDasherInterfaceBase::TextAction> m_all, m_new, m_again;
 };
 
+class CancelSpeech : public CControlBase::NodeTemplate {
+public:
+  CancelSpeech(CDasherInterfaceBase *pIntf, const std::string &strLabel, int iColour) 
+    : NodeTemplate(strLabel, iColour), m_pIntf(pIntf){}
+
+    void happen(CControlBase::CContNode *pNode) {
+    m_pIntf->Speak("", true);
+    }
+    CDasherInterfaceBase *m_pIntf;
+};
+
 class SpeechHeader : public TextActionHeader {
 public:
-  SpeechHeader(CDasherInterfaceBase *pIntf, NodeTemplate *pRoot) : TextActionHeader(pIntf, "Speak", pRoot) {
+  SpeechHeader(CDasherInterfaceBase *pIntf, NodeTemplate *pRoot) 
+    : TextActionHeader(pIntf, "Speak", pRoot), m_stop(pIntf,"Cancel",242){
+    successors.push_back(&m_stop); m_stop.successors.push_back(NULL); m_stop.successors.push_back(pRoot);
   }
   void operator()(const std::string &strText) {
-    m_pIntf->Speak(strText, true);
+    m_pIntf->Speak(strText, false);
   }
+private:
+  CancelSpeech m_stop;
 };
 
 class CopyHeader  : public TextActionHeader {
diff --git a/Src/Win32/Dasher.cpp b/Src/Win32/Dasher.cpp
index aacea66..bfa2a67 100644
--- a/Src/Win32/Dasher.cpp
+++ b/Src/Win32/Dasher.cpp
@@ -299,7 +299,10 @@ void CDasher::Speak(const string &strText, bool bInterrupt) {
        if (pVoice) {
                Tstring wideText;
                UTF8string_to_wstring(strText, wideText);
-               pVoice->Speak(wideText.c_str(), SPF_ASYNC, NULL);
+    int flags = SPF_ASYNC;
+    if (bInterrupt)
+      flags |= SPF_PURGEBEFORESPEAK;
+               pVoice->Speak(wideText.c_str(), flags, NULL);
        }
 }
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]