//========= Copyright Valve Corporation, All rights reserved. ============// // // SHOW_SOUNDS.CPP // // Show Sounds Display. //=====================================================================================// #include "vxconsole.h" #define ID_SHOWSOUNDS_LISTVIEW 100 // column id #define ID_SS_NAME 0 #define ID_SS_PREFIX 1 #define ID_SS_FORMAT 2 #define ID_SS_RATE 3 #define ID_SS_BITS 4 #define ID_SS_CHANNELS 5 #define ID_SS_SIZE 6 #define ID_SS_STREAMED 7 #define ID_SS_LOOPED 8 #define ID_SS_LENGTH 9 typedef struct { int listIndex; char *pName; char *pPrefix; char *pFormat; int rate; char rateBuff[16]; int bits; char bitsBuff[16]; int channels; char channelsBuff[16]; int numSamples; int dataSize; char dataSizeBuff[16]; int streamed; char streamedBuff[16]; int looped; char loopedBuff[16]; float length; char lengthBuff[16]; } sound_t; typedef struct { const CHAR* name; int width; int subItemIndex; CHAR nameBuff[32]; } label_t; HWND g_showSounds_hWnd; HWND g_showSounds_hWndListView; RECT g_showSounds_windowRect; int g_showSounds_sortColumn; int g_showSounds_sortDescending; sound_t *g_showSounds_pSounds; int g_showSounds_numSounds; int g_showSounds_currentFrame; label_t g_showSounds_Labels[] = { {"Name", 300, ID_SS_NAME}, {"Prefix", 80, ID_SS_PREFIX}, {"Format", 80, ID_SS_FORMAT}, {"Rate", 80, ID_SS_RATE}, {"Bits", 80, ID_SS_BITS}, {"Channels", 80, ID_SS_CHANNELS}, {"Size", 80, ID_SS_SIZE}, {"Streamed", 80, ID_SS_STREAMED}, {"Looped", 80, ID_SS_LOOPED}, {"Length", 80, ID_SS_LENGTH}, }; //----------------------------------------------------------------------------- // ShowSounds_SaveConfig // //----------------------------------------------------------------------------- void ShowSounds_SaveConfig() { char buff[256]; Sys_SetRegistryInteger( "showSoundsSortColumn", g_showSounds_sortColumn ); Sys_SetRegistryInteger( "showSoundsSortDescending", g_showSounds_sortDescending ); WINDOWPLACEMENT wp; memset( &wp, 0, sizeof( wp ) ); wp.length = sizeof( WINDOWPLACEMENT ); GetWindowPlacement( g_showSounds_hWnd, &wp ); g_showSounds_windowRect = wp.rcNormalPosition; sprintf( buff, "%d %d %d %d", g_showSounds_windowRect.left, g_showSounds_windowRect.top, g_showSounds_windowRect.right, g_showSounds_windowRect.bottom ); Sys_SetRegistryString( "showSoundsWindowRect", buff ); } //----------------------------------------------------------------------------- // ShowSounds_LoadConfig // //----------------------------------------------------------------------------- void ShowSounds_LoadConfig() { int numArgs; char buff[256]; Sys_GetRegistryInteger( "showSoundsSortColumn", ID_SS_NAME, g_showSounds_sortColumn ); Sys_GetRegistryInteger( "showSoundsSortDescending", false, g_showSounds_sortDescending ); Sys_GetRegistryString( "showSoundsWindowRect", buff, "", sizeof( buff ) ); numArgs = sscanf( buff, "%d %d %d %d", &g_showSounds_windowRect.left, &g_showSounds_windowRect.top, &g_showSounds_windowRect.right, &g_showSounds_windowRect.bottom ); if ( numArgs != 4 || g_showSounds_windowRect.left < 0 || g_showSounds_windowRect.top < 0 || g_showSounds_windowRect.right < 0 || g_showSounds_windowRect.bottom < 0 ) memset( &g_showSounds_windowRect, 0, sizeof( g_showSounds_windowRect ) ); } //----------------------------------------------------------------------------- // ShowSounds_Clear // //----------------------------------------------------------------------------- void ShowSounds_Clear() { // delete all the list view entries if ( g_showSounds_hWnd ) ListView_DeleteAllItems( g_showSounds_hWndListView ); if ( !g_showSounds_pSounds ) return; for ( int i=0; ipPrefix, pSound->pName ); // send the command to application ProcessCommand( command ); } //----------------------------------------------------------------------------- // ShowSounds_CompareFunc // //----------------------------------------------------------------------------- int CALLBACK ShowSounds_CompareFunc( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort ) { sound_t* pSoundA = ( sound_t* )lParam1; sound_t* pSoundB = ( sound_t* )lParam2; int sort = 0; switch ( g_showSounds_sortColumn ) { case ID_SS_NAME: sort = stricmp( pSoundA->pName, pSoundB->pName ); break; case ID_SS_PREFIX: sort = stricmp( pSoundA->pPrefix, pSoundB->pPrefix ); break; case ID_SS_FORMAT: sort = stricmp( pSoundA->pFormat, pSoundB->pFormat ); break; case ID_SS_RATE: sort = pSoundA->rate - pSoundB->rate; break; case ID_SS_BITS: sort = pSoundA->bits - pSoundB->bits; break; case ID_SS_CHANNELS: sort = stricmp( pSoundA->channelsBuff, pSoundB->channelsBuff ); break; case ID_SS_SIZE: sort = pSoundA->dataSize - pSoundB->dataSize; break; case ID_SS_STREAMED: sort = stricmp( pSoundA->streamedBuff, pSoundB->streamedBuff ); break; case ID_SS_LOOPED: sort = stricmp( pSoundA->loopedBuff, pSoundB->loopedBuff ); break; case ID_SS_LENGTH: if ( pSoundA->length < pSoundB->length ) sort = -1; else if ( pSoundA->length == pSoundB->length ) sort = 0; else sort = 1; break; } // flip the sort order if ( g_showSounds_sortDescending ) sort *= -1; return ( sort ); } //----------------------------------------------------------------------------- // ShowSounds_SortItems // //----------------------------------------------------------------------------- void ShowSounds_SortItems() { LVITEM lvitem; sound_t *pSound; int i; if ( !g_showSounds_hWnd ) { // only sort if window is visible return; } ListView_SortItems( g_showSounds_hWndListView, ShowSounds_CompareFunc, 0 ); memset( &lvitem, 0, sizeof( lvitem ) ); lvitem.mask = LVIF_PARAM; // get each item and reset its list index int itemCount = ListView_GetItemCount( g_showSounds_hWndListView ); for ( i=0; ilistIndex = i; } // update list view columns with sort key for ( i=0; i'; else symbol = ' '; sprintf( g_showSounds_Labels[i].nameBuff, "%s %c", g_showSounds_Labels[i].name, symbol ); memset( &lvc, 0, sizeof( lvc ) ); lvc.mask = LVCF_TEXT; lvc.pszText = ( LPSTR )g_showSounds_Labels[i].nameBuff; ListView_SetColumn( g_showSounds_hWndListView, i, &lvc ); } } //----------------------------------------------------------------------------- // ShowSounds_AddViewItem // //----------------------------------------------------------------------------- void ShowSounds_AddViewItem( sound_t* pSound ) { LVITEM lvi; if ( !g_showSounds_hWnd ) { // only valid if log window is visible return; } // update the text callback buffers if ( pSound->rate >= 0 ) sprintf( pSound->rateBuff, "%5.2f KHz", ( float )pSound->rate/1000.0f ); else strcpy( pSound->rateBuff, "???" ); if ( pSound->bits >= 0 ) sprintf( pSound->bitsBuff, "%d", pSound->bits ); else strcpy( pSound->bitsBuff, "???" ); if ( pSound->channels >= 1 ) strcpy( pSound->channelsBuff, pSound->channels == 2 ? "Stereo" : "Mono" ); else strcpy( pSound->channelsBuff, "???" ); if ( pSound->dataSize >= 0 ) sprintf( pSound->dataSizeBuff, "%d", pSound->dataSize ); else strcpy( pSound->dataSizeBuff, "???" ); if ( pSound->streamed >= 0 ) strcpy( pSound->streamedBuff, pSound->streamed ? "Stream" : "Static" ); else strcpy( pSound->streamedBuff, "???" ); if ( pSound->looped >= 0 ) strcpy( pSound->loopedBuff, pSound->looped ? "Looped" : "One-Shot" ); else strcpy( pSound->loopedBuff, "???" ); sprintf( pSound->lengthBuff, "%2.2d:%2.2d:%3.3d", ( int )pSound->length/60, ( int )pSound->length%60, ( int )( 1000*( pSound->length-( int )pSound->length ) )%1000 ); int itemCount = ListView_GetItemCount( g_showSounds_hWndListView ); // setup and insert at end of list memset( &lvi, 0, sizeof( lvi ) ); lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE; lvi.iItem = itemCount; lvi.iSubItem = 0; lvi.state = 0; lvi.stateMask = 0; lvi.pszText = LPSTR_TEXTCALLBACK; lvi.lParam = ( LPARAM )pSound; // insert and set the real index pSound->listIndex = ListView_InsertItem( g_showSounds_hWndListView, &lvi ); } //----------------------------------------------------------------------------- // ShowSounds_Refresh // //----------------------------------------------------------------------------- void ShowSounds_Refresh() { char command[256]; strcpy( command, "vx_soundlist" ); // send the command to application which replies with list data if ( g_connectedToApp ) ProcessCommand( command ); } //----------------------------------------------------------------------------- // ShowSounds_SizeWindow // //----------------------------------------------------------------------------- void ShowSounds_SizeWindow( HWND hwnd, int cx, int cy ) { if ( cx==0 || cy==0 ) { RECT rcClient; GetClientRect( hwnd, &rcClient ); cx = rcClient.right; cy = rcClient.bottom; } // position the ListView SetWindowPos( g_showSounds_hWndListView, NULL, 0, 0, cx, cy, SWP_NOZORDER ); } //----------------------------------------------------------------------------- // ShowSounds_WndProc // //----------------------------------------------------------------------------- LRESULT CALLBACK ShowSounds_WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { WORD wID = LOWORD( wParam ); sound_t* pSound; switch ( message ) { case WM_CREATE: return 0L; case WM_DESTROY: ShowSounds_SaveConfig(); g_showSounds_hWnd = NULL; return 0L; case WM_INITMENU: return 0L; case WM_SIZE: ShowSounds_SizeWindow( hwnd, LOWORD( lParam ), HIWORD( lParam ) ); return 0L; case WM_NOTIFY: switch ( ( ( LPNMHDR )lParam )->code ) { case LVN_COLUMNCLICK: NMLISTVIEW* pnmlv; pnmlv = ( NMLISTVIEW* )lParam; if ( g_showSounds_sortColumn == pnmlv->iSubItem ) { // user has clicked on same column - flip the sort g_showSounds_sortDescending ^= 1; } else { // sort by new column g_showSounds_sortColumn = pnmlv->iSubItem; } ShowSounds_SortItems(); return 0L; case LVN_GETDISPINFO: NMLVDISPINFO* plvdi; plvdi = ( NMLVDISPINFO* )lParam; pSound = ( sound_t* )plvdi->item.lParam; switch ( plvdi->item.iSubItem ) { case ID_SS_NAME: plvdi->item.pszText = pSound->pName; return 0L; case ID_SS_PREFIX: plvdi->item.pszText = pSound->pPrefix; return 0L; case ID_SS_FORMAT: plvdi->item.pszText = pSound->pFormat; return 0L; case ID_SS_RATE: plvdi->item.pszText = pSound->rateBuff; return 0L; case ID_SS_BITS: plvdi->item.pszText = pSound->bitsBuff; return 0L; case ID_SS_CHANNELS: plvdi->item.pszText = pSound->channelsBuff; return 0L; case ID_SS_SIZE: plvdi->item.pszText = pSound->dataSizeBuff; return 0L; case ID_SS_STREAMED: plvdi->item.pszText = pSound->streamedBuff; return 0L; case ID_SS_LOOPED: plvdi->item.pszText = pSound->loopedBuff; return 0L; case ID_SS_LENGTH: plvdi->item.pszText = pSound->lengthBuff; return 0L; default: break; } break; } break; case WM_COMMAND: switch ( wID ) { case IDM_OPTIONS_SUMMARY: ShowSounds_Summary(); return 0L; case IDM_OPTIONS_REFRESH: ShowSounds_Refresh(); return 0L; case IDM_OPTIONS_EXPORT: ShowSounds_Export(); return 0L; case IDM_OPTIONS_PLAYSOUND: ShowSounds_Play(); return 0L; } break; } return ( DefWindowProc( hwnd, message, wParam, lParam ) ); } //----------------------------------------------------------------------------- // ShowSounds_Init // //----------------------------------------------------------------------------- bool ShowSounds_Init() { // set up our window class WNDCLASS wndclass; memset( &wndclass, 0, sizeof( wndclass ) ); wndclass.style = 0; wndclass.lpfnWndProc = ShowSounds_WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = g_hInstance; wndclass.hIcon = g_hIcons[ICON_APPLICATION]; wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ); wndclass.hbrBackground = g_hBackgroundBrush; wndclass.lpszMenuName = MAKEINTRESOURCE( MENU_SHOWSOUNDS ); wndclass.lpszClassName = "SHOWSOUNDSCLASS"; if ( !RegisterClass( &wndclass ) ) return false; ShowSounds_LoadConfig(); return true; } //----------------------------------------------------------------------------- // ShowSounds_Open // //----------------------------------------------------------------------------- void ShowSounds_Open() { RECT clientRect; HWND hWnd; int i; if ( g_showSounds_hWnd ) { // only one instance if ( IsIconic( g_showSounds_hWnd ) ) ShowWindow( g_showSounds_hWnd, SW_RESTORE ); SetForegroundWindow( g_showSounds_hWnd ); return; } hWnd = CreateWindowEx( WS_EX_CLIENTEDGE, "SHOWSOUNDSCLASS", "Sounds", WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX|WS_MINIMIZEBOX|WS_MAXIMIZEBOX, 0, 0, 700, 400, g_hDlgMain, NULL, g_hInstance, NULL ); g_showSounds_hWnd = hWnd; GetClientRect( g_showSounds_hWnd, &clientRect ); hWnd = CreateWindow( WC_LISTVIEW, "", WS_VISIBLE|WS_CHILD|LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SINGLESEL, 0, 0, clientRect.right-clientRect.left, clientRect.bottom-clientRect.top, g_showSounds_hWnd, ( HMENU )ID_SHOWSOUNDS_LISTVIEW, g_hInstance, NULL ); g_showSounds_hWndListView = hWnd; // init list view columns for ( i=0; i 0 ) g_showSounds_pSounds[i].length = ( float )g_showSounds_pSounds[i].numSamples/( float )g_showSounds_pSounds[i].rate; else g_showSounds_pSounds[i].length = 0; // add to list view ShowSounds_AddViewItem( &g_showSounds_pSounds[i] ); } // return the result retVal = numSounds; int xboxRetVal = BigDWord( retVal ); DmSetMemory( ( void* )retAddr, sizeof( int ), &xboxRetVal, NULL ); DebugCommand( "0x%8.8x = SoundList( 0x%8.8x, 0x%8.8x )\n", retVal, numSounds, soundList ); delete [] pLocalList; // update ShowSounds_SortItems(); // success errCode = 0; cleanUp: return ( errCode ); }