Small fixes.
[wine/multimedia.git] / multimedia / mcistring.c
blob844627f66d725656ad15e3b657e0cf92f695dbf5
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * MCI stringinterface
6 * Copyright 1995 Marcus Meissner
7 */
8 /* FIXME: special commands of device drivers should be handled by those drivers
9 */
11 /* FIXME: this current implementation does not allow commands like
12 * capability <filename> can play
13 * which is allowed by the MCI standard.
16 #include <unistd.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <fcntl.h>
20 #include <sys/ioctl.h>
21 #include "windows.h"
22 #include "heap.h"
23 #include "ldt.h"
24 #include "user.h"
25 #include "driver.h"
26 #include "mmsystem.h"
27 #include "multimedia.h"
28 #include "callback.h"
29 #include "debug.h"
30 #include "xmalloc.h"
32 extern struct WINE_MCIDRIVER mciDrv[MAXMCIDRIVERS];
34 #define MCI_GetDrv(wDevID) (&mciDrv[MCI_DevIDToIndex(wDevID)])
35 #define MCI_GetOpenDrv(wDevID) (&(MCI_GetDrv(wDevID)->mop))
37 LONG WINAPI DrvDefDriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg,
38 DWORD dwParam1, DWORD dwParam2);
40 /* The reason why I just don't lowercase the keywords array in
41 * mciSendString is left as an exercise to the reader.
43 #define STRCMP(x,y) lstrcmpi32A(x,y)
45 /* standard functionparameters for all functions */
46 #define _MCISTR_PROTO_ \
47 WORD wDevID,WORD uDevTyp,LPSTR lpstrReturnString,UINT16 uReturnLength,\
48 LPCSTR dev,LPSTR *keywords,UINT16 nrofkeywords,DWORD dwFlags,\
49 HWND16 hwndCallback
51 /* copy string to return pointer including necessary checks
52 * for use in mciSendString()
54 #define _MCI_STR(s) do {\
55 TRACE(mci,"->returns '%s'\n",s);\
56 if (lpstrReturnString) {\
57 lstrcpyn32A(lpstrReturnString,s,uReturnLength);\
58 TRACE(mci,"-->'%s'\n",lpstrReturnString);\
60 } while(0)
62 /* calling DriverProc. */
63 #define _MCI_CALL_DRIVER(cmd,params) \
64 { \
65 MCIPROC32 proc = MCI_GetProc32(uDevTyp); \
66 res = (proc) ? (*proc)(MCI_GetDrv(wDevID)->modp.wDeviceID, 0, cmd, dwFlags, (DWORD)(params)) : MCIERR_DEVICE_NOT_INSTALLED; \
69 /* print a DWORD in the specified timeformat */
70 static void
71 _MCISTR_printtf(char *buf,UINT16 uDevType,DWORD timef,DWORD val) {
72 *buf='\0';
73 switch (timef) {
74 case MCI_FORMAT_MILLISECONDS:
75 case MCI_FORMAT_FRAMES:
76 case MCI_FORMAT_BYTES:
77 case MCI_FORMAT_SAMPLES:
78 case MCI_VD_FORMAT_TRACK:
79 /*case MCI_SEQ_FORMAT_SONGPTR: sameas MCI_VD_FORMAT_TRACK */
80 sprintf(buf,"%ld",val);
81 break;
82 case MCI_FORMAT_HMS:
83 /* well, the macros have the same content*/
84 /*FALLTRHOUGH*/
85 case MCI_FORMAT_MSF:
86 sprintf(buf,"%d:%d:%d",
87 MCI_HMS_HOUR(val),
88 MCI_HMS_MINUTE(val),
89 MCI_HMS_SECOND(val)
91 break;
92 case MCI_FORMAT_TMSF:
93 sprintf(buf,"%d:%d:%d:%d",
94 MCI_TMSF_TRACK(val),
95 MCI_TMSF_MINUTE(val),
96 MCI_TMSF_SECOND(val),
97 MCI_TMSF_FRAME(val)
99 break;
100 default:
101 FIXME(mci, "missing timeformat for %ld, report.\n",timef);
102 strcpy(buf,"0"); /* hmm */
103 break;
105 return;
107 /* possible different return types */
108 #define _MCISTR_int 1
109 #define _MCISTR_time 2
110 #define _MCISTR_bool 3
111 #define _MCISTR_tfname 4
112 #define _MCISTR_mode 5
113 #define _MCISTR_divtype 6
114 #define _MCISTR_seqtype 7
115 #define _MCISTR_vdmtype 8
116 #define _MCISTR_devtype 9
118 static void
119 _MCISTR_convreturn(int type,DWORD dwReturn,LPSTR lpstrReturnString,
120 WORD uReturnLength,WORD uDevTyp,int timef
122 switch (type) {
123 case _MCISTR_vdmtype:
124 switch (dwReturn) {
125 case MCI_VD_MEDIA_CLV:_MCI_STR("CLV");break;
126 case MCI_VD_MEDIA_CAV:_MCI_STR("CAV");break;
127 default:
128 case MCI_VD_MEDIA_OTHER:_MCI_STR("other");break;
130 break;
131 case _MCISTR_seqtype:
132 switch (dwReturn) {
133 case MCI_SEQ_NONE:_MCI_STR("none");break;
134 case MCI_SEQ_SMPTE:_MCI_STR("smpte");break;
135 case MCI_SEQ_FILE:_MCI_STR("file");break;
136 case MCI_SEQ_MIDI:_MCI_STR("midi");break;
137 default:FIXME(mci,"missing sequencer mode %ld\n",dwReturn);
139 break;
140 case _MCISTR_mode:
141 switch (dwReturn) {
142 case MCI_MODE_NOT_READY:_MCI_STR("not ready");break;
143 case MCI_MODE_STOP:_MCI_STR("stopped");break;
144 case MCI_MODE_PLAY:_MCI_STR("playing");break;
145 case MCI_MODE_RECORD:_MCI_STR("recording");break;
146 case MCI_MODE_SEEK:_MCI_STR("seeking");break;
147 case MCI_MODE_PAUSE:_MCI_STR("paused");break;
148 case MCI_MODE_OPEN:_MCI_STR("open");break;
149 default:break;
151 break;
152 case _MCISTR_bool:
153 if (dwReturn)
154 _MCI_STR("true");
155 else
156 _MCI_STR("false");
157 break;
158 case _MCISTR_int:{
159 char buf[16];
160 sprintf(buf,"%ld",dwReturn);
161 _MCI_STR(buf);
162 break;
164 case _MCISTR_time: {
165 char buf[100];
166 _MCISTR_printtf(buf,uDevTyp,timef,dwReturn);
167 _MCI_STR(buf);
168 break;
170 case _MCISTR_tfname:
171 switch (timef) {
172 case MCI_FORMAT_MILLISECONDS:_MCI_STR("milliseconds");break;
173 case MCI_FORMAT_FRAMES:_MCI_STR("frames");break;
174 case MCI_FORMAT_BYTES:_MCI_STR("bytes");break;
175 case MCI_FORMAT_SAMPLES:_MCI_STR("samples");break;
176 case MCI_FORMAT_HMS:_MCI_STR("hms");break;
177 case MCI_FORMAT_MSF:_MCI_STR("msf");break;
178 case MCI_FORMAT_TMSF:_MCI_STR("tmsf");break;
179 default:
180 FIXME(mci,"missing timefmt for %d, report.\n",timef);
181 break;
183 break;
184 case _MCISTR_divtype:
185 switch (dwReturn) {
186 case MCI_SEQ_DIV_PPQN:_MCI_STR("PPQN");break;
187 case MCI_SEQ_DIV_SMPTE_24:_MCI_STR("SMPTE 24 frame");break;
188 case MCI_SEQ_DIV_SMPTE_25:_MCI_STR("SMPTE 25 frame");break;
189 case MCI_SEQ_DIV_SMPTE_30:_MCI_STR("SMPTE 30 frame");break;
190 case MCI_SEQ_DIV_SMPTE_30DROP:_MCI_STR("SMPTE 30 frame drop");break;
192 case _MCISTR_devtype:
193 switch (dwReturn) {
194 case MCI_DEVTYPE_VCR:_MCI_STR("vcr");break;
195 case MCI_DEVTYPE_VIDEODISC:_MCI_STR("videodisc");break;
196 case MCI_DEVTYPE_CD_AUDIO:_MCI_STR("cd audio");break;
197 case MCI_DEVTYPE_OVERLAY:_MCI_STR("overlay");break;
198 case MCI_DEVTYPE_DAT:_MCI_STR("dat");break;
199 case MCI_DEVTYPE_SCANNER:_MCI_STR("scanner");break;
200 case MCI_DEVTYPE_ANIMATION:_MCI_STR("animation");break;
201 case MCI_DEVTYPE_DIGITAL_VIDEO:_MCI_STR("digital video");break;
202 case MCI_DEVTYPE_OTHER:_MCI_STR("other");break;
203 case MCI_DEVTYPE_WAVEFORM_AUDIO:_MCI_STR("waveform audio");break;
204 case MCI_DEVTYPE_SEQUENCER:_MCI_STR("sequencer");break;
205 default:FIXME(mci,"unknown device type %ld, report.\n",
206 dwReturn);break;
208 break;
209 default:
210 FIXME(mci,"unknown resulttype %d, report.\n",type);
211 break;
215 #define FLAG1(str,flag) \
216 if (!STRCMP(keywords[i],str)) {\
217 dwFlags |= flag;\
218 i++;\
219 continue;\
221 #define FLAG2(str1,str2,flag) \
222 if (!STRCMP(keywords[i],str1) && (i+1<nrofkeywords) && !STRCMP(keywords[i+1],str2)) {\
223 dwFlags |= flag;\
224 i+=2;\
225 continue;\
228 /* All known subcommands are implemented in single functions to avoid
229 * bloat and a xxxx lines long mciSendString(). All commands are of the
230 * format MCISTR_Cmd(_MCISTR_PROTO_) where _MCISTR_PROTO_ is the above
231 * defined line of arguments. (This is just for easy enhanceability.)
232 * All functions return the MCIERR_ errorvalue as DWORD. Returnvalues
233 * for the calls are in lpstrReturnString (If I mention return values
234 * in function headers, I mean returnvalues in lpstrReturnString.)
235 * Integers are sprintf("%d")ed integers. Boolean values are
236 * "true" and "false".
237 * timeformat depending values are "%d" "%d:%d" "%d:%d:%d" "%d:%d:%d:%d"
238 * FIXME: is above line correct?
240 * Preceding every function is a list of implemented/known arguments.
241 * Feel free to add missing arguments.
246 * Opens the specified MCI driver.
247 * Arguments: <name>
248 * Optional:
249 * "shareable"
250 * "alias <aliasname>"
251 * "element <elementname>"
252 * Additional:
253 * waveform audio:
254 * "buffer <nrBytesPerSec>"
255 * Animation:
256 * "nostatic" increaste nr of nonstatic colours
257 * "parent <windowhandle>"
258 * "style <mask>" bitmask of WS_xxxxx (see windows.h)
259 * "style child" WS_CHILD
260 * "style overlap" WS_OVERLAPPED
261 * "style popup" WS_POPUP
262 * Overlay:
263 * "parent <windowhandle>"
264 * "style <mask>" bitmask of WS_xxxxx (see windows.h)
265 * "style child" WS_CHILD
266 * "style overlap" WS_OVERLAPPED
267 * "style popup" WS_POPUP
268 * Returns nothing.
270 static DWORD
271 MCISTR_Open(_MCISTR_PROTO_) {
272 int res,i;
273 char *s;
274 union U {
275 MCI_OPEN_PARMS16 openParams;
276 MCI_WAVE_OPEN_PARMS16 waveopenParams;
277 MCI_ANIM_OPEN_PARMS16 animopenParams;
278 MCI_OVLY_OPEN_PARMS16 ovlyopenParams;
280 union U *pU = xmalloc(sizeof(union U));
282 pU->openParams.lpstrElementName = NULL;
283 s=strchr(dev,'!');
284 if (s!=NULL) {
285 *s++='\0';
286 pU->openParams.lpstrElementName=strdup(s);
287 dwFlags |= MCI_OPEN_ELEMENT;
289 uDevTyp = MCI_GetDevType(dev);
290 if (uDevTyp == 0) {
291 free(pU->openParams.lpstrElementName);
292 free(pU);
293 return MCIERR_INVALID_DEVICE_NAME;
295 wDevID=MCI_FirstDevID();
296 while(MCI_GetDrv(wDevID)->modp.wType) {
297 wDevID = MCI_NextDevID(wDevID);
298 if (!MCI_DevIDValid(wDevID)) {
299 TRACE(mci, "MAXMCIDRIVERS reached (%x) !\n", wDevID);
300 free(pU->openParams.lpstrElementName);
301 free(pU);
302 return MCIERR_INTERNAL;
305 MCI_GetDrv(wDevID)->modp.wType = uDevTyp;
306 MCI_GetDrv(wDevID)->modp.wDeviceID = 0; /* FIXME? for multiple devices */
307 pU->openParams.dwCallback = hwndCallback ;
308 pU->openParams.wDeviceID = wDevID;
309 pU->openParams.wReserved0 = 0;
310 pU->ovlyopenParams.dwStyle = 0;
311 pU->animopenParams.dwStyle = 0;
312 pU->openParams.lpstrDeviceType = strdup(dev);
313 pU->openParams.lpstrAlias = NULL;
314 dwFlags |= MCI_OPEN_TYPE;
315 i=0;
316 while (i<nrofkeywords) {
317 FLAG1("shareable",MCI_OPEN_SHAREABLE);
318 if (!STRCMP(keywords[i],"alias") && (i+1<nrofkeywords)) {
319 dwFlags |= MCI_OPEN_ALIAS;
320 pU->openParams.lpstrAlias=strdup(keywords[i+1]);
321 i+=2;
322 continue;
324 if (!STRCMP(keywords[i],"element") && (i+1<nrofkeywords)) {
325 dwFlags |= MCI_OPEN_ELEMENT;
326 pU->openParams.lpstrElementName=strdup(keywords[i+1]);
327 i+=2;
328 continue;
330 switch (uDevTyp) {
331 case MCI_DEVTYPE_ANIMATION:
332 case MCI_DEVTYPE_DIGITAL_VIDEO:
333 FLAG1("nostatic",MCI_ANIM_OPEN_NOSTATIC);
334 if (!STRCMP(keywords[i],"parent") && (i+1<nrofkeywords)) {
335 dwFlags |= MCI_ANIM_OPEN_PARENT;
336 sscanf(keywords[i+1],"%hu",&(pU->animopenParams.hWndParent));
337 i+=2;
338 continue;
340 if (!STRCMP(keywords[i],"style") && (i+1<nrofkeywords)) {
341 DWORD st;
343 dwFlags |= MCI_ANIM_OPEN_WS;
344 if (!STRCMP(keywords[i+1],"popup")) {
345 pU->animopenParams.dwStyle |= WS_POPUP;
346 } else if (!STRCMP(keywords[i+1],"overlap")) {
347 pU->animopenParams.dwStyle |= WS_OVERLAPPED;
348 } else if (!STRCMP(keywords[i+1],"child")) {
349 pU->animopenParams.dwStyle |= WS_CHILD;
350 } else if (sscanf(keywords[i+1],"%ld",&st)) {
351 pU->animopenParams.dwStyle |= st;
352 } else
353 FIXME(mci,"unknown 'style' keyword %s, please report.\n",keywords[i+1]);
354 i+=2;
355 continue;
357 break;
358 case MCI_DEVTYPE_WAVEFORM_AUDIO:
359 if (!STRCMP(keywords[i],"buffer") && (i+1<nrofkeywords)) {
360 dwFlags |= MCI_WAVE_OPEN_BUFFER;
361 sscanf(keywords[i+1],"%ld",&(pU->waveopenParams.dwBufferSeconds));
363 break;
364 case MCI_DEVTYPE_OVERLAY:
365 /* looks just like anim, but without NOSTATIC */
366 if (!STRCMP(keywords[i],"parent") && (i+1<nrofkeywords)) {
367 dwFlags |= MCI_OVLY_OPEN_PARENT;
368 sscanf(keywords[i+1],"%hd",&(pU->ovlyopenParams.hWndParent));
369 i+=2;
370 continue;
372 if (!STRCMP(keywords[i],"style") && (i+1<nrofkeywords)) {
373 DWORD st;
375 dwFlags |= MCI_OVLY_OPEN_WS;
376 if (!STRCMP(keywords[i+1],"popup")) {
377 pU->ovlyopenParams.dwStyle |= WS_POPUP;
378 } else if (!STRCMP(keywords[i+1],"overlap")) {
379 pU->ovlyopenParams.dwStyle |= WS_OVERLAPPED;
380 } else if (!STRCMP(keywords[i+1],"child")) {
381 pU->ovlyopenParams.dwStyle |= WS_CHILD;
382 } else if (sscanf(keywords[i+1],"%ld",&st)) {
383 pU->ovlyopenParams.dwStyle |= st;
384 } else
385 FIXME(mci,"unknown 'style' keyword %s, please report.\n",keywords[i+1]);
386 i+=2;
387 continue;
389 break;
391 FIXME(mci,"unknown parameter passed %s, please report.\n",
392 keywords[i]);
393 i++;
395 _MCI_CALL_DRIVER(MCI_OPEN, pU);
396 if (res==0)
397 memcpy(MCI_GetOpenDrv(wDevID),&pU->openParams,sizeof(MCI_OPEN_PARMS16));
398 else {
399 free(pU->openParams.lpstrElementName);
400 free(pU->openParams.lpstrDeviceType);
401 free(pU->openParams.lpstrAlias);
403 free(pU);
404 return res;
407 /* A help function for a lot of others ...
408 * for instance status/play/record/seek etc.
410 DWORD
411 _MCISTR_determine_timeformat(LPCSTR dev,WORD wDevID,WORD uDevTyp,int *timef)
413 int res;
414 DWORD dwFlags = MCI_STATUS_ITEM;
415 MCI_STATUS_PARMS *statusParams = xmalloc(sizeof(MCI_STATUS_PARMS));
417 if (!statusParams) return 0;
418 statusParams->dwItem = MCI_STATUS_TIME_FORMAT;
419 statusParams->dwReturn = 0;
420 _MCI_CALL_DRIVER( MCI_STATUS, statusParams );
421 if (res==0) *timef = statusParams->dwReturn;
422 free(statusParams);
423 return res;
426 /* query status of MCI drivers
427 * Arguments:
428 * Required:
429 * "mode" - returns "not ready" "paused" "playing" "stopped" "open"
430 * "parked" "recording" "seeking" ....
431 * Basics:
432 * "current track" - returns current track as integer
433 * "length [track <nr>]" - returns length [of track <nr>] in current
434 * timeformat
435 * "number of tracks" - returns number of tracks as integer
436 * "position [track <nr>]" - returns position [in track <nr>] in current
437 * timeformat
438 * "ready" - checks if device is ready to play, -> bool
439 * "start position" - returns start position in timeformat
440 * "time format" - returns timeformat (list of possible values:
441 * "ms" "msf" "milliseconds" "hmsf" "tmsf" "frames"
442 * "bytes" "samples" "hms")
443 * "media present" - returns if media is present as bool
444 * Animation:
445 * "forward" - returns "true" if device is playing forwards
446 * "speed" - returns speed for device
447 * "palette handle" - returns palette handle
448 * "window handle" - returns window handle
449 * "stretch" - returns stretch bool
450 * MIDI sequencer:
451 * "division type" - ? returns "PPQN" "SMPTE 24 frame"
452 * "SMPTE 25 frame" "SMPTE 30 frame" "SMPTE 30 drop frame"
453 * "tempo" - current tempo in (PPQN? speed in frames, SMPTE*? speed in hsmf)
454 * "offset" - offset in dito.
455 * "port" - midi port as integer
456 * "slave" - slave device ("midi","file","none","smpte")
457 * "master" - masterdevice (dito.)
458 * Overlay:
459 * "window handle" - see animation
460 * "stretch" - dito
461 * Video Disc:
462 * "speed" - speed as integer
463 * "forward" - returns bool (when playing forward)
464 * "side" - returns 1 or 2
465 * "media type" - returns "CAV" "CLV" "other"
466 * "disc size" - returns "8" or "12"
467 * WAVEFORM audio:
468 * "input" - base queries on input set
469 * "output" - base queries on output set
470 * "format tag" - return integer format tag
471 * "channels" - return integer nr of channels
472 * "bytespersec" - return average nr of bytes/sec
473 * "samplespersec" - return nr of samples per sec
474 * "bitspersample" - return bitspersample
475 * "alignment" - return block alignment
476 * "level" - return level?
479 #define ITEM1(str,item,xtype) \
480 if (!STRCMP(keywords[i],str)) {\
481 statusParams->dwItem = item;\
482 type = xtype;\
483 i++;\
484 continue;\
486 #define ITEM2(str1,str2,item,xtype) \
487 if ( !STRCMP(keywords[i],str1) &&\
488 (i+1<nrofkeywords) &&\
489 !STRCMP(keywords[i+1],str2)\
490 ) {\
491 statusParams->dwItem = item;\
492 type = xtype;\
493 i+=2;\
494 continue;\
496 #define ITEM3(str1,str2,str3,item,xtype) \
497 if ( !STRCMP(keywords[i],str1) &&\
498 (i+2<nrofkeywords) &&\
499 !STRCMP(keywords[i+1],str2) &&\
500 !STRCMP(keywords[i+2],str3)\
501 ) {\
502 statusParams->dwItem = item;\
503 type = xtype;\
504 i+=3;\
505 continue;\
507 static DWORD
508 MCISTR_Status(_MCISTR_PROTO_) {
509 MCI_STATUS_PARMS *statusParams = xmalloc(sizeof(MCI_STATUS_PARMS));
510 int type = 0,i,res,timef;
512 statusParams->dwCallback = hwndCallback;
513 dwFlags |= MCI_STATUS_ITEM;
514 res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef);
515 if (res) return res;
517 statusParams->dwReturn = 0;
518 statusParams->dwItem = 0;
519 i = 0;
521 while (i<nrofkeywords) {
522 if (!STRCMP(keywords[i],"track") && (i+1<nrofkeywords)) {
523 sscanf(keywords[i+1],"%ld",&(statusParams->dwTrack));
524 dwFlags |= MCI_TRACK;
525 i+=2;
526 continue;
528 FLAG1("start",MCI_STATUS_START);
529 /* generic things */
530 ITEM2("current","track",MCI_STATUS_CURRENT_TRACK,_MCISTR_time);
531 ITEM2("time","format",MCI_STATUS_TIME_FORMAT,_MCISTR_tfname);
532 ITEM1("ready",MCI_STATUS_READY,_MCISTR_bool);
533 ITEM1("mode",MCI_STATUS_MODE,_MCISTR_mode);
534 ITEM3("number","of","tracks",MCI_STATUS_NUMBER_OF_TRACKS,_MCISTR_int);
535 ITEM1("length",MCI_STATUS_LENGTH,_MCISTR_time);
536 ITEM1("position",MCI_STATUS_POSITION,_MCISTR_time);
537 ITEM2("media","present",MCI_STATUS_MEDIA_PRESENT,_MCISTR_bool);
539 switch (uDevTyp) {
540 case MCI_DEVTYPE_ANIMATION:
541 case MCI_DEVTYPE_DIGITAL_VIDEO:
542 ITEM2("palette","handle",MCI_ANIM_STATUS_HPAL,_MCISTR_int);
543 ITEM2("window","handle",MCI_ANIM_STATUS_HWND,_MCISTR_int);
544 ITEM1("stretch",MCI_ANIM_STATUS_STRETCH,_MCISTR_bool);
545 ITEM1("speed",MCI_ANIM_STATUS_SPEED,_MCISTR_int);
546 ITEM1("forward",MCI_ANIM_STATUS_FORWARD,_MCISTR_bool);
547 break;
548 case MCI_DEVTYPE_SEQUENCER:
549 /* just completing the list, not working correctly */
550 ITEM2("division","type",MCI_SEQ_STATUS_DIVTYPE,_MCISTR_divtype);
551 /* tempo ... PPQN in frames/second, SMPTE in hmsf */
552 ITEM1("tempo",MCI_SEQ_STATUS_TEMPO,_MCISTR_int);
553 ITEM1("port",MCI_SEQ_STATUS_PORT,_MCISTR_int);
554 ITEM1("slave",MCI_SEQ_STATUS_SLAVE,_MCISTR_seqtype);
555 ITEM1("master",MCI_SEQ_STATUS_SLAVE,_MCISTR_seqtype);
556 /* offset ... PPQN in frames/second, SMPTE in hmsf */
557 ITEM1("offset",MCI_SEQ_STATUS_SLAVE,_MCISTR_time);
558 break;
559 case MCI_DEVTYPE_OVERLAY:
560 ITEM2("window","handle",MCI_OVLY_STATUS_HWND,_MCISTR_int);
561 ITEM1("stretch",MCI_OVLY_STATUS_STRETCH,_MCISTR_bool);
562 break;
563 case MCI_DEVTYPE_VIDEODISC:
564 ITEM1("speed",MCI_VD_STATUS_SPEED,_MCISTR_int);
565 ITEM1("forward",MCI_VD_STATUS_FORWARD,_MCISTR_bool);
566 ITEM1("side",MCI_VD_STATUS_SIDE,_MCISTR_int);
567 ITEM2("media","type",MCI_VD_STATUS_SIDE,_MCISTR_vdmtype);
568 /* returns 8 or 12 */
569 ITEM2("disc","size",MCI_VD_STATUS_DISC_SIZE,_MCISTR_int);
570 break;
571 case MCI_DEVTYPE_WAVEFORM_AUDIO:
572 /* I am not quite sure if foll. 2 lines are right. */
573 FLAG1("input",MCI_WAVE_INPUT);
574 FLAG1("output",MCI_WAVE_OUTPUT);
576 ITEM2("format","tag",MCI_WAVE_STATUS_FORMATTAG,_MCISTR_int);
577 ITEM1("channels",MCI_WAVE_STATUS_CHANNELS,_MCISTR_int);
578 ITEM1("bytespersec",MCI_WAVE_STATUS_AVGBYTESPERSEC,_MCISTR_int);
579 ITEM1("samplespersec",MCI_WAVE_STATUS_SAMPLESPERSEC,_MCISTR_int);
580 ITEM1("bitspersample",MCI_WAVE_STATUS_BITSPERSAMPLE,_MCISTR_int);
581 ITEM1("alignment",MCI_WAVE_STATUS_BLOCKALIGN,_MCISTR_int);
582 ITEM1("level",MCI_WAVE_STATUS_LEVEL,_MCISTR_int);
583 break;
585 FIXME(mci,"unknown keyword '%s'\n",keywords[i]);
586 i++;
588 if (!statusParams->dwItem)
589 return MCIERR_MISSING_STRING_ARGUMENT;
591 _MCI_CALL_DRIVER( MCI_STATUS, statusParams );
592 if (res==0)
593 _MCISTR_convreturn(type,statusParams->dwReturn,lpstrReturnString,uReturnLength,uDevTyp,timef);
594 free(statusParams);
595 return res;
597 #undef ITEM1
598 #undef ITEM2
599 #undef ITEM3
601 /* set specified parameters in respective MCI drivers
602 * Arguments:
603 * "door open" eject media or somesuch
604 * "door close" load media
605 * "time format <timeformatname>" "ms" "milliseconds" "msf" "hmsf"
606 * "tmsf" "SMPTE 24" "SMPTE 25" "SMPTE 30"
607 * "SMPTE drop 30"
608 * "audio [all|left|right] [on|off]" sets specified audiochannel on or off
609 * "video [on|off]" sets video on/off
610 * Waveform audio:
611 * "formattag pcm" sets format to pcm
612 * "formattag <nr>" sets integer formattag value
613 * "any input" accept input from any known source
614 * "any output" output to any known destination
615 * "input <nr>" input from source <nr>
616 * "output <nr>" output to destination <nr>
617 * "channels <nr>" sets nr of channels
618 * "bytespersec <nr>" sets average bytes per second
619 * "samplespersec <nr>" sets average samples per second (1 sample can
620 * be 2 bytes!)
621 * "alignment <nr>" sets the blockalignment to <nr>
622 * "bitspersample <nr>" sets the nr of bits per sample
623 * Sequencer:
624 * "master [midi|file|smpte|none]" sets the midi master device
625 * "slave [midi|file|smpte|none]" sets the midi master device
626 * "port mapper" midioutput to portmapper
627 * "port <nr>" midioutput to specified port
628 * "tempo <nr>" tempo of track (depends on timeformat/divtype)
629 * "offset <nr>" start offset?
631 static DWORD
632 MCISTR_Set(_MCISTR_PROTO_) {
633 union U {
634 MCI_SET_PARMS setParams;
635 MCI_WAVE_SET_PARMS16 wavesetParams;
636 MCI_SEQ_SET_PARMS seqsetParams;
638 union U *pU = xmalloc(sizeof(union U));
639 int i,res;
641 pU->setParams.dwCallback = hwndCallback;
642 i = 0;
643 while (i<nrofkeywords) {
644 FLAG2("door","open",MCI_SET_DOOR_OPEN);
645 FLAG2("door","closed",MCI_SET_DOOR_CLOSED);
647 if ( !STRCMP(keywords[i],"time") &&
648 (i+2<nrofkeywords) &&
649 !STRCMP(keywords[i+1],"format")
651 dwFlags |= MCI_SET_TIME_FORMAT;
653 /* FIXME:is this a shortcut for milliseconds or
654 * minutes:seconds? */
655 if (!STRCMP(keywords[i+2],"ms"))
656 pU->setParams.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
658 if (!STRCMP(keywords[i+2],"milliseconds"))
659 pU->setParams.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
660 if (!STRCMP(keywords[i+2],"msf"))
661 pU->setParams.dwTimeFormat = MCI_FORMAT_MSF;
662 if (!STRCMP(keywords[i+2],"hms"))
663 pU->setParams.dwTimeFormat = MCI_FORMAT_HMS;
664 if (!STRCMP(keywords[i+2],"frames"))
665 pU->setParams.dwTimeFormat = MCI_FORMAT_FRAMES;
666 if (!STRCMP(keywords[i+2],"track"))
667 pU->setParams.dwTimeFormat = MCI_VD_FORMAT_TRACK;
668 if (!STRCMP(keywords[i+2],"bytes"))
669 pU->setParams.dwTimeFormat = MCI_FORMAT_BYTES;
670 if (!STRCMP(keywords[i+2],"samples"))
671 pU->setParams.dwTimeFormat = MCI_FORMAT_SAMPLES;
672 if (!STRCMP(keywords[i+2],"tmsf"))
673 pU->setParams.dwTimeFormat = MCI_FORMAT_TMSF;
674 if ( !STRCMP(keywords[i+2],"song") &&
675 (i+3<nrofkeywords) &&
676 !STRCMP(keywords[i+3],"pointer")
678 pU->setParams.dwTimeFormat = MCI_SEQ_FORMAT_SONGPTR;
679 if (!STRCMP(keywords[i+2],"smpte") && (i+3<nrofkeywords)) {
680 if (!STRCMP(keywords[i+3],"24"))
681 pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_24;
682 if (!STRCMP(keywords[i+3],"25"))
683 pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_25;
684 if (!STRCMP(keywords[i+3],"30"))
685 pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_30;
686 if (!STRCMP(keywords[i+3],"drop") && (i+4<nrofkeywords) && !STRCMP(keywords[i+4],"30")) {
687 pU->setParams.dwTimeFormat = MCI_FORMAT_SMPTE_30DROP;
688 i++;
690 i++;
691 /*FALLTHROUGH*/
693 i+=3;
694 continue;
696 if (!STRCMP(keywords[i],"audio") && (i+1<nrofkeywords)) {
697 dwFlags |= MCI_SET_AUDIO;
698 if (!STRCMP(keywords[i+1],"all"))
699 pU->setParams.dwAudio = MCI_SET_AUDIO_ALL;
700 if (!STRCMP(keywords[i+1],"left"))
701 pU->setParams.dwAudio = MCI_SET_AUDIO_LEFT;
702 if (!STRCMP(keywords[i+1],"right"))
703 pU->setParams.dwAudio = MCI_SET_AUDIO_RIGHT;
704 i+=2;
705 continue;
707 FLAG1("video",MCI_SET_VIDEO);
708 FLAG1("on",MCI_SET_ON);
709 FLAG1("off",MCI_SET_OFF);
710 switch (uDevTyp) {
711 case MCI_DEVTYPE_WAVEFORM_AUDIO:
712 FLAG2("any","input",MCI_WAVE_SET_ANYINPUT);
713 FLAG2("any","output",MCI_WAVE_SET_ANYOUTPUT);
715 if ( !STRCMP(keywords[i],"formattag") &&
716 (i+1<nrofkeywords) &&
717 !STRCMP(keywords[i+1],"pcm")
719 dwFlags |= MCI_WAVE_SET_FORMATTAG;
720 pU->wavesetParams.wFormatTag = WAVE_FORMAT_PCM;
721 i+=2;
722 continue;
725 /* <keyword> <integer> */
726 #define WII(str,flag,fmt,element) \
727 if (!STRCMP(keywords[i],str) && (i+1<nrofkeywords)) {\
728 sscanf(keywords[i+1],fmt,&(pU->wavesetParams. element ));\
729 dwFlags |= flag;\
730 i+=2;\
731 continue;\
733 WII("formattag",MCI_WAVE_SET_FORMATTAG,"%hu",wFormatTag);
734 WII("channels",MCI_WAVE_SET_CHANNELS,"%hu",nChannels);
735 WII("bytespersec",MCI_WAVE_SET_AVGBYTESPERSEC,"%lu",nAvgBytesPerSec);
736 WII("samplespersec",MCI_WAVE_SET_SAMPLESPERSEC,"%lu",nSamplesPerSec);
737 WII("alignment",MCI_WAVE_SET_BLOCKALIGN,"%hu",nBlockAlign);
738 WII("bitspersample",MCI_WAVE_SET_BITSPERSAMPLE,"%hu",wBitsPerSample);
739 WII("input",MCI_WAVE_INPUT,"%hu",wInput);
740 WII("output",MCI_WAVE_OUTPUT,"%hu",wOutput);
741 #undef WII
742 break;
743 case MCI_DEVTYPE_SEQUENCER:
744 if (!STRCMP(keywords[i],"master") && (i+1<nrofkeywords)) {
745 dwFlags |= MCI_SEQ_SET_MASTER;
746 if (!STRCMP(keywords[i+1],"midi"))
747 pU->seqsetParams.dwMaster = MCI_SEQ_MIDI;
748 if (!STRCMP(keywords[i+1],"file"))
749 pU->seqsetParams.dwMaster = MCI_SEQ_FILE;
750 if (!STRCMP(keywords[i+1],"smpte"))
751 pU->seqsetParams.dwMaster = MCI_SEQ_SMPTE;
752 if (!STRCMP(keywords[i+1],"none"))
753 pU->seqsetParams.dwMaster = MCI_SEQ_NONE;
754 i+=2;
755 continue;
757 if (!STRCMP(keywords[i],"slave") && (i+1<nrofkeywords)) {
758 dwFlags |= MCI_SEQ_SET_SLAVE;
759 if (!STRCMP(keywords[i+1],"midi"))
760 pU->seqsetParams.dwMaster = MCI_SEQ_MIDI;
761 if (!STRCMP(keywords[i+1],"file"))
762 pU->seqsetParams.dwMaster = MCI_SEQ_FILE;
763 if (!STRCMP(keywords[i+1],"smpte"))
764 pU->seqsetParams.dwMaster = MCI_SEQ_SMPTE;
765 if (!STRCMP(keywords[i+1],"none"))
766 pU->seqsetParams.dwMaster = MCI_SEQ_NONE;
767 i+=2;
768 continue;
770 if ( !STRCMP(keywords[i],"port") &&
771 (i+1<nrofkeywords) &&
772 !STRCMP(keywords[i+1],"mapper")
774 pU->seqsetParams.dwPort=-1;/* FIXME:not sure*/
775 dwFlags |= MCI_SEQ_SET_PORT;
776 i+=2;
777 continue;
779 #define SII(str,flag,element) \
780 if (!STRCMP(keywords[i],str) && (i+1<nrofkeywords)) {\
781 sscanf(keywords[i+1],"%ld",&(pU->seqsetParams. element ));\
782 dwFlags |= flag;\
783 i+=2;\
784 continue;\
786 SII("tempo",MCI_SEQ_SET_TEMPO,dwTempo);
787 SII("port",MCI_SEQ_SET_PORT,dwPort);
788 SII("offset",MCI_SEQ_SET_PORT,dwOffset);
790 i++;
792 if (!dwFlags)
793 return MCIERR_MISSING_STRING_ARGUMENT;
794 _MCI_CALL_DRIVER( MCI_SET, pU );
795 free(pU);
796 return res;
799 /* specify break key
800 * Arguments:
801 * "off" disable break
802 * "on <keyid>" enable break on key with keyid
803 * (I strongly suspect, that there is another parameter:
804 * "window <handle>"
805 * but I don't see it mentioned in my documentation.
806 * Returns nothing.
808 static DWORD
809 MCISTR_Break(_MCISTR_PROTO_)
811 MCI_BREAK_PARMS16 *breakParams = xmalloc(sizeof(MCI_BREAK_PARMS16));
812 int res,i;
814 if (!breakParams) return 0;
815 /*breakParams.hwndBreak ? */
816 for (i = 0; i < nrofkeywords; i++) {
817 FLAG1("off",MCI_BREAK_OFF);
818 if (!strcmp(keywords[i],"on") && (nrofkeywords>i+1)) {
819 dwFlags&=~MCI_BREAK_OFF;
820 dwFlags|=MCI_BREAK_KEY;
821 sscanf(keywords[i+1],"%hd",&(breakParams->nVirtKey));
822 i+=2;
823 continue;
826 _MCI_CALL_DRIVER( MCI_BREAK, breakParams );
827 free(breakParams);
828 return res;
831 #define ITEM1(str,item,xtype) \
832 if (!STRCMP(keywords[i],str)) {\
833 gdcParams->dwItem = item;\
834 type = xtype;\
835 i++;\
836 continue;\
838 #define ITEM2(str1,str2,item,xtype) \
839 if ( !STRCMP(keywords[i],str1) &&\
840 (i+1<nrofkeywords) &&\
841 !STRCMP(keywords[i+1],str2)\
842 ) {\
843 gdcParams->dwItem = item;\
844 type = xtype;\
845 i+=2;\
846 continue;\
848 #define ITEM3(str1,str2,str3,item,xtype) \
849 if ( !STRCMP(keywords[i],str1) &&\
850 (i+2<nrofkeywords) &&\
851 !STRCMP(keywords[i+1],str2) &&\
852 !STRCMP(keywords[i+2],str3)\
853 ) {\
854 gdcParams->dwItem = item;\
855 type = xtype;\
856 i+=3;\
857 continue;\
859 /* get device capabilities of MCI drivers
860 * Arguments:
861 * Generic:
862 * "device type" returns device name as string
863 * "has audio" returns bool
864 * "has video" returns bool
865 * "uses files" returns bool
866 * "compound device" returns bool
867 * "can record" returns bool
868 * "can play" returns bool
869 * "can eject" returns bool
870 * "can save" returns bool
871 * Animation:
872 * "palettes" returns nr of available palette entries
873 * "windows" returns nr of available windows
874 * "can reverse" returns bool
875 * "can stretch" returns bool
876 * "slow play rate" returns the slow playrate
877 * "fast play rate" returns the fast playrate
878 * "normal play rate" returns the normal playrate
879 * Overlay:
880 * "windows" returns nr of available windows
881 * "can stretch" returns bool
882 * "can freeze" returns bool
883 * Videodisc:
884 * "cav" assume CAV discs (default if no disk inserted)
885 * "clv" assume CLV discs
886 * "can reverse" returns bool
887 * "slow play rate" returns the slow playrate
888 * "fast play rate" returns the fast playrate
889 * "normal play rate" returns the normal playrate
890 * Waveform audio:
891 * "inputs" returns nr of inputdevices
892 * "outputs" returns nr of outputdevices
894 static DWORD
895 MCISTR_Capability(_MCISTR_PROTO_) {
896 MCI_GETDEVCAPS_PARMS *gdcParams = xmalloc(sizeof(MCI_GETDEVCAPS_PARMS));
897 int type=0,i,res;
899 gdcParams->dwCallback = hwndCallback;
900 if (!nrofkeywords)
901 return MCIERR_MISSING_STRING_ARGUMENT;
902 /* well , thats default */
903 dwFlags |= MCI_GETDEVCAPS_ITEM;
904 gdcParams->dwItem = 0;
905 i=0;
906 while (i<nrofkeywords) {
907 ITEM2("device","type",MCI_GETDEVCAPS_DEVICE_TYPE,_MCISTR_devtype);
908 ITEM2("has","audio",MCI_GETDEVCAPS_HAS_AUDIO,_MCISTR_bool);
909 ITEM2("has","video",MCI_GETDEVCAPS_HAS_VIDEO,_MCISTR_bool);
910 ITEM2("uses","files",MCI_GETDEVCAPS_USES_FILES,_MCISTR_bool);
911 ITEM2("compound","device",MCI_GETDEVCAPS_COMPOUND_DEVICE,_MCISTR_bool);
912 ITEM2("can","record",MCI_GETDEVCAPS_CAN_RECORD,_MCISTR_bool);
913 ITEM2("can","play",MCI_GETDEVCAPS_CAN_PLAY,_MCISTR_bool);
914 ITEM2("can","eject",MCI_GETDEVCAPS_CAN_EJECT,_MCISTR_bool);
915 ITEM2("can","save",MCI_GETDEVCAPS_CAN_SAVE,_MCISTR_bool);
916 switch (uDevTyp) {
917 case MCI_DEVTYPE_ANIMATION:
918 ITEM1("palettes",MCI_ANIM_GETDEVCAPS_PALETTES,_MCISTR_int);
919 ITEM1("windows",MCI_ANIM_GETDEVCAPS_MAX_WINDOWS,_MCISTR_int);
920 ITEM2("can","reverse",MCI_ANIM_GETDEVCAPS_CAN_REVERSE,_MCISTR_bool);
921 ITEM2("can","stretch",MCI_ANIM_GETDEVCAPS_CAN_STRETCH,_MCISTR_bool);
922 ITEM3("slow","play","rate",MCI_ANIM_GETDEVCAPS_SLOW_RATE,_MCISTR_int);
923 ITEM3("fast","play","rate",MCI_ANIM_GETDEVCAPS_FAST_RATE,_MCISTR_int);
924 ITEM3("normal","play","rate",MCI_ANIM_GETDEVCAPS_NORMAL_RATE,_MCISTR_int);
925 break;
926 case MCI_DEVTYPE_OVERLAY:
927 ITEM1("windows",MCI_OVLY_GETDEVCAPS_MAX_WINDOWS,_MCISTR_int);
928 ITEM2("can","freeze",MCI_OVLY_GETDEVCAPS_CAN_FREEZE,_MCISTR_bool);
929 ITEM2("can","stretch",MCI_OVLY_GETDEVCAPS_CAN_STRETCH,_MCISTR_bool);
930 break;
931 case MCI_DEVTYPE_VIDEODISC:
932 FLAG1("cav",MCI_VD_GETDEVCAPS_CAV);
933 FLAG1("clv",MCI_VD_GETDEVCAPS_CLV);
934 ITEM2("can","reverse",MCI_VD_GETDEVCAPS_CAN_REVERSE,_MCISTR_bool);
935 ITEM3("slow","play","rate",MCI_VD_GETDEVCAPS_SLOW_RATE,_MCISTR_int);
936 ITEM3("fast","play","rate",MCI_VD_GETDEVCAPS_FAST_RATE,_MCISTR_int);
937 ITEM3("normal","play","rate",MCI_VD_GETDEVCAPS_NORMAL_RATE,_MCISTR_int);
938 break;
939 case MCI_DEVTYPE_WAVEFORM_AUDIO:
940 ITEM1("inputs",MCI_WAVE_GETDEVCAPS_INPUTS,_MCISTR_int);
941 ITEM1("outputs",MCI_WAVE_GETDEVCAPS_OUTPUTS,_MCISTR_int);
942 break;
944 i++;
946 _MCI_CALL_DRIVER( MCI_GETDEVCAPS, gdcParams );
947 /* no timeformat needed */
948 if (res==0)
949 _MCISTR_convreturn( type, gdcParams->dwReturn, lpstrReturnString,
950 uReturnLength, uDevTyp, 0 );
951 free(gdcParams);
952 return res;
954 #undef ITEM1
955 #undef ITEM2
956 #undef ITEM3
957 /* resumes operation of device. no arguments, no return values */
958 static DWORD
959 MCISTR_Resume(_MCISTR_PROTO_)
961 MCI_GENERIC_PARMS *genParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
962 int res;
963 genParams->dwCallback = hwndCallback;
964 _MCI_CALL_DRIVER( MCI_RESUME, genParams );
965 return res;
968 /* pauses operation of device. no arguments, no return values */
969 static DWORD
970 MCISTR_Pause(_MCISTR_PROTO_)
972 MCI_GENERIC_PARMS *genParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
973 int res;
974 genParams->dwCallback = hwndCallback;
975 _MCI_CALL_DRIVER( MCI_PAUSE, genParams );
976 return res;
979 /* stops operation of device. no arguments, no return values */
980 static DWORD
981 MCISTR_Stop(_MCISTR_PROTO_)
983 MCI_GENERIC_PARMS *genParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
984 int res;
985 genParams->dwCallback = hwndCallback;
986 _MCI_CALL_DRIVER( MCI_STOP, genParams );
987 return res;
990 /* starts recording.
991 * Arguments:
992 * "overwrite" overwrite existing things
993 * "insert" insert at current position
994 * "to <time>" record up to <time> (specified in timeformat)
995 * "from <time>" record from <time> (specified in timeformat)
997 static DWORD
998 MCISTR_Record(_MCISTR_PROTO_) {
999 int i,res,timef,nrargs,j,k,a[4];
1000 char *parsestr;
1001 MCI_RECORD_PARMS *recordParams = xmalloc(sizeof(MCI_RECORD_PARMS));
1003 res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef);
1004 if (res) return res;
1006 switch (timef) {
1007 case MCI_FORMAT_MILLISECONDS:
1008 case MCI_FORMAT_FRAMES:
1009 case MCI_FORMAT_BYTES:
1010 case MCI_FORMAT_SAMPLES:
1011 nrargs=1;
1012 parsestr="%d";
1013 break;
1014 case MCI_FORMAT_HMS:
1015 case MCI_FORMAT_MSF:
1016 parsestr="%d:%d:%d";
1017 nrargs=3;
1018 break;
1019 case MCI_FORMAT_TMSF:
1020 parsestr="%d:%d:%d:%d";
1021 nrargs=4;
1022 break;
1023 default:FIXME(mci,"unknown timeformat %d, please report.\n",timef);
1024 parsestr="%d";
1025 nrargs=1;
1026 break;
1028 recordParams->dwCallback = hwndCallback;
1029 i = 0;
1030 while (i<nrofkeywords) {
1031 if (!strcmp(keywords[i],"to") && (i+1<nrofkeywords)) {
1032 dwFlags |= MCI_TO;
1033 a[0]=a[1]=a[2]=a[3]=0;
1034 j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
1035 /* add up all integers we got, if we have more
1036 * shift them. (Well I should use the macros in
1037 * mmsystem.h, right).
1039 recordParams->dwTo=0;
1040 for (k=0;k<j;k++)
1041 recordParams->dwTo+=a[k]<<(8*(nrargs-k));
1042 i+=2;
1043 continue;
1045 if (!strcmp(keywords[i],"from") && (i+1<nrofkeywords)) {
1046 dwFlags |= MCI_FROM;
1047 a[0]=a[1]=a[2]=a[3]=0;
1048 j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
1049 /* dito. */
1050 recordParams->dwFrom=0;
1051 for (k=0;k<j;k++)
1052 recordParams->dwFrom+=a[k]<<(8*(nrargs-k));
1053 i+=2;
1054 continue;
1056 FLAG1("insert",MCI_RECORD_INSERT);
1057 FLAG1("overwrite",MCI_RECORD_OVERWRITE);
1058 i++;
1060 _MCI_CALL_DRIVER( MCI_RECORD, recordParams );
1061 free(recordParams);
1062 return res;
1065 /* play media
1066 * Arguments:
1067 * "to <time>" play up to <time> (specified in set timeformat)
1068 * "from <time>" play from <time> (specified in set timeformat)
1069 * Animation:
1070 * "slow" play slow
1071 * "fast" play fast
1072 * "scan" play as fast as possible (with audio disabled perhaps)
1073 * "reverse" play reverse
1074 * "speed <fps>" play with specified frames per second
1075 * Videodisc:
1076 * "slow" play slow
1077 * "fast" play fast
1078 * "scan" play as fast as possible (with audio disabled perhaps)
1079 * "reverse" play reverse
1080 * "speed <fps>" play with specified frames per second
1082 static DWORD
1083 MCISTR_Play(_MCISTR_PROTO_) {
1084 int i,res,timef,nrargs,j,k,a[4];
1085 char *parsestr;
1086 union U {
1087 MCI_PLAY_PARMS playParams;
1088 MCI_VD_PLAY_PARMS vdplayParams;
1089 MCI_ANIM_PLAY_PARMS animplayParams;
1091 union U *pU = xmalloc(sizeof(union U));
1093 res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef);
1094 if (res) return res;
1095 switch (timef) {
1096 case MCI_FORMAT_MILLISECONDS:
1097 case MCI_FORMAT_FRAMES:
1098 case MCI_FORMAT_BYTES:
1099 case MCI_FORMAT_SAMPLES:
1100 nrargs=1;
1101 parsestr="%d";
1102 break;
1103 case MCI_FORMAT_HMS:
1104 case MCI_FORMAT_MSF:
1105 parsestr="%d:%d:%d";
1106 nrargs=3;
1107 break;
1108 case MCI_FORMAT_TMSF:
1109 parsestr="%d:%d:%d:%d";
1110 nrargs=4;
1111 break;
1112 default:FIXME(mci,"unknown timeformat %d, please report.\n",timef);
1113 parsestr="%d";
1114 nrargs=1;
1115 break;
1117 pU->playParams.dwCallback=hwndCallback;
1118 i=0;
1119 while (i<nrofkeywords) {
1120 if (!strcmp(keywords[i],"to") && (i+1<nrofkeywords)) {
1121 dwFlags |= MCI_TO;
1122 a[0]=a[1]=a[2]=a[3]=0;
1123 j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
1124 /* add up all integers we got, if we have more
1125 * shift them. (Well I should use the macros in
1126 * mmsystem.h, right).
1128 pU->playParams.dwTo=0;
1129 for (k=0;k<j;k++)
1130 pU->playParams.dwTo+=a[k]<<(8*(nrargs-k));
1131 i+=2;
1132 continue;
1134 if (!strcmp(keywords[i],"from") && (i+1<nrofkeywords)) {
1135 dwFlags |= MCI_FROM;
1136 a[0]=a[1]=a[2]=a[3]=0;
1137 j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
1138 /* dito. */
1139 pU->playParams.dwFrom=0;
1140 for (k=0;k<j;k++)
1141 pU->playParams.dwFrom+=a[k]<<(8*(nrargs-k));
1142 i+=2;
1143 continue;
1145 switch (uDevTyp) {
1146 case MCI_DEVTYPE_VIDEODISC:
1147 FLAG1("slow",MCI_VD_PLAY_SLOW);
1148 FLAG1("fast",MCI_VD_PLAY_FAST);
1149 FLAG1("scan",MCI_VD_PLAY_SCAN);
1150 FLAG1("reverse",MCI_VD_PLAY_REVERSE);
1151 if (!STRCMP(keywords[i],"speed") && (i+1<nrofkeywords)) {
1152 dwFlags |= MCI_VD_PLAY_SPEED;
1153 sscanf(keywords[i+1],"%ld",&(pU->vdplayParams.dwSpeed));
1154 i+=2;
1155 continue;
1157 break;
1158 case MCI_DEVTYPE_ANIMATION:
1159 FLAG1("slow",MCI_ANIM_PLAY_SLOW);
1160 FLAG1("fast",MCI_ANIM_PLAY_FAST);
1161 FLAG1("scan",MCI_ANIM_PLAY_SCAN);
1162 FLAG1("reverse",MCI_ANIM_PLAY_REVERSE);
1163 if (!STRCMP(keywords[i],"speed") && (i+1<nrofkeywords)) {
1164 dwFlags |= MCI_ANIM_PLAY_SPEED;
1165 sscanf(keywords[i+1],"%ld",&(pU->animplayParams.dwSpeed));
1166 i+=2;
1167 continue;
1169 break;
1171 i++;
1173 _MCI_CALL_DRIVER( MCI_PLAY, pU );
1174 free(pU);
1175 return res;
1178 /* seek to a specified position
1179 * Arguments:
1180 * "to start" seek to start of medium
1181 * "to end" seek to end of medium
1182 * "to <time>" seek to <time> specified in current timeformat
1184 static DWORD
1185 MCISTR_Seek(_MCISTR_PROTO_) {
1186 int i,res,timef,nrargs,j,k,a[4];
1187 char *parsestr;
1188 MCI_SEEK_PARMS *seekParams = xmalloc(sizeof(MCI_SEEK_PARMS));
1190 res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef);
1191 if (res) return res;
1192 switch (timef) {
1193 case MCI_FORMAT_MILLISECONDS:
1194 case MCI_FORMAT_FRAMES:
1195 case MCI_FORMAT_BYTES:
1196 case MCI_FORMAT_SAMPLES:
1197 nrargs=1;
1198 parsestr="%d";
1199 break;
1200 case MCI_FORMAT_HMS:
1201 case MCI_FORMAT_MSF:
1202 parsestr="%d:%d:%d";
1203 nrargs=3;
1204 break;
1205 case MCI_FORMAT_TMSF:
1206 parsestr="%d:%d:%d:%d";
1207 nrargs=4;
1208 break;
1209 default:FIXME(mci,"unknown timeformat %d, please report.\n",timef);
1210 parsestr="%d";
1211 nrargs=1;
1212 break;
1214 seekParams->dwCallback=hwndCallback;
1215 i=0;
1216 while (i<nrofkeywords) {
1217 if ( !STRCMP(keywords[i],"to") && (i+1<nrofkeywords)) {
1218 if (!STRCMP(keywords[i+1],"start")) {
1219 dwFlags|=MCI_SEEK_TO_START;
1220 seekParams->dwTo=0;
1221 i+=2;
1222 continue;
1224 if (!STRCMP(keywords[i+1],"end")) {
1225 dwFlags|=MCI_SEEK_TO_END;
1226 seekParams->dwTo=0;
1227 i+=2;
1228 continue;
1230 dwFlags|=MCI_TO;
1231 i+=2;
1232 a[0]=a[1]=a[2]=a[3]=0;
1233 j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
1234 seekParams->dwTo=0;
1235 for (k=0;k<j;k++)
1236 seekParams->dwTo+=a[k]<<(8*(nrargs-k));
1237 continue;
1239 switch (uDevTyp) {
1240 case MCI_DEVTYPE_VIDEODISC:
1241 FLAG1("reverse",MCI_VD_SEEK_REVERSE);
1242 break;
1244 i++;
1246 _MCI_CALL_DRIVER( MCI_SEEK, seekParams );
1247 free(seekParams);
1248 return res;
1251 /* close media/driver */
1252 static DWORD
1253 MCISTR_Close(_MCISTR_PROTO_)
1255 MCI_GENERIC_PARMS *closeParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
1256 int res;
1257 _MCI_CALL_DRIVER( MCI_CLOSE, closeParams );
1258 free(closeParams);
1259 return res;
1262 /* return information.
1263 * Arguments:
1264 * "product" return product name (human readable)
1265 * "file" return filename
1266 * Animation:
1267 * "text" returns text?
1268 * Overlay:
1269 * "text" returns text?
1271 static DWORD
1272 MCISTR_Info(_MCISTR_PROTO_)
1274 MCI_INFO_PARMS16 *infoParams = xmalloc(sizeof(MCI_INFO_PARMS16));
1275 DWORD sflags;
1276 int i,res;
1278 sflags = dwFlags;
1279 i=0;while (i<nrofkeywords) {
1280 FLAG1("product",MCI_INFO_PRODUCT);
1281 FLAG1("file",MCI_INFO_FILE);
1282 switch (uDevTyp) {
1283 case MCI_DEVTYPE_ANIMATION:
1284 FLAG1("text",MCI_ANIM_INFO_TEXT);
1285 break;
1286 case MCI_DEVTYPE_OVERLAY:
1287 FLAG1("text",MCI_OVLY_INFO_TEXT);
1288 break;
1290 i++;
1292 if (dwFlags == sflags)
1293 return MCIERR_MISSING_STRING_ARGUMENT;
1294 /* MCI driver will fill in lpstrReturn, dwRetSize.
1295 * FIXME: I don't know if this is correct behaviour
1297 _MCI_CALL_DRIVER( MCI_INFO, infoParams );
1298 if (res==0)
1299 _MCI_STR(infoParams->lpstrReturn);
1300 free(infoParams);
1301 return res;
1304 /* query MCI driver itself for information
1305 * Arguments:
1306 * "installname" return install name of <device> (system.ini)
1307 * "quantity" return nr of installed drivers
1308 * "open" open drivers only (additional flag)
1309 * "name <nr>" return nr of devices with <devicetyp>
1310 * "name all" return nr of all devices
1312 * FIXME: mciSysInfo16() is broken I think.
1314 static DWORD
1315 MCISTR_Sysinfo(_MCISTR_PROTO_) {
1316 MCI_SYSINFO_PARMS16 sysinfoParams;
1317 int i,res;
1319 sysinfoParams.lpstrReturn = lpstrReturnString;
1320 sysinfoParams.dwRetSize = uReturnLength;
1321 sysinfoParams.wDeviceType = uDevTyp;
1323 for (i = 0; i < nrofkeywords; i++) {
1324 FLAG1("installname",MCI_SYSINFO_INSTALLNAME);
1325 FLAG1("quantity",MCI_SYSINFO_INSTALLNAME);
1326 FLAG1("open",MCI_SYSINFO_OPEN);
1327 if (!strcmp(keywords[i],"name") && (i+1<nrofkeywords)) {
1328 sscanf(keywords[i+1],"%ld",&(sysinfoParams.dwNumber));
1329 dwFlags |= MCI_SYSINFO_NAME;
1330 i++;
1333 res = mciSendCommand16(0, MCI_SYSINFO, dwFlags, (DWORD)&sysinfoParams);
1335 if (dwFlags & MCI_SYSINFO_QUANTITY) {
1336 char buf[100];
1338 sprintf(buf,"%ld",*(long*)lpstrReturnString);
1339 _MCI_STR(buf);
1341 /* no need to copy anything back, mciSysInfo did it for us */
1342 return res;
1345 /* load file
1346 * Argument: "<filename>"
1347 * Overlay: "at <left> <top> <right> <bottom>" additional
1349 static DWORD
1350 MCISTR_Load(_MCISTR_PROTO_) {
1351 union U {
1352 MCI_LOAD_PARMS16 loadParams;
1353 MCI_OVLY_LOAD_PARMS16 ovlyloadParams;
1355 union U *pU = xmalloc(sizeof(union U));
1356 int i,len,res;
1357 char *s;
1359 i=0;len=0;
1360 while (i<nrofkeywords) {
1361 switch (uDevTyp) {
1362 case MCI_DEVTYPE_OVERLAY:
1363 if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
1364 dwFlags |= MCI_OVLY_RECT;
1365 sscanf(keywords[i+1],"%hd",&(pU->ovlyloadParams.rc.left));
1366 sscanf(keywords[i+2],"%hd",&(pU->ovlyloadParams.rc.top));
1367 sscanf(keywords[i+3],"%hd",&(pU->ovlyloadParams.rc.right));
1368 sscanf(keywords[i+4],"%hd",&(pU->ovlyloadParams.rc.bottom));
1369 memcpy(keywords+i,keywords+(i+5),nrofkeywords-(i+5));
1370 continue;
1372 break;
1374 len+=strlen(keywords[i])+1;
1375 i++;
1377 s=(char*)xmalloc(len);
1378 *s='\0';
1379 while (i<nrofkeywords) {
1380 strcat(s,keywords[i]);
1381 i++;
1382 if (i<nrofkeywords) strcat(s," ");
1384 pU->loadParams.lpfilename=s;
1385 dwFlags |= MCI_LOAD_FILE;
1386 _MCI_CALL_DRIVER( MCI_LOAD, pU );
1387 free(s);
1388 free(pU);
1389 return res;
1392 /* save to file
1393 * Argument: "<filename>"
1394 * Overlay: "at <left> <top> <right> <bottom>" additional
1396 static DWORD
1397 MCISTR_Save(_MCISTR_PROTO_) {
1398 union U {
1399 MCI_SAVE_PARMS saveParams;
1400 MCI_OVLY_SAVE_PARMS16 ovlysaveParams;
1402 union U *pU = xmalloc(sizeof(union U));
1403 int i,len,res;
1404 char *s;
1406 i=0;len=0;
1407 while (i<nrofkeywords) {
1408 switch (uDevTyp) {
1409 case MCI_DEVTYPE_OVERLAY:
1410 if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
1411 dwFlags |= MCI_OVLY_RECT;
1412 sscanf(keywords[i+1],"%hd",&(pU->ovlysaveParams.rc.left));
1413 sscanf(keywords[i+2],"%hd",&(pU->ovlysaveParams.rc.top));
1414 sscanf(keywords[i+3],"%hd",&(pU->ovlysaveParams.rc.right));
1415 sscanf(keywords[i+4],"%hd",&(pU->ovlysaveParams.rc.bottom));
1416 memcpy(keywords+i,keywords+(i+5),nrofkeywords-(i+5));
1417 continue;
1419 break;
1421 len+=strlen(keywords[i])+1;
1422 i++;
1424 s=(char*)xmalloc(len);
1425 *s='\0';
1426 while (i<nrofkeywords) {
1427 strcat(s,keywords[i]);
1428 i++;
1429 if (i<nrofkeywords) strcat(s," ");
1431 pU->saveParams.lpfilename=s;
1432 dwFlags |= MCI_LOAD_FILE;
1433 _MCI_CALL_DRIVER( MCI_SAVE, pU );
1434 free(s);
1435 free(pU);
1436 return res;
1439 /* prepare device for input/output
1440 * (only applyable to waveform audio)
1442 static DWORD
1443 MCISTR_Cue(_MCISTR_PROTO_) {
1444 MCI_GENERIC_PARMS *cueParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
1445 int i,res;
1447 i=0;
1448 while (i<nrofkeywords) {
1449 switch (uDevTyp) {
1450 case MCI_DEVTYPE_WAVEFORM_AUDIO:
1451 FLAG1("input",MCI_WAVE_INPUT);
1452 FLAG1("output",MCI_WAVE_OUTPUT);
1453 break;
1455 i++;
1457 _MCI_CALL_DRIVER( MCI_CUE, cueParams );
1458 free(cueParams);
1459 return res;
1462 /* delete information */
1463 static DWORD
1464 MCISTR_Delete(_MCISTR_PROTO_) {
1465 int timef,nrargs,i,j,k,a[4],res;
1466 char *parsestr;
1467 MCI_WAVE_DELETE_PARMS *deleteParams = xmalloc(sizeof(MCI_WAVE_DELETE_PARMS));
1469 /* only implemented for waveform audio */
1470 if (uDevTyp != MCI_DEVTYPE_WAVEFORM_AUDIO)
1471 return MCIERR_UNSUPPORTED_FUNCTION; /* well it fits */
1472 res = _MCISTR_determine_timeformat(dev,wDevID,uDevTyp,&timef);
1473 if (res) return res;
1474 switch (timef) {
1475 case MCI_FORMAT_MILLISECONDS:
1476 case MCI_FORMAT_FRAMES:
1477 case MCI_FORMAT_BYTES:
1478 case MCI_FORMAT_SAMPLES:
1479 nrargs=1;
1480 parsestr="%d";
1481 break;
1482 case MCI_FORMAT_HMS:
1483 case MCI_FORMAT_MSF:
1484 parsestr="%d:%d:%d";
1485 nrargs=3;
1486 break;
1487 case MCI_FORMAT_TMSF:
1488 parsestr="%d:%d:%d:%d";
1489 nrargs=4;
1490 break;
1491 default:FIXME(mci,"unknown timeformat %d, please report.\n",timef);
1492 parsestr="%d";
1493 nrargs=1;
1494 break;
1496 i=0;
1497 while (i<nrofkeywords) {
1498 if (!strcmp(keywords[i],"to") && (i+1<nrofkeywords)) {
1499 dwFlags |= MCI_TO;
1500 a[0]=a[1]=a[2]=a[3]=0;
1501 j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
1502 /* add up all integers we got, if we have more
1503 * shift them. (Well I should use the macros in
1504 * mmsystem.h, right).
1506 deleteParams->dwTo=0;
1507 for (k=0;k<j;k++)
1508 deleteParams->dwTo+=a[k]<<(8*(nrargs-k));
1509 i+=2;
1510 continue;
1512 if (!strcmp(keywords[i],"from") && (i+1<nrofkeywords)) {
1513 dwFlags |= MCI_FROM;
1514 a[0]=a[1]=a[2]=a[3]=0;
1515 j=sscanf(keywords[i+1],parsestr,&a[0],&a[1],&a[2],&a[3]);
1516 /* dito. */
1517 deleteParams->dwFrom=0;
1518 for (k=0;k<j;k++)
1519 deleteParams->dwFrom+=a[k]<<(8*(nrargs-k));
1520 i+=2;
1521 continue;
1523 i++;
1525 _MCI_CALL_DRIVER( MCI_DELETE, deleteParams );
1526 free(deleteParams);
1527 return res;
1530 /* send command to device. only applies to videodisc */
1531 static DWORD
1532 MCISTR_Escape(_MCISTR_PROTO_)
1534 MCI_VD_ESCAPE_PARMS16 *escapeParams = xmalloc(sizeof(MCI_VD_ESCAPE_PARMS16));
1535 int i,len,res;
1536 char *s;
1538 if (uDevTyp != MCI_DEVTYPE_VIDEODISC)
1539 return MCIERR_UNSUPPORTED_FUNCTION;
1540 i=0;len=0;
1541 while (i<nrofkeywords) {
1542 len+=strlen(keywords[i])+1;
1543 i++;
1545 s=(char*)malloc(len);
1546 *s='\0';
1547 while (i<nrofkeywords) {
1548 strcat(s,keywords[i]);
1549 i++;
1550 if (i<nrofkeywords) strcat(s," ");
1552 escapeParams->lpstrCommand = s;
1553 dwFlags |= MCI_VD_ESCAPE_STRING;
1554 _MCI_CALL_DRIVER( MCI_ESCAPE, escapeParams );
1555 free(s);
1556 free(escapeParams);
1557 return res;
1560 /* unfreeze [part of] the overlayed video
1561 * only applyable to Overlay devices
1563 static DWORD
1564 MCISTR_Unfreeze(_MCISTR_PROTO_)
1566 MCI_OVLY_RECT_PARMS16 *unfreezeParams = xmalloc(sizeof(MCI_OVLY_RECT_PARMS16));
1567 int i,res;
1569 if (uDevTyp != MCI_DEVTYPE_OVERLAY)
1570 return MCIERR_UNSUPPORTED_FUNCTION;
1571 i=0;while (i<nrofkeywords) {
1572 if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
1573 sscanf(keywords[i+1],"%hd",&(unfreezeParams->rc.left));
1574 sscanf(keywords[i+2],"%hd",&(unfreezeParams->rc.top));
1575 sscanf(keywords[i+3],"%hd",&(unfreezeParams->rc.right));
1576 sscanf(keywords[i+4],"%hd",&(unfreezeParams->rc.bottom));
1577 dwFlags |= MCI_OVLY_RECT;
1578 i+=5;
1579 continue;
1581 i++;
1583 _MCI_CALL_DRIVER( MCI_UNFREEZE, unfreezeParams );
1584 free(unfreezeParams);
1585 return res;
1587 /* freeze [part of] the overlayed video
1588 * only applyable to Overlay devices
1590 static DWORD
1591 MCISTR_Freeze(_MCISTR_PROTO_)
1593 MCI_OVLY_RECT_PARMS16 *freezeParams = xmalloc(sizeof(MCI_OVLY_RECT_PARMS16));
1594 int i,res;
1596 if (uDevTyp != MCI_DEVTYPE_OVERLAY)
1597 return MCIERR_UNSUPPORTED_FUNCTION;
1598 i=0;while (i<nrofkeywords) {
1599 if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
1600 sscanf(keywords[i+1],"%hd",&(freezeParams->rc.left));
1601 sscanf(keywords[i+2],"%hd",&(freezeParams->rc.top));
1602 sscanf(keywords[i+3],"%hd",&(freezeParams->rc.right));
1603 sscanf(keywords[i+4],"%hd",&(freezeParams->rc.bottom));
1604 dwFlags |= MCI_OVLY_RECT;
1605 i+=5;
1606 continue;
1608 i++;
1610 _MCI_CALL_DRIVER( MCI_FREEZE, freezeParams );
1611 free(freezeParams);
1612 return res;
1615 /* copy parts of image to somewhere else
1616 * "source [at <left> <top> <right> <bottom>]" source is framebuffer [or rect]
1617 * "destination [at <left> <top> <right> <bottom>]" destination is framebuffer [or rect]
1618 * Overlay:
1619 * "frame [at <left> <top> <right> <bottom>]" frame is framebuffer [or rect]
1620 * where the video input is placed
1621 * "video [at <left> <top> <right> <bottom>]" video is whole video [or rect]
1622 * (defining part of input to
1623 * be displayed)
1625 * FIXME: This whole junk is passing multiple rectangles.
1626 * I don't know how to do that with the present interface.
1627 * (Means code below is broken)
1629 static DWORD
1630 MCISTR_Put(_MCISTR_PROTO_) {
1631 union U {
1632 MCI_OVLY_RECT_PARMS16 ovlyputParams;
1633 MCI_ANIM_RECT_PARMS16 animputParams;
1635 union U *pU = xmalloc(sizeof(union U));
1636 int i,res;
1637 i=0;while (i<nrofkeywords) {
1638 switch (uDevTyp) {
1639 case MCI_DEVTYPE_ANIMATION:
1640 FLAG1("source",MCI_ANIM_PUT_SOURCE);
1641 FLAG1("destination",MCI_ANIM_PUT_DESTINATION);
1642 if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
1643 sscanf(keywords[i+1],"%hd",&(pU->animputParams.rc.left));
1644 sscanf(keywords[i+2],"%hd",&(pU->animputParams.rc.top));
1645 sscanf(keywords[i+3],"%hd",&(pU->animputParams.rc.right));
1646 sscanf(keywords[i+4],"%hd",&(pU->animputParams.rc.bottom));
1647 dwFlags |= MCI_ANIM_RECT;
1648 i+=5;
1649 continue;
1651 break;
1652 case MCI_DEVTYPE_OVERLAY:
1653 FLAG1("source",MCI_OVLY_PUT_SOURCE);
1654 FLAG1("destination",MCI_OVLY_PUT_DESTINATION);
1655 FLAG1("video",MCI_OVLY_PUT_VIDEO);
1656 FLAG1("frame",MCI_OVLY_PUT_FRAME);
1657 if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
1658 sscanf(keywords[i+1],"%hd",&(pU->ovlyputParams.rc.left));
1659 sscanf(keywords[i+2],"%hd",&(pU->ovlyputParams.rc.top));
1660 sscanf(keywords[i+3],"%hd",&(pU->ovlyputParams.rc.right));
1661 sscanf(keywords[i+4],"%hd",&(pU->ovlyputParams.rc.bottom));
1662 dwFlags |= MCI_OVLY_RECT;
1663 i+=5;
1664 continue;
1666 break;
1668 i++;
1670 _MCI_CALL_DRIVER( MCI_PUT, pU );
1671 free(pU);
1672 return res;
1675 /* palette behaviour changing
1676 * (Animation only)
1677 * "normal" realize the palette normally
1678 * "background" realize the palette as background palette
1680 static DWORD
1681 MCISTR_Realize(_MCISTR_PROTO_)
1683 MCI_GENERIC_PARMS *realizeParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
1684 int i,res;
1686 if (uDevTyp != MCI_DEVTYPE_ANIMATION)
1687 return MCIERR_UNSUPPORTED_FUNCTION;
1688 i=0;
1689 while (i<nrofkeywords) {
1690 FLAG1("background",MCI_ANIM_REALIZE_BKGD);
1691 FLAG1("normal",MCI_ANIM_REALIZE_NORM);
1692 i++;
1694 _MCI_CALL_DRIVER( MCI_REALIZE, realizeParams );
1695 free(realizeParams);
1696 return res;
1699 /* videodisc spinning
1700 * "up"
1701 * "down"
1703 static DWORD
1704 MCISTR_Spin(_MCISTR_PROTO_)
1706 MCI_GENERIC_PARMS *spinParams = xmalloc(sizeof(MCI_GENERIC_PARMS));
1707 int i,res;
1709 if (uDevTyp != MCI_DEVTYPE_VIDEODISC)
1710 return MCIERR_UNSUPPORTED_FUNCTION;
1711 i=0;
1712 while (i<nrofkeywords) {
1713 FLAG1("up",MCI_VD_SPIN_UP);
1714 FLAG1("down",MCI_VD_SPIN_UP);
1715 i++;
1717 _MCI_CALL_DRIVER( MCI_SPIN, spinParams );
1718 free(spinParams);
1719 return res;
1722 /* step single frames
1723 * "reverse" optional flag
1724 * "by <nr>" for <nr> frames
1726 static DWORD
1727 MCISTR_Step(_MCISTR_PROTO_) {
1728 union U {
1729 MCI_ANIM_STEP_PARMS animstepParams;
1730 MCI_VD_STEP_PARMS vdstepParams;
1732 union U *pU = xmalloc(sizeof(union U));
1733 int i,res;
1735 i=0;
1736 while (i<nrofkeywords) {
1737 switch (uDevTyp) {
1738 case MCI_DEVTYPE_ANIMATION:
1739 FLAG1("reverse",MCI_ANIM_STEP_REVERSE);
1740 if (!STRCMP(keywords[i],"by") && (i+1<nrofkeywords)) {
1741 sscanf(keywords[i+1],"%ld",&(pU->animstepParams.dwFrames));
1742 dwFlags |= MCI_ANIM_STEP_FRAMES;
1743 i+=2;
1744 continue;
1746 break;
1747 case MCI_DEVTYPE_VIDEODISC:
1748 FLAG1("reverse",MCI_VD_STEP_REVERSE);
1749 if (!STRCMP(keywords[i],"by") && (i+1<nrofkeywords)) {
1750 sscanf(keywords[i+1],"%ld",&(pU->vdstepParams.dwFrames));
1751 dwFlags |= MCI_VD_STEP_FRAMES;
1752 i+=2;
1753 continue;
1755 break;
1757 i++;
1759 _MCI_CALL_DRIVER( MCI_STEP, pU );
1760 free(pU);
1761 return res;
1764 /* update animation window
1765 * Arguments:
1766 * "at <left> <top> <right> <bottom>" only in this rectangle
1767 * "hdc" device context
1769 static DWORD
1770 MCISTR_Update(_MCISTR_PROTO_) {
1771 int i,res;
1772 MCI_ANIM_UPDATE_PARMS16 *updateParams = xmalloc(sizeof(MCI_ANIM_UPDATE_PARMS16));
1774 i=0;
1775 while (i<nrofkeywords) {
1776 if (!STRCMP(keywords[i],"at") && (i+4<nrofkeywords)) {
1777 sscanf(keywords[i+1],"%hd",&(updateParams->rc.left));
1778 sscanf(keywords[i+2],"%hd",&(updateParams->rc.top));
1779 sscanf(keywords[i+3],"%hd",&(updateParams->rc.right));
1780 sscanf(keywords[i+4],"%hd",&(updateParams->rc.bottom));
1781 dwFlags |= MCI_ANIM_RECT;
1782 i+=5;
1783 continue;
1785 if (!STRCMP(keywords[i],"hdc") && (i+1<nrofkeywords)) {
1786 dwFlags |= MCI_ANIM_UPDATE_HDC;
1787 sscanf(keywords[i+1],"%hd",&(updateParams->hDC));
1788 i+=2;
1789 continue;
1791 i++;
1793 _MCI_CALL_DRIVER( MCI_UPDATE, updateParams );
1794 free(updateParams);
1795 return res;
1798 /* where command for animation and overlay drivers.
1799 * just returns the specified rectangle as a string
1800 * Arguments:
1801 * "source"
1802 * "destination"
1803 * Overlay special:
1804 * "video"
1805 * "frame"
1807 static DWORD
1808 MCISTR_Where(_MCISTR_PROTO_) {
1809 union U {
1810 MCI_ANIM_RECT_PARMS16 animwhereParams;
1811 MCI_OVLY_RECT_PARMS16 ovlywhereParams;
1813 union U *pU = xmalloc(sizeof(union U));
1814 int i,res;
1816 i=0;
1817 while (i<nrofkeywords) {
1818 switch (uDevTyp) {
1819 case MCI_DEVTYPE_ANIMATION:
1820 FLAG1("source",MCI_ANIM_WHERE_SOURCE);
1821 FLAG1("destination",MCI_ANIM_WHERE_DESTINATION);
1822 break;
1823 case MCI_DEVTYPE_OVERLAY:
1824 FLAG1("source",MCI_OVLY_WHERE_SOURCE);
1825 FLAG1("destination",MCI_OVLY_WHERE_DESTINATION);
1826 FLAG1("video",MCI_OVLY_WHERE_VIDEO);
1827 FLAG1("frame",MCI_OVLY_WHERE_FRAME);
1828 break;
1830 i++;
1832 _MCI_CALL_DRIVER( MCI_WHERE, pU );
1833 if (res==0) {
1834 char buf[100];
1835 switch (uDevTyp) {
1836 case MCI_DEVTYPE_ANIMATION:
1837 sprintf(buf,"%d %d %d %d",
1838 pU->animwhereParams.rc.left,
1839 pU->animwhereParams.rc.top,
1840 pU->animwhereParams.rc.right,
1841 pU->animwhereParams.rc.bottom
1843 break;
1844 case MCI_DEVTYPE_OVERLAY:
1845 sprintf(buf,"%d %d %d %d",
1846 pU->ovlywhereParams.rc.left,
1847 pU->ovlywhereParams.rc.top,
1848 pU->ovlywhereParams.rc.right,
1849 pU->ovlywhereParams.rc.bottom
1851 break;
1852 default:strcpy(buf,"0 0 0 0");break;
1854 _MCI_STR(buf);
1856 free(pU);
1857 return res;
1860 static DWORD
1861 MCISTR_Window(_MCISTR_PROTO_) {
1862 int i,res;
1863 char *s;
1864 union U {
1865 MCI_ANIM_WINDOW_PARMS16 animwindowParams;
1866 MCI_OVLY_WINDOW_PARMS16 ovlywindowParams;
1868 union U *pU = xmalloc(sizeof(union U));
1870 s=NULL;
1871 i=0;
1872 while (i<nrofkeywords) {
1873 switch (uDevTyp) {
1874 case MCI_DEVTYPE_ANIMATION:
1875 if (!STRCMP(keywords[i],"handle") && (i+1<nrofkeywords)) {
1876 dwFlags |= MCI_ANIM_WINDOW_HWND;
1877 if (!STRCMP(keywords[i+1],"default"))
1878 pU->animwindowParams.hWnd = MCI_OVLY_WINDOW_DEFAULT;
1879 else
1880 sscanf(keywords[i+1],"%hd",&(pU->animwindowParams.hWnd));
1881 i+=2;
1882 continue;
1884 if (!STRCMP(keywords[i],"state") && (i+1<nrofkeywords)) {
1885 dwFlags |= MCI_ANIM_WINDOW_STATE;
1886 if (!STRCMP(keywords[i+1],"hide"))
1887 pU->animwindowParams.nCmdShow = SW_HIDE;
1888 if (!STRCMP(keywords[i+1],"iconic"))
1889 pU->animwindowParams.nCmdShow = SW_SHOWMINNOACTIVE; /* correct? */
1890 if (!STRCMP(keywords[i+1],"minimized"))
1891 pU->animwindowParams.nCmdShow = SW_SHOWMINIMIZED;
1892 if (!STRCMP(keywords[i+1],"maximized"))
1893 pU->animwindowParams.nCmdShow = SW_SHOWMAXIMIZED;
1894 if (!STRCMP(keywords[i+1],"minimize"))
1895 pU->animwindowParams.nCmdShow = SW_MINIMIZE;
1896 if (!STRCMP(keywords[i+1],"normal"))
1897 pU->animwindowParams.nCmdShow = SW_NORMAL;
1898 if (!STRCMP(keywords[i+1],"show"))
1899 pU->animwindowParams.nCmdShow = SW_SHOW;
1900 if (!STRCMP(keywords[i+1],"no") && (i+2<nrofkeywords)) {
1901 if (!STRCMP(keywords[i+2],"active"))
1902 pU->animwindowParams.nCmdShow = SW_SHOWNOACTIVATE;
1903 if (!STRCMP(keywords[i+2],"action"))
1904 pU->animwindowParams.nCmdShow = SW_SHOWNA;/* correct?*/
1905 i++;
1907 i+=2;
1908 continue;
1910 /* text is enclosed in " ... " as it seems */
1911 if (!STRCMP(keywords[i],"text")) {
1912 char *t;
1913 int len,j,k;
1915 if (keywords[i+1][0]!='"') {
1916 i++;
1917 continue;
1919 dwFlags |= MCI_ANIM_WINDOW_TEXT;
1920 len = strlen(keywords[i+1])+1;
1921 j = i+2;
1922 while (j<nrofkeywords) {
1923 len += strlen(keywords[j])+1;
1924 if (strchr(keywords[j],'"'))
1925 break;
1926 j++;
1928 s=(char*)xmalloc(len);
1929 strcpy(s,keywords[i+1]+1);
1930 k=j;j=i+2;
1931 while (j<=k) {
1932 strcat(s," ");
1933 strcat(s,keywords[j]);
1935 if ((t=strchr(s,'"'))) *t='\0';
1936 /* FIXME: segmented pointer? */
1937 pU->animwindowParams.lpstrText = s;
1938 i=k+1;
1939 continue;
1941 FLAG1("stretch",MCI_ANIM_WINDOW_ENABLE_STRETCH);
1942 break;
1943 case MCI_DEVTYPE_OVERLAY:
1944 if (!STRCMP(keywords[i],"handle") && (i+1<nrofkeywords)) {
1945 dwFlags |= MCI_OVLY_WINDOW_HWND;
1946 if (!STRCMP(keywords[i+1],"default"))
1947 pU->ovlywindowParams.hWnd = MCI_OVLY_WINDOW_DEFAULT;
1948 else
1949 sscanf(keywords[i+1],"%hd",&(pU->ovlywindowParams.hWnd));
1950 i+=2;
1951 continue;
1953 if (!STRCMP(keywords[i],"state") && (i+1<nrofkeywords)) {
1954 dwFlags |= MCI_OVLY_WINDOW_STATE;
1955 if (!STRCMP(keywords[i+1],"hide"))
1956 pU->ovlywindowParams.nCmdShow = SW_HIDE;
1957 if (!STRCMP(keywords[i+1],"iconic"))
1958 pU->ovlywindowParams.nCmdShow = SW_SHOWMINNOACTIVE; /* correct? */
1959 if (!STRCMP(keywords[i+1],"minimized"))
1960 pU->ovlywindowParams.nCmdShow = SW_SHOWMINIMIZED;
1961 if (!STRCMP(keywords[i+1],"maximized"))
1962 pU->ovlywindowParams.nCmdShow = SW_SHOWMAXIMIZED;
1963 if (!STRCMP(keywords[i+1],"minimize"))
1964 pU->ovlywindowParams.nCmdShow = SW_MINIMIZE;
1965 if (!STRCMP(keywords[i+1],"normal"))
1966 pU->ovlywindowParams.nCmdShow = SW_NORMAL;
1967 if (!STRCMP(keywords[i+1],"show"))
1968 pU->ovlywindowParams.nCmdShow = SW_SHOW;
1969 if (!STRCMP(keywords[i+1],"no") && (i+2<nrofkeywords)) {
1970 if (!STRCMP(keywords[i+2],"active"))
1971 pU->ovlywindowParams.nCmdShow = SW_SHOWNOACTIVATE;
1972 if (!STRCMP(keywords[i+2],"action"))
1973 pU->ovlywindowParams.nCmdShow = SW_SHOWNA;/* correct?*/
1974 i++;
1976 i+=2;
1977 continue;
1979 /* text is enclosed in " ... " as it seems */
1980 if (!STRCMP(keywords[i],"text")) {
1981 char *t;
1982 int len,j,k;
1984 if (keywords[i+1][0]!='"') {
1985 i++;
1986 continue;
1988 dwFlags |= MCI_OVLY_WINDOW_TEXT;
1989 len = strlen(keywords[i+1])+1;
1990 j = i+2;
1991 while (j<nrofkeywords) {
1992 len += strlen(keywords[j])+1;
1993 if (strchr(keywords[j],'"'))
1994 break;
1995 j++;
1997 s=(char*)xmalloc(len);
1998 strcpy(s,keywords[i+1]+1);
1999 k=j;j=i+2;
2000 while (j<=k) {
2001 strcat(s," ");
2002 strcat(s,keywords[j]);
2004 if ((t=strchr(s,'"'))) *t='\0';
2005 /* FIXME: segmented pointer? */
2006 pU->ovlywindowParams.lpstrText = s;
2007 i=k+1;
2008 continue;
2010 FLAG1("stretch",MCI_OVLY_WINDOW_ENABLE_STRETCH);
2011 break;
2013 i++;
2015 _MCI_CALL_DRIVER( MCI_WINDOW, pU );
2016 if (s) free(s);
2017 free(pU);
2018 return res;
2021 struct _MCISTR_cmdtable {
2022 char *cmd;
2023 DWORD (*fun)(_MCISTR_PROTO_);
2024 } MCISTR_cmdtable[]={
2025 {"break", MCISTR_Break},
2026 {"capability", MCISTR_Capability},
2027 {"close", MCISTR_Close},
2028 {"cue", MCISTR_Cue},
2029 {"delete", MCISTR_Delete},
2030 {"escape", MCISTR_Escape},
2031 {"freeze", MCISTR_Freeze},
2032 {"info", MCISTR_Info},
2033 {"load", MCISTR_Load},
2034 {"open", MCISTR_Open},
2035 {"pause", MCISTR_Pause},
2036 {"play", MCISTR_Play},
2037 {"put", MCISTR_Put},
2038 {"realize", MCISTR_Realize},
2039 {"record", MCISTR_Record},
2040 {"resume", MCISTR_Resume},
2041 {"save", MCISTR_Save},
2042 {"seek", MCISTR_Seek},
2043 {"set", MCISTR_Set},
2044 {"spin", MCISTR_Spin},
2045 {"status", MCISTR_Status},
2046 {"step", MCISTR_Step},
2047 {"stop", MCISTR_Stop},
2048 {"sysinfo", MCISTR_Sysinfo},
2049 {"unfreeze", MCISTR_Unfreeze},
2050 {"update", MCISTR_Update},
2051 {"where", MCISTR_Where},
2052 {"window", MCISTR_Window},
2053 {NULL, NULL}
2056 /**************************************************************************
2057 * mciSendString16 [MMSYSTEM.702]
2059 /* The usercode sends a string with a command (and flags) expressed in
2060 * words in it... We do our best to call aprobiate drivers,
2061 * and return a errorcode AND a readable string (if lpstrRS!=NULL)
2062 * Info gathered by watching cool134.exe and from Borland's mcistrwh.hlp
2064 /* FIXME: "all" is a valid devicetype and we should access all devices if
2065 * it is used. (imagine "close all"). Not implemented yet.
2067 DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrReturnString,
2068 UINT16 uReturnLength, HWND16 hwndCallback)
2070 char *cmd,*dev,*args,**keywords,*filename;
2071 WORD uDevTyp=0,wDevID=0;
2072 DWORD dwFlags;
2073 int res=0,i,nrofkeywords;
2075 TRACE(mci,"('%s', %p, %d, %X)\n",
2076 lpstrCommand, lpstrReturnString, uReturnLength, hwndCallback);
2078 /* format is <command> <device> <optargs> */
2079 cmd=strdup(lpstrCommand);
2080 dev=strchr(cmd,' ');
2081 if (dev==NULL) {
2082 free(cmd);
2083 return MCIERR_MISSING_DEVICE_NAME;
2085 *dev++='\0';
2086 args=strchr(dev,' ');
2087 if (args!=NULL) *args++='\0';
2088 CharUpper32A(dev);
2089 if (args!=NULL) {
2090 char *s;
2091 i=1;/* nrofkeywords = nrofspaces+1 */
2092 s=args;
2093 while ((s=strchr(s,' '))!=NULL) i++,s++;
2094 keywords=(char**)xmalloc(sizeof(char*)*(i+2));
2095 nrofkeywords=i;
2096 s=args;i=0;
2097 while (s && i<nrofkeywords) {
2098 keywords[i++]=s;
2099 s=strchr(s,' ');
2100 if (s) *s++='\0';
2102 keywords[i]=NULL;
2103 } else {
2104 nrofkeywords=0;
2105 keywords=(char**)xmalloc(sizeof(char*));
2107 dwFlags = 0; /* default flags */
2108 for (i=0;i<nrofkeywords;) {
2109 /* take care, there is also a "device type" capability */
2110 if ((!STRCMP(keywords[i],"type")) && (i<nrofkeywords-1)) {
2111 filename = dev;
2112 dev = keywords[i+1];
2113 memcpy(keywords+i,keywords+(i+2),(nrofkeywords-i-2)*sizeof(char *));
2114 nrofkeywords -= 2;
2115 continue;
2117 if (!STRCMP(keywords[i],"wait")) {
2118 dwFlags |= MCI_WAIT;
2119 memcpy(keywords+i,keywords+(i+1),(nrofkeywords-i-1)*sizeof(char *));
2120 nrofkeywords--;
2121 continue;
2123 if (!STRCMP(keywords[i],"notify")) {
2124 dwFlags |= MCI_NOTIFY;
2125 memcpy(keywords+i,keywords+(i+1),(nrofkeywords-i-1)*sizeof(char *));
2126 nrofkeywords--;
2127 continue;
2129 i++;
2132 /* determine wDevID and uDevTyp for all commands except "open" */
2133 if (STRCMP(cmd,"open")!=0) {
2134 wDevID = MCI_FirstDevID();
2135 while (1) {
2136 LPSTR dname;
2138 dname=MCI_GetOpenDrv(wDevID)->lpstrAlias;
2139 if (dname==NULL)
2140 dname=MCI_GetOpenDrv(wDevID)->lpstrDeviceType;
2141 if (dname != NULL && !STRCMP(dname,dev))
2142 break;
2143 wDevID = MCI_NextDevID(wDevID);
2144 if (!MCI_DevIDValid(wDevID)) {
2145 TRACE(mci, "MAXMCIDRIVERS reached!\n");
2146 free(keywords);free(cmd);
2147 return MCIERR_INVALID_DEVICE_NAME;
2150 uDevTyp=MCI_GetDrv(wDevID)->modp.wType;
2153 for (i=0;MCISTR_cmdtable[i].cmd!=NULL;i++) {
2154 if (!STRCMP(MCISTR_cmdtable[i].cmd,cmd)) {
2155 res=MCISTR_cmdtable[i].fun(
2156 wDevID,uDevTyp,lpstrReturnString,
2157 uReturnLength,dev,(LPSTR*)keywords,nrofkeywords,
2158 dwFlags,hwndCallback
2160 break;
2163 if (MCISTR_cmdtable[i].cmd!=NULL) {
2164 free(keywords);free(cmd);
2165 return res;
2167 FIXME(mci,"('%s', %p, %u, %X): unimplemented, please report.\n",
2168 lpstrCommand, lpstrReturnString, uReturnLength, hwndCallback);
2169 free(keywords);free(cmd);
2170 return MCIERR_MISSING_COMMAND_STRING;
2173 /**************************************************************************
2174 * mciSendString32A [MMSYSTEM.702][WINMM.51]
2176 DWORD WINAPI mciSendString32A(LPCSTR lpstrCommand, LPSTR lpstrReturnString,
2177 UINT32 uReturnLength, HWND32 hwndCallback)
2179 return mciSendString16(lpstrCommand, lpstrReturnString, uReturnLength, hwndCallback);
2182 /**************************************************************************
2183 * mciSendString32W [WINMM.52]
2185 DWORD WINAPI mciSendString32W(LPCWSTR lpwstrCommand, LPSTR lpstrReturnString,
2186 UINT32 uReturnLength, HWND32 hwndCallback)
2188 LPSTR lpstrCommand;
2189 UINT32 ret;
2191 /* FIXME: is there something to do with lpstrReturnString ? */
2192 lpstrCommand = HEAP_strdupWtoA(GetProcessHeap(), 0, lpwstrCommand);
2193 ret = mciSendString16(lpstrCommand, lpstrReturnString, uReturnLength, hwndCallback);
2194 HeapFree(GetProcessHeap(), 0, lpstrCommand);
2195 return ret;