Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

778 lines
20 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // SHOW_SOUNDS.CPP
  4. //
  5. // Show Sounds Display.
  6. //=====================================================================================//
  7. #include "vxconsole.h"
  8. #define ID_SHOWSOUNDS_LISTVIEW 100
  9. // column id
  10. #define ID_SS_NAME 0
  11. #define ID_SS_PREFIX 1
  12. #define ID_SS_FORMAT 2
  13. #define ID_SS_RATE 3
  14. #define ID_SS_BITS 4
  15. #define ID_SS_CHANNELS 5
  16. #define ID_SS_SIZE 6
  17. #define ID_SS_STREAMED 7
  18. #define ID_SS_LOOPED 8
  19. #define ID_SS_LENGTH 9
  20. typedef struct
  21. {
  22. int listIndex;
  23. char *pName;
  24. char *pPrefix;
  25. char *pFormat;
  26. int rate;
  27. char rateBuff[16];
  28. int bits;
  29. char bitsBuff[16];
  30. int channels;
  31. char channelsBuff[16];
  32. int numSamples;
  33. int dataSize;
  34. char dataSizeBuff[16];
  35. int streamed;
  36. char streamedBuff[16];
  37. int looped;
  38. char loopedBuff[16];
  39. float length;
  40. char lengthBuff[16];
  41. } sound_t;
  42. typedef struct
  43. { const CHAR* name;
  44. int width;
  45. int subItemIndex;
  46. CHAR nameBuff[32];
  47. } label_t;
  48. HWND g_showSounds_hWnd;
  49. HWND g_showSounds_hWndListView;
  50. RECT g_showSounds_windowRect;
  51. int g_showSounds_sortColumn;
  52. int g_showSounds_sortDescending;
  53. sound_t *g_showSounds_pSounds;
  54. int g_showSounds_numSounds;
  55. int g_showSounds_currentFrame;
  56. label_t g_showSounds_Labels[] =
  57. {
  58. {"Name", 300, ID_SS_NAME},
  59. {"Prefix", 80, ID_SS_PREFIX},
  60. {"Format", 80, ID_SS_FORMAT},
  61. {"Rate", 80, ID_SS_RATE},
  62. {"Bits", 80, ID_SS_BITS},
  63. {"Channels", 80, ID_SS_CHANNELS},
  64. {"Size", 80, ID_SS_SIZE},
  65. {"Streamed", 80, ID_SS_STREAMED},
  66. {"Looped", 80, ID_SS_LOOPED},
  67. {"Length", 80, ID_SS_LENGTH},
  68. };
  69. //-----------------------------------------------------------------------------
  70. // ShowSounds_SaveConfig
  71. //
  72. //-----------------------------------------------------------------------------
  73. void ShowSounds_SaveConfig()
  74. {
  75. char buff[256];
  76. Sys_SetRegistryInteger( "showSoundsSortColumn", g_showSounds_sortColumn );
  77. Sys_SetRegistryInteger( "showSoundsSortDescending", g_showSounds_sortDescending );
  78. WINDOWPLACEMENT wp;
  79. memset( &wp, 0, sizeof( wp ) );
  80. wp.length = sizeof( WINDOWPLACEMENT );
  81. GetWindowPlacement( g_showSounds_hWnd, &wp );
  82. g_showSounds_windowRect = wp.rcNormalPosition;
  83. sprintf( buff, "%d %d %d %d", g_showSounds_windowRect.left, g_showSounds_windowRect.top, g_showSounds_windowRect.right, g_showSounds_windowRect.bottom );
  84. Sys_SetRegistryString( "showSoundsWindowRect", buff );
  85. }
  86. //-----------------------------------------------------------------------------
  87. // ShowSounds_LoadConfig
  88. //
  89. //-----------------------------------------------------------------------------
  90. void ShowSounds_LoadConfig()
  91. {
  92. int numArgs;
  93. char buff[256];
  94. Sys_GetRegistryInteger( "showSoundsSortColumn", ID_SS_NAME, g_showSounds_sortColumn );
  95. Sys_GetRegistryInteger( "showSoundsSortDescending", false, g_showSounds_sortDescending );
  96. Sys_GetRegistryString( "showSoundsWindowRect", buff, "", sizeof( buff ) );
  97. numArgs = sscanf( buff, "%d %d %d %d", &g_showSounds_windowRect.left, &g_showSounds_windowRect.top, &g_showSounds_windowRect.right, &g_showSounds_windowRect.bottom );
  98. if ( numArgs != 4 || g_showSounds_windowRect.left < 0 || g_showSounds_windowRect.top < 0 || g_showSounds_windowRect.right < 0 || g_showSounds_windowRect.bottom < 0 )
  99. memset( &g_showSounds_windowRect, 0, sizeof( g_showSounds_windowRect ) );
  100. }
  101. //-----------------------------------------------------------------------------
  102. // ShowSounds_Clear
  103. //
  104. //-----------------------------------------------------------------------------
  105. void ShowSounds_Clear()
  106. {
  107. // delete all the list view entries
  108. if ( g_showSounds_hWnd )
  109. ListView_DeleteAllItems( g_showSounds_hWndListView );
  110. if ( !g_showSounds_pSounds )
  111. return;
  112. for ( int i=0; i<g_showSounds_numSounds; i++ )
  113. {
  114. free( g_showSounds_pSounds[i].pName );
  115. free( g_showSounds_pSounds[i].pPrefix );
  116. free( g_showSounds_pSounds[i].pFormat );
  117. }
  118. g_showSounds_pSounds = NULL;
  119. g_showSounds_numSounds = 0;
  120. }
  121. //-----------------------------------------------------------------------------
  122. // ShowSounds_Export
  123. //
  124. //-----------------------------------------------------------------------------
  125. void ShowSounds_Export()
  126. {
  127. }
  128. //-----------------------------------------------------------------------------
  129. // ShowSounds_Summary
  130. //
  131. //-----------------------------------------------------------------------------
  132. void ShowSounds_Summary()
  133. {
  134. char buff[1024];
  135. // tally the totals
  136. int totalStreamed = 0;
  137. int totalStatic = 0;
  138. for ( int i=0; i<g_showSounds_numSounds; i++ )
  139. {
  140. if ( g_showSounds_pSounds[i].streamed )
  141. {
  142. totalStreamed += g_showSounds_pSounds[i].dataSize;
  143. }
  144. else
  145. {
  146. totalStatic += g_showSounds_pSounds[i].dataSize;
  147. }
  148. }
  149. sprintf(
  150. buff,
  151. "Entries:\t\t\t%d\n"
  152. "Static Memory:\t\t%.2f MB\n"
  153. "Streamed Memory:\t\t%.2f MB\n",
  154. g_showSounds_numSounds,
  155. ( float )totalStatic/( 1024.0F*1024.0F ),
  156. ( float )totalStreamed/( 1024.0F*1024.0F ) );
  157. MessageBox( g_showSounds_hWnd, buff, "Sound Summary", MB_OK|MB_APPLMODAL );
  158. }
  159. //-----------------------------------------------------------------------------
  160. // ShowSounds_Play
  161. //
  162. //-----------------------------------------------------------------------------
  163. void ShowSounds_Play()
  164. {
  165. char command[256];
  166. sound_t* pSound;
  167. int selection;
  168. LVITEM lvitem;
  169. if ( !g_connectedToApp )
  170. return;
  171. selection = ListView_GetSelectionMark( g_showSounds_hWndListView );
  172. if ( selection == -1 )
  173. return;
  174. memset( &lvitem, 0, sizeof( lvitem ) );
  175. lvitem.mask = LVIF_PARAM;
  176. lvitem.iItem = selection;
  177. ListView_GetItem( g_showSounds_hWndListView, &lvitem );
  178. pSound = ( sound_t* )lvitem.lParam;
  179. sprintf( command, "play %s%s", pSound->pPrefix, pSound->pName );
  180. // send the command to application
  181. ProcessCommand( command );
  182. }
  183. //-----------------------------------------------------------------------------
  184. // ShowSounds_CompareFunc
  185. //
  186. //-----------------------------------------------------------------------------
  187. int CALLBACK ShowSounds_CompareFunc( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort )
  188. {
  189. sound_t* pSoundA = ( sound_t* )lParam1;
  190. sound_t* pSoundB = ( sound_t* )lParam2;
  191. int sort = 0;
  192. switch ( g_showSounds_sortColumn )
  193. {
  194. case ID_SS_NAME:
  195. sort = stricmp( pSoundA->pName, pSoundB->pName );
  196. break;
  197. case ID_SS_PREFIX:
  198. sort = stricmp( pSoundA->pPrefix, pSoundB->pPrefix );
  199. break;
  200. case ID_SS_FORMAT:
  201. sort = stricmp( pSoundA->pFormat, pSoundB->pFormat );
  202. break;
  203. case ID_SS_RATE:
  204. sort = pSoundA->rate - pSoundB->rate;
  205. break;
  206. case ID_SS_BITS:
  207. sort = pSoundA->bits - pSoundB->bits;
  208. break;
  209. case ID_SS_CHANNELS:
  210. sort = stricmp( pSoundA->channelsBuff, pSoundB->channelsBuff );
  211. break;
  212. case ID_SS_SIZE:
  213. sort = pSoundA->dataSize - pSoundB->dataSize;
  214. break;
  215. case ID_SS_STREAMED:
  216. sort = stricmp( pSoundA->streamedBuff, pSoundB->streamedBuff );
  217. break;
  218. case ID_SS_LOOPED:
  219. sort = stricmp( pSoundA->loopedBuff, pSoundB->loopedBuff );
  220. break;
  221. case ID_SS_LENGTH:
  222. if ( pSoundA->length < pSoundB->length )
  223. sort = -1;
  224. else if ( pSoundA->length == pSoundB->length )
  225. sort = 0;
  226. else
  227. sort = 1;
  228. break;
  229. }
  230. // flip the sort order
  231. if ( g_showSounds_sortDescending )
  232. sort *= -1;
  233. return ( sort );
  234. }
  235. //-----------------------------------------------------------------------------
  236. // ShowSounds_SortItems
  237. //
  238. //-----------------------------------------------------------------------------
  239. void ShowSounds_SortItems()
  240. {
  241. LVITEM lvitem;
  242. sound_t *pSound;
  243. int i;
  244. if ( !g_showSounds_hWnd )
  245. {
  246. // only sort if window is visible
  247. return;
  248. }
  249. ListView_SortItems( g_showSounds_hWndListView, ShowSounds_CompareFunc, 0 );
  250. memset( &lvitem, 0, sizeof( lvitem ) );
  251. lvitem.mask = LVIF_PARAM;
  252. // get each item and reset its list index
  253. int itemCount = ListView_GetItemCount( g_showSounds_hWndListView );
  254. for ( i=0; i<itemCount; i++ )
  255. {
  256. lvitem.iItem = i;
  257. ListView_GetItem( g_showSounds_hWndListView, &lvitem );
  258. pSound = ( sound_t* )lvitem.lParam;
  259. pSound->listIndex = i;
  260. }
  261. // update list view columns with sort key
  262. for ( i=0; i<sizeof( g_showSounds_Labels )/sizeof( g_showSounds_Labels[0] ); i++ )
  263. {
  264. char symbol;
  265. LVCOLUMN lvc;
  266. if ( i == g_showSounds_sortColumn )
  267. symbol = g_showSounds_sortDescending ? '<' : '>';
  268. else
  269. symbol = ' ';
  270. sprintf( g_showSounds_Labels[i].nameBuff, "%s %c", g_showSounds_Labels[i].name, symbol );
  271. memset( &lvc, 0, sizeof( lvc ) );
  272. lvc.mask = LVCF_TEXT;
  273. lvc.pszText = ( LPSTR )g_showSounds_Labels[i].nameBuff;
  274. ListView_SetColumn( g_showSounds_hWndListView, i, &lvc );
  275. }
  276. }
  277. //-----------------------------------------------------------------------------
  278. // ShowSounds_AddViewItem
  279. //
  280. //-----------------------------------------------------------------------------
  281. void ShowSounds_AddViewItem( sound_t* pSound )
  282. {
  283. LVITEM lvi;
  284. if ( !g_showSounds_hWnd )
  285. {
  286. // only valid if log window is visible
  287. return;
  288. }
  289. // update the text callback buffers
  290. if ( pSound->rate >= 0 )
  291. sprintf( pSound->rateBuff, "%5.2f KHz", ( float )pSound->rate/1000.0f );
  292. else
  293. strcpy( pSound->rateBuff, "???" );
  294. if ( pSound->bits >= 0 )
  295. sprintf( pSound->bitsBuff, "%d", pSound->bits );
  296. else
  297. strcpy( pSound->bitsBuff, "???" );
  298. if ( pSound->channels >= 1 )
  299. strcpy( pSound->channelsBuff, pSound->channels == 2 ? "Stereo" : "Mono" );
  300. else
  301. strcpy( pSound->channelsBuff, "???" );
  302. if ( pSound->dataSize >= 0 )
  303. sprintf( pSound->dataSizeBuff, "%d", pSound->dataSize );
  304. else
  305. strcpy( pSound->dataSizeBuff, "???" );
  306. if ( pSound->streamed >= 0 )
  307. strcpy( pSound->streamedBuff, pSound->streamed ? "Stream" : "Static" );
  308. else
  309. strcpy( pSound->streamedBuff, "???" );
  310. if ( pSound->looped >= 0 )
  311. strcpy( pSound->loopedBuff, pSound->looped ? "Looped" : "One-Shot" );
  312. else
  313. strcpy( pSound->loopedBuff, "???" );
  314. 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 );
  315. int itemCount = ListView_GetItemCount( g_showSounds_hWndListView );
  316. // setup and insert at end of list
  317. memset( &lvi, 0, sizeof( lvi ) );
  318. lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
  319. lvi.iItem = itemCount;
  320. lvi.iSubItem = 0;
  321. lvi.state = 0;
  322. lvi.stateMask = 0;
  323. lvi.pszText = LPSTR_TEXTCALLBACK;
  324. lvi.lParam = ( LPARAM )pSound;
  325. // insert and set the real index
  326. pSound->listIndex = ListView_InsertItem( g_showSounds_hWndListView, &lvi );
  327. }
  328. //-----------------------------------------------------------------------------
  329. // ShowSounds_Refresh
  330. //
  331. //-----------------------------------------------------------------------------
  332. void ShowSounds_Refresh()
  333. {
  334. char command[256];
  335. strcpy( command, "vx_soundlist" );
  336. // send the command to application which replies with list data
  337. if ( g_connectedToApp )
  338. ProcessCommand( command );
  339. }
  340. //-----------------------------------------------------------------------------
  341. // ShowSounds_SizeWindow
  342. //
  343. //-----------------------------------------------------------------------------
  344. void ShowSounds_SizeWindow( HWND hwnd, int cx, int cy )
  345. {
  346. if ( cx==0 || cy==0 )
  347. {
  348. RECT rcClient;
  349. GetClientRect( hwnd, &rcClient );
  350. cx = rcClient.right;
  351. cy = rcClient.bottom;
  352. }
  353. // position the ListView
  354. SetWindowPos( g_showSounds_hWndListView, NULL, 0, 0, cx, cy, SWP_NOZORDER );
  355. }
  356. //-----------------------------------------------------------------------------
  357. // ShowSounds_WndProc
  358. //
  359. //-----------------------------------------------------------------------------
  360. LRESULT CALLBACK ShowSounds_WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
  361. {
  362. WORD wID = LOWORD( wParam );
  363. sound_t* pSound;
  364. switch ( message )
  365. {
  366. case WM_CREATE:
  367. return 0L;
  368. case WM_DESTROY:
  369. ShowSounds_SaveConfig();
  370. g_showSounds_hWnd = NULL;
  371. return 0L;
  372. case WM_INITMENU:
  373. return 0L;
  374. case WM_SIZE:
  375. ShowSounds_SizeWindow( hwnd, LOWORD( lParam ), HIWORD( lParam ) );
  376. return 0L;
  377. case WM_NOTIFY:
  378. switch ( ( ( LPNMHDR )lParam )->code )
  379. {
  380. case LVN_COLUMNCLICK:
  381. NMLISTVIEW* pnmlv;
  382. pnmlv = ( NMLISTVIEW* )lParam;
  383. if ( g_showSounds_sortColumn == pnmlv->iSubItem )
  384. {
  385. // user has clicked on same column - flip the sort
  386. g_showSounds_sortDescending ^= 1;
  387. }
  388. else
  389. {
  390. // sort by new column
  391. g_showSounds_sortColumn = pnmlv->iSubItem;
  392. }
  393. ShowSounds_SortItems();
  394. return 0L;
  395. case LVN_GETDISPINFO:
  396. NMLVDISPINFO* plvdi;
  397. plvdi = ( NMLVDISPINFO* )lParam;
  398. pSound = ( sound_t* )plvdi->item.lParam;
  399. switch ( plvdi->item.iSubItem )
  400. {
  401. case ID_SS_NAME:
  402. plvdi->item.pszText = pSound->pName;
  403. return 0L;
  404. case ID_SS_PREFIX:
  405. plvdi->item.pszText = pSound->pPrefix;
  406. return 0L;
  407. case ID_SS_FORMAT:
  408. plvdi->item.pszText = pSound->pFormat;
  409. return 0L;
  410. case ID_SS_RATE:
  411. plvdi->item.pszText = pSound->rateBuff;
  412. return 0L;
  413. case ID_SS_BITS:
  414. plvdi->item.pszText = pSound->bitsBuff;
  415. return 0L;
  416. case ID_SS_CHANNELS:
  417. plvdi->item.pszText = pSound->channelsBuff;
  418. return 0L;
  419. case ID_SS_SIZE:
  420. plvdi->item.pszText = pSound->dataSizeBuff;
  421. return 0L;
  422. case ID_SS_STREAMED:
  423. plvdi->item.pszText = pSound->streamedBuff;
  424. return 0L;
  425. case ID_SS_LOOPED:
  426. plvdi->item.pszText = pSound->loopedBuff;
  427. return 0L;
  428. case ID_SS_LENGTH:
  429. plvdi->item.pszText = pSound->lengthBuff;
  430. return 0L;
  431. default:
  432. break;
  433. }
  434. break;
  435. }
  436. break;
  437. case WM_COMMAND:
  438. switch ( wID )
  439. {
  440. case IDM_OPTIONS_SUMMARY:
  441. ShowSounds_Summary();
  442. return 0L;
  443. case IDM_OPTIONS_REFRESH:
  444. ShowSounds_Refresh();
  445. return 0L;
  446. case IDM_OPTIONS_EXPORT:
  447. ShowSounds_Export();
  448. return 0L;
  449. case IDM_OPTIONS_PLAYSOUND:
  450. ShowSounds_Play();
  451. return 0L;
  452. }
  453. break;
  454. }
  455. return ( DefWindowProc( hwnd, message, wParam, lParam ) );
  456. }
  457. //-----------------------------------------------------------------------------
  458. // ShowSounds_Init
  459. //
  460. //-----------------------------------------------------------------------------
  461. bool ShowSounds_Init()
  462. {
  463. // set up our window class
  464. WNDCLASS wndclass;
  465. memset( &wndclass, 0, sizeof( wndclass ) );
  466. wndclass.style = 0;
  467. wndclass.lpfnWndProc = ShowSounds_WndProc;
  468. wndclass.cbClsExtra = 0;
  469. wndclass.cbWndExtra = 0;
  470. wndclass.hInstance = g_hInstance;
  471. wndclass.hIcon = g_hIcons[ICON_APPLICATION];
  472. wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
  473. wndclass.hbrBackground = g_hBackgroundBrush;
  474. wndclass.lpszMenuName = MAKEINTRESOURCE( MENU_SHOWSOUNDS );
  475. wndclass.lpszClassName = "SHOWSOUNDSCLASS";
  476. if ( !RegisterClass( &wndclass ) )
  477. return false;
  478. ShowSounds_LoadConfig();
  479. return true;
  480. }
  481. //-----------------------------------------------------------------------------
  482. // ShowSounds_Open
  483. //
  484. //-----------------------------------------------------------------------------
  485. void ShowSounds_Open()
  486. {
  487. RECT clientRect;
  488. HWND hWnd;
  489. int i;
  490. if ( g_showSounds_hWnd )
  491. {
  492. // only one instance
  493. if ( IsIconic( g_showSounds_hWnd ) )
  494. ShowWindow( g_showSounds_hWnd, SW_RESTORE );
  495. SetForegroundWindow( g_showSounds_hWnd );
  496. return;
  497. }
  498. hWnd = CreateWindowEx(
  499. WS_EX_CLIENTEDGE,
  500. "SHOWSOUNDSCLASS",
  501. "Sounds",
  502. WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX|WS_MINIMIZEBOX|WS_MAXIMIZEBOX,
  503. 0,
  504. 0,
  505. 700,
  506. 400,
  507. g_hDlgMain,
  508. NULL,
  509. g_hInstance,
  510. NULL );
  511. g_showSounds_hWnd = hWnd;
  512. GetClientRect( g_showSounds_hWnd, &clientRect );
  513. hWnd = CreateWindow(
  514. WC_LISTVIEW,
  515. "",
  516. WS_VISIBLE|WS_CHILD|LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SINGLESEL,
  517. 0,
  518. 0,
  519. clientRect.right-clientRect.left,
  520. clientRect.bottom-clientRect.top,
  521. g_showSounds_hWnd,
  522. ( HMENU )ID_SHOWSOUNDS_LISTVIEW,
  523. g_hInstance,
  524. NULL );
  525. g_showSounds_hWndListView = hWnd;
  526. // init list view columns
  527. for ( i=0; i<sizeof( g_showSounds_Labels )/sizeof( g_showSounds_Labels[0] ); i++ )
  528. {
  529. LVCOLUMN lvc;
  530. memset( &lvc, 0, sizeof( lvc ) );
  531. lvc.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
  532. lvc.iSubItem = 0;
  533. lvc.cx = g_showSounds_Labels[i].width;
  534. lvc.fmt = LVCFMT_LEFT;
  535. lvc.pszText = ( LPSTR )g_showSounds_Labels[i].name;
  536. ListView_InsertColumn( g_showSounds_hWndListView, i, &lvc );
  537. }
  538. ListView_SetBkColor( g_showSounds_hWndListView, g_backgroundColor );
  539. ListView_SetTextBkColor( g_showSounds_hWndListView, g_backgroundColor );
  540. DWORD style = LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP;
  541. ListView_SetExtendedListViewStyleEx( g_showSounds_hWndListView, style, style );
  542. // populate list view
  543. for ( i=0; i<g_showSounds_numSounds; i++ )
  544. ShowSounds_AddViewItem( &g_showSounds_pSounds[i] );
  545. ShowSounds_SortItems();
  546. if ( g_showSounds_windowRect.right && g_showSounds_windowRect.bottom )
  547. MoveWindow( g_showSounds_hWnd, g_showSounds_windowRect.left, g_showSounds_windowRect.top, g_showSounds_windowRect.right-g_showSounds_windowRect.left, g_showSounds_windowRect.bottom-g_showSounds_windowRect.top, FALSE );
  548. ShowWindow( g_showSounds_hWnd, SHOW_OPENWINDOW );
  549. // get data from application
  550. ShowSounds_Refresh();
  551. }
  552. //-----------------------------------------------------------------------------
  553. // rc_SoundList
  554. //
  555. // Sent from application with sound list
  556. //-----------------------------------------------------------------------------
  557. int rc_SoundList( char* commandPtr )
  558. {
  559. char* cmdToken;
  560. int numSounds;
  561. int soundList;
  562. int retAddr;
  563. int retVal;
  564. int errCode = -1;
  565. xrSound_t* pLocalList;
  566. int prefixLen;
  567. char *pStr;
  568. // remove old entries
  569. ShowSounds_Clear();
  570. // get number of sounds
  571. cmdToken = GetToken( &commandPtr );
  572. if ( !cmdToken[0] )
  573. goto cleanUp;
  574. sscanf( cmdToken, "%x", &numSounds );
  575. // get sound list
  576. cmdToken = GetToken( &commandPtr );
  577. if ( !cmdToken[0] )
  578. goto cleanUp;
  579. sscanf( cmdToken, "%x", &soundList );
  580. // get retAddr
  581. cmdToken = GetToken( &commandPtr );
  582. if ( !cmdToken[0] )
  583. goto cleanUp;
  584. sscanf( cmdToken, "%x", &retAddr );
  585. pLocalList = new xrSound_t[numSounds];
  586. memset( pLocalList, 0, numSounds*sizeof( xrSound_t ) );
  587. g_showSounds_numSounds = numSounds;
  588. g_showSounds_pSounds = new sound_t[numSounds];
  589. memset( g_showSounds_pSounds, 0, numSounds*sizeof( sound_t ) );
  590. // get the caller's command list
  591. DmGetMemory( ( void* )soundList, numSounds*sizeof( xrSound_t ), pLocalList, NULL );
  592. // build out the resident list
  593. for ( int i=0; i<numSounds; i++ )
  594. {
  595. // swap the structure
  596. pLocalList[i].rate = BigDWord( pLocalList[i].rate );
  597. pLocalList[i].bits = BigDWord( pLocalList[i].bits );
  598. pLocalList[i].channels = BigDWord( pLocalList[i].channels );
  599. pLocalList[i].looped = BigDWord( pLocalList[i].looped );
  600. pLocalList[i].dataSize = BigDWord( pLocalList[i].dataSize );
  601. pLocalList[i].numSamples = BigDWord( pLocalList[i].numSamples );
  602. pLocalList[i].streamed = BigDWord( pLocalList[i].streamed );
  603. // strip the prefix
  604. pStr = pLocalList[i].nameString;
  605. while ( *pStr )
  606. {
  607. if ( __iscsym( *pStr ) )
  608. {
  609. // first non-preifx character
  610. break;
  611. }
  612. pStr++;
  613. }
  614. g_showSounds_pSounds[i].pName = strdup( pStr );
  615. char prefixString[256];
  616. prefixLen = pStr - pLocalList[i].nameString;
  617. memcpy( prefixString, pLocalList[i].nameString, prefixLen );
  618. prefixString[prefixLen] = '\0';
  619. g_showSounds_pSounds[i].pPrefix = strdup( prefixString );
  620. // get the format name
  621. g_showSounds_pSounds[i].pFormat = strdup( pLocalList[i].formatString );
  622. g_showSounds_pSounds[i].rate = pLocalList[i].rate;
  623. g_showSounds_pSounds[i].bits = pLocalList[i].bits;
  624. g_showSounds_pSounds[i].channels = pLocalList[i].channels;
  625. g_showSounds_pSounds[i].dataSize = pLocalList[i].dataSize;
  626. g_showSounds_pSounds[i].numSamples = pLocalList[i].numSamples;
  627. g_showSounds_pSounds[i].streamed = pLocalList[i].streamed;
  628. g_showSounds_pSounds[i].looped = pLocalList[i].looped;
  629. // determine duration
  630. // must use sample count due to compression
  631. if ( g_showSounds_pSounds[i].rate > 0 )
  632. g_showSounds_pSounds[i].length = ( float )g_showSounds_pSounds[i].numSamples/( float )g_showSounds_pSounds[i].rate;
  633. else
  634. g_showSounds_pSounds[i].length = 0;
  635. // add to list view
  636. ShowSounds_AddViewItem( &g_showSounds_pSounds[i] );
  637. }
  638. // return the result
  639. retVal = numSounds;
  640. int xboxRetVal = BigDWord( retVal );
  641. DmSetMemory( ( void* )retAddr, sizeof( int ), &xboxRetVal, NULL );
  642. DebugCommand( "0x%8.8x = SoundList( 0x%8.8x, 0x%8.8x )\n", retVal, numSounds, soundList );
  643. delete [] pLocalList;
  644. // update
  645. ShowSounds_SortItems();
  646. // success
  647. errCode = 0;
  648. cleanUp:
  649. return ( errCode );
  650. }