| 1 | /* | 
|---|
| 2 | * mmplayer.c (C) Chris Wohlgemuth 2002-2003 | 
|---|
| 3 | * | 
|---|
| 4 | */ | 
|---|
| 5 | /* | 
|---|
| 6 | * This program is free software; you can redistribute it and/or modify | 
|---|
| 7 | * it under the terms of the GNU General Public License as published by | 
|---|
| 8 | * the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 9 | * any later version. | 
|---|
| 10 | * | 
|---|
| 11 | * This program is distributed in the hope that it will be useful, | 
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 14 | * GNU General Public License for more details. | 
|---|
| 15 | * | 
|---|
| 16 | * You should have received a copy of the GNU General Public License | 
|---|
| 17 | * along with this program; see the file COPYING.  If not, write to | 
|---|
| 18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
| 19 | */ | 
|---|
| 20 | /* | 
|---|
| 21 | * If you need another license for your project/product (commercial, | 
|---|
| 22 | * noncommercial, whatever) contact me at | 
|---|
| 23 | * | 
|---|
| 24 | * http://www.os2world.com/cdwriting | 
|---|
| 25 | * http://www.geocities.com/SiliconValley/Sector/5785/ | 
|---|
| 26 | * | 
|---|
| 27 | */ | 
|---|
| 28 |  | 
|---|
| 29 | #define INCL_DOS | 
|---|
| 30 | #define INCL_DOSFILEMGR | 
|---|
| 31 | #define INCL_DOSERRORS | 
|---|
| 32 | #define INCL_WIN | 
|---|
| 33 | #define INCL_OS2MM | 
|---|
| 34 | #define INCL_MMIOOS2 | 
|---|
| 35 | #define INCL_MCIOS2 | 
|---|
| 36 | #define INCL_GPI | 
|---|
| 37 | #define INCL_PM | 
|---|
| 38 |  | 
|---|
| 39 | #include <os2.h> | 
|---|
| 40 |  | 
|---|
| 41 | #include <sys\types.h> | 
|---|
| 42 | #include <sys\stat.h> | 
|---|
| 43 | #include <stdio.h> | 
|---|
| 44 | #include <string.h> | 
|---|
| 45 | #include <stdlib.h> | 
|---|
| 46 | #include "os2me.h" | 
|---|
| 47 | #include "common.h" | 
|---|
| 48 | #include "mmplayerres.h" | 
|---|
| 49 | #include "mmplayer.h" | 
|---|
| 50 |  | 
|---|
| 51 | /* The object window controling the trac playing */ | 
|---|
| 52 | HWND hwndPlayObject; | 
|---|
| 53 | extern PID ulPid; | 
|---|
| 54 | /* TRUE when track is playing */ | 
|---|
| 55 | extern BOOL bIsPlaying; | 
|---|
| 56 | /* TRUE when track is paused */ | 
|---|
| 57 | extern BOOL bPaused; | 
|---|
| 58 | /* Current time in track */ | 
|---|
| 59 | extern ULONG ulPos; | 
|---|
| 60 | extern ULONG ulTotalLength; | 
|---|
| 61 | extern BOOL bIsMidi; | 
|---|
| 62 | extern ULONG ulVolume; | 
|---|
| 63 |  | 
|---|
| 64 | extern char chrSourceName[CCHMAXPATH]; | 
|---|
| 65 |  | 
|---|
| 66 | void showPlayTimeDisplay(HWND hwndFrame, BOOL bShow); | 
|---|
| 67 | void _resetDisplay(HWND hwndFrame); | 
|---|
| 68 | void setPlayTimeText2( HWND hwndDialog, char * theText); | 
|---|
| 69 |  | 
|---|
| 70 | BOOL pauseAudioFile(HWND hwndFrame) | 
|---|
| 71 | { | 
|---|
| 72 | int iWavePriv; | 
|---|
| 73 | char chrCommand[50]; | 
|---|
| 74 | char retMsg[100]; | 
|---|
| 75 | ULONG rc; | 
|---|
| 76 |  | 
|---|
| 77 | iWavePriv=ulPid; | 
|---|
| 78 |  | 
|---|
| 79 | if(bPaused) { | 
|---|
| 80 | sprintf(chrCommand,"RESUME wave%d wait", iWavePriv); | 
|---|
| 81 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 82 | bPaused=FALSE; | 
|---|
| 83 | showPlayTimeDisplay( hwndFrame, TRUE); | 
|---|
| 84 | } | 
|---|
| 85 | else { | 
|---|
| 86 | sprintf(chrCommand,"PAUSE wave%d wait", iWavePriv); | 
|---|
| 87 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 88 | bPaused=TRUE; | 
|---|
| 89 | } | 
|---|
| 90 | return TRUE; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | BOOL stopAudioFile(HWND hwndFrame) | 
|---|
| 94 | { | 
|---|
| 95 | int iWavePriv; | 
|---|
| 96 | char chrCommand[50]; | 
|---|
| 97 | char retMsg[100]; | 
|---|
| 98 | ULONG rc; | 
|---|
| 99 |  | 
|---|
| 100 | iWavePriv=ulPid; | 
|---|
| 101 |  | 
|---|
| 102 | if(bIsPlaying) { | 
|---|
| 103 | sprintf(chrCommand,"stop wave%d wait", iWavePriv); | 
|---|
| 104 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 105 |  | 
|---|
| 106 | sprintf(chrCommand,"close wave%d wait", iWavePriv); | 
|---|
| 107 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 108 |  | 
|---|
| 109 | _resetDisplay(hwndFrame); | 
|---|
| 110 | showPlayTimeDisplay( hwndFrame, TRUE); | 
|---|
| 111 | WinStopTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY); | 
|---|
| 112 | bIsPlaying=FALSE; | 
|---|
| 113 | bPaused=FALSE; | 
|---|
| 114 | } | 
|---|
| 115 | return TRUE; | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 | ULONG playAudioFile(HWND hwndFrame) | 
|---|
| 119 | { | 
|---|
| 120 | char chrCommand[CCHMAXPATH*2]; | 
|---|
| 121 | char chrDevice[30]; | 
|---|
| 122 | char retMsg[20]; | 
|---|
| 123 | ULONG rc; | 
|---|
| 124 | int iWavePriv; | 
|---|
| 125 | int iTime2 = 0; | 
|---|
| 126 | HWND hwndNotify; | 
|---|
| 127 |  | 
|---|
| 128 |  | 
|---|
| 129 | if(bPaused) | 
|---|
| 130 | { | 
|---|
| 131 | pauseAudioFile(hwndFrame); | 
|---|
| 132 | return 1; | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 |  | 
|---|
| 136 | iWavePriv=++ulPid; | 
|---|
| 137 | ulPos=0; | 
|---|
| 138 |  | 
|---|
| 139 | stopAudioFile(hwndFrame); | 
|---|
| 140 |  | 
|---|
| 141 | #if 0 | 
|---|
| 142 | #endif | 
|---|
| 143 |  | 
|---|
| 144 | #if 0 | 
|---|
| 145 | if(!getMessage(chrCommand, IDSTR_STARTINGTRACK, sizeof(chrCommand), queryResModuleHandle(),  hwndFrame)) | 
|---|
| 146 | #endif | 
|---|
| 147 | sprintf(chrCommand, "Starting track..."); | 
|---|
| 148 | setPlayTimeText2(hwndFrame, chrCommand); | 
|---|
| 149 |  | 
|---|
| 150 | if(bIsMidi) | 
|---|
| 151 | strncpy(chrDevice,"SEQUENCER", sizeof(chrDevice)); | 
|---|
| 152 | else | 
|---|
| 153 | strncpy(chrDevice,"WAVEAUDIO", sizeof(chrDevice)); | 
|---|
| 154 |  | 
|---|
| 155 | hwndNotify=hwndFrame;//WinWindowFromID(hwndTop, IDDLG_TOPMIDDLE); | 
|---|
| 156 |  | 
|---|
| 157 | /* Start audio file */ | 
|---|
| 158 | sprintf(chrCommand,"open \"%s\"  type %s alias wave%d SHAREABLE wait", chrSourceName, chrDevice, iWavePriv); | 
|---|
| 159 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), hwndNotify, 0); | 
|---|
| 160 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) | 
|---|
| 161 | return 0; | 
|---|
| 162 |  | 
|---|
| 163 | /* Set time format */ | 
|---|
| 164 | sprintf(chrCommand,"SET wave%d TIME FORMAT MILLISECONDS wait", iWavePriv); | 
|---|
| 165 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 166 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) { | 
|---|
| 167 | sprintf(chrCommand,"close wave%d wait",iWavePriv); | 
|---|
| 168 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 169 | return 0; | 
|---|
| 170 | } | 
|---|
| 171 |  | 
|---|
| 172 | #if 0 | 
|---|
| 173 | sprintf(chrCommand,"SETPOSITIONADVISE wave%d ON EVERY 1000 notify", iWavePriv); | 
|---|
| 174 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg),hwndNotify, 0); | 
|---|
| 175 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) { | 
|---|
| 176 | sprintf(chrCommand,"close wave%d wait",iWavePriv); | 
|---|
| 177 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 178 | return 0; | 
|---|
| 179 | } | 
|---|
| 180 | #endif | 
|---|
| 181 |  | 
|---|
| 182 | /* Get wave length in ms */ | 
|---|
| 183 | sprintf(chrCommand,"STATUS wave%d LENGTH WAIT", iWavePriv); | 
|---|
| 184 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 185 | if((rc & 0x0000ffff)==MCIERR_SUCCESS) { | 
|---|
| 186 | iTime2=atoi(retMsg); | 
|---|
| 187 | sprintf(chrCommand,"%d:%02d  %d:%02d  -%d:%02d",iTime2/1000/60,(iTime2/1000)%60, | 
|---|
| 188 | 0, 0, | 
|---|
| 189 | iTime2/1000/60,(iTime2/1000)%60); | 
|---|
| 190 | } | 
|---|
| 191 | ulTotalLength=iTime2; | 
|---|
| 192 |  | 
|---|
| 193 |  | 
|---|
| 194 | /* Set volume */ | 
|---|
| 195 | sprintf(chrCommand,"SET wave%d AUDIO VOLUME %ld wait", iWavePriv, ulVolume); | 
|---|
| 196 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 197 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) { | 
|---|
| 198 | sprintf(chrCommand,"close wave%d",iWavePriv); | 
|---|
| 199 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 200 | return 0; | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 | sprintf(chrCommand,"play wave%d FROM 0", iWavePriv); | 
|---|
| 204 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 205 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) { | 
|---|
| 206 | sprintf(chrCommand,"close wave%d",iWavePriv); | 
|---|
| 207 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 208 | return 0; | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | WinStartTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY, PLAYTIMER_DELAY); | 
|---|
| 212 |  | 
|---|
| 213 | bIsPlaying=TRUE; | 
|---|
| 214 | return 1; | 
|---|
| 215 | } | 
|---|
| 216 |  | 
|---|
| 217 | BOOL seekAudioFile(LONG lPosSec) | 
|---|
| 218 | { | 
|---|
| 219 | char chrCommand[50]; | 
|---|
| 220 | char retMsg[20]; | 
|---|
| 221 | APIRET rc; | 
|---|
| 222 |  | 
|---|
| 223 | sprintf(chrCommand,"PLAY wave%ld from %ld", ulPid, lPosSec); | 
|---|
| 224 | rc=mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0); | 
|---|
| 225 | //  ulStartPosition=lPosSec; | 
|---|
| 226 | bPaused=FALSE; | 
|---|
| 227 |  | 
|---|
| 228 | return TRUE; | 
|---|
| 229 | } | 
|---|
| 230 |  | 
|---|
| 231 | void controlPlaying(HWND hwndDialog, ULONG ulAction, ULONG ulReserved) | 
|---|
| 232 | { | 
|---|
| 233 | WinPostMsg(hwndPlayObject, WM_APPTERMINATENOTIFY, MPFROMP(hwndDialog), MPFROMLONG(ulAction)); | 
|---|
| 234 | } | 
|---|
| 235 |  | 
|---|
| 236 | MRESULT EXPENTRY playObjectProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 237 | { | 
|---|
| 238 | switch (msg) | 
|---|
| 239 | { | 
|---|
| 240 | case WM_APPTERMINATENOTIFY: | 
|---|
| 241 | { | 
|---|
| 242 | HWND hwndFrame=HWNDFROMMP(mp1); | 
|---|
| 243 |  | 
|---|
| 244 |  | 
|---|
| 245 | switch(LONGFROMMP(mp2)) | 
|---|
| 246 | { | 
|---|
| 247 | case PLAY_FIRST: | 
|---|
| 248 | playAudioFile(hwndFrame); | 
|---|
| 249 | break; | 
|---|
| 250 | case STOP_TRACK: | 
|---|
| 251 | stopAudioFile(hwndFrame); | 
|---|
| 252 | break; | 
|---|
| 253 | case PAUSE_TRACK: | 
|---|
| 254 | pauseAudioFile(hwndFrame); | 
|---|
| 255 | break; | 
|---|
| 256 | default: | 
|---|
| 257 | break; | 
|---|
| 258 | } | 
|---|
| 259 | return (MRESULT)0; | 
|---|
| 260 | } | 
|---|
| 261 | case WM_CLOSE: | 
|---|
| 262 |  | 
|---|
| 263 | break; | 
|---|
| 264 | default: | 
|---|
| 265 | break; | 
|---|
| 266 | } | 
|---|
| 267 | return WinDefWindowProc( hwnd, msg, mp1, mp2); | 
|---|
| 268 | } | 
|---|
| 269 |  | 
|---|
| 270 | /* Every folder has one running play thread to handle play commands */ | 
|---|
| 271 | void _Optlink playThreadFunc (void *arg) | 
|---|
| 272 | { | 
|---|
| 273 | HAB  hab; | 
|---|
| 274 | HMQ  hmq; | 
|---|
| 275 | QMSG qmsg; | 
|---|
| 276 |  | 
|---|
| 277 | hab=WinInitialize(0); | 
|---|
| 278 | if(hab) { | 
|---|
| 279 | hmq=WinCreateMsgQueue(hab,0); | 
|---|
| 280 | if(hmq) { | 
|---|
| 281 |  | 
|---|
| 282 | hwndPlayObject=WinCreateWindow(HWND_OBJECT,WC_STATIC,"MFObj",0,0,0,0,0,NULLHANDLE,HWND_BOTTOM,13343,NULL,NULL); | 
|---|
| 283 | if(hwndPlayObject) { | 
|---|
| 284 | WinSubclassWindow(hwndPlayObject,&playObjectProc); | 
|---|
| 285 | /* Window created. */ | 
|---|
| 286 | while(WinGetMsg(hab,&qmsg,(HWND)NULL,0,0)) | 
|---|
| 287 | WinDispatchMsg(hab,&qmsg); | 
|---|
| 288 |  | 
|---|
| 289 | WinDestroyWindow(hwndPlayObject); | 
|---|
| 290 | } | 
|---|
| 291 | WinDestroyMsgQueue(hmq); | 
|---|
| 292 | } | 
|---|
| 293 | WinTerminate(hab); | 
|---|
| 294 | } | 
|---|
| 295 | } | 
|---|
| 296 |  | 
|---|
| 297 |  | 
|---|