source: trunk/mediafolder/c/cdfldr/cdfolderoverriddenwpmethods.cpp@ 4

Last change on this file since 4 was 4, checked in by stevenhl, 8 years ago

Import modifications from cwmm-0_2_9-work-01_10_2006.zip dated 2006-08-27

File size: 23.2 KB
Line 
1/*
2 * This file is (C) Chris Wohlgemuth 2002-2005
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
32extern HMTX hmtxFileName;
33extern int iWaveDev;
34PFNWP 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. */
39typedef ULONG SOMLINK somTP_MMCDTrack_cwmmQueryTrackInfo(MMCDTrack *somSelf,
40 char** chrString,
41 ULONG ulSize,
42 int iWhich);
43typedef somTP_MMCDTrack_cwmmQueryTrackInfo *somTD_MMCDTrack_cwmmQueryTrackInfo;
44extern somTD_MMCDTrack_cwmmQueryTrackInfo methodPtrCDTrack;
45
46BOOL extern CDQueryCDDrives(int *iNumCD, char * cFirstDrive);
47
48BOOL getMessage(char* text,ULONG ulID, LONG lSizeText, HMODULE hResource,HWND hwnd);
49HMODULE queryResModuleHandle(void);
50
51ULONG cwRequestMutex(HMTX hmtxBMP, ULONG ulTimeOut);
52ULONG cwReleaseMutex(HMTX hmtxBMP);
53
54SOMClass* somhlpGetSomClass(char* chrClassName);
55extern BOOL somhlpQueryCWCDTrackMethodPtr(CWMediaFolder *thisPtr);
56MRESULT EXPENTRY cdFrameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
57extern void showPlayTimeDisplay(CWMediaFolder *thisPtr, BOOL bShow);
58void setPlayTimeText2(CWMediaFolder *thisPtr, char * theText);
59
60/* Get the HWND of the play control dialog. This Dialog is on top of
61 the top frame control. */
62HWND playControlDialogFromFrameHWND(HWND hwndFrame);
63
64
65BOOL 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
119BOOL 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
140BOOL CWCDFolder::wpSaveState()
141{
142
143 wpSaveString("CWCDFolder", KEY_DRIVE, (PBYTE)&chrDrive);
144
145 return CWMediaFolder::wpSaveState();
146}
147
148BOOL 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
160ULONG 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
166ULONG CWCDFolder::wpAddObjectGeneralPage2(HWND hwndNotebook)
167{
168 return SETTINGS_PAGE_REMOVED;
169}
170
171ULONG CWCDFolder::wpAddFolderSortPage(HWND hwndNotebook)
172{
173 return SETTINGS_PAGE_REMOVED;
174}
175
176ULONG CWCDFolder::wpAddFolderIncludePage(HWND hwndNotebook)
177{
178 return SETTINGS_PAGE_REMOVED;
179}
180
181ULONG CWCDFolder::wpQueryConcurrentView()
182{
183 /* Only one view allowed */
184 return 2;//CCVIEW_OFF
185}
186
187MRESULT CWCDFolder::wpDragOver(HWND hwndCnr,PDRAGINFO pDragInfo)
188{
189 return MRFROM2SHORT( DOR_NEVERDROP, DO_MOVE);/* Dropping is not allowed */
190}
191
192BOOL 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
208HWND 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
249BOOL 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
267ULONG 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:
346 case PLAY_NEXT_CDFLDR:
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
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 // }
458
459 strncpy(chrDevice,"CDAUDIO", sizeof(chrDevice));
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
487 /* Start audio file */
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)
492 return 0;
493
494 /* Set volume */
495 sprintf(chrCommand,"SET wave%d AUDIO VOLUME %d wait", iWavePriv, ulVolume);
496 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
497 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
498 sprintf(chrCommand,"close wave%d",iWavePriv);
499 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
500 return 0;
501 }
502
503 sprintf(chrCommand,"SET wave%d TIME FORMAT TMSF wait", iWavePriv);
504 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
505 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
506 sprintf(chrCommand,"close wave%d wait",iWavePriv);
507 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
508 return 0;
509 }
510
511 //sprintf(chrCommand,"play wave%d FROM %d TO %d", iWavePriv, iTime2, iTime2+1);
512 sprintf(chrCommand,"play wave%d FROM %d ", iWavePriv, iTime2);
513 // HlpWriteToTrapLog(chrCommand);
514 // HlpWriteToTrapLog("\niTime2: %d\n", iTime2);
515
516 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
517 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
518 sprintf(chrCommand,"close wave%d",iWavePriv);
519 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
520 return 0;
521 }
522 }/* if( ...|| !mrcPlaying) */
523
524 if(iPrevTrack+1==iTime2 && ulWhich!=PLAY_NEXT_CDFLDR) {
525 /* Previous track ended, now playing the next. Or user pressed 'Next' while playing */
526 if(ulPos*1000 < ulTotalLength) {
527 WinStopTimer(WinQueryAnchorBlock(hwndFrame), playControlDialogFromFrameHWND(hwndFrame), IDTIMER_PLAY);
528 sprintf(chrCommand,"SET wave%d TIME FORMAT TMSF wait", iWave);
529 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
530 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
531 sprintf(chrCommand,"close wave%d wait",iWave);
532 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
533 return 0;
534 }
535
536 sprintf(chrCommand,"play wave%d FROM %d ", iWave, iTime2);
537 // HlpWriteToTrapLog(chrCommand);
538 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
539 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
540 sprintf(chrCommand,"close wave%d",iWavePriv);
541 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
542 return 0;
543 }
544 }
545 }
546
547 /* Get length in ms */
548 if(!methodPtrCDTrack)
549 somhlpQueryCWCDTrackMethodPtr(this);
550 if(methodPtrCDTrack){ /* Query playtime in secs */
551 iTime2=methodPtrCDTrack((MMCDTrack*)contentObject, NULLHANDLE, 0, IDINFO_PLAYTIME);
552 }
553
554 sprintf(chrCommand,"%d:%02d %d:%02d -%d:%02d", iTime2/60, iTime2%60,
555 0, 0,
556 iTime2/60, iTime2%60);
557
558
559 // WinSetWindowText(WinWindowFromID(hwndTop, IDST_PLAYTIME), chrCommand);
560 // WinSetWindowText(playTimeControlFromFrameHWND(HWND hwndFrame), chrCommand);
561 ulTotalLength=iTime2*1000; /* convert to ms */
562 // HlpWriteToTrapLog("ulTotalLength: %d\n", ulTotalLength);
563
564 /* Set emphasis by adding the object to the inuse list */
565 memset(&myViewItem, 0,sizeof(myViewItem));
566 myViewItem.useItem.type=USAGE_OPENVIEW;
567 myViewItem.viewItem.view=OPEN_PLAYING;
568
569 // HlpWriteToTrapLog("Adding to inuse list\n");
570 WPObject* wpObject=cwGetFileSystemObject(tempObject);
571 // HlpWriteToTrapLog("wpObject: %x somIsObj(wpObject): %x \n", wpObject, somIsObj(wpObject));
572
573
574 if(!myViewItem.bIsInUseList) {
575 if(wpObject->wpAddToObjUseList(&myViewItem.useItem))
576 myViewItem.bIsInUseList=TRUE;
577 };
578
579 /* Select the object */
580 WinSendMsg(hwndContainer,CM_SETRECORDEMPHASIS, MPFROMP(mrc),
581 MPFROM2SHORT(TRUE, CRA_SELECTED));
582
583 /* Start pos timer. SET MCIPOSITIONADVICE fails when seeking in the wave.
584 Don't know why. */
585 WinStartTimer(WinQueryAnchorBlock(hwndFrame), playControlDialogFromFrameHWND(hwndFrame),
586 IDTIMER_PLAY, PLAYTIMER_DELAY);
587
588 currentObject=wpObject;
589 mrcPlaying=mrc;
590 /* The start position of the play command */
591 ulStartPosition=0;
592 ulPos=0;
593 bPaused=FALSE;
594 return 0;
595}
596
597
598BOOL CWCDFolder::cwSeekAudioFile(LONG lPosMSSec)
599{
600 char chrCommand[50];
601 char retMsg[20];
602 APIRET rc;
603 int iCurrentTrack;
604 ULONG ulPosTrack;
605
606 sprintf(chrCommand,"SET wave%d TIME FORMAT MS wait", iWave);
607 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
608 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
609 return 0;
610 }
611
612 sprintf(chrCommand,"STATUS wave%d CURRENT TRACK WAIT", iWave);
613 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
614 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
615 return FALSE;
616 }
617 iCurrentTrack=atoi(retMsg);
618
619 sprintf(chrCommand,"STATUS wave%d POSITION TRACK %d WAIT", iWave, iCurrentTrack);
620 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
621 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
622 /* Problem with MCI. Clean up. The Timer will be stopped in the method */
623 return FALSE;
624 }
625 ulPosTrack=atoi(retMsg);
626
627 sprintf(chrCommand,"PLAY wave%d from %d ", iWave, lPosMSSec+ulPosTrack);
628 rc=mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
629 ulStartPosition=lPosMSSec/1000;
630 bPaused=FALSE;
631
632#if 0
633 sprintf(chrCommand,"STATUS wave%d POSITION IN TRACK WAIT", iWave);
634 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
635 if((rc & 0x0000ffff)==MCIERR_SUCCESS) {
636 /* Problem with MCI. Clean up. The Timer will be stopped in the method */
637 ulPos=atoi(retMsg)/1000;
638 }
639#endif
640
641 ulPos=lPosMSSec/1000;
642
643 sprintf(chrCommand,"SET wave%d TIME FORMAT TMSF wait", iWave);
644 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
645
646 return TRUE;
647}
648
649void CWCDFolder::cwPlayTimeCallback(HWND hwndFrame, LONG lPosSec)
650{
651 char chrCommand[50];
652 char retMsg[20];
653 ULONG rc;
654 int iPrevTrack;
655 int iCurrentTrack;
656
657 //SysWriteToTrapLog("\n%s:\n", __FUNCTION__);
658
659 sprintf(chrCommand,"STATUS wave%d MODE WAIT", iWave);
660 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
661 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
662 /* Problem with MCI. Clean up. The Timer will be stopped in the method */
663 cwStopAudioFile(hwndFrame);
664 return;
665 }
666 else
667 if(!stricmp(retMsg, "stopped")) {
668 /* Audio file played. Start next */
669 cwPlayAudioFile(hwndFrame, PLAY_NEXT);
670 showPlayTimeDisplay(this, TRUE);/* Ensure display is visible */
671 return;
672 }
673
674 /* Get track num */
675 if(!methodPtrCDTrack)
676 somhlpQueryCWCDTrackMethodPtr(this);
677 if(methodPtrCDTrack && currentObject)
678 iPrevTrack=methodPtrCDTrack((MMCDTrack*)currentObject, NULLHANDLE, 0, IDINFO_TRACKNUM);
679
680 sprintf(chrCommand,"STATUS wave%d CURRENT TRACK WAIT", iWave);
681 rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
682 // HlpWriteToTrapLog("Track: %d, retmsg: %s\n", iPrevTrack, retMsg);
683 if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
684 /* Problem with MCI. Clean up. The Timer will be stopped in the method */
685 cwStopAudioFile(hwndFrame);
686 }
687 else {
688 iCurrentTrack=atoi(retMsg);
689 //SysWriteToTrapLog(" iWave: %d. iPrevTrack: %d, iCurrentrack: %d\n", iWave, iPrevTrack, iCurrentTrack);
690 /* Timeout. Check if track is still playing */
691 if(iCurrentTrack==iPrevTrack+1) {
692 /* Audio file played. Start next */
693 //SysWriteToTrapLog(" iWave: %d. iPrevTrack: %d, iCurrentrack: %d, startinb next (%d)\n", iWave, iPrevTrack, iCurrentTrack, __LINE__);
694 cwPlayAudioFile(hwndFrame, PLAY_NEXT_CDFLDR);
695 }
696 }
697}
698
699
700
Note: See TracBrowser for help on using the repository browser.