📄 chsound.cpp
字号:
return devSpeech;
}
#endif // defined( CH_USE_VOXWARE )
return devAll;
}
chflag32 ChSoundMainInfo::ParseEvents( const string& strEvents )
{
chflag32 flOptions = 0;
string strWorking( strEvents );
if (!strEvents.IsEmpty())
{
int iOptionsCount = sizeof( soundEventsList ) /
sizeof( OptionsNameType );
char* pstrCopy;
char* pstrToken;
strWorking.MakeLower();
pstrCopy = new char[strWorking.GetLength() + 2];
strcpy( pstrCopy, strWorking );
pstrToken = strtok( pstrCopy, SOUND_HTML_DELIM );
while (pstrToken)
{
bool boolFound = false;
int iLoop;
string strTok( pstrToken );
for (iLoop = 0; (iLoop < iOptionsCount) && !boolFound;
iLoop++)
{
if (strTok == soundEventsList[iLoop].pstrName)
{
flOptions |= soundEventsList[iLoop].flOption;
boolFound = true;
}
}
pstrToken = strtok( 0, SOUND_HTML_DELIM );
}
delete [] pstrCopy;
}
return flOptions;
}
chflag32 ChSoundMainInfo::ParseOptions( const string& strOptions )
{
chflag32 flOptions = 0;
string strWorking( strOptions );
if (!strOptions.IsEmpty())
{
int iOptionsCount = sizeof( soundOptionsList ) /
sizeof( OptionsNameType );
char* pstrCopy;
char* pstrToken;
strWorking.MakeLower();
pstrCopy = new char[strWorking.GetLength() + 2];
strcpy( pstrCopy, strWorking );
pstrToken = strtok( pstrCopy, SOUND_HTML_DELIM );
while (pstrToken)
{
bool boolFound = false;
int iLoop;
string strTok( pstrToken );
for (iLoop = 0; (iLoop < iOptionsCount) && !boolFound;
iLoop++)
{
if (strTok == soundOptionsList[iLoop].pstrName)
{
flOptions |= soundOptionsList[iLoop].flOption;
boolFound = true;
}
}
pstrToken = strtok( 0, SOUND_HTML_DELIM );
}
delete [] pstrCopy;
}
return flOptions;
}
chflag32 ChSoundMainInfo::ParseSpeechOptions( const string& strOptions )
{
chflag32 flOptions = 0;
string strWorking( strOptions );
if (!strOptions.IsEmpty())
{
int iOptionsCount = sizeof( speechOptionsList ) /
sizeof( OptionsNameType );
char* pstrCopy;
char* pstrToken;
strWorking.MakeLower();
pstrCopy = new char[strWorking.GetLength() + 2];
strcpy( pstrCopy, strWorking );
pstrToken = strtok( pstrCopy, SOUND_HTML_DELIM );
while (pstrToken)
{
bool boolFound = false;
int iLoop;
string strTok( pstrToken );
for (iLoop = 0; (iLoop < iOptionsCount) && !boolFound;
iLoop++)
{
if (strTok == speechOptionsList[iLoop].pstrName)
{
flOptions |= speechOptionsList[iLoop].flOption;
boolFound = true;
}
}
pstrToken = strtok( 0, SOUND_HTML_DELIM );
}
delete [] pstrCopy;
}
return flOptions;
}
/*----------------------------------------------------------------------------
Chaco module library entry point
----------------------------------------------------------------------------*/
#if defined( CH_MSW ) && defined( CH_ARCH_16 )
CH_EXTERN_LIBRARY( void )
InitChSoundDLL();
#endif
#ifdef __linux__
CH_IMPLEMENT_MAIN_HANDLER( ChMainEntryMidi )
#else
#if defined( CH_PUEBLO_PLUGIN )
STDAPI_(int)
ChMainEntrySound( ChMsg &msg, ChCore *pCore, ChMainInfo *pMainInfo,
ChModuleID idModule, const string *pstrModule,
ChArgumentList *pArgList )
#else
ChMain
#endif
#endif
{
chparam retVal = 0;
switch( msg.GetMessage() )
{
case CH_MSG_INIT:
{
ChInitMsg *pMsg = (ChInitMsg *)&msg;
string strLoadParam;
ChModuleID idServerModule;
#if defined( CH_MSW ) && defined( CH_ARCH_16 )
{
// Initialize MFC
InitChSoundDLL();
}
#endif // defined( CH_MSW ) && defined( CH_ARCH_16 )
pMsg->GetParams( idModule, strLoadParam, idServerModule );
if (*pstrModule == CH_MODULE_SOUND)
{
ChSoundMainInfo *pMainInfo;
pMainInfo = new ChSoundMainInfo( idModule, pCore, strLoadParam );
retVal = (chparam)pMainInfo;
}
break;
}
case CH_MSG_TERM:
{
delete pMainInfo;
break;
}
}
return retVal;
}
/*----------------------------------------------------------------------------
Chaco message handlers
----------------------------------------------------------------------------*/
CH_IMPLEMENT_MESSAGE_HANDLER( defSoundHandler )
{
chparam retVal = 0;
return retVal;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundInitHandler )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
pInfo->Initialize();
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundLoadCompleteHandler )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
ChLoadCompleteMsg* pMsg = (ChLoadCompleteMsg*)&msg;
string strModuleName;
ChModuleID idModule;
string strFilename;
chparam userData;
pMsg->GetParams( strModuleName, idModule, strFilename, userData );
if (0 == idModule)
{
ChSoundInfo* pSoundInfo;
int iMimeType;
pSoundInfo = (ChSoundInfo*)userData;
ASSERT( pSoundInfo );
iMimeType = ChHTTPConn::GetMimeType( pMsg->GetType() );
pInfo->HandleSoundFile( strFilename, iMimeType, pSoundInfo );
delete pSoundInfo;
}
else
{ // Module load complete...
if (CH_MODULE_WORLD == strModuleName)
{
pInfo->SetWorldID( idModule );
}
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundShowModuleHandler )
{
ChShowModuleMsg* pMsg = (ChShowModuleMsg*)&msg;
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
pInfo->ShowModule( pMsg->IsShowing() );
return 0;
}
#if !defined( CH_PUEBLO_PLUGIN )
CH_IMPLEMENT_MESSAGE_HANDLER( soundGetPageCountHandler )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
ChGetPageCountMsg* pMsg = (ChGetPageCountMsg*)&msg;
ChPageType type;
int iPageCount;
pMsg->GetParams( type );
if (pInfo->IsShown())
{
switch( type )
{
case pagePreferences:
{
#if defined( CH_USE_VOXWARE )
{
iPageCount = 2;
}
#else // defined( CH_USE_VOXWARE )
{
iPageCount = 1;
}
#endif // defined( CH_USE_VOXWARE )
break;
}
default:
{
iPageCount = 0;
break;
}
}
}
else
{
iPageCount = 0;
}
return iPageCount;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundGetPagesHandler )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
ChGetPagesMsg* pMsg = (ChGetPagesMsg*)&msg;
ChPageType type;
chint16 sCount;
chparam* pPages;
pMsg->GetParams( type, sCount, pPages );
switch( type )
{
case pagePreferences:
{
#if defined( CH_USE_VOXWARE )
{
ASSERT( 2 == sCount );
}
#else // defined( CH_USE_VOXWARE )
{
ASSERT( 1 == sCount );
}
#endif // defined( CH_USE_VOXWARE )
#if defined( CH_MSW )
{
ChSoundPrefs* pPage;
pPage = new ChSoundPrefs();
// Set data into dialog
pPage->SetMainInfo( pInfo );
//pPage->SetDeviceFound( pInfo->SoundDeviceFound() );
pPages[0] = (chparam)pPage;
}
#endif
#if defined( CH_USE_VOXWARE )
{
if (pPages[1])
{
ChSpeechPrefs* pPage;
pPage = new ChSpeechPrefs();
// Set data into dialog
pPage->SetMainInfo( pInfo );
pPages[1] = (chparam)pPage;
}
}
#endif // defined( CH_USE_VOXWARE )
break;
}
default:
{
break;
}
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundGetPageDataHandler )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
ChGetPageDataMsg* pMsg = (ChGetPageDataMsg*)&msg;
ChPageType type;
chint16 sCount;
chparam* pPages;
pMsg->GetParams( type, sCount, pPages );
switch( type )
{
case pagePreferences:
{
#if defined( CH_USE_VOXWARE )
{
ASSERT( 2 == sCount );
}
#else // defined( CH_USE_VOXWARE )
{
ASSERT( 1 == sCount );
}
#endif // defined( CH_USE_VOXWARE )
#if defined( CH_MSW )
{
if (pPages[0])
{
ChSoundPrefs* pPage = (ChSoundPrefs*)pPages[0];
pPage->OnCommit();
}
#if defined( CH_USE_VOXWARE )
{
if (pPages[1])
{
ChSpeechPrefs* pPage = (ChSpeechPrefs*)pPages[1];
pPage->OnCommit();
}
}
#endif // defined( CH_USE_VOXWARE )
}
#endif // defined( CH_MSW )
break;
}
default:
{
break;
}
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundReleasePagesHandler )
{
ChReleasePagesMsg* pMsg = (ChReleasePagesMsg*)&msg;
ChPageType type;
chint16 sCount;
chparam* pPages;
pMsg->GetParams( type, sCount, pPages );
switch( type )
{
case pagePreferences:
{
#if defined( CH_USE_VOXWARE )
{
ASSERT( 2 == sCount );
}
#else // defined( CH_USE_VOXWARE )
{
ASSERT( 1 == sCount );
}
#endif // defined( CH_USE_VOXWARE )
#if defined( CH_MSW )
{
if (pPages[0])
{
ChSoundPrefs* pPage = (ChSoundPrefs*)pPages[0];
delete pPage;
}
#if defined( CH_USE_VOXWARE )
{
if (pPages[1])
{
ChSpeechPrefs* pPage = (ChSpeechPrefs*)pPages[1];
delete pPage;
}
}
#endif // defined( CH_USE_VOXWARE )
}
#endif // defined( CH_MSW )
break;
}
default:
{
break;
}
}
return 0;
}
#endif // #if !defined(CH_PUEBLO_PLUGIN )
CH_IMPLEMENT_MESSAGE_HANDLER( soundCommandHandler )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
ChCmdMsg* pMsg = (ChCmdMsg*)&msg;
string strArgs;
pMsg->GetParams( strArgs );
if (!strArgs.IsEmpty())
{
bool boolProcessed;
boolProcessed = pInfo->DoCommand( strArgs, false );
pMsg->SetProcessed( boolProcessed );
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundInlineHandler )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
ChInlineMsg* pMsg = (ChInlineMsg*)&msg;
string strArgs;
pMsg->GetParams( strArgs );
if (!strArgs.IsEmpty())
{
bool boolProcessed;
boolProcessed = pInfo->DoCommand( strArgs, true );
pMsg->SetProcessed( boolProcessed );
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundAlertHandler )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
pInfo->DoAlertCommand();
msg.SetProcessed();
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundMediaPlayHandler )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
ChMediaPlayMsg* pMsg = (ChMediaPlayMsg*)&msg;
string strURL;
bool boolLooping;
pMsg->GetParams( strURL, boolLooping );
pInfo->Play( strURL, boolLooping );
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundMediaStopHandler )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
pInfo->StopAll();
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( soundConnectedHandler )
{
#if defined( CH_USE_VOXWARE )
{
ChSoundMainInfo* pInfo = (ChSoundMainInfo*)pMainInfo;
ChConnectedMsg* pMsg = (ChConnectedMsg*)&msg;
string strPort;
strPort.Format( "%d", (int)pInfo->GetSpeechPort() );
pMsg->AppendPuebloClientParam( TNT_PUEBLOSOUND_PARAM, strPort );
}
#endif // defined( CH_USE_VOXWARE )
return 0;
}
/*----------------------------------------------------------------------------
Utility functions
----------------------------------------------------------------------------*/
CH_GLOBAL_FUNC( string )
GetSysSoundFilesPath()
{
char dir[MAX_PATH + 100];
string strPath;
GetWindowsDirectory( dir, sizeof( dir ) );
strPath = dir;
strPath += "\\";
if (ChCore::GetClientInfo()->GetPlatform() == osWin95)
{
/* Win95 sounds are in the Media
directory */
strPath += "Media\\";
}
return strPath;
}
// Local Variables: ***
// tab-width:4 ***
// End: ***
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -