[2] | 1 | /*
|
---|
[4] | 2 | * This file is (C) Chris Wohlgemuth 2002-2005
|
---|
[2] | 3 | *
|
---|
| 4 | * It's part of the Media-Folder distribution
|
---|
| 5 | */
|
---|
| 6 | /*
|
---|
| 7 | * This program is free software; you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation; either version 2, or (at your option)
|
---|
| 10 | * any later version.
|
---|
| 11 | *
|
---|
| 12 | * This program is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with this program; see the file COPYING. If not, write to
|
---|
| 19 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #define INCL_DOSERRORS
|
---|
| 23 | #include <stdio.h>
|
---|
| 24 | #include <stdlib.h>
|
---|
| 25 | #include <ctype.h>
|
---|
| 26 | #include "cdfolder.hh"
|
---|
| 27 | #include "mediafolderres.h"
|
---|
| 28 | #include "cwcdtrack.hh"
|
---|
| 29 |
|
---|
| 30 | #include "sys_funcs.h"
|
---|
| 31 |
|
---|
| 32 | extern HMTX hmtxFileName;
|
---|
| 33 | extern int iWaveDev;
|
---|
| 34 | PFNWP pfnwpGenericCDFrame;
|
---|
| 35 |
|
---|
| 36 | /* For calling the method in the MMAudio class. Linking to the DLL would require the
|
---|
| 37 | new audio classes. By dynamically querying the method the media folder works without
|
---|
| 38 | installing the audio classes. */
|
---|
| 39 | typedef ULONG SOMLINK somTP_MMCDTrack_cwmmQueryTrackInfo(MMCDTrack *somSelf,
|
---|
| 40 | char** chrString,
|
---|
| 41 | ULONG ulSize,
|
---|
| 42 | int iWhich);
|
---|
| 43 | typedef somTP_MMCDTrack_cwmmQueryTrackInfo *somTD_MMCDTrack_cwmmQueryTrackInfo;
|
---|
| 44 | extern somTD_MMCDTrack_cwmmQueryTrackInfo methodPtrCDTrack;
|
---|
| 45 |
|
---|
| 46 | BOOL extern CDQueryCDDrives(int *iNumCD, char * cFirstDrive);
|
---|
| 47 |
|
---|
| 48 | BOOL getMessage(char* text,ULONG ulID, LONG lSizeText, HMODULE hResource,HWND hwnd);
|
---|
| 49 | HMODULE queryResModuleHandle(void);
|
---|
| 50 |
|
---|
| 51 | ULONG cwRequestMutex(HMTX hmtxBMP, ULONG ulTimeOut);
|
---|
| 52 | ULONG cwReleaseMutex(HMTX hmtxBMP);
|
---|
| 53 |
|
---|
| 54 | SOMClass* somhlpGetSomClass(char* chrClassName);
|
---|
| 55 | extern BOOL somhlpQueryCWCDTrackMethodPtr(CWMediaFolder *thisPtr);
|
---|
| 56 | MRESULT EXPENTRY cdFrameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
|
---|
| 57 | extern void showPlayTimeDisplay(CWMediaFolder *thisPtr, BOOL bShow);
|
---|
| 58 | void setPlayTimeText2(CWMediaFolder *thisPtr, char * theText);
|
---|
[4] | 59 |
|
---|
[2] | 60 | /* Get the HWND of the play control dialog. This Dialog is on top of
|
---|
| 61 | the top frame control. */
|
---|
| 62 | HWND playControlDialogFromFrameHWND(HWND hwndFrame);
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | BOOL CWCDFolder::wpSetupOnce(PSZ pSetupString)
|
---|
| 66 | {
|
---|
| 67 | /**************************************************
|
---|
| 68 | * *
|
---|
| 69 | * *
|
---|
| 70 | **************************************************/
|
---|
| 71 | BOOL rcParent=FALSE;
|
---|
| 72 | char buffer[CCHMAXPATH];
|
---|
| 73 | ULONG bufferSize;
|
---|
| 74 | int iIndex;
|
---|
| 75 |
|
---|
| 76 | rcParent=CWMediaFolder::wpSetupOnce(pSetupString);
|
---|
| 77 |
|
---|
| 78 | /* Doing our own setup here if not done by the user. */
|
---|
| 79 | #if 0
|
---|
| 80 | /* This is already done in the media folder class */
|
---|
| 81 | bufferSize=sizeof(buffer);
|
---|
| 82 | if(!wpScanSetupString(pSetupString,"DEFAULTVIEW",buffer,&bufferSize))
|
---|
| 83 | wpSetup( "DEFAULTVIEW=DETAILS");/* Fill in defaults */
|
---|
| 84 |
|
---|
| 85 | bufferSize=sizeof(buffer);
|
---|
| 86 | if(!wpScanSetupString(pSetupString,"ICONVIEW",buffer,&bufferSize))
|
---|
| 87 | wpSetup( "ICONVIEW=NONFLOWED,MINI");/* Fill in defaults */
|
---|
| 88 |
|
---|
| 89 | /* Size and position of the folder window */
|
---|
| 90 | bufferSize=sizeof(buffer);
|
---|
| 91 | if(!wpScanSetupString(pSetupString,"ICONVIEWPOS",buffer,&bufferSize))
|
---|
| 92 | wpSetup( "ICONVIEWPOS=20,10,60,75");/* Fill in defaults */
|
---|
| 93 | #endif
|
---|
| 94 |
|
---|
| 95 | /* Set folder details- and sortclass to CWAudioShadow so track infos are shown */
|
---|
| 96 | bufferSize=sizeof(buffer);
|
---|
| 97 | if(!wpScanSetupString(pSetupString,"DETAILSCLASS",buffer,&bufferSize))
|
---|
| 98 | wpSetup("DETAILSCLASS=MMAudio");/* Fill in defaults */
|
---|
| 99 |
|
---|
| 100 | bufferSize=sizeof(buffer);
|
---|
| 101 | if(!wpScanSetupString(pSetupString,"SORTCLASS",buffer,&bufferSize))
|
---|
| 102 | wpSetup("SORTCLASS=MMCDTrack");/* Fill in defaults */
|
---|
| 103 |
|
---|
| 104 | /* This works only on Warp 4 and above */
|
---|
| 105 | bufferSize=sizeof(buffer);
|
---|
| 106 | if(!wpScanSetupString(pSetupString,"DETAILSTODISPLAY",buffer,&bufferSize))
|
---|
| 107 | /* This works only on Warp 4 and above */
|
---|
| 108 | wpSetup("DETAILSTODISPLAY=0,1,12,16,17,18");/* Fill in defaults */
|
---|
| 109 |
|
---|
| 110 | /* This works only on Warp 4 and above */
|
---|
| 111 | bufferSize=sizeof(buffer);
|
---|
| 112 | if(!wpScanSetupString(pSetupString,"SORTBYATTR",buffer,&bufferSize))
|
---|
| 113 | /* This works only on Warp 4 and above */
|
---|
| 114 | wpSetup("SORTBYATTR=6,24,28,29,30");/* Fill in defaults */
|
---|
| 115 |
|
---|
| 116 | return rcParent;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | BOOL CWCDFolder::wpSetup(PSZ pSetupString)
|
---|
| 120 | {
|
---|
| 121 | /**************************************************
|
---|
| 122 | * *
|
---|
| 123 | * *
|
---|
| 124 | **************************************************/
|
---|
| 125 | char buffer[3];
|
---|
| 126 | ULONG bufferSize;
|
---|
| 127 |
|
---|
| 128 | /* Set drive letter */
|
---|
| 129 | bufferSize=sizeof(buffer);
|
---|
| 130 | if(wpScanSetupString(pSetupString, CDFLDR_DRIVE, buffer,&bufferSize))
|
---|
| 131 | {
|
---|
| 132 | if(buffer[1]==':' /*&& (buffer[0]>='A' && buffer[0]<='Z' )*/) {
|
---|
| 133 | buffer[2]=0;
|
---|
| 134 | strcpy(chrDrive, buffer);
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 | return CWMediaFolder::wpSetup(pSetupString);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | BOOL CWCDFolder::wpSaveState()
|
---|
| 141 | {
|
---|
| 142 |
|
---|
| 143 | wpSaveString("CWCDFolder", KEY_DRIVE, (PBYTE)&chrDrive);
|
---|
| 144 |
|
---|
| 145 | return CWMediaFolder::wpSaveState();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | BOOL CWCDFolder::wpRestoreState(ULONG ulReserved)
|
---|
| 149 | {
|
---|
| 150 | ULONG dataSize;
|
---|
| 151 |
|
---|
| 152 | chrDrive[0]=0;
|
---|
| 153 | dataSize=sizeof(chrDrive);
|
---|
| 154 | if(wpRestoreString("CWCDFolder",KEY_DRIVE,(PBYTE)&chrDrive,&dataSize))
|
---|
| 155 | chrDrive[2]=0;
|
---|
| 156 |
|
---|
| 157 | return CWMediaFolder::wpRestoreState(ulReserved);
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | ULONG CWCDFolder::wpFilterPopupMenu(ULONG ulFlags, HWND hwndCnr, BOOL fMultiSelect)
|
---|
| 161 | {
|
---|
| 162 | return CWMediaFolder::wpFilterPopupMenu(ulFlags, hwndCnr, fMultiSelect)&
|
---|
| 163 | ~(CTXT_SORT|CTXT_ARRANGE|CTXT_COPY|CTXT_ICON|CTXT_CHANGETOICON|CTXT_CHANGETOTREE|CTXT_CHANGETODETAILS);
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | ULONG CWCDFolder::wpAddObjectGeneralPage2(HWND hwndNotebook)
|
---|
| 167 | {
|
---|
| 168 | return SETTINGS_PAGE_REMOVED;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | ULONG CWCDFolder::wpAddFolderSortPage(HWND hwndNotebook)
|
---|
| 172 | {
|
---|
| 173 | return SETTINGS_PAGE_REMOVED;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | ULONG CWCDFolder::wpAddFolderIncludePage(HWND hwndNotebook)
|
---|
| 177 | {
|
---|
| 178 | return SETTINGS_PAGE_REMOVED;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | ULONG CWCDFolder::wpQueryConcurrentView()
|
---|
| 182 | {
|
---|
| 183 | /* Only one view allowed */
|
---|
| 184 | return 2;//CCVIEW_OFF
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | MRESULT CWCDFolder::wpDragOver(HWND hwndCnr,PDRAGINFO pDragInfo)
|
---|
| 188 | {
|
---|
| 189 | return MRFROM2SHORT( DOR_NEVERDROP, DO_MOVE);/* Dropping is not allowed */
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | BOOL CWCDFolder::wpRefresh(ULONG ulView, PVOID pReserved)
|
---|
| 193 | {
|
---|
| 194 | // SysWriteToTrapLog("%s: view: %d, %x, %x\n",
|
---|
| 195 | // __FUNCTION__, ulView, ulView, cwQueryMFldrFlags() );
|
---|
| 196 |
|
---|
| 197 | /* User changes the view of the CD-Folder, don't reinsert the tracks when changing from/to
|
---|
| 198 | compact view. */
|
---|
| 199 | if(ulView==OPEN_DETAILS && !(cwQueryMFldrFlags() & MFLDR_VIEW_COMPACT))
|
---|
| 200 | cwInsertAllTracks(chrDrive);
|
---|
| 201 | /* Normal refresh */
|
---|
| 202 | if(ulView==0)
|
---|
| 203 | cwInsertAllTracks(chrDrive);
|
---|
| 204 | return CWMediaFolder::wpRefresh(ulView, pReserved);
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 |
|
---|
| 208 | HWND CWCDFolder::wpOpen(HWND hwndCnr,ULONG ulView,ULONG ulParam)
|
---|
| 209 | {
|
---|
| 210 |
|
---|
| 211 | if(ulView==OPEN_CONTENTS||ulView==OPEN_TREE||ulView==OPEN_DETAILS||ulView==OPEN_DEFAULT /*|| ulView==OPEN_MMDISK*/) {
|
---|
| 212 | /* OPEN_MMDISK is a private view to indicate the folder was opened from the CD drive */
|
---|
| 213 | cwInsertAllTracks(chrDrive);
|
---|
| 214 | hwndFrameCDFldr=CWMediaFolder::wpOpen(hwndCnr, ulView, ulParam);
|
---|
| 215 |
|
---|
| 216 | if(hwndFrameCDFldr) {
|
---|
| 217 | /* We have the folder window */
|
---|
| 218 | char chrTemp[50];
|
---|
| 219 | HOBJECT hObject;
|
---|
| 220 |
|
---|
| 221 | /* Add view to drives inuse list */
|
---|
| 222 | sprintf(chrTemp,"<WP_DRIVE_%c>",chrDrive[0]);
|
---|
| 223 | if((hObject=WinQueryObject(chrTemp))!=NULLHANDLE) {
|
---|
| 224 | WPObject *wpObject;
|
---|
| 225 |
|
---|
| 226 | wpObject=((M_WPObject*)__ClassObject)->wpclsQueryObject( hObject);
|
---|
| 227 | if(somIsObj(wpObject)) {
|
---|
| 228 | diskUseItem.wpDiskObj=wpObject;
|
---|
| 229 | diskUseItem.useItem.type=USAGE_OPENVIEW;
|
---|
| 230 | memset(&diskUseItem.viewItem, 0, sizeof(VIEWITEM));
|
---|
| 231 | diskUseItem.viewItem.handle=hwndFrameCDFldr;
|
---|
| 232 | diskUseItem.viewItem.view=OPEN_DEFAULT;
|
---|
| 233 | wpObject->wpAddToObjUseList(&diskUseItem.useItem);
|
---|
| 234 | }/* somIsObj() */
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | /* Remove random checkbox for now... */
|
---|
| 238 | WinShowWindow( WinWindowFromID(playControlDialogFromFrameHWND(hwndFrameCDFldr), IDCB_RANDOM)
|
---|
| 239 | , FALSE);
|
---|
| 240 | /* Subclass frame to remove items from menubar */
|
---|
| 241 | pfnwpCDFrame=WinSubclassWindow(hwndFrameCDFldr, cdFrameProc);
|
---|
| 242 | pfnwpGenericCDFrame=pfnwpFrame;
|
---|
| 243 | }/* if(hwnd) */
|
---|
| 244 | return hwndFrameCDFldr;
|
---|
| 245 | }
|
---|
| 246 | return CWMediaFolder::wpOpen(hwndCnr, ulView, ulParam);
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | BOOL CWCDFolder::cwClose(HWND hwndFrame)
|
---|
| 250 | {
|
---|
| 251 | BOOL bRC;
|
---|
| 252 |
|
---|
| 253 | bRC=CWMediaFolder::cwClose(hwndFrame);
|
---|
| 254 |
|
---|
| 255 | if(bRC) {
|
---|
| 256 | /* User confirmed close */
|
---|
| 257 | if(somIsObj(diskUseItem.wpDiskObj)) {
|
---|
| 258 | diskUseItem.wpDiskObj->wpDeleteFromObjUseList(&diskUseItem.useItem);
|
---|
| 259 | /* The disk object is locked because of wpclQueryObject in wpOpen() */
|
---|
| 260 | diskUseItem.wpDiskObj->wpUnlockObject();
|
---|
| 261 | hwndFrameCDFldr=NULLHANDLE;
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | return bRC;
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | ULONG CWCDFolder::cwPlayAudioFile(HWND hwndFrame, ULONG ulWhich)
|
---|
| 268 | {
|
---|
| 269 | HWND hwndContainer;
|
---|
| 270 | PMINIRECORDCORE mrc, mrcTemp;
|
---|
| 271 | WPObject * contentObject;
|
---|
| 272 | WPObject * tempObject;
|
---|
| 273 | SOMClass *mmCDTrackClass;
|
---|
| 274 | char chrCommand[CCHMAXPATH*2];
|
---|
| 275 | char chrDevice[30];
|
---|
| 276 | char retMsg[20];
|
---|
| 277 | ULONG rc;
|
---|
| 278 | int iWavePriv;
|
---|
| 279 | int iTime2;
|
---|
| 280 | int iPrevTrack=0;
|
---|
| 281 |
|
---|
| 282 |
|
---|
| 283 | hwndContainer=WinWindowFromID(hwndFrame, FID_CLIENT);
|
---|
| 284 | if(!WinIsWindow(WinQueryAnchorBlock(hwndFrame), hwndContainer))
|
---|
| 285 | return 0;
|
---|
| 286 |
|
---|
| 287 | /* Get class object */
|
---|
| 288 | mmCDTrackClass=somhlpGetSomClass("MMCDTrack");
|
---|
| 289 | if(!mmCDTrackClass)
|
---|
| 290 | return 0;
|
---|
| 291 |
|
---|
| 292 | /* Get new ID for wave device */
|
---|
| 293 | if(cwRequestMutex(hmtxFileName, 100000)==ERROR_TIMEOUT)
|
---|
| 294 | return FALSE;
|
---|
| 295 | iWaveDev++;
|
---|
| 296 | if(iWaveDev==1000)
|
---|
| 297 | iWaveDev=1;
|
---|
| 298 | iWavePriv=iWaveDev;
|
---|
| 299 | cwReleaseMutex(hmtxFileName);
|
---|
| 300 |
|
---|
| 301 | BOOL notFound;
|
---|
| 302 |
|
---|
| 303 | switch(ulWhich) {
|
---|
| 304 | case PLAY_FIRST:
|
---|
| 305 | {
|
---|
| 306 |
|
---|
| 307 | /* Get first selected container item of our folder */
|
---|
| 308 | mrc=(PMINIRECORDCORE)WinSendMsg(hwndContainer,CM_QUERYRECORDEMPHASIS, MPFROMSHORT(CMA_FIRST),
|
---|
| 309 | MPFROMSHORT(CRA_SELECTED));
|
---|
| 310 |
|
---|
| 311 | if(iWave!=0 && mrc && (int)mrc!=-1) {
|
---|
| 312 |
|
---|
| 313 | cwStopAudioFile(hwndFrame);
|
---|
| 314 | return cwPlayAudioFile(hwndFrame, PLAY_FIRST);
|
---|
| 315 | }
|
---|
| 316 | if(!mrc || (int)mrc==-1)
|
---|
| 317 | /* Get first container item of our folder */
|
---|
| 318 | mrc=(PMINIRECORDCORE)WinSendMsg(hwndContainer,CM_QUERYRECORD,NULL,
|
---|
| 319 | MPFROM2SHORT(CMA_FIRST,CMA_ITEMORDER));
|
---|
| 320 |
|
---|
| 321 | if(!mrc || (int)mrc==-1)
|
---|
| 322 | return 0;
|
---|
| 323 |
|
---|
| 324 | notFound=TRUE;
|
---|
| 325 | do {
|
---|
| 326 | contentObject=(WPObject*)OBJECT_FROM_PREC(mrc);//Get object
|
---|
| 327 | if(somIsObj(contentObject)) {
|
---|
| 328 | /* Get file system object or NULL */
|
---|
| 329 | if((contentObject=cwGetFileSystemObject(contentObject))==NULLHANDLE)
|
---|
| 330 | continue;
|
---|
| 331 | tempObject=contentObject;
|
---|
| 332 | }
|
---|
| 333 | else
|
---|
| 334 | return 0;/* Error */
|
---|
| 335 |
|
---|
| 336 | if(contentObject->somIsA(mmCDTrackClass))
|
---|
| 337 | notFound=FALSE;
|
---|
| 338 | else
|
---|
| 339 | /* Try next object */
|
---|
| 340 | mrc=(PMINIRECORDCORE)WinSendMsg(hwndContainer,CM_QUERYRECORD, mrc,
|
---|
| 341 | MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
|
---|
| 342 | }while(notFound && mrc);
|
---|
| 343 | break;
|
---|
| 344 | }
|
---|
| 345 | case PLAY_NEXT:
|
---|
[4] | 346 | case PLAY_NEXT_CDFLDR:
|
---|
[2] | 347 | if(iWave==0)
|
---|
| 348 | return cwPlayAudioFile(hwndFrame, PLAY_FIRST);/* Not yet playing */
|
---|
| 349 |
|
---|
| 350 | /* We are currently playing */
|
---|
| 351 | mrcTemp=mrcPlaying;
|
---|
| 352 |
|
---|
| 353 | /* Get next container item of our folder */
|
---|
| 354 | mrc=(PMINIRECORDCORE)WinSendMsg(hwndContainer,CM_QUERYRECORD,mrcTemp,
|
---|
| 355 | MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
|
---|
| 356 |
|
---|
| 357 | if(!mrc || (int)mrc==-1)
|
---|
| 358 | return 0;
|
---|
| 359 |
|
---|
| 360 | notFound=TRUE;
|
---|
| 361 | while(notFound && mrc && (int)mrc!=-1){
|
---|
| 362 | contentObject=(WPObject*)OBJECT_FROM_PREC(mrc);//Get object
|
---|
| 363 | if(somIsObj(contentObject)) {
|
---|
| 364 | /* Get file system object or NULL */
|
---|
| 365 | if((contentObject=cwGetFileSystemObject(contentObject))==NULLHANDLE)
|
---|
| 366 | continue;
|
---|
| 367 | tempObject=contentObject;
|
---|
| 368 | }
|
---|
| 369 | else
|
---|
| 370 | return 0;/* Error */
|
---|
| 371 |
|
---|
| 372 | if(contentObject->somIsA(mmCDTrackClass))
|
---|
| 373 | notFound=FALSE;
|
---|
| 374 | else
|
---|
| 375 | /* Try next object */
|
---|
| 376 | mrc=(PMINIRECORDCORE)WinSendMsg(hwndContainer,CM_QUERYRECORD, mrc,
|
---|
| 377 | MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
|
---|
| 378 | };
|
---|
| 379 |
|
---|
| 380 | /* Remove from inuse list */
|
---|
| 381 | if(myViewItem.bIsInUseList)
|
---|
| 382 | {
|
---|
| 383 | WPObject *wpObject=cwGetFileSystemObject(currentObject);
|
---|
| 384 | if(wpObject->wpDeleteFromObjUseList(&myViewItem.useItem))
|
---|
| 385 | myViewItem.bIsInUseList=FALSE;
|
---|
| 386 | };
|
---|
| 387 |
|
---|
| 388 | /* Deselect the object */
|
---|
| 389 | if(WinIsWindow(WinQueryAnchorBlock(hwndFrame), hwndContainer))
|
---|
| 390 | WinSendMsg(hwndContainer,CM_SETRECORDEMPHASIS, MPFROMP(mrcPlaying),
|
---|
| 391 | MPFROM2SHORT(FALSE, CRA_SELECTED));
|
---|
| 392 |
|
---|
| 393 | if(!mrc) {
|
---|
| 394 | if(ulFlags & FLAG_REPEAT)
|
---|
| 395 | return cwPlayAudioFile(hwndFrame, PLAY_FIRST);
|
---|
| 396 | else {
|
---|
| 397 | cwStopAudioFile(hwndFrame);
|
---|
| 398 | return 0;
|
---|
| 399 | }
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | break;
|
---|
| 403 | case PLAY_PREV:
|
---|
| 404 |
|
---|
| 405 | if(iWave==0)
|
---|
| 406 | return cwPlayAudioFile(hwndFrame, PLAY_FIRST);/* Not yet playing, so start the first one. */
|
---|
| 407 |
|
---|
| 408 | /* We are currently playing */
|
---|
| 409 | mrcTemp=mrcPlaying;
|
---|
| 410 | /* Check the current time. If we are at the very beginning of the track skip to the previous track
|
---|
| 411 | otherwise skip to the beginning of the current track. */
|
---|
| 412 | if(ulPos<=2) {
|
---|
| 413 | /* Get previous container item of our folder */
|
---|
| 414 | mrc=(PMINIRECORDCORE)WinSendMsg(hwndContainer,CM_QUERYRECORD,mrcTemp,
|
---|
| 415 | MPFROM2SHORT(CMA_PREV,CMA_ITEMORDER));
|
---|
| 416 | }
|
---|
| 417 | else
|
---|
| 418 | mrc=NULLHANDLE;
|
---|
| 419 |
|
---|
| 420 | cwStopAudioFile(hwndFrame);
|
---|
| 421 | if(!mrc)
|
---|
| 422 | mrc=mrcTemp;
|
---|
| 423 |
|
---|
| 424 | /* Find an audio file */
|
---|
| 425 | notFound=TRUE;
|
---|
| 426 | while(notFound && mrc && (int)mrc!=-1){
|
---|
| 427 | contentObject=(WPObject*)OBJECT_FROM_PREC(mrc);//Get object
|
---|
| 428 | if(somIsObj(contentObject)) {
|
---|
| 429 | /* Get file system object or NULL */
|
---|
| 430 | if((contentObject=cwGetFileSystemObject(contentObject))==NULLHANDLE)
|
---|
| 431 | continue;
|
---|
| 432 | tempObject=contentObject;
|
---|
| 433 | }
|
---|
| 434 | else
|
---|
| 435 | return 0;/* Error!! */
|
---|
| 436 |
|
---|
| 437 | /* Check if it's an audio file thus playable */
|
---|
| 438 | if(contentObject->somIsA(mmCDTrackClass))
|
---|
| 439 | notFound=FALSE;
|
---|
| 440 | else
|
---|
| 441 | /* Try next object */
|
---|
| 442 | mrc=(PMINIRECORDCORE)WinSendMsg(hwndContainer,CM_QUERYRECORD, mrc,
|
---|
| 443 | MPFROM2SHORT(CMA_PREV,CMA_ITEMORDER));
|
---|
| 444 | };
|
---|
| 445 | if(!mrc)
|
---|
| 446 | return 0;
|
---|
| 447 |
|
---|
| 448 | break;
|
---|
| 449 | default:
|
---|
| 450 | return 0;
|
---|
| 451 | }/* switch */
|
---|
| 452 |
|
---|
[4] | 453 | // if(ulWhich!=PLAY_NEXT_CDFLDR) {
|
---|
| 454 | if(!getMessage(chrCommand, IDSTR_STARTINGTRACK, sizeof(chrCommand), queryResModuleHandle(), hwndFrame))
|
---|
| 455 | sprintf(chrCommand, "Starting track...");
|
---|
| 456 | setPlayTimeText2(this, chrCommand);
|
---|
| 457 | // }
|
---|
[2] | 458 |
|
---|
[142] | 459 | strncpy(chrDevice,"CDAUDIO", sizeof(chrDevice) - 1);
|
---|
[2] | 460 |
|
---|
| 461 | PSZ pszObjectID;
|
---|
| 462 | if((pszObjectID=wpQueryObjectID())!=NULLHANDLE) {
|
---|
| 463 | int iNumCD;
|
---|
| 464 | char chrFirstCD;
|
---|
| 465 |
|
---|
| 466 | strncpy(chrCommand, pszObjectID,sizeof(chrCommand));
|
---|
| 467 | chrCommand[sizeof(chrCommand)-1]=0;
|
---|
| 468 | if(CDQueryCDDrives(&iNumCD, &chrFirstCD))
|
---|
| 469 | sprintf(chrDevice,"CDAUDIO%02d", chrCommand[strlen(chrCommand)-2]-chrFirstCD+1);
|
---|
| 470 | }
|
---|
| 471 |
|
---|
| 472 | chrDevice[sizeof(chrDevice)-1]=0;
|
---|
| 473 |
|
---|
| 474 | /* Get track num */
|
---|
| 475 | if(!methodPtrCDTrack)
|
---|
| 476 | somhlpQueryCWCDTrackMethodPtr(this);
|
---|
| 477 | if(methodPtrCDTrack)
|
---|
| 478 | iTime2=methodPtrCDTrack((MMCDTrack*)contentObject, NULLHANDLE, 0, IDINFO_TRACKNUM);
|
---|
| 479 | if(methodPtrCDTrack && currentObject)
|
---|
| 480 | iPrevTrack=methodPtrCDTrack((MMCDTrack*)currentObject, NULLHANDLE, 0, IDINFO_TRACKNUM);
|
---|
| 481 |
|
---|
| 482 | // HlpWriteToTrapLog("PrevTrack: %d new track: %d\n", iPrevTrack, iTime2);
|
---|
| 483 |
|
---|
| 484 | if(iPrevTrack+1!=iTime2 || !mrcPlaying) {
|
---|
| 485 | iWave=iWavePriv;
|
---|
| 486 |
|
---|
[62] | 487 | /* Start audio file */
|
---|
[2] | 488 | sprintf(chrCommand,"open \"%s\" alias wave%d SHAREABLE wait", chrDevice, iWavePriv);
|
---|
| 489 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), playControlDialogFromFrameHWND(hwndFrame), 0);
|
---|
| 490 |
|
---|
| 491 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS)
|
---|
[62] | 492 | return 0;
|
---|
[2] | 493 |
|
---|
[62] | 494 | /* enable the "digital transfer" connector */
|
---|
| 495 | sprintf(chrCommand,"CONNECTOR wave%d ENABLE TYPE CD stream WAIT", iWavePriv);
|
---|
| 496 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), playControlDialogFromFrameHWND(hwndFrame), 0);
|
---|
| 497 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS)
|
---|
| 498 | return 0;
|
---|
| 499 |
|
---|
[2] | 500 | /* Set volume */
|
---|
| 501 | sprintf(chrCommand,"SET wave%d AUDIO VOLUME %d wait", iWavePriv, ulVolume);
|
---|
| 502 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 503 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
| 504 | sprintf(chrCommand,"close wave%d",iWavePriv);
|
---|
| 505 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 506 | return 0;
|
---|
| 507 | }
|
---|
| 508 |
|
---|
| 509 | sprintf(chrCommand,"SET wave%d TIME FORMAT TMSF wait", iWavePriv);
|
---|
| 510 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 511 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
| 512 | sprintf(chrCommand,"close wave%d wait",iWavePriv);
|
---|
| 513 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 514 | return 0;
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | //sprintf(chrCommand,"play wave%d FROM %d TO %d", iWavePriv, iTime2, iTime2+1);
|
---|
| 518 | sprintf(chrCommand,"play wave%d FROM %d ", iWavePriv, iTime2);
|
---|
| 519 | // HlpWriteToTrapLog(chrCommand);
|
---|
| 520 | // HlpWriteToTrapLog("\niTime2: %d\n", iTime2);
|
---|
| 521 |
|
---|
| 522 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 523 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
| 524 | sprintf(chrCommand,"close wave%d",iWavePriv);
|
---|
| 525 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 526 | return 0;
|
---|
| 527 | }
|
---|
| 528 | }/* if( ...|| !mrcPlaying) */
|
---|
| 529 |
|
---|
[4] | 530 | if(iPrevTrack+1==iTime2 && ulWhich!=PLAY_NEXT_CDFLDR) {
|
---|
[2] | 531 | /* Previous track ended, now playing the next. Or user pressed 'Next' while playing */
|
---|
| 532 | if(ulPos*1000 < ulTotalLength) {
|
---|
| 533 | WinStopTimer(WinQueryAnchorBlock(hwndFrame), playControlDialogFromFrameHWND(hwndFrame), IDTIMER_PLAY);
|
---|
| 534 | sprintf(chrCommand,"SET wave%d TIME FORMAT TMSF wait", iWave);
|
---|
| 535 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 536 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
| 537 | sprintf(chrCommand,"close wave%d wait",iWave);
|
---|
| 538 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 539 | return 0;
|
---|
| 540 | }
|
---|
| 541 |
|
---|
| 542 | sprintf(chrCommand,"play wave%d FROM %d ", iWave, iTime2);
|
---|
| 543 | // HlpWriteToTrapLog(chrCommand);
|
---|
| 544 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 545 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
| 546 | sprintf(chrCommand,"close wave%d",iWavePriv);
|
---|
| 547 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 548 | return 0;
|
---|
| 549 | }
|
---|
| 550 | }
|
---|
| 551 | }
|
---|
| 552 |
|
---|
| 553 | /* Get length in ms */
|
---|
| 554 | if(!methodPtrCDTrack)
|
---|
| 555 | somhlpQueryCWCDTrackMethodPtr(this);
|
---|
| 556 | if(methodPtrCDTrack){ /* Query playtime in secs */
|
---|
| 557 | iTime2=methodPtrCDTrack((MMCDTrack*)contentObject, NULLHANDLE, 0, IDINFO_PLAYTIME);
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 | sprintf(chrCommand,"%d:%02d %d:%02d -%d:%02d", iTime2/60, iTime2%60,
|
---|
| 561 | 0, 0,
|
---|
| 562 | iTime2/60, iTime2%60);
|
---|
| 563 |
|
---|
| 564 |
|
---|
| 565 | // WinSetWindowText(WinWindowFromID(hwndTop, IDST_PLAYTIME), chrCommand);
|
---|
| 566 | // WinSetWindowText(playTimeControlFromFrameHWND(HWND hwndFrame), chrCommand);
|
---|
| 567 | ulTotalLength=iTime2*1000; /* convert to ms */
|
---|
| 568 | // HlpWriteToTrapLog("ulTotalLength: %d\n", ulTotalLength);
|
---|
| 569 |
|
---|
| 570 | /* Set emphasis by adding the object to the inuse list */
|
---|
| 571 | memset(&myViewItem, 0,sizeof(myViewItem));
|
---|
| 572 | myViewItem.useItem.type=USAGE_OPENVIEW;
|
---|
| 573 | myViewItem.viewItem.view=OPEN_PLAYING;
|
---|
| 574 |
|
---|
| 575 | // HlpWriteToTrapLog("Adding to inuse list\n");
|
---|
| 576 | WPObject* wpObject=cwGetFileSystemObject(tempObject);
|
---|
| 577 | // HlpWriteToTrapLog("wpObject: %x somIsObj(wpObject): %x \n", wpObject, somIsObj(wpObject));
|
---|
| 578 |
|
---|
| 579 |
|
---|
| 580 | if(!myViewItem.bIsInUseList) {
|
---|
| 581 | if(wpObject->wpAddToObjUseList(&myViewItem.useItem))
|
---|
| 582 | myViewItem.bIsInUseList=TRUE;
|
---|
| 583 | };
|
---|
| 584 |
|
---|
| 585 | /* Select the object */
|
---|
| 586 | WinSendMsg(hwndContainer,CM_SETRECORDEMPHASIS, MPFROMP(mrc),
|
---|
| 587 | MPFROM2SHORT(TRUE, CRA_SELECTED));
|
---|
| 588 |
|
---|
| 589 | /* Start pos timer. SET MCIPOSITIONADVICE fails when seeking in the wave.
|
---|
| 590 | Don't know why. */
|
---|
| 591 | WinStartTimer(WinQueryAnchorBlock(hwndFrame), playControlDialogFromFrameHWND(hwndFrame),
|
---|
| 592 | IDTIMER_PLAY, PLAYTIMER_DELAY);
|
---|
| 593 |
|
---|
| 594 | currentObject=wpObject;
|
---|
| 595 | mrcPlaying=mrc;
|
---|
| 596 | /* The start position of the play command */
|
---|
| 597 | ulStartPosition=0;
|
---|
| 598 | ulPos=0;
|
---|
| 599 | bPaused=FALSE;
|
---|
| 600 | return 0;
|
---|
| 601 | }
|
---|
| 602 |
|
---|
| 603 |
|
---|
| 604 | BOOL CWCDFolder::cwSeekAudioFile(LONG lPosMSSec)
|
---|
| 605 | {
|
---|
| 606 | char chrCommand[50];
|
---|
| 607 | char retMsg[20];
|
---|
| 608 | APIRET rc;
|
---|
| 609 | int iCurrentTrack;
|
---|
| 610 | ULONG ulPosTrack;
|
---|
| 611 |
|
---|
| 612 | sprintf(chrCommand,"SET wave%d TIME FORMAT MS wait", iWave);
|
---|
| 613 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 614 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
| 615 | return 0;
|
---|
| 616 | }
|
---|
| 617 |
|
---|
| 618 | sprintf(chrCommand,"STATUS wave%d CURRENT TRACK WAIT", iWave);
|
---|
| 619 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 620 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
| 621 | return FALSE;
|
---|
| 622 | }
|
---|
| 623 | iCurrentTrack=atoi(retMsg);
|
---|
| 624 |
|
---|
| 625 | sprintf(chrCommand,"STATUS wave%d POSITION TRACK %d WAIT", iWave, iCurrentTrack);
|
---|
| 626 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 627 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
| 628 | /* Problem with MCI. Clean up. The Timer will be stopped in the method */
|
---|
| 629 | return FALSE;
|
---|
| 630 | }
|
---|
| 631 | ulPosTrack=atoi(retMsg);
|
---|
| 632 |
|
---|
| 633 | sprintf(chrCommand,"PLAY wave%d from %d ", iWave, lPosMSSec+ulPosTrack);
|
---|
| 634 | rc=mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 635 | ulStartPosition=lPosMSSec/1000;
|
---|
| 636 | bPaused=FALSE;
|
---|
| 637 |
|
---|
| 638 | #if 0
|
---|
| 639 | sprintf(chrCommand,"STATUS wave%d POSITION IN TRACK WAIT", iWave);
|
---|
| 640 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 641 | if((rc & 0x0000ffff)==MCIERR_SUCCESS) {
|
---|
| 642 | /* Problem with MCI. Clean up. The Timer will be stopped in the method */
|
---|
| 643 | ulPos=atoi(retMsg)/1000;
|
---|
| 644 | }
|
---|
| 645 | #endif
|
---|
| 646 |
|
---|
| 647 | ulPos=lPosMSSec/1000;
|
---|
| 648 |
|
---|
| 649 | sprintf(chrCommand,"SET wave%d TIME FORMAT TMSF wait", iWave);
|
---|
| 650 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 651 |
|
---|
| 652 | return TRUE;
|
---|
| 653 | }
|
---|
| 654 |
|
---|
| 655 | void CWCDFolder::cwPlayTimeCallback(HWND hwndFrame, LONG lPosSec)
|
---|
| 656 | {
|
---|
| 657 | char chrCommand[50];
|
---|
| 658 | char retMsg[20];
|
---|
| 659 | ULONG rc;
|
---|
| 660 | int iPrevTrack;
|
---|
| 661 | int iCurrentTrack;
|
---|
| 662 |
|
---|
[4] | 663 | //SysWriteToTrapLog("\n%s:\n", __FUNCTION__);
|
---|
| 664 |
|
---|
[2] | 665 | sprintf(chrCommand,"STATUS wave%d MODE WAIT", iWave);
|
---|
| 666 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 667 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
| 668 | /* Problem with MCI. Clean up. The Timer will be stopped in the method */
|
---|
| 669 | cwStopAudioFile(hwndFrame);
|
---|
| 670 | return;
|
---|
| 671 | }
|
---|
| 672 | else
|
---|
| 673 | if(!stricmp(retMsg, "stopped")) {
|
---|
| 674 | /* Audio file played. Start next */
|
---|
| 675 | cwPlayAudioFile(hwndFrame, PLAY_NEXT);
|
---|
| 676 | showPlayTimeDisplay(this, TRUE);/* Ensure display is visible */
|
---|
| 677 | return;
|
---|
| 678 | }
|
---|
| 679 |
|
---|
| 680 | /* Get track num */
|
---|
| 681 | if(!methodPtrCDTrack)
|
---|
| 682 | somhlpQueryCWCDTrackMethodPtr(this);
|
---|
| 683 | if(methodPtrCDTrack && currentObject)
|
---|
| 684 | iPrevTrack=methodPtrCDTrack((MMCDTrack*)currentObject, NULLHANDLE, 0, IDINFO_TRACKNUM);
|
---|
| 685 |
|
---|
| 686 | sprintf(chrCommand,"STATUS wave%d CURRENT TRACK WAIT", iWave);
|
---|
| 687 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 688 | // HlpWriteToTrapLog("Track: %d, retmsg: %s\n", iPrevTrack, retMsg);
|
---|
| 689 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
| 690 | /* Problem with MCI. Clean up. The Timer will be stopped in the method */
|
---|
| 691 | cwStopAudioFile(hwndFrame);
|
---|
| 692 | }
|
---|
| 693 | else {
|
---|
| 694 | iCurrentTrack=atoi(retMsg);
|
---|
[4] | 695 | //SysWriteToTrapLog(" iWave: %d. iPrevTrack: %d, iCurrentrack: %d\n", iWave, iPrevTrack, iCurrentTrack);
|
---|
[2] | 696 | /* Timeout. Check if track is still playing */
|
---|
| 697 | if(iCurrentTrack==iPrevTrack+1) {
|
---|
| 698 | /* Audio file played. Start next */
|
---|
[4] | 699 | //SysWriteToTrapLog(" iWave: %d. iPrevTrack: %d, iCurrentrack: %d, startinb next (%d)\n", iWave, iPrevTrack, iCurrentTrack, __LINE__);
|
---|
| 700 | cwPlayAudioFile(hwndFrame, PLAY_NEXT_CDFLDR);
|
---|
[2] | 701 | }
|
---|
| 702 | }
|
---|
| 703 | }
|
---|
| 704 |
|
---|
| 705 |
|
---|
| 706 |
|
---|