1 | /*
|
---|
2 | * pmmp3dec.c (C) Chris Wohlgemuth 2002
|
---|
3 | *
|
---|
4 | * This helper decodes an MP3
|
---|
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 | * If you need another license for your project/product (commercial,
|
---|
23 | * noncommercial, whatever) contact me at
|
---|
24 | *
|
---|
25 | * http://www.os2world.com/cdwriting
|
---|
26 | * http://www.geocities.com/SiliconValley/Sector/5785/
|
---|
27 | *
|
---|
28 | */
|
---|
29 |
|
---|
30 | #define INCL_DOS
|
---|
31 | #define INCL_DOSFILEMGR
|
---|
32 | #define INCL_DOSERRORS
|
---|
33 | #define INCL_WIN
|
---|
34 | #define INCL_OS2MM
|
---|
35 | #define INCL_MMIOOS2
|
---|
36 | #define INCL_MCIOS2
|
---|
37 |
|
---|
38 | #include <os2.h>
|
---|
39 |
|
---|
40 | #include <sys\types.h>
|
---|
41 | #include <sys\stat.h>
|
---|
42 | #include <stdio.h>
|
---|
43 | #include <stdlib.h>
|
---|
44 | #include <string.h>
|
---|
45 | #include <ctype.h>
|
---|
46 | #include "os2me.h"
|
---|
47 | #include "common.h"
|
---|
48 | #include "mmres.h"
|
---|
49 | #include "mmprogs_defaults.h"
|
---|
50 |
|
---|
51 | #include "sys_funcs.h"
|
---|
52 |
|
---|
53 | #define MSG_CONVERTDONE 1L
|
---|
54 | #define MSG_CONVERTPERCENT 2L
|
---|
55 | #define MSG_CONVERTERROR 3L
|
---|
56 |
|
---|
57 | #define ID_TIMER 1
|
---|
58 | #define TIMER_DELAY 200
|
---|
59 |
|
---|
60 | #define CONVERTBUFFERSIZE 500000
|
---|
61 | #define NUMPARAMS 3
|
---|
62 | /* argv[0]: progname
|
---|
63 | * argv[1]: wavefile
|
---|
64 | * argv[2]: IO proc name
|
---|
65 | */
|
---|
66 |
|
---|
67 | //#define DEBUG
|
---|
68 |
|
---|
69 | //#define INI_NAME_APP "audioconv"
|
---|
70 | //#define INI_NAME_COLOR "color"
|
---|
71 |
|
---|
72 | void HlpSendCommandToObject(PSZ chrObject, PSZ command);
|
---|
73 | BOOL percentRegisterBarClass(void);
|
---|
74 | BOOL IniSaveWindowPos(PSZ iniFile, PSZ chrApp, PSZ chrKey, HWND hwnd);
|
---|
75 | BOOL IniRestoreWindowPos(PSZ iniFile, PSZ chrApp, PSZ chrKey, HWND hwnd);
|
---|
76 | BOOL IniSaveWindowClrs(PSZ chrIniFile, PSZ chrApp , HWND hwnd);
|
---|
77 | BOOL IniRestoreWindowClrs(PSZ chrIniFile, PSZ chrApp , HWND hwnd);
|
---|
78 | BOOL HlpBuildMMProgIniFileName(PSZ chrProgname, PSZ chrBuffer, ULONG ulBufferSize);
|
---|
79 | HMODULE queryResModuleHandle(PSZ chrExePath);
|
---|
80 | void freeResHandle();
|
---|
81 | BOOL getMessage(PSZ text,ULONG ulID, LONG lSizeText, HMODULE hResource,HWND hwnd);
|
---|
82 | ULONG messageBox( PSZ text, ULONG ulTextID , LONG lSizeText,
|
---|
83 | PSZ title, ULONG ulTitleID, LONG lSizeTitle,
|
---|
84 | HMODULE hResource, HWND hwnd, ULONG ulFlags);
|
---|
85 |
|
---|
86 |
|
---|
87 | char logName[]="convert.log";
|
---|
88 |
|
---|
89 | extern SWP swpWindow;
|
---|
90 | BOOL bHaveWindowPos=FALSE;
|
---|
91 |
|
---|
92 | UCHAR chrTargetName[CCHMAXPATH]={0};
|
---|
93 | UCHAR chrSourceName[CCHMAXPATH]={0};
|
---|
94 | UCHAR chrProcName[CCHMAXPATH]={0};
|
---|
95 | UCHAR chrIniFile[CCHMAXPATH];
|
---|
96 |
|
---|
97 | int numArgs;
|
---|
98 | char* params[NUMPARAMS];
|
---|
99 |
|
---|
100 | #define NUMIOPROCS 1000
|
---|
101 | int iIoProc; /* Position of IO-Proc in global data area of MMOS2. 0 based */
|
---|
102 | int iPrivIOProc[NUMIOPROCS]; /* Number of possible IO-Procs. I'm lazy here and use a static array.
|
---|
103 | If there ever will be more than 1000 procs there'll be a problem... */
|
---|
104 |
|
---|
105 |
|
---|
106 | int iSampleRate;
|
---|
107 | int iBitsPerSample;
|
---|
108 | SHORT sChannels;
|
---|
109 | LONG lSec;
|
---|
110 | LONG lAudioSize;
|
---|
111 |
|
---|
112 | TID tidThread=0;
|
---|
113 | BOOL bBreak=FALSE;
|
---|
114 | PMMFORMATINFO pMemFormatInfo=NULLHANDLE;
|
---|
115 | HMODULE RESSOURCEHANDLE=0;
|
---|
116 | BOOL bNoProcGiven=FALSE;
|
---|
117 |
|
---|
118 | void pmUsage();
|
---|
119 |
|
---|
120 | BOOL createTargetName(PSZ sourceName, PSZ chrExt)
|
---|
121 | {
|
---|
122 | PCHAR textPtr=NULL;
|
---|
123 |
|
---|
124 | strcpy((PCHAR)chrTargetName, (PCHAR)sourceName);
|
---|
125 | if((textPtr=strrchr((PCHAR)chrTargetName, '.'))!=NULL)
|
---|
126 | *textPtr=0;
|
---|
127 | else
|
---|
128 | textPtr=(PCHAR)chrTargetName;
|
---|
129 | strcat(textPtr,".");
|
---|
130 | strcat(textPtr, (PCHAR)chrExt);
|
---|
131 | #if 0
|
---|
132 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, textPtr,
|
---|
133 | "",
|
---|
134 | 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
|
---|
135 | #endif
|
---|
136 | return TRUE;
|
---|
137 | }
|
---|
138 |
|
---|
139 | BOOL insertIOProcItems( HWND hwndDrop )
|
---|
140 | {
|
---|
141 | // CHAR szBuffer[ sizeof( FOURCC ) + CCHMAXPATH + 4 ];
|
---|
142 | MMFORMATINFO mmFormatInfo;
|
---|
143 | PMMFORMATINFO pmmFormatInfoArray;
|
---|
144 | ULONG ulReturnCode;
|
---|
145 | LONG lFormatsRead;
|
---|
146 | LONG index;
|
---|
147 | LONG lBytesRead;
|
---|
148 |
|
---|
149 |
|
---|
150 | LONG lNumIOProcs;
|
---|
151 | int sIdx;
|
---|
152 | memset( &mmFormatInfo,
|
---|
153 | '\0',
|
---|
154 | sizeof(MMFORMATINFO) );
|
---|
155 |
|
---|
156 | mmFormatInfo.ulMediaType |= MMIO_MEDIATYPE_AUDIO;
|
---|
157 | mmFormatInfo.ulFlags|=MMIO_CANWRITETRANSLATED;
|
---|
158 | ulReturnCode = mmioQueryFormatCount ( &mmFormatInfo,
|
---|
159 | &lNumIOProcs,
|
---|
160 | 0,
|
---|
161 | 0 );
|
---|
162 |
|
---|
163 | if( ulReturnCode != MMIO_SUCCESS )
|
---|
164 | {
|
---|
165 | /*
|
---|
166 | * Error - mmioQueryFormatCount failed.
|
---|
167 | */
|
---|
168 | return FALSE;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /*
|
---|
172 | * Allocate enough memory for n number of FormatInfo blocks
|
---|
173 | */
|
---|
174 | pmmFormatInfoArray = (PMMFORMATINFO) malloc (lNumIOProcs * sizeof( MMFORMATINFO ) );
|
---|
175 | pMemFormatInfo=pmmFormatInfoArray;
|
---|
176 | if( pmmFormatInfoArray == NULL )
|
---|
177 | {
|
---|
178 | /*
|
---|
179 | * Could not allocate enough memory for mmFormatInfo array.
|
---|
180 | */
|
---|
181 | return FALSE;
|
---|
182 | }
|
---|
183 |
|
---|
184 | /*
|
---|
185 | * call mmioGetFormats to get info on the formats supported.
|
---|
186 | */
|
---|
187 | ulReturnCode = mmioGetFormats( &mmFormatInfo,
|
---|
188 | lNumIOProcs,
|
---|
189 | pmmFormatInfoArray,
|
---|
190 | &lFormatsRead,
|
---|
191 | 0,
|
---|
192 | 0 );
|
---|
193 | if( ulReturnCode != MMIO_SUCCESS )
|
---|
194 | {
|
---|
195 | /*
|
---|
196 | * mmioGetFormats failed.
|
---|
197 | */
|
---|
198 | free(pmmFormatInfoArray);
|
---|
199 | return FALSE;
|
---|
200 | }
|
---|
201 |
|
---|
202 | if( lFormatsRead != lNumIOProcs )
|
---|
203 | {
|
---|
204 | /*
|
---|
205 | * Error in MMIO - number of formats read in by
|
---|
206 | * mmioGetFormats is not equal to number of formats
|
---|
207 | * found by mmioQueryFormatCount.
|
---|
208 | */
|
---|
209 | free(pmmFormatInfoArray);
|
---|
210 | return FALSE;
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | for ( index = 0, sIdx=0; index <lNumIOProcs; index++ )
|
---|
215 | {
|
---|
216 | UCHAR szName[CCHMAXPATH];
|
---|
217 |
|
---|
218 | mmioGetFormatName(pmmFormatInfoArray, szName, &lBytesRead, 0L, 0L);
|
---|
219 | /* Insert NULL string terminator */
|
---|
220 | *( szName + lBytesRead ) = 0;
|
---|
221 |
|
---|
222 | #ifdef DEBUG
|
---|
223 | SysWriteToTrapLog("%d IO-Proc: %s, %s\n", index,
|
---|
224 | pmmFormatInfoArray->szDefaultFormatExt,
|
---|
225 | szName);
|
---|
226 | #endif
|
---|
227 |
|
---|
228 | if(pmmFormatInfoArray->ulFlags & MMIO_CANWRITETRANSLATED)
|
---|
229 | {
|
---|
230 | /* Insert into list box */
|
---|
231 | WinSendMsg(hwndDrop, LM_INSERTITEM,(MPARAM)LIT_END,
|
---|
232 | (MPARAM)szName);
|
---|
233 |
|
---|
234 |
|
---|
235 | iPrivIOProc[sIdx]=index;
|
---|
236 |
|
---|
237 | #ifdef DEBUG
|
---|
238 | SysWriteToTrapLog("-- %d %d, sIdx: %d %s\n", index, iPrivIOProc[sIdx], sIdx,
|
---|
239 | pmmFormatInfoArray->szDefaultFormatExt
|
---|
240 | );
|
---|
241 | #endif
|
---|
242 |
|
---|
243 |
|
---|
244 | /* Set text field */
|
---|
245 | if(bNoProcGiven) {
|
---|
246 | WinSetWindowText(hwndDrop, szName);
|
---|
247 | createTargetName(chrSourceName, (PSZ)pmmFormatInfoArray->szDefaultFormatExt);
|
---|
248 | iIoProc=iPrivIOProc[sIdx];
|
---|
249 | bNoProcGiven=FALSE;
|
---|
250 | }
|
---|
251 | else {
|
---|
252 | if(!stricmp((PCHAR)szName, (PCHAR)chrProcName)) {
|
---|
253 | WinSetWindowText(hwndDrop, szName);
|
---|
254 | /* Create target name */
|
---|
255 | createTargetName(chrSourceName, (PSZ)pmmFormatInfoArray->szDefaultFormatExt);
|
---|
256 | iIoProc=iPrivIOProc[sIdx];
|
---|
257 | }
|
---|
258 | sIdx++;
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | /*
|
---|
263 | * advance to next entry in mmFormatInfo array
|
---|
264 | */
|
---|
265 | pmmFormatInfoArray++;
|
---|
266 | }
|
---|
267 | return TRUE;
|
---|
268 | }
|
---|
269 |
|
---|
270 | BOOL queryAudioInfo(PSZ chrFile)
|
---|
271 | {
|
---|
272 | HMMIO hmmio;
|
---|
273 | MMAUDIOHEADER mmAudioHeader;
|
---|
274 | MMIOINFO mmioinfo;
|
---|
275 | LONG lBytesRead=0;
|
---|
276 | APIRET rc;
|
---|
277 |
|
---|
278 | memset(&mmioinfo,0, sizeof(mmioinfo));
|
---|
279 | mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER;
|
---|
280 | mmioinfo.ulFlags=MMIO_READ|MMIO_DENYNONE;
|
---|
281 | /* open source file */
|
---|
282 | if((hmmio=mmioOpen(chrFile, &mmioinfo,MMIO_READ))==NULLHANDLE)
|
---|
283 | {
|
---|
284 | return FALSE;
|
---|
285 | }
|
---|
286 | memset(&mmAudioHeader,0,sizeof(MMAUDIOHEADER));
|
---|
287 | rc = mmioGetHeader(hmmio, &mmAudioHeader,sizeof(MMAUDIOHEADER),
|
---|
288 | &lBytesRead, 0, 0);
|
---|
289 | if(rc!=MMIO_SUCCESS) {
|
---|
290 | mmioClose(hmmio, 0);
|
---|
291 | // fprintf(stderr,"mmioGetHeader error!\n");
|
---|
292 | return FALSE;
|
---|
293 | }
|
---|
294 |
|
---|
295 | iSampleRate=mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec;
|
---|
296 | sChannels=mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels;
|
---|
297 | iBitsPerSample=mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample;
|
---|
298 | lSec=mmAudioHeader.mmXWAVHeader.XWAVHeaderInfo.ulAudioLengthInBytes/
|
---|
299 | mmAudioHeader.mmXWAVHeader.WAVEHeader.ulAvgBytesPerSec;
|
---|
300 | lAudioSize=mmAudioHeader.mmXWAVHeader.XWAVHeaderInfo.ulAudioLengthInBytes;
|
---|
301 |
|
---|
302 | /* close source */
|
---|
303 | mmioClose(hmmio,0);
|
---|
304 | return TRUE;
|
---|
305 | }
|
---|
306 |
|
---|
307 | #if 0
|
---|
308 | BOOL createTargetName(char *sourceName)
|
---|
309 | {
|
---|
310 | char *textPtr;
|
---|
311 |
|
---|
312 | strcpy(chrTargetName, sourceName);
|
---|
313 | if((textPtr=strrchr(chrTargetName, '.'))!=NULLHANDLE)
|
---|
314 | *textPtr=0;
|
---|
315 | else
|
---|
316 | textPtr=chrTargetName;
|
---|
317 | strcat(textPtr, ".wav");
|
---|
318 |
|
---|
319 | return TRUE;
|
---|
320 | }
|
---|
321 | #endif
|
---|
322 |
|
---|
323 | void convertThreadFunc (void *arg)
|
---|
324 | {
|
---|
325 | HAB hab;
|
---|
326 | HMQ hmq;
|
---|
327 | HWND hwnd=(HWND)arg;
|
---|
328 |
|
---|
329 | hab=WinInitialize(0);
|
---|
330 | if(hab) {
|
---|
331 | hmq=WinCreateMsgQueue(hab,0);
|
---|
332 | if(hmq) {
|
---|
333 | HMMIO hmmio, hmmioTarget;
|
---|
334 | MMIOINFO mmioinfo;
|
---|
335 | MMAUDIOHEADER mmAudioHeader;
|
---|
336 | LONG lBytesRead=0;
|
---|
337 | LONG lBytesWritten=0;
|
---|
338 | ULONG rc;
|
---|
339 | PCHAR buffer=NULL;
|
---|
340 |
|
---|
341 | do {
|
---|
342 | /*******************************/
|
---|
343 | /* Set up/open the SOURCE file */
|
---|
344 | /*******************************/
|
---|
345 | memset(&mmioinfo,0, sizeof(mmioinfo));
|
---|
346 | mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
---|
347 | mmioinfo.ulFlags=MMIO_READ|MMIO_DENYNONE;
|
---|
348 |
|
---|
349 | if((hmmio=mmioOpen(chrSourceName, &mmioinfo,MMIO_READ))==NULLHANDLE)
|
---|
350 | {
|
---|
351 | UCHAR text[500];
|
---|
352 | snprintf((PCHAR)text, sizeof(text)-1,"mmioOpen error with file %s\n", chrSourceName);
|
---|
353 | WinMessageBox(hwnd, hwnd, (PSZ)"",
|
---|
354 | text,
|
---|
355 | 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
|
---|
356 | break;
|
---|
357 | }
|
---|
358 | memset(&mmAudioHeader,0,sizeof(MMAUDIOHEADER));
|
---|
359 | rc = mmioGetHeader(hmmio, &mmAudioHeader,sizeof(MMAUDIOHEADER),
|
---|
360 | &lBytesRead, 0, 0);
|
---|
361 | if(rc!=MMIO_SUCCESS) {
|
---|
362 | UCHAR text[500];
|
---|
363 | mmioClose(hmmio, 0);
|
---|
364 | snprintf((PCHAR)text, sizeof(text)-1,"mmioGetHeader error!");
|
---|
365 | WinMessageBox(hwnd, hwnd, (PSZ)"",
|
---|
366 | text,
|
---|
367 | 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
|
---|
368 | break;
|
---|
369 | }
|
---|
370 |
|
---|
371 | /*******************************/
|
---|
372 | /* Set up/open the TARGET file */
|
---|
373 | /*******************************/
|
---|
374 | memset(&mmioinfo,0, sizeof(mmioinfo));
|
---|
375 | mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
---|
376 | mmioinfo.ulFlags=MMIO_WRITE|MMIO_CREATE;
|
---|
377 |
|
---|
378 | // mmioinfo.fccIOProc=mmioStringToFOURCC("WAVE", MMIO_TOUPPER);
|
---|
379 | mmioinfo.fccIOProc=pMemFormatInfo[iIoProc].fccIOProc;
|
---|
380 | if((hmmioTarget=mmioOpen(chrTargetName, &mmioinfo, MMIO_WRITE|MMIO_CREATE))==NULLHANDLE)
|
---|
381 | {
|
---|
382 | UCHAR chrError[64];
|
---|
383 | UCHAR text[CCHMAXPATH*2];
|
---|
384 | rc=mmioGetLastError(hmmioTarget);
|
---|
385 | mciGetErrorString(mmioinfo.ulErrorRet ,chrError, sizeof(chrError)-1);
|
---|
386 | snprintf((PCHAR)text, sizeof(text)-1,"mmioOpen error with file %s:\n%s\n%lu", chrTargetName, chrError,mmioinfo.ulErrorRet);
|
---|
387 | mmioClose(hmmio,0);
|
---|
388 | WinMessageBox(hwnd, hwnd, (PSZ)"",
|
---|
389 | text,
|
---|
390 | 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
|
---|
391 | break;
|
---|
392 | }
|
---|
393 | /* Set parameters */
|
---|
394 | rc = mmioSetHeader(hmmioTarget, &mmAudioHeader,sizeof(MMAUDIOHEADER),
|
---|
395 | &lBytesWritten, 0, 0);
|
---|
396 |
|
---|
397 | /* Get buffer */
|
---|
398 | if((buffer=(PCHAR)malloc(CONVERTBUFFERSIZE))==NULLHANDLE) {
|
---|
399 | UCHAR text[500];
|
---|
400 | mmioClose(hmmio, 0);
|
---|
401 | mmioClose(hmmioTarget,0);
|
---|
402 | snprintf((PCHAR)text, sizeof(text)-1,"Can't get memory buffer!");
|
---|
403 | WinMessageBox(hwnd, hwnd, (PSZ)"",
|
---|
404 | text,
|
---|
405 | 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
|
---|
406 |
|
---|
407 | break;
|
---|
408 | }
|
---|
409 |
|
---|
410 | /* convert */
|
---|
411 | lBytesWritten=0;
|
---|
412 | do{
|
---|
413 | rc=mmioRead(hmmio, buffer, CONVERTBUFFERSIZE);
|
---|
414 | if(bBreak)
|
---|
415 | break;
|
---|
416 | if(rc!=0 && rc!=MMIO_ERROR ) {
|
---|
417 | mmioWrite(hmmioTarget, buffer, rc);
|
---|
418 | lBytesWritten+=rc;
|
---|
419 | WinSendMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTPERCENT), MPFROMLONG((lBytesWritten)/(lAudioSize/100)));
|
---|
420 | }
|
---|
421 | }while(rc!=0 && rc!=MMIO_ERROR && !bBreak/*&& lBytesWritten <1000000*/);
|
---|
422 | if(rc==MMIO_ERROR) {
|
---|
423 | UCHAR text[500];
|
---|
424 | snprintf((PCHAR)text, sizeof(text)-1,"Error while reading audio data!");
|
---|
425 | WinMessageBox(hwnd, hwnd, (PSZ)"",
|
---|
426 | text,
|
---|
427 | 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
|
---|
428 | }
|
---|
429 | if(!bBreak) {
|
---|
430 | UCHAR chrCommand[CCHMAXPATH*2];
|
---|
431 | WinSendMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTPERCENT), MPFROMLONG(100));
|
---|
432 | /* Refresh details view */
|
---|
433 | HlpSendCommandToObject(chrTargetName, (PSZ)"CWAUDIOREFRESH=1");
|
---|
434 | sprintf((PCHAR)chrCommand,"CWAUDIOCOPYTAGTO=%s;", chrTargetName);
|
---|
435 | HlpSendCommandToObject(chrSourceName, chrCommand);
|
---|
436 | }
|
---|
437 | free(buffer);
|
---|
438 | /* close source */
|
---|
439 | mmioClose(hmmio,0);
|
---|
440 | /* close target */
|
---|
441 | mmioClose(hmmioTarget,0);
|
---|
442 | break;
|
---|
443 | }
|
---|
444 | while(TRUE);
|
---|
445 | WinSendMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTDONE), 0);
|
---|
446 | WinDestroyMsgQueue(hmq);
|
---|
447 | }
|
---|
448 | WinTerminate(hab);
|
---|
449 | }
|
---|
450 | tidThread=0;
|
---|
451 | bBreak=FALSE;
|
---|
452 | }
|
---|
453 |
|
---|
454 | void convertAudioFile(HWND hwnd)
|
---|
455 | {
|
---|
456 | tidThread=_beginthread(convertThreadFunc,NULL, 8192*16, (void*)hwnd); //Fehlerbehandlung fehlt
|
---|
457 | if(tidThread==-1) {
|
---|
458 | DosBeep(100, 500);
|
---|
459 | tidThread=0;
|
---|
460 | }
|
---|
461 | }
|
---|
462 |
|
---|
463 | /* This Proc handles the on-the-fly data CD writing */
|
---|
464 | MRESULT EXPENTRY decodeStatusDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
465 | {
|
---|
466 | UCHAR text[CCHMAXPATH*4 +10];
|
---|
467 | UCHAR title[CCHMAXPATH*4];
|
---|
468 | SWCNTRL swctl;
|
---|
469 | PID pid;
|
---|
470 | int iPercent;
|
---|
471 |
|
---|
472 | switch (msg)
|
---|
473 | {
|
---|
474 | case WM_INITDLG:
|
---|
475 |
|
---|
476 | /* Add switch entry */
|
---|
477 | memset(&swctl,0,sizeof(swctl));
|
---|
478 | WinQueryWindowProcess(hwnd,&pid,NULL);
|
---|
479 | swctl.hwnd=hwnd;
|
---|
480 | swctl.uchVisibility=SWL_VISIBLE;
|
---|
481 | swctl.idProcess=pid;
|
---|
482 | swctl.bProgType=PROG_DEFAULT;
|
---|
483 | swctl.fbJump=SWL_JUMPABLE;
|
---|
484 | WinAddSwitchEntry(&swctl);
|
---|
485 |
|
---|
486 | #if 0
|
---|
487 | sprintf(text,"1: %s, 2: %s, 3: %s 4: %s 5: %s 6: %s",params[1],params[2],params[3],
|
---|
488 | params[4], params[4],params[4]);
|
---|
489 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text,
|
---|
490 | params[4],
|
---|
491 | 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
|
---|
492 | #endif
|
---|
493 |
|
---|
494 | WinSendMsg(WinWindowFromID(hwnd,IDST_CONVERTNAME),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)CCHMAXPATH),0);
|
---|
495 |
|
---|
496 | WinSetWindowText(WinWindowFromID(hwnd,IDST_CONVERTCDBITS), (PSZ)"");
|
---|
497 |
|
---|
498 | /* Filename */
|
---|
499 | WinSetWindowText(WinWindowFromID(hwnd,IDST_CONVERTNAME), chrSourceName);
|
---|
500 |
|
---|
501 | /* Set dialog font to WarpSans for Warp 4 and above */
|
---|
502 | if(SysQueryOSRelease()>=40) {
|
---|
503 | WinSetPresParam(hwnd,
|
---|
504 | PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
|
---|
505 | DEFAULT_DIALOG_FONT );
|
---|
506 | }
|
---|
507 |
|
---|
508 | /* Set percent bars to 0. */
|
---|
509 | WinSetWindowText(WinWindowFromID(hwnd,IDBAR_CONVERTPROGRESS),(PSZ)"0#0%");
|
---|
510 |
|
---|
511 | WinSendMsg(WinWindowFromID(hwnd,IDEF_CONVERTTARGETNAME), EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)CCHMAXPATH),0);
|
---|
512 | insertIOProcItems( WinWindowFromID(hwnd, IDDD_IOPROC) );
|
---|
513 | WinSetWindowText( WinWindowFromID(hwnd,IDEF_CONVERTTARGETNAME), chrTargetName );
|
---|
514 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTABORT), FALSE);
|
---|
515 |
|
---|
516 | /* Channels */
|
---|
517 | getMessage(title, IDSTR_CONVERTCHANNELS, sizeof(title), RESSOURCEHANDLE, hwnd);
|
---|
518 | sprintf((PCHAR)text, (PCHAR)title, sChannels);
|
---|
519 | WinSetWindowText(WinWindowFromID(hwnd,IDST_CONVERTCHANNELS),text);
|
---|
520 |
|
---|
521 | /* Samplerate */
|
---|
522 | getMessage(title, IDSTR_CONVERTSAMPLERATE, sizeof(title), RESSOURCEHANDLE, hwnd);
|
---|
523 | sprintf((PCHAR)text, (PCHAR)title, iSampleRate);
|
---|
524 | WinSetWindowText(WinWindowFromID(hwnd,IDST_CONVERTSAMPLERATE),text);
|
---|
525 |
|
---|
526 | /* Playtime */
|
---|
527 | getMessage(title, IDSTR_CONVERTPLAYTIME, sizeof(title), RESSOURCEHANDLE, hwnd);
|
---|
528 | sprintf((PCHAR)text, (PCHAR)title, lSec/60, lSec%60);
|
---|
529 | WinSetWindowText(WinWindowFromID(hwnd,IDST_CONVERTPLAYTIME),text);
|
---|
530 |
|
---|
531 | IniRestoreWindowPos(chrIniFile, INI_AUDIOCONV_APP, INI_WINDOWPOS_KEY, hwnd);
|
---|
532 | IniRestoreWindowClrs(chrIniFile, INI_AUDIOCONV_APP , hwnd);
|
---|
533 |
|
---|
534 | WinSetFocus(HWND_DESKTOP, hwnd);
|
---|
535 | return (MRESULT) TRUE;
|
---|
536 |
|
---|
537 | /* WM_APPTERMINATENOTIFY messages are sent from the helper programs e.g. format checker. */
|
---|
538 | case WM_APPTERMINATENOTIFY:
|
---|
539 | switch(LONGFROMMP(mp1))
|
---|
540 | {
|
---|
541 | case MSG_CONVERTERROR:
|
---|
542 | case MSG_CONVERTDONE:
|
---|
543 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTOK), TRUE);
|
---|
544 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTABORT), FALSE);
|
---|
545 | break;
|
---|
546 | case MSG_CONVERTPERCENT:
|
---|
547 | iPercent=LONGFROMMP(mp2);
|
---|
548 | if(iPercent>100)
|
---|
549 | iPercent=100;
|
---|
550 | if(iPercent<0)
|
---|
551 | iPercent=0;
|
---|
552 |
|
---|
553 | /* Update track percent bar value. The helper prog sends us the actual decoded %. */
|
---|
554 | sprintf(text,"%d#%d%%", iPercent, iPercent);
|
---|
555 | WinSetWindowText(WinWindowFromID(hwnd,IDBAR_CONVERTPROGRESS), text);
|
---|
556 | break;
|
---|
557 | default:
|
---|
558 | break;
|
---|
559 | }
|
---|
560 | return FALSE;
|
---|
561 |
|
---|
562 | case WM_CLOSE:
|
---|
563 | if(tidThread) {
|
---|
564 | bBreak=TRUE;
|
---|
565 | if(!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER, TIMER_DELAY))
|
---|
566 | {
|
---|
567 | /* Save window position */
|
---|
568 | IniSaveWindowPos(chrIniFile, INI_AUDIOCONV_APP, INI_WINDOWPOS_KEY, hwnd);
|
---|
569 | IniSaveWindowClrs(chrIniFile, INI_AUDIOCONV_APP , hwnd);
|
---|
570 | WinDismissDlg(hwnd,0);
|
---|
571 | }
|
---|
572 | else
|
---|
573 | return FALSE;
|
---|
574 | }
|
---|
575 | /* Save window position */
|
---|
576 | IniSaveWindowPos(chrIniFile, INI_AUDIOCONV_APP, INI_WINDOWPOS_KEY, hwnd);
|
---|
577 | IniSaveWindowClrs(chrIniFile, INI_AUDIOCONV_APP , hwnd);
|
---|
578 | WinDismissDlg(hwnd,0);
|
---|
579 | return FALSE;
|
---|
580 | case WM_CONTROL:
|
---|
581 | if(SHORT1FROMMP(mp1)==IDDD_IOPROC)
|
---|
582 | {
|
---|
583 | if(SHORT2FROMMP(mp1)==EN_CHANGE) {
|
---|
584 | SHORT sIdx;
|
---|
585 | sIdx=SHORT1FROMMR(WinSendMsg(HWNDFROMMP(mp2),LM_QUERYSELECTION, MPFROMLONG(LIT_FIRST),0));
|
---|
586 | iIoProc=iPrivIOProc[sIdx];
|
---|
587 |
|
---|
588 | #ifdef DEBUG
|
---|
589 | SysWriteToTrapLog("sIdx: %d IO-Proc Idx: %d %s\n", sIdx, iPrivIOProc[sIdx],
|
---|
590 | pMemFormatInfo[iIoProc].szDefaultFormatExt
|
---|
591 | );
|
---|
592 | #endif
|
---|
593 |
|
---|
594 | createTargetName(chrSourceName, pMemFormatInfo[iIoProc].szDefaultFormatExt);
|
---|
595 | WinSetWindowText( WinWindowFromID(hwnd,IDEF_CONVERTTARGETNAME), chrTargetName );
|
---|
596 | }
|
---|
597 | }
|
---|
598 | break;
|
---|
599 | case WM_TIMER:
|
---|
600 | if(SHORT1FROMMP(mp1)==ID_TIMER)
|
---|
601 | {
|
---|
602 | if(!tidThread) {
|
---|
603 | /* Convert thread ended. Quit. */
|
---|
604 | WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER);
|
---|
605 | WinPostMsg(hwnd, WM_CLOSE, 0, 0);
|
---|
606 | }
|
---|
607 | return MRFALSE;
|
---|
608 | }
|
---|
609 | break;
|
---|
610 | case WM_COMMAND:
|
---|
611 | switch(SHORT1FROMMP(mp1))
|
---|
612 | {
|
---|
613 | case IDPB_CONVERTBROWSE:
|
---|
614 | {
|
---|
615 | UCHAR chrTitle[200];
|
---|
616 | FILEDLG fd = { 0 };
|
---|
617 | /* User pressed the browse button */
|
---|
618 | fd.cbSize = sizeof( fd );
|
---|
619 | /* It's an centered 'Open'-dialog */
|
---|
620 | fd.fl = FDS_OPEN_DIALOG|FDS_CENTER;
|
---|
621 | /* Set the title of the file dialog */
|
---|
622 | fd.pszTitle = chrTitle;
|
---|
623 | if(!getMessage(chrTitle, IDSTR_AUDIOBROWSETITLE, sizeof(chrTitle), RESSOURCEHANDLE, hwnd))
|
---|
624 | fd.pszTitle = "Wave name";
|
---|
625 | /* Only show * files */
|
---|
626 | //sprintf(fd.szFullFile,"%s","*");
|
---|
627 | strcpy(fd.szFullFile, chrTargetName);
|
---|
628 | if( WinFileDlg( HWND_DESKTOP, hwnd, &fd ) == NULLHANDLE )
|
---|
629 | {
|
---|
630 | /* WinFileDlg failed */
|
---|
631 | break;
|
---|
632 | }
|
---|
633 | if( fd.lReturn == DID_OK )
|
---|
634 | {
|
---|
635 | WinSetWindowText( WinWindowFromID(hwnd,IDEF_CONVERTTARGETNAME), fd.szFullFile );
|
---|
636 | }
|
---|
637 | break;
|
---|
638 | }
|
---|
639 | case IDPB_CONVERTCLOSE:
|
---|
640 | bBreak=TRUE;
|
---|
641 | if(!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER, TIMER_DELAY))
|
---|
642 | WinPostMsg(hwnd, WM_CLOSE, 0, 0);/* Timer error so do a hard quit */
|
---|
643 | break;
|
---|
644 | case IDPB_CONVERTABORT:
|
---|
645 | bBreak=TRUE;
|
---|
646 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTABORT), FALSE);
|
---|
647 | break;
|
---|
648 | case IDPB_CONVERTOK:
|
---|
649 | {
|
---|
650 | FSALLOCATE fsAlloc;
|
---|
651 | long long lFreeSpace;
|
---|
652 | ULONG ulDiskNum;
|
---|
653 | char cLetter;
|
---|
654 |
|
---|
655 | WinQueryWindowText( WinWindowFromID(hwnd,IDEF_CONVERTTARGETNAME), sizeof(chrTargetName), chrTargetName );
|
---|
656 |
|
---|
657 | /* Check if diskspace is sufficient. Only for *.wav */
|
---|
658 | if(!stricmp(pMemFormatInfo[iIoProc].szDefaultFormatExt, "WAV")) {
|
---|
659 | cLetter=tolower(chrTargetName[0]);
|
---|
660 | ulDiskNum=cLetter-'a'+1;
|
---|
661 | if(DosQueryFSInfo(ulDiskNum, FSIL_ALLOC,&fsAlloc,sizeof(fsAlloc)))
|
---|
662 | lFreeSpace=0;
|
---|
663 | else
|
---|
664 | lFreeSpace=fsAlloc.cUnitAvail*fsAlloc.cbSector*fsAlloc.cSectorUnit;
|
---|
665 | }
|
---|
666 | else
|
---|
667 | lFreeSpace=lAudioSize; /* Fake sufficient space */
|
---|
668 |
|
---|
669 | if(lFreeSpace<lAudioSize) {
|
---|
670 | /*
|
---|
671 | Text:
|
---|
672 | Title:
|
---|
673 | */
|
---|
674 | getMessage(title, IDSTR_CONVERTNOSPACETEXT,sizeof(title), RESSOURCEHANDLE, hwnd);
|
---|
675 | sprintf(text,title,lAudioSize/1000000 );
|
---|
676 | getMessage(title, IDSTR_CONVERTNOSPACETITLE,sizeof(title), RESSOURCEHANDLE, hwnd);
|
---|
677 | WinMessageBox( HWND_DESKTOP, hwnd, text,
|
---|
678 | title,
|
---|
679 | 1234UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
|
---|
680 | }
|
---|
681 | else {
|
---|
682 | /* Start decoding an audio file */
|
---|
683 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTOK), FALSE);
|
---|
684 | WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTABORT), TRUE);
|
---|
685 | convertAudioFile(hwnd);
|
---|
686 | }
|
---|
687 |
|
---|
688 | break;
|
---|
689 | }
|
---|
690 | default:
|
---|
691 | break;
|
---|
692 | }
|
---|
693 | return (MRESULT) FALSE;
|
---|
694 | default:
|
---|
695 | break;
|
---|
696 | }/* switch */
|
---|
697 |
|
---|
698 | return WinDefDlgProc( hwnd, msg, mp1, mp2);
|
---|
699 | }
|
---|
700 |
|
---|
701 |
|
---|
702 | int main (int argc, char *argv[])
|
---|
703 | {
|
---|
704 | HAB hab;
|
---|
705 | HMQ hmq;
|
---|
706 | char text[CCHMAXPATH];
|
---|
707 | char title[CCHMAXPATH];
|
---|
708 | short a;
|
---|
709 |
|
---|
710 | /* Create a copy of the args */
|
---|
711 | /* argv[0]: progname
|
---|
712 | * argv[1]: wavefile
|
---|
713 | * argv[2]: IO proc name
|
---|
714 | */
|
---|
715 |
|
---|
716 |
|
---|
717 | numArgs=argc;
|
---|
718 |
|
---|
719 | for(a=0;a<argc;a++)
|
---|
720 | {
|
---|
721 | params[a]=argv[a];
|
---|
722 | }
|
---|
723 |
|
---|
724 |
|
---|
725 | hab=WinInitialize(0);
|
---|
726 | if(hab) {
|
---|
727 | hmq=WinCreateMsgQueue(hab,0);
|
---|
728 | if(hmq) {
|
---|
729 | /* Check if user started prog by hand */
|
---|
730 | if(argc<NUMPARAMS-1) {/* Not the actual num of params */
|
---|
731 | pmUsage();
|
---|
732 | }
|
---|
733 | else {
|
---|
734 | /* Save source name */
|
---|
735 | strcpy(chrSourceName,params[1]);
|
---|
736 | if(argc==NUMPARAMS)
|
---|
737 | strcpy(chrProcName,params[2]);
|
---|
738 | else {
|
---|
739 | bNoProcGiven=TRUE;
|
---|
740 | strcpy(chrProcName, "");
|
---|
741 | }
|
---|
742 | /* Get our ressource dll */
|
---|
743 | // RESSOURCEHANDLE=0;
|
---|
744 | RESSOURCEHANDLE=queryResModuleHandle(argv[0]);
|
---|
745 | HlpBuildMMProgIniFileName(argv[0], chrIniFile, sizeof(chrIniFile));
|
---|
746 | /* Register the percent bar window class */
|
---|
747 | percentRegisterBarClass();
|
---|
748 | /* Get audio file characteristics */
|
---|
749 | if(queryAudioInfo(chrSourceName)) {
|
---|
750 | if( WinDlgBox( HWND_DESKTOP, NULLHANDLE, decodeStatusDialogProc, RESSOURCEHANDLE, IDDLG_CONVERT, 0) == DID_ERROR )
|
---|
751 | {
|
---|
752 | /*
|
---|
753 | Text:
|
---|
754 | Title: "Installation problem"
|
---|
755 | */
|
---|
756 | messageBox( text, IDSTR_CONVERTDIALOGERROR , sizeof(text),
|
---|
757 | title, IDSTR_INSTALLERRORTITLE , sizeof(title),
|
---|
758 | RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
|
---|
759 | freeResHandle();
|
---|
760 | WinDestroyMsgQueue( hmq );
|
---|
761 | WinTerminate( hab );
|
---|
762 | DosBeep(100,600);
|
---|
763 | return( 1 );
|
---|
764 | }
|
---|
765 | }
|
---|
766 | }
|
---|
767 | freeResHandle();
|
---|
768 | WinDestroyMsgQueue(hmq);
|
---|
769 | }
|
---|
770 | WinTerminate(hab);
|
---|
771 | }
|
---|
772 | return 0;
|
---|
773 | }
|
---|