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 | #if 0
|
---|
52 | #define _PMPRINTF_
|
---|
53 | #include "PMPRINTF.H"
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | /* The object window controling the trac playing */
|
---|
57 | HWND hwndPlayObject;
|
---|
58 | extern PID ulPid;
|
---|
59 | /* TRUE when track is playing */
|
---|
60 | extern BOOL bIsPlaying;
|
---|
61 | /* TRUE when track is paused */
|
---|
62 | extern BOOL bPaused;
|
---|
63 | /* Current time in track */
|
---|
64 | extern ULONG ulPos;
|
---|
65 | extern ULONG ulTotalLength;
|
---|
66 | extern BOOL bIsMidi;
|
---|
67 | extern ULONG ulVolume;
|
---|
68 |
|
---|
69 | extern char chrSourceName[CCHMAXPATH];
|
---|
70 |
|
---|
71 | void showPlayTimeDisplay(HWND hwndFrame, BOOL bShow);
|
---|
72 | void _resetDisplay(HWND hwndFrame);
|
---|
73 | void setPlayTimeText2( HWND hwndDialog, char * theText);
|
---|
74 |
|
---|
75 | BOOL pauseAudioFile(HWND hwndFrame)
|
---|
76 | {
|
---|
77 | int iWavePriv;
|
---|
78 | char chrCommand[50];
|
---|
79 | char retMsg[100];
|
---|
80 |
|
---|
81 | iWavePriv=ulPid;
|
---|
82 |
|
---|
83 | if(bPaused) {
|
---|
84 | sprintf(chrCommand,"RESUME wave%d wait", iWavePriv);
|
---|
85 | mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
86 | bPaused=FALSE;
|
---|
87 | showPlayTimeDisplay( hwndFrame, TRUE);
|
---|
88 | }
|
---|
89 | else {
|
---|
90 | sprintf(chrCommand,"PAUSE wave%d wait", iWavePriv);
|
---|
91 | mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
92 | bPaused=TRUE;
|
---|
93 | }
|
---|
94 | return TRUE;
|
---|
95 | }
|
---|
96 |
|
---|
97 | BOOL stopAudioFile(HWND hwndFrame)
|
---|
98 | {
|
---|
99 | int iWavePriv;
|
---|
100 | char chrCommand[50];
|
---|
101 | char retMsg[100];
|
---|
102 |
|
---|
103 | iWavePriv=ulPid;
|
---|
104 |
|
---|
105 | if(bIsPlaying) {
|
---|
106 | sprintf(chrCommand,"stop wave%d wait", iWavePriv);
|
---|
107 | mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
108 |
|
---|
109 | sprintf(chrCommand,"close wave%d wait", iWavePriv);
|
---|
110 | mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
111 |
|
---|
112 | _resetDisplay(hwndFrame);
|
---|
113 | showPlayTimeDisplay( hwndFrame, TRUE);
|
---|
114 | WinStopTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY);
|
---|
115 | bIsPlaying=FALSE;
|
---|
116 | bPaused=FALSE;
|
---|
117 | }
|
---|
118 | return TRUE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | ULONG playAudioFile(HWND hwndFrame)
|
---|
122 | {
|
---|
123 | char chrCommand[CCHMAXPATH*2];
|
---|
124 | char chrDevice[30] = {0};
|
---|
125 | char retMsg[20];
|
---|
126 | ULONG rc;
|
---|
127 | int iWavePriv;
|
---|
128 | int iTime2 = 0;
|
---|
129 | HWND hwndNotify;
|
---|
130 |
|
---|
131 |
|
---|
132 | if(bPaused)
|
---|
133 | {
|
---|
134 | pauseAudioFile(hwndFrame);
|
---|
135 | return 1;
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | iWavePriv=++ulPid;
|
---|
140 | ulPos=0;
|
---|
141 |
|
---|
142 | stopAudioFile(hwndFrame);
|
---|
143 |
|
---|
144 | #if 0
|
---|
145 | #endif
|
---|
146 |
|
---|
147 | #if 0
|
---|
148 | if(!getMessage(chrCommand, IDSTR_STARTINGTRACK, sizeof(chrCommand), queryResModuleHandle(), hwndFrame))
|
---|
149 | #endif
|
---|
150 | sprintf(chrCommand, "Starting track...");
|
---|
151 | setPlayTimeText2(hwndFrame, chrCommand);
|
---|
152 |
|
---|
153 | if(bIsMidi)
|
---|
154 | strncpy(chrDevice,"sequencer", sizeof(chrDevice) - 1);
|
---|
155 | else
|
---|
156 | strncpy(chrDevice,"WAVEAUDIO", sizeof(chrDevice) - 1);
|
---|
157 |
|
---|
158 | hwndNotify=hwndFrame;//WinWindowFromID(hwndTop, IDDLG_TOPMIDDLE);
|
---|
159 | /* Start audio file */
|
---|
160 | sprintf(chrCommand,"open \"%s\" type %s alias wave%d shareable wait", chrSourceName, chrDevice, iWavePriv);
|
---|
161 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), hwndNotify, 0);
|
---|
162 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
163 | return 0;
|
---|
164 | }
|
---|
165 |
|
---|
166 | /* Set time format */
|
---|
167 | sprintf(chrCommand,"SET wave%d TIME FORMAT MILLISECONDS wait", iWavePriv);
|
---|
168 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
169 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
170 | sprintf(chrCommand,"close wave%d wait",iWavePriv);
|
---|
171 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
172 | return 0;
|
---|
173 | }
|
---|
174 |
|
---|
175 | #if 0
|
---|
176 | sprintf(chrCommand,"SETPOSITIONADVISE wave%d ON EVERY 1000 notify", iWavePriv);
|
---|
177 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg),hwndNotify, 0);
|
---|
178 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
179 | sprintf(chrCommand,"close wave%d wait",iWavePriv);
|
---|
180 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
181 | return 0;
|
---|
182 | }
|
---|
183 | #endif
|
---|
184 |
|
---|
185 | /* Get wave length in ms */
|
---|
186 | sprintf(chrCommand,"STATUS wave%d LENGTH WAIT", iWavePriv);
|
---|
187 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
188 | if((rc & 0x0000ffff)==MCIERR_SUCCESS) {
|
---|
189 | iTime2=atoi(retMsg);
|
---|
190 | sprintf(chrCommand,"%d:%02d %d:%02d -%d:%02d",iTime2/1000/60,(iTime2/1000)%60,
|
---|
191 | 0, 0,
|
---|
192 | iTime2/1000/60,(iTime2/1000)%60);
|
---|
193 | }
|
---|
194 | ulTotalLength=iTime2;
|
---|
195 |
|
---|
196 |
|
---|
197 | /* Set volume */
|
---|
198 | sprintf(chrCommand,"SET wave%d AUDIO VOLUME %ld wait", iWavePriv, ulVolume);
|
---|
199 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
200 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
201 | sprintf(chrCommand,"close wave%d",iWavePriv);
|
---|
202 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
203 | return 0;
|
---|
204 | }
|
---|
205 |
|
---|
206 | sprintf(chrCommand,"play wave%d FROM 0", iWavePriv);
|
---|
207 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
208 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
---|
209 | sprintf(chrCommand,"close wave%d",iWavePriv);
|
---|
210 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
211 | return 0;
|
---|
212 | }
|
---|
213 |
|
---|
214 | WinStartTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY, PLAYTIMER_DELAY);
|
---|
215 |
|
---|
216 | bIsPlaying=TRUE;
|
---|
217 | return 1;
|
---|
218 | }
|
---|
219 |
|
---|
220 | BOOL seekAudioFile(LONG lPosSec)
|
---|
221 | {
|
---|
222 | char chrCommand[50];
|
---|
223 | char retMsg[20];
|
---|
224 |
|
---|
225 | sprintf(chrCommand,"PLAY wave%ld from %ld", ulPid, lPosSec);
|
---|
226 | mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
227 | // ulStartPosition=lPosSec;
|
---|
228 | bPaused=FALSE;
|
---|
229 |
|
---|
230 | return TRUE;
|
---|
231 | }
|
---|
232 |
|
---|
233 | void controlPlaying(HWND hwndDialog, ULONG ulAction, ULONG ulReserved)
|
---|
234 | {
|
---|
235 | WinPostMsg(hwndPlayObject, WM_APPTERMINATENOTIFY, MPFROMP(hwndDialog), MPFROMLONG(ulAction));
|
---|
236 | }
|
---|
237 |
|
---|
238 | MRESULT EXPENTRY playObjectProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
239 | {
|
---|
240 | switch (msg)
|
---|
241 | {
|
---|
242 | case WM_APPTERMINATENOTIFY:
|
---|
243 | {
|
---|
244 | HWND hwndFrame=HWNDFROMMP(mp1);
|
---|
245 |
|
---|
246 |
|
---|
247 | switch(LONGFROMMP(mp2))
|
---|
248 | {
|
---|
249 | case PLAY_FIRST:
|
---|
250 | playAudioFile(hwndFrame);
|
---|
251 | break;
|
---|
252 | case STOP_TRACK:
|
---|
253 | stopAudioFile(hwndFrame);
|
---|
254 | break;
|
---|
255 | case PAUSE_TRACK:
|
---|
256 | pauseAudioFile(hwndFrame);
|
---|
257 | break;
|
---|
258 | default:
|
---|
259 | break;
|
---|
260 | }
|
---|
261 | return (MRESULT)0;
|
---|
262 | }
|
---|
263 | case WM_CLOSE:
|
---|
264 |
|
---|
265 | break;
|
---|
266 | default:
|
---|
267 | break;
|
---|
268 | }
|
---|
269 | return WinDefWindowProc( hwnd, msg, mp1, mp2);
|
---|
270 | }
|
---|
271 |
|
---|
272 | /* Every folder has one running play thread to handle play commands */
|
---|
273 | void playThreadFunc (void *arg)
|
---|
274 | {
|
---|
275 | HAB hab;
|
---|
276 | HMQ hmq;
|
---|
277 | QMSG qmsg;
|
---|
278 |
|
---|
279 | hab=WinInitialize(0);
|
---|
280 | if(hab) {
|
---|
281 | hmq=WinCreateMsgQueue(hab,0);
|
---|
282 | if(hmq) {
|
---|
283 |
|
---|
284 | hwndPlayObject=WinCreateWindow(HWND_OBJECT,WC_STATIC,"MFObj",0,0,0,0,0,NULLHANDLE,HWND_BOTTOM,13343,NULL,NULL);
|
---|
285 | if(hwndPlayObject) {
|
---|
286 | WinSubclassWindow(hwndPlayObject,&playObjectProc);
|
---|
287 | /* Window created. */
|
---|
288 | while(WinGetMsg(hab,&qmsg,(HWND)NULL,0,0))
|
---|
289 | WinDispatchMsg(hab,&qmsg);
|
---|
290 |
|
---|
291 | WinDestroyWindow(hwndPlayObject);
|
---|
292 | }
|
---|
293 | WinDestroyMsgQueue(hmq);
|
---|
294 | }
|
---|
295 | WinTerminate(hab);
|
---|
296 | }
|
---|
297 | }
|
---|
298 |
|
---|
299 |
|
---|