[Amis-vcs] SF.net SVN: amis: [2390] branches/amis3/AmisGuiMFC2
Brought to you by:
julienq,
marisademeglio
From: <dan...@us...> - 2008-03-05 04:09:06
|
Revision: 2390 http://amis.svn.sourceforge.net/amis/?rev=2390&view=rev Author: daniel_weck Date: 2008-03-04 20:09:10 -0800 (Tue, 04 Mar 2008) Log Message: ----------- -- Very important update -- * the self-voicing backend is now very robust, and has been tested in Release as well as Debug mode. There has been major architectural changes, but the code still contains obsolete parts that will be removed in a later commit. * fixed many memory leaks, by simplifying the design wherever possible and double-checking every possible scenario (interrupted playback threads, interlocking situations due to mixed critical sections, etc.). Please note that the self-voicing UI has been tested with and without a book open (which is important because there are potential COM conflicts with Ambulant's own DirectShow renderer and the IE browser widget). Modified Paths: -------------- branches/amis3/AmisGuiMFC2/include/gui/MainFrm.h branches/amis3/AmisGuiMFC2/include/gui/dialogs/SkipDialog.h branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequenceComponent.h branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequencePlayer.h branches/amis3/AmisGuiMFC2/include/gui/self-voicing/PreTranslateMessageHandler.h branches/amis3/AmisGuiMFC2/include/gui/self-voicing/dialogs/MenuVoicing.h branches/amis3/AmisGuiMFC2/include/gui/self-voicing/directshow/dx_audio_player.h branches/amis3/AmisGuiMFC2/resource.h branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp branches/amis3/AmisGuiMFC2/src/gui/MainFrm.cpp branches/amis3/AmisGuiMFC2/src/gui/dialogs/AmisDialogBase.cpp branches/amis3/AmisGuiMFC2/src/gui/dialogs/SkipDialog.cpp branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequenceComponent.cpp branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp branches/amis3/AmisGuiMFC2/src/gui/self-voicing/PreTranslateMessageHandler.cpp branches/amis3/AmisGuiMFC2/src/gui/self-voicing/dialogs/MenuVoicing.cpp branches/amis3/AmisGuiMFC2/src/gui/self-voicing/directshow/dx_audio_player.cpp Modified: branches/amis3/AmisGuiMFC2/include/gui/MainFrm.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/MainFrm.h 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/include/gui/MainFrm.h 2008-03-05 04:09:10 UTC (rev 2390) @@ -60,6 +60,7 @@ CReBar mBasicRebar; CMenu mSavedMenu; + virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu); afx_msg void OnMenuSelect( UINT nItemID, UINT nFlags, HMENU hSysMenu ); Modified: branches/amis3/AmisGuiMFC2/include/gui/dialogs/SkipDialog.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/dialogs/SkipDialog.h 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/include/gui/dialogs/SkipDialog.h 2008-03-05 04:09:10 UTC (rev 2390) @@ -27,7 +27,6 @@ #include "gui/dialogs/AmisDialogBase.h" #include "../resource.h" -//#define TESTING namespace amis { @@ -36,13 +35,7 @@ namespace dialogs { -class SkipDialog : -#ifdef TESTING -public CDialog -#else -public AmisDialogBase -#endif - +class SkipDialog : public AmisDialogBase { //friend class amis::gui::spoken::SkipDialogVoicing; friend class SkipDialogVoicing; Modified: branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequenceComponent.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequenceComponent.h 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequenceComponent.h 2008-03-05 04:09:10 UTC (rev 2390) @@ -26,7 +26,6 @@ ~AudioSequenceComponent(); AudioSequenceComponent* clone(); BOOL m_isAudioClip; - bool mWasCloned; CString m_String; amis::AudioNode* m_AudioClip; Modified: branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequencePlayer.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequencePlayer.h 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/include/gui/self-voicing/AudioSequencePlayer.h 2008-03-05 04:09:10 UTC (rev 2390) @@ -3,7 +3,7 @@ #pragma once -#include <process.h> +//#include <process.h> #include <stdlib.h> #ifndef TRACE @@ -35,7 +35,10 @@ static bool InstanceExists(); static AudioSequencePlayer* Instance(); void Play(AudioSequence* audioSequence, bool doNotRegisterInHistory = false); - void Stop(); + + void Stop(bool fromPlay = false); + void playNext(bool fromEndEvent); + void RepeatLast(); void TTSAudioEndNotify(); void ClipAudioEndNotify(); @@ -56,21 +59,25 @@ HANDLE m_hEventEnd; CRITICAL_SECTION m_csSequence; bool m_bAbort; + bool bIgnoreTTSEnd; +void checkEndSeq(); +void WaitForEndSeqAndRestartBook(); void waitForSequenceEnd(); //static void AppendAudioSequenceStringResource(AudioSequence* seq, int nItemID); //static void AppendAudioSequenceStringID(AudioSequence* seq, string); - static AudioSequence* playPromptFromUiId(int nItemID, bool playImmediately = true, AudioSequence* seq = NULL); - static AudioSequence* playContainerPromptFromId(string id, bool playImmediately, AudioSequence* seq = NULL); - static AudioSequence* playPromptFromStringId(string, bool playImmediately = true, AudioSequence* seq = NULL, PromptResolver* pResolver = NULL); - static AudioSequence* playPromptItemFromStringId(string, bool playImmediately = true, AudioSequence* seq = NULL, PromptResolver* pResolver = NULL); - static AudioSequence* playDialogInstructionsFromUiId(int nItemID, bool playImmediately = true, AudioSequence* seq = NULL); - static AudioSequence* playDialogTextControlsFromUiId(int nItemID, bool playImmediately = true, AudioSequence* seq = NULL, string switchCondition = ""); - static AudioSequence* playDialogControlFromUiIds(int dlgID, int ctrlId, bool playImmediately = true, AudioSequence* seq = NULL, string switchCondition = ""); + static void playPromptFromUiId(int nItemID, AudioSequence* seq = NULL); + static void playPromptFromStringId(string); + static void playPromptItemFromStringId(string); + static void playDialogInstructionsFromUiId(int nItemID); + static void playDialogTextControlsFromUiId(int nItemID); + static void playDialogControlFromUiIds(int dlgID, int ctrlId); + + static void fillSequenceContainerPromptFromId(AudioSequence* seq, string id); static void fillSequencePrompt(AudioSequence* seq, Prompt* prompt, PromptResolver* pResolver = NULL); static void fillSequenceCaptionAndDescription(AudioSequence* seq, UiItem* uiItem); static void fillSequenceSwitch(AudioSequence* seq, UiItem* uiItem, string switchCondition = ""); Modified: branches/amis3/AmisGuiMFC2/include/gui/self-voicing/PreTranslateMessageHandler.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/self-voicing/PreTranslateMessageHandler.h 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/include/gui/self-voicing/PreTranslateMessageHandler.h 2008-03-05 04:09:10 UTC (rev 2390) @@ -19,8 +19,7 @@ ~PreTranslateMessageHandler(void); CString normalizeTextEntry(CString str, int nStartChar, int nEndChar); - AudioSequence* handle(bool playNow, - AudioSequence*, + void handle( MSG* pMsg, int idUiFocus, bool ignoreSpaceKey = false, @@ -28,6 +27,8 @@ CString strTextField = CString(L""), CString strTextFieldFULL = CString(L""), bool ignoreCharKeys = false); + +void handleCommand(WPARAM cmdid); private: @@ -37,7 +38,6 @@ int m_instructionsDialogID; bool mbKeyControl; - AudioSequence* mSeq; WPARAM mLastKeyDown; //bool processGeneralDialogFeedback(bool playNow, AudioSequence*, MSG* pMsg, int idUiFocus, bool ignoreSpaceKey, bool ignoreArrowKeys, CString strTextField); Modified: branches/amis3/AmisGuiMFC2/include/gui/self-voicing/dialogs/MenuVoicing.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/self-voicing/dialogs/MenuVoicing.h 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/include/gui/self-voicing/dialogs/MenuVoicing.h 2008-03-05 04:09:10 UTC (rev 2390) @@ -16,6 +16,8 @@ MenuVoicing(CMainFrame * frm); ~MenuVoicing(void); + AudioSequence* createSeqPrepend(UINT nFlags); + std::string computeRootMenuFromFirstChildID(unsigned int firstItemId, bool playPrompt); void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu); }; Modified: branches/amis3/AmisGuiMFC2/include/gui/self-voicing/directshow/dx_audio_player.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/self-voicing/directshow/dx_audio_player.h 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/include/gui/self-voicing/directshow/dx_audio_player.h 2008-03-05 04:09:10 UTC (rev 2390) @@ -37,6 +37,7 @@ #include <initguid.h> + //#include "ambulant/common/playable.h" //#include "ambulant/lib/win32/win32_error.h" //#include "ambulant/lib/logger.h" Modified: branches/amis3/AmisGuiMFC2/resource.h =================================================================== --- branches/amis3/AmisGuiMFC2/resource.h 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/resource.h 2008-03-05 04:09:10 UTC (rev 2390) @@ -2,6 +2,9 @@ // Microsoft Visual C++ generated include file. // Used by AmisGuiMFC2.rc // + +#define SELF_VOICING_PLAY_NEXT 6969 + #define IDD_ABOUTBOX 100 #define IDS_PROPSHT_CAPTION 102 #define IDD_SIDEBAR 103 Modified: branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp 2008-03-05 04:09:10 UTC (rev 2390) @@ -21,6 +21,8 @@ */ #include "stdafx.h" +#include <winbase.h> + #include "../resource.h" #include "AmisCore.h" #include "util/FilePathTools.h" @@ -69,7 +71,7 @@ #if _DEBUG //get Visual Leak Detector version 1.0 here: http://dmoulding.googlepages.com/downloads -//#include <vld.h> +#include <vld.h> #endif using namespace amis::gui; @@ -244,6 +246,8 @@ int CAmisApp::ExitInstance() { + TRACE("\nEXITING...\n\n"); + Preferences::Instance()->setWasExitClean(true); PreferencesFileIO prefs_io; prefs_io.writeToFile(Preferences::Instance()->getSourceUrl()->get_file(), Preferences::Instance()); @@ -259,9 +263,8 @@ amis::gui::MenuManip::Instance()->DestroyInstance(); amis::gui::MainWndParts::Instance()->DestroyInstance(); - if (AudioSequencePlayer::InstanceExists()) { AudioSequencePlayer::Instance()->DestroyInstance(); - } + DataTree::Instance()->DestroyInstance(); @@ -270,6 +273,8 @@ amis::util::Log::Instance()->endLog(); amis::util::Log::Instance()->DestroyInstance(); CoUninitialize(); + + TRACE("\nEXIT.\n\n"); return CWinApp::ExitInstance(); } @@ -326,15 +331,16 @@ new_data_reader.setAppPath(mAppPath); amis::ErrorCode did_it_work = new_data_reader.readFile(lang_xml_file.get_file(), p_new_data_tree); - if (false && did_it_work == amis::OK) + if (did_it_work == amis::OK) { //test print to an output file //p_new_data_tree->testPrint("c:\\devel\\amis\\Langpacks\\sandbox\\dataout.txt"); - /*AudioSequence* seq = new AudioSequence; - seq->append(L"AMIS"); - seq = AudioSequencePlayer::playPromptFromStringId("canceled", false, seq); - AudioSequencePlayer::Instance()->Play(seq);*/ + //AudioSequence* seq = new AudioSequence; + //seq->append(L"A"); + //seq = AudioSequencePlayer::playPromptFromStringId("canceled", false, seq); + //seq->append(CString('1')); + //AudioSequencePlayer::Instance()->Play(seq); } //if the UI file could not be read, then disable self-voicing @@ -346,6 +352,9 @@ { amis::Preferences::Instance()->setIsSelfVoicing(false); } + +//TODO: this is for testing until the alpha 2 (in alpha 1, Self-Voicing is totally disabled) +amis::Preferences::Instance()->setIsSelfVoicing(true); } const ambulant::net::url& CAmisApp::getBookURL() const @@ -651,8 +660,7 @@ amis::util::Log::Instance()->writeMessage("Showing reading options dialog (skippability)", "CAmisApp::OnSkipInfo", "AmisGuiMFC2"); amis::gui::dialogs::SkipDialog skip_dialog; skip_dialog.initializeData(amis::dtb::DtbWithHooks::Instance()->getCustomTestSet()); - //skip_dialog.do_modal(); - skip_dialog.DoModal(); + skip_dialog.do_modal(); amis::dtb::DtbWithHooks::Instance()->updateCustomTestStates(); } @@ -792,7 +800,7 @@ dialogs::PublicationSummaryDialog summary; amis::util::Log::Instance()->writeMessage("Showing publication summary dialog", "CAmisApp::OnPublicationSummary", "AmisGuiMFC2"); summary.setBook(amis::dtb::DtbWithHooks::Instance()); - summary.DoModal(); + summary.do_modal(); } void CAmisApp::OnToggleView() { @@ -845,29 +853,45 @@ return b_was_playing; } + void CAmisApp::afterModalBox(bool b_was_playing) { if (amis::Preferences::Instance()->getIsSelfVoicing() == true) { - AudioSequencePlayer::Instance()->Stop(); + //AudioSequencePlayer::Instance()->Stop(); AudioSequencePlayer::playPromptFromStringId("dialogClosed"); - AudioSequencePlayer::Instance()->waitForSequenceEnd(); + + if (b_was_playing == true) + { + + AudioSequencePlayer::Instance()->WaitForEndSeqAndRestartBook(); + } + + } else { + //resume playback if (b_was_playing == true) { - MmView *view = MainWndParts::Instance()->mpMmView; + + //MainWndParts::Instance()->mpMainFrame->PostMessage(WM_COMMAND, ID_AMBULANT_PLAY); + + MmView *view = MainWndParts::Instance()->mpMmView; view->OnFilePlay(); + } + } } void CAmisApp::generalBookErrorMsgBox(CString str) { bool b = beforeModalBox(); - AudioSequencePlayer::Instance()->Stop(); - AudioSequencePlayer::playPromptFromStringId("generalBookError"); + //AudioSequencePlayer::Instance()->Stop(); + if (amis::Preferences::Instance()->getIsSelfVoicing() == true) { + AudioSequencePlayer::playPromptFromStringId("generalBookError"); + } AfxMessageBox(str); afterModalBox(b); } Modified: branches/amis3/AmisGuiMFC2/src/gui/MainFrm.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/MainFrm.cpp 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/src/gui/MainFrm.cpp 2008-03-05 04:09:10 UTC (rev 2390) @@ -122,6 +122,15 @@ delete mCommonPreTranslateMessageHandler; delete mMenuVoicing; } +BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam) +{ + if (amis::Preferences::Instance()->getIsSelfVoicing() == true) + { + mCommonPreTranslateMessageHandler->handleCommand(wParam); + } + + return CMDIFrameWnd::OnCommand(wParam, lParam); +} int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; @@ -366,7 +375,7 @@ if (m_lastOpenPopupMenu != NULL) { m_lastOpenPopupMenu = NULL; } - TRACE("\n---------------DANOUL\n\n"); + TRACE("\n---------------DANOUL1\n\n"); TRACE(L"%d", cwnd); } } @@ -374,18 +383,18 @@ (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP)) { CWnd* cwnd = this->GetFocus(); - if (cwnd) mCommonPreTranslateMessageHandler->handle(true, NULL, pMsg, (cwnd == NULL ? -1 : cwnd->GetDlgCtrlID())); + if (cwnd) mCommonPreTranslateMessageHandler->handle(pMsg, (cwnd == NULL ? -1 : cwnd->GetDlgCtrlID())); } if (pMsg->message == WM_CANCELMODE) { - TRACE("\n---------------DANOUL\n\n"); + TRACE("\n---------------DANOUL2\n\n"); TRACE(L"%d", pMsg->message); } if (pMsg->wParam == WM_CANCELMODE) { - TRACE("\n---------------DANOUL\n\n"); + TRACE("\n---------------DANOUL3\n\n"); TRACE(L"%d", pMsg->wParam); } if (pMsg->lParam == WM_CANCELMODE) { - TRACE("\n---------------DANOUL\n\n"); + TRACE("\n---------------DANOUL4\n\n"); TRACE(L"%d", pMsg->lParam); } return CFrameWnd::PreTranslateMessage(pMsg); Modified: branches/amis3/AmisGuiMFC2/src/gui/dialogs/AmisDialogBase.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/dialogs/AmisDialogBase.cpp 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/src/gui/dialogs/AmisDialogBase.cpp 2008-03-05 04:09:10 UTC (rev 2390) @@ -42,7 +42,7 @@ if (cwnd) { mCommonPreTranslateMessageHandler->handle - (true, NULL, pMsg, (cwnd == NULL ? -1 : cwnd->GetDlgCtrlID())); + (pMsg, (cwnd == NULL ? -1 : cwnd->GetDlgCtrlID())); } } @@ -51,41 +51,12 @@ INT_PTR AmisDialogBase::do_modal() { - /* - if (amis::Preferences::Instance()->getIsSelfVoicing() == true) - { - AudioSequencePlayer::Instance()->Stop(); - } - - MmView *view = MainWndParts::Instance()->mpMmView; - bool b_was_playing = view->isPlaying(); - if (b_was_playing == true) - { - view->OnFilePause(); - }*/ - bool b = amis::gui::CAmisApp::beforeModalBox(); INT_PTR ret = DoModal(); theApp.afterModalBox(b); - /* - if (amis::Preferences::Instance()->getIsSelfVoicing() == true) - { - AudioSequencePlayer::Instance()->Stop(); - // DanToDo: make blocking...so that there is no overlap with the book playback. - AudioSequencePlayer::playPromptFromStringId("dialogClosed"); - - AudioSequencePlayer::Instance()->waitForSequenceEnd(); - } - - //resume playback - if (b_was_playing == true) - { - view->OnFilePlay(); - }*/ - return ret; } Modified: branches/amis3/AmisGuiMFC2/src/gui/dialogs/SkipDialog.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/dialogs/SkipDialog.cpp 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/src/gui/dialogs/SkipDialog.cpp 2008-03-05 04:09:10 UTC (rev 2390) @@ -38,12 +38,7 @@ amis::gui::dialogs::SkipDialogVoicing * mpSkipDialogVoicing = NULL; SkipDialog::SkipDialog(CWnd* pParent /*=NULL*/) - -#ifdef TESTING - : CDialog(SkipDialog::IDD) -#else : AmisDialogBase(SkipDialog::IDD) -#endif { if (Preferences::Instance()->getIsSelfVoicing() == true) @@ -68,14 +63,14 @@ { return CDialog::PreTranslateMessage(pMsg); } -#ifndef TESTING + if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP) { CWnd* cwnd = this->GetFocus(); if (cwnd) { int id = cwnd->GetDlgCtrlID(); - mCommonPreTranslateMessageHandler->handle(true, NULL, pMsg, (cwnd == NULL ? -1 : id), (id == IDC_SKIPS ? true : false), (id == IDC_SKIPS ? true : false), L"", L"", (id == IDC_SKIPS ? true : false)); + mCommonPreTranslateMessageHandler->handle(pMsg, (cwnd == NULL ? -1 : id), (id == IDC_SKIPS ? true : false), (id == IDC_SKIPS ? true : false), L"", L"", (id == IDC_SKIPS ? true : false)); if (pMsg->message == WM_KEYUP) { @@ -86,7 +81,7 @@ } } } -#endif + return CDialog::PreTranslateMessage(pMsg); } @@ -178,16 +173,12 @@ void SkipDialog::OnPaint() { -#ifdef TESTING - CDialog::OnPaint(); - return; -#endif CPaintDC dc(this); // device context for painting // Let the window do its default painting... CWnd::DefWindowProc( WM_PAINT, (WPARAM)dc.m_hDC, 0 ); //call the base class on_paint function -#ifndef TESTING + on_paint(); -#endif + } \ No newline at end of file Modified: branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequenceComponent.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequenceComponent.cpp 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequenceComponent.cpp 2008-03-05 04:09:10 UTC (rev 2390) @@ -3,15 +3,14 @@ using namespace amis::gui::spoken; AudioSequenceComponent::AudioSequenceComponent(){ - mWasCloned = false; + } AudioSequenceComponent::~AudioSequenceComponent(){ m_String.Empty(); - if (mWasCloned) { delete m_AudioClip; - } + m_AudioClip = NULL; } @@ -20,7 +19,6 @@ comp->m_AudioClip = (m_AudioClip ? (amis::AudioNode*)m_AudioClip->clone() : NULL); comp->m_String = m_String; comp->m_isAudioClip = m_isAudioClip; - comp->mWasCloned = true; return comp; } \ No newline at end of file Modified: branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/src/gui/self-voicing/AudioSequencePlayer.cpp 2008-03-05 04:09:10 UTC (rev 2390) @@ -19,6 +19,7 @@ #include "gui/MmView.h" //#include "ambulant/net/url.h" +#include "../../AmisGuiMFC2/resource.h" using namespace amis::tts; @@ -303,14 +304,14 @@ return; } #ifdef CCS_ACTIVE - //EnterCriticalSection(&m_csSequence); + EnterCriticalSection(&m_csSequence); #endif m_wakeUpOriginator = 3; // AUDIO CLIP END TRACE(L"\n ---- m_hEventWakeup AUDIO end\n"); SetEvent(m_hEventWakeup); #ifdef CCS_ACTIVE - //LeaveCriticalSection(&m_csSequence); + LeaveCriticalSection(&m_csSequence); #endif /* if (m_wakeUpAction != 0) { @@ -326,12 +327,27 @@ //The message callback function ... signals end of the tts static void ttsFinishedCallback() { - AudioSequencePlayer::Instance()->TTSAudioEndNotify(); + if (AudioSequencePlayer::Instance()->bIgnoreTTSEnd) { + AudioSequencePlayer::Instance()->bIgnoreTTSEnd = false; + return; + } + AudioSequencePlayer::Instance()->checkEndSeq(); + //AudioSequencePlayer::Instance()->playNext(true); + + //HWND hWnd = MainWndParts::Instance()->mpMainFrame->GetSafeHwnd(); + MainWndParts::Instance()->mpMainFrame->PostMessage(WM_COMMAND, (WPARAM)SELF_VOICING_PLAY_NEXT, (LPARAM)0); } +void AudioSequencePlayer::checkEndSeq() { + if (m_currentAudioSequence != NULL && m_currentAudioSequence->GetCount() == 0) {SetEvent(m_hEventEnd);} +} //The message callback function ... signals end of the clip static void clipFinishedCallback() { - AudioSequencePlayer::Instance()->ClipAudioEndNotify(); + //AudioSequencePlayer::Instance()->playNext(true); + AudioSequencePlayer::Instance()->checkEndSeq(); + + //HWND hWnd = MainWndParts::Instance()->mpMainFrame->GetSafeHwnd(); + MainWndParts::Instance()->mpMainFrame->PostMessage(WM_COMMAND, (WPARAM)SELF_VOICING_PLAY_NEXT, (LPARAM)0); } bool AudioSequencePlayer::InstanceExists() { @@ -355,6 +371,8 @@ m_hThread = NULL; m_bAbort = false; + bIgnoreTTSEnd = false; + m_wakeUpAction = 3; m_wakeUpOriginator = -1; m_nEndEventsToExpect = 0; @@ -365,9 +383,9 @@ InitializeCriticalSection(&m_csSequence); - m_hEventWakeup = CreateEvent(NULL, TRUE, FALSE, NULL); + /* m_hEventWakeup = CreateEvent(NULL, TRUE, FALSE, NULL); _ASSERT(m_hEventWakeup); - ResetEvent(m_hEventWakeup); + ResetEvent(m_hEventWakeup); */ m_hEventEnd = CreateEvent(NULL, TRUE, FALSE, NULL); _ASSERT(m_hEventEnd); @@ -378,15 +396,18 @@ if (m_hThread == NULL) { /* - m_hThread = (HANDLE) _beginthreadex(NULL, 0, ThreadProc, (void*) this, 0, &threadID); */ + m_hThread = (HANDLE) _beginthreadex(NULL, 0, ThreadProc, (void*) this, 0, &threadID); unsigned long threadID; m_hThread = CreateThread(NULL, 0, ThreadProc, this, 0, &threadID); _ASSERT(m_hThread != NULL); + */ } } void AudioSequencePlayer::waitForSequenceEnd() { + +TRACE("\nWAIT for SEQ end.\n"); DWORD hr = WaitForSingleObject(m_hEventEnd, 3000); switch (hr) { case WAIT_FAILED: { @@ -408,6 +429,8 @@ break;} } + +TRACE("\nWAIT for SEQ end DONE.\n"); } void AudioSequencePlayer::DestroyInstance() { @@ -424,7 +447,7 @@ AudioSequencePlayer::~AudioSequencePlayer(void) { BOOL rc; - _ASSERT(m_hThread != NULL); + //_ASSERT(m_hThread != NULL); #ifdef CCS_ACTIVE EnterCriticalSection(&m_csSequence); @@ -440,13 +463,13 @@ #endif m_wakeUpOriginator = 0; // DESTRUCTOR - rc = SetEvent(m_hEventWakeup); - _ASSERT(rc); + /* rc = SetEvent(m_hEventWakeup); + _ASSERT(rc); */ rc = SetEvent(m_hEventEnd); _ASSERT(rc); - +/* DWORD hr = WaitForSingleObject(m_hThread, 2000); switch (hr) { case WAIT_FAILED: { @@ -467,11 +490,11 @@ int i = 0; break;} - } + }*/ - CloseHandle(m_hThread); + //CloseHandle(m_hThread); - CloseHandle(m_hEventWakeup); + //CloseHandle(m_hEventWakeup); CloseHandle(m_hEventEnd); @@ -481,26 +504,41 @@ void AudioSequencePlayer::RepeatLast() { -#ifdef CCS_ACTIVE - EnterCriticalSection(&m_csSequence); -#endif //AudioSequence* audioSequence = new AudioSequence(); if (m_previousAudioSequence) { Play(m_previousAudioSequence); } -#ifdef CCS_ACTIVE - LeaveCriticalSection(&m_csSequence); -#endif } -void AudioSequencePlayer::Stop() +//unsigned __stdcall eventHandler(void* lpParam) { +DWORD __stdcall eventHandlerY(LPVOID lpParam) { +//UINT __cdecl eventHandlerX( LPVOID pParam ) { + + AudioSequencePlayer::Instance()->waitForSequenceEnd(); + //MmView *view = MainWndParts::Instance()->mpMmView; + //view->OnFilePlay(); + MainWndParts::Instance()->mpMainFrame->PostMessage(WM_COMMAND, ID_AMBULANT_PLAY); + + //_endthreadex( 0 ); + return 0; +} +void AudioSequencePlayer::WaitForEndSeqAndRestartBook() { + + unsigned long lpdwThreadID; + //hEventHandler = (HANDLE) _beginthreadex(NULL, 0, eventHandler, (void*) this, 0, &lpdwThreadID); + HANDLE xeventHandler = CreateThread(NULL, 0, &eventHandlerY, 0, 0, &lpdwThreadID); + //AfxBeginThread(eventHandlerX,0); +} + +void AudioSequencePlayer::Stop(bool fromPlay) { +SetEvent(m_hEventEnd); { #ifdef CCS_ACTIVE + if (!fromPlay) EnterCriticalSection(&m_csSequence); #endif - m_wakeUpAction = 0; m_nEndEventsToExpect = 0; @@ -513,12 +551,12 @@ bool bExpectEndEventForWakeUp = false; if (TTSPlayer::Instance()->IsSpeaking()) { - bExpectEndEventForWakeUp = true; + bIgnoreTTSEnd = true; m_nEndEventsToExpect++; //ResetEvent(pThis->m_hEventWakeup); TTSPlayer::Instance()->Stop(); //TTSPlayer::Instance()->WaitUntilDone(); - TRACE(L"####### -- STOP TTS"); + TRACE(L"\n####### ++++ STOP TTS\n"); } if (ambulantX::gui::dx::audio_playerX::Instance()->is_playing()) { @@ -528,7 +566,7 @@ ambulantX::gui::dx::audio_playerX::Instance()->stop(false); //m_wakeUpOriginator = 3; // AUDIO CLIP END //SetEvent(m_hEventWakeup); - TRACE(L"####### -- STOP AUDIO"); + TRACE(L"\n####### ++++ STOP AUDIO\n"); } if (!bExpectEndEventForWakeUp) { @@ -538,17 +576,121 @@ } #ifdef CCS_ACTIVE + if (!fromPlay) LeaveCriticalSection(&m_csSequence); #endif } } +void AudioSequencePlayer::playNext(bool fromEndEvent) { + + if (m_currentAudioSequence == NULL) return; + +#ifdef CCS_ACTIVE + if (fromEndEvent) EnterCriticalSection(&m_csSequence); +#endif + + TRACE(L"\n*** PLAY NEXT\n"); + +if (m_currentAudioSequence->GetCount() == 0) { + + delete m_currentAudioSequence; + m_currentAudioSequence = NULL; + return; + } + + AudioSequenceComponent* comp = m_currentAudioSequence->RemoveTail(); + + +if (comp->m_isAudioClip) { + + if (fromEndEvent) { + HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + if (hr == S_FALSE) CoUninitialize(); + _ASSERT(hr == S_FALSE); + } + + TRACE(L"\n============ PLAY AUDIO CLIP\n"); + playAudioPrompt(comp->m_AudioClip); + +//if (fromEndEvent) {CoUninitialize();} + + delete comp; + comp=NULL; + + } else { + CString strDebug; + strDebug.Format(_T("============ PLAY AUDIO TTS: --%s--\n"), comp->m_String); + TRACE(strDebug); + bIgnoreTTSEnd = false; + TTSPlayer::Instance()->Play(comp->m_String); + delete comp; + comp=NULL; + } +#ifdef CCS_ACTIVE + if (fromEndEvent) LeaveCriticalSection(&m_csSequence); +#endif +} + +//unsigned __stdcall eventHandler(void* lpParam) { +DWORD __stdcall eventHandlerX(LPVOID lpParam) { + + AudioSequencePlayer *pPlayer = (AudioSequencePlayer*)lpParam; + + TRACE(L"\n/// THREAD PLAY BEGIN\n"); + + pPlayer->playNext(true); + + TRACE(L"\n/// THREAD PLAY END\n"); + + //_endthreadex( 0 ); + return 0; +} + + void AudioSequencePlayer::Play(AudioSequence* audioSequence, bool doNotRegisterInHistory) { - Stop(); + if (audioSequence == NULL || audioSequence->GetCount() == 0) { + int debugHere = 0; + } { #ifdef CCS_ACTIVE EnterCriticalSection(&m_csSequence); #endif + + TRACE(L"\n####### -- PLAY SEQ\n"); + + Stop(true); + +if (!doNotRegisterInHistory) { + if (m_previousAudioSequence) { + if (audioSequence != m_previousAudioSequence) { // Not replaying + delete m_previousAudioSequence; + } + } + m_previousAudioSequence = audioSequence->clone(); + } + + + m_currentAudioSequence = audioSequence; + ResetEvent(m_hEventEnd); + + +#ifdef CCS_ACTIVE + LeaveCriticalSection(&m_csSequence); +#endif + + //HWND hWnd = MainWndParts::Instance()->mpMainFrame->GetSafeHwnd(); + MainWndParts::Instance()->mpMainFrame->PostMessage(WM_COMMAND, (WPARAM)SELF_VOICING_PLAY_NEXT, (LPARAM)0); + //playNext(false); + + /* + unsigned long lpdwThreadID; + //hEventHandler = (HANDLE) _beginthreadex(NULL, 0, eventHandler, (void*) this, 0, &lpdwThreadID); + HANDLE xeventHandler = CreateThread(NULL, 0, &eventHandlerX, this, 0, &lpdwThreadID); + */ + + return; + if (!m_bAbort) { m_wakeUpAction = 0; @@ -576,7 +718,7 @@ //ResetEvent(pThis->m_hEventWakeup); TTSPlayer::Instance()->Stop(); //TTSPlayer::Instance()->WaitUntilDone(); - TRACE(L"####### STOP TTS"); + TRACE(L"\n#######--- STOP TTS\n"); } if (ambulantX::gui::dx::audio_playerX::Instance()->is_playing()) { bExpectEndEventForWakeUp = true; @@ -585,7 +727,7 @@ ambulantX::gui::dx::audio_playerX::Instance()->stop(false); //m_wakeUpOriginator = 3; // AUDIO CLIP END //SetEvent(m_hEventWakeup); - TRACE(L"####### STOP AUDIO"); + TRACE(L"\n#######--- STOP AUDIO\n"); } ResetEvent(m_hEventEnd); @@ -672,11 +814,15 @@ //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// // This works for Containers (menus). -AudioSequence* AudioSequencePlayer::playPromptFromUiId(int nItemID, bool playImmediately, AudioSequence* seq) +void AudioSequencePlayer::playPromptFromUiId(int nItemID, AudioSequence* seq) { //amis::Preferences::Instance()->mbUseTTSNotAudio == true) if (nItemID != -1) { + if (seq == NULL) { + seq = new AudioSequence; + } + amis::RecentBooks* books = theApp.getRecentBooks(); int nRecentBooks = (books ? books->getNumberOfEntries() : 0); @@ -697,9 +843,7 @@ } } - if (seq == NULL) { - seq = new AudioSequence; - } + //AppendAudioSequenceStringResource(seq, nItemID); UiItem* p_uiItem = DataTree::Instance()->findUiItemInContainers(nItemID, strCondition); @@ -777,78 +921,71 @@ } //strText.Empty(); } - if (playImmediately) AudioSequencePlayer::Instance()->Play(seq); - return seq; + + if (seq->GetCount() == 0) { + delete seq; + + } else { + + AudioSequencePlayer::Instance()->Play(seq); + } } - - return NULL; } //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// // This works for Containers (menus). -AudioSequence* AudioSequencePlayer::playContainerPromptFromId(string id, bool playImmediately, AudioSequence* seq) { +void AudioSequencePlayer::fillSequenceContainerPromptFromId(AudioSequence* seq, string id) { - if (!id.empty()) { Container* p_container = DataTree::Instance()->findContainer(id); if (p_container != NULL) { - if (seq == NULL) { - seq = new AudioSequence; - } - - Label* keyboardShortcutAccelerator = p_container->getKeyboardAccelerator(); fillSequenceCaptionAndDescription(seq, p_container); + Label* keyboardShortcutAccelerator = p_container->getKeyboardAccelerator(); if (keyboardShortcutAccelerator != NULL) { fillSequenceContentAndPrompt(seq, keyboardShortcutAccelerator); } - - if (playImmediately) AudioSequencePlayer::Instance()->Play(seq); - return seq; } } - return NULL; } //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// // This works for Prompts. -AudioSequence* AudioSequencePlayer::playPromptFromStringId(string promptId, bool playImmediately, AudioSequence* seq, PromptResolver* pResolver) +void AudioSequencePlayer::playPromptFromStringId(string promptId) { + - if (seq == NULL) { - seq = new AudioSequence; - } - //AppendAudioSequenceStringID(seq, promptId); - - Prompt* p_prompt_ = DataTree::Instance()->findPrompt(promptId); if (p_prompt_ != NULL) { - fillSequencePrompt(seq, p_prompt_, pResolver); + AudioSequence * seq = new AudioSequence; + fillSequencePrompt(seq, p_prompt_, NULL); + if (seq->GetCount() == 0) { + delete seq; + } else { + AudioSequencePlayer::Instance()->Play(seq); + } } - - if (playImmediately) AudioSequencePlayer::Instance()->Play(seq); - return seq; } //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// // This works for Prompts. -AudioSequence* AudioSequencePlayer::playPromptItemFromStringId(string promptId, bool playImmediately, AudioSequence* seq, PromptResolver* pResolver) +void AudioSequencePlayer::playPromptItemFromStringId(string promptId) { - if (seq == NULL) { - seq = new AudioSequence; - } + + AudioSequence * seq = new AudioSequence; + PromptItem* p_prompt_ = DataTree::Instance()->findPromptItem(promptId); @@ -856,22 +993,17 @@ { fillSequenceContents(seq, p_prompt_); } - if (playImmediately) AudioSequencePlayer::Instance()->Play(seq); - return seq; + AudioSequencePlayer::Instance()->Play(seq); } //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// // This works for Dialogs, plays the instructions. -AudioSequence* AudioSequencePlayer::playDialogInstructionsFromUiId(int nItemID, bool playImmediately, AudioSequence* seq) { +void AudioSequencePlayer::playDialogInstructionsFromUiId(int nItemID) { if (nItemID != -1) { - - if (seq == NULL) { - seq = new AudioSequence; - } - //AppendAudioSequenceStringResource(seq, nItemID); + AudioSequence * seq = new AudioSequence; Dialog* p_dialog = DataTree::Instance()->findDialog(nItemID); if (p_dialog != NULL) { @@ -880,29 +1012,29 @@ fillSequencePrompt(seq, prompt); } } - if (playImmediately) AudioSequencePlayer::Instance()->Play(seq, true); - return seq; + if (seq->GetCount() == 0) { + delete seq; + } + else { + AudioSequencePlayer::Instance()->Play(seq, true); + } } - return NULL; + } //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// // This works for Dialogs -AudioSequence* AudioSequencePlayer::playDialogTextControlsFromUiId(int nItemID, bool playImmediately, AudioSequence* seq, string switchCondition) { +void AudioSequencePlayer::playDialogTextControlsFromUiId(int nItemID) { if (nItemID != -1) { - - if (seq == NULL) { - seq = new AudioSequence; - } - //AppendAudioSequenceStringResource(seq, nItemID); - + AudioSequence * seq = new AudioSequence; + Dialog* p_dialog = DataTree::Instance()->findDialog(nItemID); if (p_dialog != NULL) { fillSequenceCaptionAndDescription(seq, p_dialog); - fillSequenceSwitch(seq, p_dialog, switchCondition); + fillSequenceSwitch(seq, p_dialog); int count = p_dialog->getNumChildControls(); for (int i = 0 ; i < count; i++) { @@ -915,16 +1047,15 @@ } } - if (playImmediately) AudioSequencePlayer::Instance()->Play(seq); - return seq; + if (seq->GetCount()==0){delete seq;return;}else{ AudioSequencePlayer::Instance()->Play(seq);} + } - return NULL; } //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// // This works for Dialogs -AudioSequence* AudioSequencePlayer::playDialogControlFromUiIds(int dlgID, int ctrlId, bool playImmediately, AudioSequence* seq, string switchCondition) { +void AudioSequencePlayer::playDialogControlFromUiIds(int dlgID, int ctrlId) { if ( (dlgID != -1 && ctrlId != -1) @@ -932,9 +1063,8 @@ ) { - if (seq == NULL) { - seq = new AudioSequence; - } + AudioSequence * seq = new AudioSequence; + if (dlgID == -1) { if (ctrlId == IDCANCEL) { @@ -996,10 +1126,15 @@ } } - if (playImmediately) AudioSequencePlayer::Instance()->Play(seq); - return seq; + if (seq != NULL && seq->GetCount() == 0) { + delete seq; + + } else { + + AudioSequencePlayer::Instance()->Play(seq); + } + } - return NULL; } //////////////////////////////////////////////////////////////////////////////////// @@ -1083,7 +1218,7 @@ amis::AudioNode* audio = pair->getAudio(); if (!Preferences::Instance()->getUseTTSNotAudio() && audio != NULL && audio->getSrc().length() != 0) { - seq->append(audio); + seq->append(audio->clone()); } else { @@ -1114,7 +1249,7 @@ amis::AudioNode* audio = pair->getAudio(); if (!Preferences::Instance()->getUseTTSNotAudio() && audio != NULL && audio->getSrc().length() != 0) { - seq->append(audio); + seq->append(audio->clone()); } else { @@ -1138,7 +1273,7 @@ amis::AudioNode* audio = pair->getAudio(); if (!Preferences::Instance()->getUseTTSNotAudio() && audio != NULL && audio->getSrc().length() != 0) { - seq->append(audio); + seq->append(audio->clone()); } else { @@ -1165,7 +1300,7 @@ amis::AudioNode* audio = pair->getAudio(); if (!Preferences::Instance()->getUseTTSNotAudio() && audio != NULL && audio->getSrc().length() != 0) { - seq->append(audio); + seq->append(audio->clone()); } else { Modified: branches/amis3/AmisGuiMFC2/src/gui/self-voicing/PreTranslateMessageHandler.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/self-voicing/PreTranslateMessageHandler.cpp 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/src/gui/self-voicing/PreTranslateMessageHandler.cpp 2008-03-05 04:09:10 UTC (rev 2390) @@ -1,5 +1,7 @@ #include "gui/self-voicing/pretranslatemessagehandler.h" + +#include "../../AmisGuiMFC2/resource.h" //#include "gui/AmisApp.h" PreTranslateMessageHandler::PreTranslateMessageHandler(int idUiDialog) @@ -7,7 +9,6 @@ m_instructionsDialogID = idUiDialog; mbKeyControl = false; mLastKeyDown = -1; - mSeq = NULL; } PreTranslateMessageHandler::~PreTranslateMessageHandler(void) @@ -20,230 +21,223 @@ CString PreTranslateMessageHandler::normalizeTextEntry(CString str, int nStartChar, int nEndChar) { - CString strNew = str; - if (nStartChar == nEndChar && nStartChar != -1) { - if (nStartChar >= str.GetLength()) { - //str = L""; - } else { - strNew = str.Mid(nStartChar, 1); - } - } else if (nStartChar != -1 && nEndChar != -1) { - strNew = str.Mid(nStartChar, nEndChar-nStartChar); - } - return strNew; + CString strNew = str; + if (nStartChar == nEndChar && nStartChar != -1) { + if (nStartChar >= str.GetLength()) { + //str = L""; + } else { + strNew = str.Mid(nStartChar, 1); + } + } else if (nStartChar != -1 && nEndChar != -1) { + strNew = str.Mid(nStartChar, nEndChar-nStartChar); + } + return strNew; } CString PreTranslateMessageHandler::convertKeystrokeToSpeakableString(WPARAM ch, bool ignoreSpaceKey, bool ignoreArrowKeys, bool ignoreCharKeys) { - - CString cstr; - if (!ignoreCharKeys) - { - switch (ch) - { - case 0x08: - - // Process a backspace. - - break; - - case 0x0A: - - // Process a linefeed. - - break; - - case 0x1B: - - // Process an escape. - - break; - - case 0x09: - - // Process a tab. - - break; - - case 0x0D: - - // Process a carriage return. - - break; - - default: - - // Process displayable characters. - - //echo keystrokes - cstr.AppendChar(ch); - /*if (cstr == L".") { - cstr = L"dot"; - } else if (cstr == L"-") { - cstr = L"minus"; - } else if (!ignoreSpaceKey && cstr == L" ") { - cstr = L"space"; - }*/ - } - } - return cstr; + if (!ignoreCharKeys) + { + switch (ch) + { + case 0x08: + + // Process a backspace. + + break; + + case 0x0A: + + // Process a linefeed. + + break; + + case 0x1B: + + // Process an escape. + + break; + + case 0x09: + + // Process a tab. + + break; + + case 0x0D: + + // Process a carriage return. + + break; + + default: + + // Process displayable characters. + + //echo keystrokes + return CString((char)ch); + /*if (cstr == L".") { + cstr = L"dot"; + } else if (cstr == L"-") { + cstr = L"minus"; + } else if (!ignoreSpaceKey && cstr == L" ") { + cstr = L"space"; + }*/ + } + } + return L""; } CString PreTranslateMessageHandler::convertKeystrokeToSpeakableString(MSG* pMsg, bool ignoreSpaceKey, bool ignoreArrowKeys, bool ignoreCharKeys) { - - CString cstr; - WPARAM ch = pMsg->wParam; /*if (pMsg->message == WM_CHAR) { - cstr = convertKeystrokeToSpeakableString(ch, ignoreSpaceKey, ignoreArrowKeys, ignoreCharKeys); + cstr = convertKeystrokeToSpeakableString(ch, ignoreSpaceKey, ignoreArrowKeys, ignoreCharKeys); } else*/ if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP) { - if (ch == VK_BACK) - { - cstr = L"backspace"; - } else if (ch == VK_CONTROL) - { - cstr = L"control"; - } else if (ch == VK_SHIFT) - { - cstr = L"shift"; - } else if (ch == VK_LEFT) - { - if (!ignoreArrowKeys) cstr = L"left"; - } else if (ch == VK_UP) - { - if (!ignoreArrowKeys) cstr = L"up"; - } else if (ch == VK_RIGHT) - { - if (!ignoreArrowKeys) cstr = L"right"; - } else if (ch == VK_DOWN) - { - if (!ignoreArrowKeys) cstr = L"down"; - } else if (ch == VK_ESCAPE) - { - cstr = L"escape"; - } else if (ch == VK_HOME) - { - if (!ignoreArrowKeys) cstr = L"home"; - } else if (ch == VK_END) - { - if (!ignoreArrowKeys) cstr = L"end"; - } else if (ch == VK_RETURN) - { - cstr = L"return"; - } - else if (ch == VK_TAB) - { - cstr = L"tab"; - } - else if (ch == VK_SPACE) - { - if (!ignoreSpaceKey) cstr = L"space"; - } - else if (ch == VK_DELETE) - { - cstr = L"delete"; - } - else if (ch == VK_F1) - { - cstr = L"f one"; - } - else if (ch == VK_F2) - { - cstr = L"f two"; - } - else if (ch == VK_F3) - { - cstr = L"f three"; - } - else if (ch == VK_F4) - { - cstr = L"f four"; - } - else if (ch == VK_F5) - { - cstr = L"f five"; - } - else if (ch == VK_F6) - { - cstr = L"f six"; - } - else if (ch == VK_F7) - { - cstr = L"f seven"; - } - else if (ch == VK_F8) - { - cstr = L"f eight"; - } - else if (ch == VK_F9) - { - cstr = L"f nine"; - } - else if (ch == VK_F10) - { - cstr = L"f ten"; - } - else if (ch == VK_F11) - { - cstr = L"f eleven"; - } - else if (ch == VK_F12) - { - cstr = L"f twelve"; - } else { - cstr = convertKeystrokeToSpeakableString(ch, ignoreSpaceKey, ignoreArrowKeys, ignoreCharKeys); - } + if (ch == VK_BACK) + { + return L"backspace"; + } else if (ch == VK_CONTROL) + { + return L"control"; + } else if (ch == VK_SHIFT) + { + return L"shift"; + } else if (ch == VK_LEFT) + { + if (!ignoreArrowKeys) return L"left"; + } else if (ch == VK_UP) + { + if (!ignoreArrowKeys) return L"up"; + } else if (ch == VK_RIGHT) + { + if (!ignoreArrowKeys) return L"right"; + } else if (ch == VK_DOWN) + { + if (!ignoreArrowKeys) return L"down"; + } else if (ch == VK_ESCAPE) + { + return L"escape"; + } else if (ch == VK_HOME) + { + if (!ignoreArrowKeys) return L"home"; + } else if (ch == VK_END) + { + if (!ignoreArrowKeys) return L"end"; + } else if (ch == VK_RETURN) + { + return L"return"; + } + else if (ch == VK_TAB) + { + return L"tab"; + } + else if (ch == VK_SPACE) + { + if (!ignoreSpaceKey) return L"space"; + } + else if (ch == VK_DELETE) + { + return L"delete"; + } + else if (ch == VK_F1) + { + return L"f one"; + } + else if (ch == VK_F2) + { + return L"f two"; + } + else if (ch == VK_F3) + { + return L"f three"; + } + else if (ch == VK_F4) + { + return L"f four"; + } + else if (ch == VK_F5) + { + return L"f five"; + } + else if (ch == VK_F6) + { + return L"f six"; + } + else if (ch == VK_F7) + { + return L"f seven"; + } + else if (ch == VK_F8) + { + return L"f eight"; + } + else if (ch == VK_F9) + { + return L"f nine"; + } + else if (ch == VK_F10) + { + return L"f ten"; + } + else if (ch == VK_F11) + { + return L"f eleven"; + } + else if (ch == VK_F12) + { + return L"f twelve"; + } else { + return convertKeystrokeToSpeakableString(ch, ignoreSpaceKey, ignoreArrowKeys, ignoreCharKeys); + } } - return cstr; + return L""; } -AudioSequence* PreTranslateMessageHandler::handle(bool playNow, AudioSequence* seq, MSG* pMsg, int idUiFocus, bool ignoreSpaceKey, bool ignoreArrowKeys, CString strTextField, CString strTextFieldFULL, bool ignoreCharKeys) { -//NOTE: playNow usually true and seq usually NULL +void PreTranslateMessageHandler::handleCommand(WPARAM cmdid) { + if (SELF_VOICING_PLAY_NEXT == cmdid) { + AudioSequencePlayer::Instance()->playNext(true); + } +} +void PreTranslateMessageHandler::handle(MSG* pMsg, int idUiFocus, bool ignoreSpaceKey, bool ignoreArrowKeys, CString strTextField, CString strTextFieldFULL, bool ignoreCharKeys) { if (pMsg->message == WM_KEYDOWN) { if (mLastKeyDown == pMsg->wParam) { //Prevents repeat - if (seq == NULL) { - seq = new AudioSequence(); - } - return seq; + return; } mLastKeyDown = pMsg->wParam; - TRACE(L"PreTranslateMessageHandler::handle KEY DOWN"); - if (seq == NULL) { - if (mSeq == NULL) { - seq = new AudioSequence(); - mSeq = seq; - } else { - seq = mSeq; - } - } if (pMsg->wParam == VK_CONTROL) { mbKeyControl = true; } - - CString cstr = convertKeystrokeToSpeakableString(pMsg, ignoreSpaceKey, ignoreArrowKeys, ignoreCharKeys); - + + /* + CString cstr = convertKeystrokeToSpeakableString(pMsg, ignoreSpaceKey, ignoreArrowKeys, ignoreCharKeys); + if (!cstr.IsEmpty()) { - + TRACE(cstr); - seq->append(cstr); - if (playNow) { - //mSeq = NULL; - //AudioSequencePlayer::Instance()->Play(seq, true); - } + if (mSeq == NULL) { + mSeq = new AudioSequence(); + mSeq->append(cstr); } + */ + return; + + //mSeq = NULL; + //AudioSequencePlayer::Instance()->Play(seq, true); + + } else if (pMsg->message == WM_KEYUP) { @@ -252,158 +246,131 @@ mLastKeyDown = -1; wasSameKey = true; } - if (pMsg->wParam == VK_CONTROL) { - if (mSeq != NULL) { - delete mSeq; - mSeq = NULL; - } if (mbKeyControl && wasSameKey) { //if (seq != NULL && !(seq->IsEmpty()) && playNow) AudioSequencePlayer::Instance()->Play(seq, true); //else AudioSequencePlayer::Instance()->Stop(); AudioSequencePlayer::Instance()->Stop(); } mbKeyControl = false; + return; } else if(pMsg->wParam == 'I' && mbKeyControl == true) { - if (mSeq != NULL) { - delete mSeq; - mSeq = NULL; - } - if (seq == NULL) { - seq = new AudioSequence(); - } - mbKeyControl = false; //repeat the instructions - AudioSequencePlayer::Instance()->playDialogInstructionsFromUiId(m_instructionsDialogID, playNow, seq); + AudioSequencePlayer::Instance()->playDialogInstructionsFromUiId(m_instructionsDialogID); + return; } else if(pMsg->wParam == 'R' && mbKeyControl == true) { - if (mSeq != NULL) { - delete mSeq; - mSeq = NULL; - } mbKeyControl = false; AudioSequencePlayer::Instance()->RepeatLast(); + return; } else if(pMsg->wParam == 'T' && mbKeyControl == true && !strTextFieldFULL.IsEmpty()) { - if (mSeq != NULL) { - delete mSeq; - mSeq = NULL; + AudioSequence * mSeq = new AudioSequence(); + + mbKeyControl = false; + if (strTextFieldFULL.GetLength() == 1) { + strTextFieldFULL = convertKeystrokeToSpeakableString(strTextFieldFULL.GetAt(0)); } - if (seq == NULL) { - seq = new AudioSequence(); - } - mbKeyControl = false; - if (strTextFieldFULL.GetLength() == 1) { - strTextFieldFULL = convertKeystrokeToSpeakableString(strTextFieldFULL.GetAt(0)); - } - seq->append(strTextFieldFULL); - if (playNow) AudioSequencePlayer::Instance()->Play(seq); + mSeq->append(strTextFieldFULL); + AudioSequencePlayer::Instance()->Play(mSeq); + return; } else { - - if (seq == NULL) { - if (mSeq == NULL) { - seq = new AudioSequence(); - //mSeq = seq; - } else { - seq = mSeq; - mSeq = NULL; - } - } else { - if (mSeq != NULL) { - delete mSeq; - mSeq = NULL; - } - } - - if (pMsg->wParam == VK_TAB || (!ignoreArrowKeys && (pMsg->wParam == VK_HOME || pMsg->wParam == VK_END || pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN || pMsg->wParam == VK_LEFT || pMsg->wParam == VK_RIGHT))) - { - /* - if (pMsg->wParam == VK_TAB) { - seq->append(L"tab"); - } else if (pMsg->wParam == VK_UP) { - seq->append(L"up"); - } else if (pMsg->wParam == VK_DOWN) { - seq->append(L"down"); - } else if (pMsg->wParam == VK_LEFT) { - seq->append(L"left"); - } else if (pMsg->wParam == VK_RIGHT) { - seq->append(L"right"); - } - */ - if (idUiFocus == IDOK) + if (pMsg->wParam == VK_TAB || (!ignoreArrowKeys && (pMsg->wParam == VK_HOME || pMsg->wParam == VK_END || pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN || pMsg->wParam == VK_LEFT || pMsg->wParam == VK_RIGHT))) { - AudioSequencePlayer::Instance()->playDialogControlFromUiIds(m_instructionsDialogID, IDOK, playNow, seq); - } - else if (idUiFocus == IDCANCEL) - { - AudioSequencePlayer::Instance()->playDialogControlFromUiIds(m_instructionsDialogID, IDCANCEL, playNow, seq); - } else if (idUiFocus >= 0) { + if (idUiFocus == IDOK) + { + AudioSequencePlayer::Instance()->playDialogControlFromUiIds(m_instructionsDialogID, IDOK); + return; + } + else if (idUiFocus == IDCANCEL) + { + AudioSequencePlayer::Instance()->playDialogControlFromUiIds(m_instructionsDialogID, IDCANCEL); + return; + + } else if (idUiFocus >= 0) { + + /* + AudioSequence * mSeq = new AudioSequence(); + if (! strTextField.IsEmpty()) { + if (strTextField.GetLength() == 1) { + strTextField = convertKeystrokeToSpeakableString(strTextField.GetAt(0)); + } + mSeq->append(strTextField); + //if (playNow) AudioSequencePlayer::Instance()->Play(seq); + }*/ + AudioSequencePlayer::Instance()->playDialogControlFromUiIds(m_instructionsDialogID, idUiFocus); + return; + } + + } else { + + AudioSequence * mSeq = new AudioSequence(); + if (! strTextField.IsEmpty()) { if (strTextField.GetLength() == 1) { strTextField = convertKeystrokeToSpeakableString(strTextField.GetAt(0)); } - seq->append(strTextField); + mSeq->append(strTextField); //if (playNow) AudioSequencePlayer::Instance()->Play(seq); } - AudioSequencePlayer::Instance()->playDialogControlFromUiIds(m_instructionsDialogID, idUiFocus, playNow, seq); - } - } else { - if (! strTextField.IsEmpty()) { - if (strTextField.GetLength() == 1) { - strTextField = convertKeystrokeToSpeakableString(strTextField.GetAt(0)); + if (!(mSeq->IsEmpty()) && wasSameKey) { + AudioSequencePlayer::Instance()->Play(mSeq, true); + + return; + } else { + delete mSeq; } - seq->append(strTextField); - //if (playNow) AudioSequencePlayer::Instance()->Play(seq); } - if (seq != NULL && !(seq->IsEmpty()) && playNow && wasSameKey) { - AudioSequencePlayer::Instance()->Play(seq, true); - } } - } } //bool doProcessKeyFeedback = processGeneralDialogFeedback(playNow, seq ,pMsg, idUiFocus, ignoreSpaceKey, ignoreArrowKeys, strTextField); //if (doProcessKeyFeedback) processGeneralKeyPressFeedback(playNow, seq, pMsg, ignoreSpaceKey, ignoreArrowKeys); - return seq; + /* + if (mSeq != NULL && mSeq->GetCount() == 0) + delete mSeq; + mSeq=NULL; + } + */ } /* bool PreTranslateMessageHandler::processGeneralDialogFeedback(bool playNow, AudioSequence* seq, MSG* pMsg, int idUiFocus, bool ignoreSpaceKey, bool ignoreArrowKeys, CString strTextField) { - - if (seq == NULL) { - seq = new AudioSequence(); - } - if (pMsg->message == WM_KEYDOWN) - { - } - else if (pMsg->message == WM_KEYUP) - { +if (seq == NULL) { +seq = new AudioSequence(); +} - } +if (pMsg->message == WM_KEYDOWN) +{ +} +else if (pMsg->message == WM_KEYUP) +{ - return true; } +return true; +} + void PreTranslateMessageHandler::processGeneralKeyPressFeedback(bool playNow, AudioSequence* seq, MSG* pMsg, bool ignoreSpaceKey, bool ignoreArrowKeys) { - - if (seq == NULL) { - seq = new AudioSequence(); - } - if (pMsg->message == WM_KEYDOWN) - { - } + +if (seq == NULL) { +seq = new AudioSequence(); } +if (pMsg->message == WM_KEYDOWN) +{ +} +} */ \ No newline at end of file Modified: branches/amis3/AmisGuiMFC2/src/gui/self-voicing/dialogs/MenuVoicing.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/self-voicing/dialogs/MenuVoicing.cpp 2008-03-05 00:00:57 UTC (rev 2389) +++ branches/amis3/AmisGuiMFC2/src/gui/self-voicing/dialogs/MenuVoicing.cpp 2008-03-05 04:09:10 UTC (rev 2390) @@ -84,8 +84,10 @@ if (!str_id.empty()) { if (playPrompt) { - AudioSequence* seq = AudioSequencePlayer::playContainerPromptFromId(str_id, false); + AudioSequence* seq = new AudioSequence(); + AudioSequencePlayer::fillSequenceContainerPromptFromId(seq, str_id); + PromptItem* p_prompt_ = DataTree::Instance()->findPromptItem("menu"); if (p_prompt_ != NULL) @@ -96,13 +98,32 @@ seq->append(_T("menu")); } - AudioSequencePlayer::Instance()->Play(seq); + if (seq->GetCount() == 0) { + delete seq; + } else { + AudioSequencePlayer::Instance()->Play(seq); + } } } return str_id; } + AudioSequence* MenuVoicing::createSeqPrepend(UINT nFlags) { + + AudioSequence* seq = new AudioSequence(); + + if ( nFlags & MF_GRAYED ) + { + PromptItem* promptNotAvailable = DataTree::Instance()->findPromptItem("not_available"); + if (promptNotAvailable != NULL) + { + + AudioSequencePlayer::fillSequenceContents(seq, promptNotAvailable); + } + } + return seq; + } void MenuVoicing::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu) { @@ -167,11 +188,6 @@ } - if (nItemID) { - // - - CString s; - } //don't read separators if (nFlags & MF_SEPARATOR) { @@ -183,18 +199,6 @@ string prompt; - AudioSequence* seq = NULL; - seq = new AudioSequence(); - - if ( nFlags & MF_GRAYED ) - { - PromptItem* promptNotAvailable = DataTree::Instance()->findPromptItem("not_available"); - if (promptNotAvailable != NULL) - { - - AudioSequencePlayer::fillSequenceContents(seq, promptNotAvailable); - } - } if ( nFlags & MF_POPUP ) { if ( nFlags & MF_BYPOSITION ) @@ -215,8 +219,11 @@ TRACE(s); TRACE(prompt.c_str()); + + AudioSequence* seq = createSeqPrepend(nFlags); + if (prompt.compare("file") == 0 || prompt.compare("recentBooksList") == 0) { - seq = AudioSequencePlayer::playContainerPromptFromId("recentBooksList", false, seq); + AudioSequencePlayer::fillSequenceContainerPromptFromId(seq, "recentBooksList"); PromptItem* p_prompt_ = DataTree::Instance()->findPromptItem("menu"); @@ -228,10 +235,16 @@ seq->append(_T("menu")); } - AudioSequencePlayer::Instance()->Play(seq); + if (seq->GetCount() == 0) { + delete seq; + } else { + AudioSequencePlayer::Instance()->Play(seq); + } + return; } else if (prompt.compare("navigate") == 0 || prompt.compare("sectiondepth") == 0) { - seq = AudioSequencePlayer::playContainerPromptFromId("sectiondepth", false, seq); + AudioSequencePlayer::fillSequenceContainerPromptFromId(seq, "sectiondepth"); + PromptItem* p_prompt_ = DataTree::Instance()->findPromptItem("menu"); if (p_prompt_ != NULL) @@ -241,9 +254,15 @@ else { seq->append(_T("menu")); } - AudioSequencePlayer::Instance()->Play(seq); + + if (seq->GetCount() == 0) { + delete seq; + } else { + AudioSequencePlayer::Instance()->Play(seq); + } + return; } else { - int i = 0; // NOP, for breakpoint + delete seq; } } else if ((nItemID >=0 && nItemID <=6) && (mFrm->m_lastOpenPopupMenu == NULL)) { //TODO: Yuuk ! UGLY ! This is only a temporary workaround ! //(nFlags & MF_GRAYED) @@ -251,27 +270,29 @@ TRACE(s); + AudioSequence* seq = createSeqPrepend(nFlags); + switch (nItemID) { case 0: - seq = AudioSequencePlayer::playContainerPromptFromId("file", false, seq); + AudioSequencePlayer::fillSequenceContainerPromptFromId(seq, "file"); break; case 1: - seq = AudioSequencePlayer::playContainerPromptFromId("view", false, seq); + AudioSequencePlayer::fillSequenceContainerPromptFromId(seq, "view"); break; case 2: - seq = AudioSequencePlayer::playContainerPromptFromId("play", false, seq); + AudioSequencePlayer::fillSequenceContainerPromptFromId(seq, "play"); break; case 3: - seq = AudioSequencePlayer::playContainerPromptFromId("navigate", false, seq); + AudioSequencePlayer::fillSequenceContainerPromptFromId(seq, "navigate"); break; case 4: - seq = AudioSequencePlayer::playContainerPromptFromId("bookmarks", false, seq); + AudioSequencePlayer::fillSequenceContainerPromptFromId(seq, "bookmarks"); break; case 5: - seq = AudioSequencePlayer::playContainerPromptFromId("info", false, seq); + AudioSequencePlayer::fillSequenceContainerPromptFromId(seq, "info"); break; case 6: - seq = AudioSequencePlayer::playContainerPromptFromId("help", false, seq); + AudioSequencePlayer::fillSequenceContainerPromptFromId(seq, "help"); break; //default: seq = new AudioSequence(); } @@ -282,14 +303,17 @@ AudioSequencePlayer::fillSequenceContents(seq, p_prompt_); } else { - if (seq != NULL) { - seq->append(_T("menu")); - } + seq->append(_T("menu")); + } - if (seq != NULL) { + if (seq->GetCount() == 0) { + delete seq; + } else { AudioSequencePlayer::Instance()->Play(seq); } + return; + } } else @@ -310,9 +334,15 @@ //DanTodo: surely, there must be a way to get a title instead of rendering the URL with TTS ??! (see bookmark methd commented below) string str = p_entry->mPath.get_url(); + + AudioSequence* seq = createSeqPrepend(nFlags); + seq->append(A2T(str.c_str())); + AudioSequencePlayer::Instance()->Play(seq); + return; + //CString cstr_f... [truncated message content] |