source: branches/classes/mm-progs/MMPlayer/playaudio.c@ 202

Last change on this file since 202 was 108, checked in by gyoung, 23 months ago

Fix all the warnings and errors reported by CPPCheck.

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