forked from bangstk/ogg-winmm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwav-winmm.c
844 lines (684 loc) · 22.1 KB
/
wav-winmm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
/*
* Copyright (c) 2012 Toni Spets <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <windows.h>
#include <stdio.h>
#include <ctype.h>
#include <dirent.h>
#include "player.h"
#define MAGIC_DEVICEID 0xBEEF
#define MAX_TRACKS 99
#ifdef WIN32
#define snprintf _snprintf
#endif
struct track_info
{
char path[MAX_PATH]; // full path to ogg
unsigned int length; // seconds
unsigned int position; // seconds
};
static struct track_info tracks[MAX_TRACKS];
struct play_info
{
int first;
int last;
};
#ifdef _DEBUG
#define dprintf(...) if (fh) { fprintf(fh, __VA_ARGS__); fflush(NULL); }
FILE *fh = NULL;
#else
#define dprintf(...)
#endif
int playing = 0;
int updateTrack = 0;
int closed = 0;
HANDLE player = NULL;
int firstTrack = -1;
int lastTrack = 0;
int numTracks = 0;
char music_path[2048];
int time_format = MCI_FORMAT_TMSF;
CRITICAL_SECTION cs;
static struct play_info info = { -1, -1 };
int player_main()
{
int first;
int last;
int current;
while (!closed)
{
//set track info
if (updateTrack)
{
first = info.first;
last = info.last;
current = first;
updateTrack = 0;
}
//stop if at end of 'playlist'
//note "last" track is NON-inclusive
//if the "first" track equals "last" track then play that single track
if (first == last && current > last || first != last && current == last)
playing = 0;
//try to play song
else
{
dprintf("Next track: %s\r\n", tracks[current].path);
playing = plr_play(tracks[current].path);
}
while (1)
{
//check control signals
if (closed) //MCI_CLOSE
break;
if (!playing) //MCI_STOP
{
plr_stop(); //end playback
SuspendThread(player); //pause thread until next MCI_PLAY
}
if (plr_pump() == 0) //done playing song
break;
if (updateTrack) //MCI_PLAY
break;
}
current++;
}
plr_stop();
playing = 0;
return 0;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
#ifdef _DEBUG
fh = fopen("winmm.txt", "w");
#endif
GetModuleFileName(hinstDLL, music_path, sizeof music_path);
memset(tracks, 0, sizeof tracks);
InitializeCriticalSection(&cs);
char *last = strrchr(music_path, '\\');
if (last)
{
*last = '\0';
}
strncat(music_path, "\\MUSIC", sizeof music_path - 1);
dprintf("ogg-winmm music directory is %s\r\n", music_path);
dprintf("ogg-winmm searching tracks...\r\n");
unsigned int position = 0;
for (int i = 0; i < MAX_TRACKS; i++)
{
snprintf(tracks[i].path, sizeof tracks[i].path, "%s\\Track%02d.ogg", music_path, i);
tracks[i].length = plr_length(tracks[i].path);
tracks[i].position = position;
if (tracks[i].length < 4)
{
tracks[i].path[0] = '\0';
position += 4; // missing tracks are 4 second data tracks for us
}
else
{
if (firstTrack == -1)
{
firstTrack = i;
}
dprintf("Track %02d: %02d:%02d @ %d seconds\r\n", i, tracks[i].length / 60, tracks[i].length % 60, tracks[i].position);
numTracks++;
lastTrack = i;
position += tracks[i].length;
}
}
dprintf("Emulating total of %d CD tracks.\r\n\r\n", numTracks);
}
#ifdef _DEBUG
if (fdwReason == DLL_PROCESS_DETACH)
{
if (fh)
{
fclose(fh);
fh = NULL;
}
}
#endif
return TRUE;
}
MCIERROR WINAPI fake_mciSendCommandA(MCIDEVICEID IDDevice, UINT uMsg, DWORD_PTR fdwCommand, DWORD_PTR dwParam)
{
char cmdbuf[1024];
dprintf("mciSendCommandA(IDDevice=%p, uMsg=%p, fdwCommand=%p, dwParam=%p)\r\n", IDDevice, uMsg, fdwCommand, dwParam);
if (fdwCommand & MCI_NOTIFY)
{
dprintf(" MCI_NOTIFY\r\n");
}
if (fdwCommand & MCI_WAIT)
{
dprintf(" MCI_WAIT\r\n");
}
if (uMsg == MCI_OPEN)
{
LPMCI_OPEN_PARMS parms = (LPVOID)dwParam;
dprintf(" MCI_OPEN\r\n");
if (fdwCommand & MCI_OPEN_ALIAS)
{
dprintf(" MCI_OPEN_ALIAS\r\n");
}
if (fdwCommand & MCI_OPEN_SHAREABLE)
{
dprintf(" MCI_OPEN_SHAREABLE\r\n");
}
if (fdwCommand & MCI_OPEN_TYPE_ID)
{
dprintf(" MCI_OPEN_TYPE_ID\r\n");
if (LOWORD(parms->lpstrDeviceType) == MCI_DEVTYPE_CD_AUDIO)
{
dprintf(" Returning magic device id for MCI_DEVTYPE_CD_AUDIO\r\n");
parms->wDeviceID = MAGIC_DEVICEID;
return 0;
}
}
if (fdwCommand & MCI_OPEN_TYPE && !(fdwCommand & MCI_OPEN_TYPE_ID))
{
dprintf(" MCI_OPEN_TYPE\r\n");
dprintf(" -> %s\r\n", parms->lpstrDeviceType);
if (strcmp(parms->lpstrDeviceType, "cdaudio") == 0)
{
dprintf(" Returning magic device id for MCI_DEVTYPE_CD_AUDIO\r\n");
parms->wDeviceID = MAGIC_DEVICEID;
return 0;
}
}
}
if (IDDevice == MAGIC_DEVICEID || IDDevice == 0 || IDDevice == 0xFFFFFFFF)
{
if (uMsg == MCI_SET)
{
LPMCI_SET_PARMS parms = (LPVOID)dwParam;
dprintf(" MCI_SET\r\n");
if (fdwCommand & MCI_SET_TIME_FORMAT)
{
dprintf(" MCI_SET_TIME_FORMAT\r\n");
time_format = parms->dwTimeFormat;
if (parms->dwTimeFormat == MCI_FORMAT_BYTES)
{
dprintf(" MCI_FORMAT_BYTES\r\n");
}
if (parms->dwTimeFormat == MCI_FORMAT_FRAMES)
{
dprintf(" MCI_FORMAT_FRAMES\r\n");
}
if (parms->dwTimeFormat == MCI_FORMAT_HMS)
{
dprintf(" MCI_FORMAT_HMS\r\n");
}
if (parms->dwTimeFormat == MCI_FORMAT_MILLISECONDS)
{
dprintf(" MCI_FORMAT_MILLISECONDS\r\n");
}
if (parms->dwTimeFormat == MCI_FORMAT_MSF)
{
dprintf(" MCI_FORMAT_MSF\r\n");
}
if (parms->dwTimeFormat == MCI_FORMAT_SAMPLES)
{
dprintf(" MCI_FORMAT_SAMPLES\r\n");
}
if (parms->dwTimeFormat == MCI_FORMAT_TMSF)
{
dprintf(" MCI_FORMAT_TMSF\r\n");
}
}
}
if (uMsg == MCI_CLOSE)
{
dprintf(" MCI_CLOSE\r\n");
if (player)
{
ResumeThread(player); //just in case it's suspended, else deadlock
closed = 1;
playing = 0;
}
playing = 0;
player = NULL;
}
if (uMsg == MCI_PLAY)
{
LPMCI_PLAY_PARMS parms = (LPVOID)dwParam;
dprintf(" MCI_PLAY\r\n");
if (fdwCommand & MCI_FROM)
{
dprintf(" dwFrom: %d\r\n", parms->dwFrom);
// FIXME: rounding to nearest track
if (time_format == MCI_FORMAT_TMSF)
{
info.first = MCI_TMSF_TRACK(parms->dwFrom);
dprintf(" TRACK %d\n", MCI_TMSF_TRACK(parms->dwFrom));
dprintf(" MINUTE %d\n", MCI_TMSF_MINUTE(parms->dwFrom));
dprintf(" SECOND %d\n", MCI_TMSF_SECOND(parms->dwFrom));
dprintf(" FRAME %d\n", MCI_TMSF_FRAME(parms->dwFrom));
}
else if (time_format == MCI_FORMAT_MILLISECONDS)
{
info.first = 0;
for (int i = 0; i < MAX_TRACKS; i++)
{
// FIXME: take closest instead of absolute
if (tracks[i].position == parms->dwFrom / 1000)
{
info.first = i;
}
}
dprintf(" mapped milliseconds to %d\n", info.first);
}
else
{
// FIXME: not really
info.first = parms->dwFrom;
}
if (info.first < firstTrack)
info.first = firstTrack;
if (info.first > lastTrack)
info.first = lastTrack;
info.last = info.first;
}
if (fdwCommand & MCI_TO)
{
dprintf(" dwTo: %d\r\n", parms->dwTo);
if (time_format == MCI_FORMAT_TMSF)
{
info.last = MCI_TMSF_TRACK(parms->dwTo);
dprintf(" TRACK %d\n", MCI_TMSF_TRACK(parms->dwTo));
dprintf(" MINUTE %d\n", MCI_TMSF_MINUTE(parms->dwTo));
dprintf(" SECOND %d\n", MCI_TMSF_SECOND(parms->dwTo));
dprintf(" FRAME %d\n", MCI_TMSF_FRAME(parms->dwTo));
}
else if (time_format == MCI_FORMAT_MILLISECONDS)
{
info.last = info.first;
for (int i = info.first; i < MAX_TRACKS; i++)
{
// FIXME: use better matching
if (tracks[i].position + tracks[i].length > parms->dwFrom / 1000)
{
info.last = i;
break;
}
}
dprintf(" mapped milliseconds to %d\n", info.last);
}
else
info.last = parms->dwTo;
if (info.last < info.first)
info.last = info.first;
if (info.last > lastTrack)
info.last = lastTrack;
}
if (info.first && (fdwCommand & MCI_FROM))
{
updateTrack = 1;
playing = 1;
//track info is now a global variable for live updating
if (player == NULL)
player = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)player_main, NULL, 0, NULL);
else
ResumeThread(player);
}
}
if (uMsg == MCI_STOP)
{
dprintf(" MCI_STOP\r\n");
playing = 0;
}
if (uMsg == MCI_STATUS)
{
LPMCI_STATUS_PARMS parms = (LPVOID)dwParam;
dprintf(" MCI_STATUS\r\n");
parms->dwReturn = 0;
if (fdwCommand & MCI_TRACK)
{
dprintf(" MCI_TRACK\r\n");
dprintf(" dwTrack = %d\r\n", parms->dwTrack);
}
if (fdwCommand & MCI_STATUS_ITEM)
{
dprintf(" MCI_STATUS_ITEM\r\n");
if (parms->dwItem == MCI_STATUS_CURRENT_TRACK)
{
dprintf(" MCI_STATUS_CURRENT_TRACK\r\n");
}
if (parms->dwItem == MCI_STATUS_LENGTH)
{
dprintf(" MCI_STATUS_LENGTH\r\n");
int seconds = tracks[parms->dwTrack].length;
if (seconds)
{
if (time_format == MCI_FORMAT_MILLISECONDS)
{
parms->dwReturn = seconds * 1000;
}
else
{
parms->dwReturn = MCI_MAKE_MSF(seconds / 60, seconds % 60, 0);
}
}
}
if (parms->dwItem == MCI_CDA_STATUS_TYPE_TRACK)
{
dprintf(" MCI_CDA_STATUS_TYPE_TRACK\r\n");
}
if (parms->dwItem == MCI_STATUS_MEDIA_PRESENT)
{
dprintf(" MCI_STATUS_MEDIA_PRESENT\r\n");
parms->dwReturn = lastTrack > 0;
}
if (parms->dwItem == MCI_STATUS_NUMBER_OF_TRACKS)
{
dprintf(" MCI_STATUS_NUMBER_OF_TRACKS\r\n");
parms->dwReturn = numTracks;
}
if (parms->dwItem == MCI_STATUS_POSITION)
{
dprintf(" MCI_STATUS_POSITION\r\n");
if (fdwCommand & MCI_TRACK)
{
// FIXME: implying milliseconds
parms->dwReturn = tracks[parms->dwTrack].position * 1000;
}
}
if (parms->dwItem == MCI_STATUS_MODE)
{
dprintf(" MCI_STATUS_MODE\r\n");
dprintf(" we are %s\r\n", playing ? "playing" : "NOT playing");
parms->dwReturn = playing ? MCI_MODE_PLAY : MCI_MODE_STOP;
}
if (parms->dwItem == MCI_STATUS_READY)
{
dprintf(" MCI_STATUS_READY\r\n");
}
if (parms->dwItem == MCI_STATUS_TIME_FORMAT)
{
dprintf(" MCI_STATUS_TIME_FORMAT\r\n");
}
if (parms->dwItem == MCI_STATUS_START)
{
dprintf(" MCI_STATUS_START\r\n");
}
}
dprintf(" dwReturn %d\n", parms->dwReturn);
}
return 0;
}
/* fallback */
return MCIERR_UNRECOGNIZED_COMMAND;
}
/*
# LIST OF ALL POSSIBLE mciSendString COMMANDS (mark with "-" partially or completely implemented functions)#
break
capability
capture
-close
configure
copy
cue
cut
delete
escape
freeze
index
info
list
load
mark
monitor
-open
paste
pause
-play
put
quality
realize
record
reserve
restore
resume
save
seek
-set
setaudio
settimecode
settuner
setvideo
signal
spin
status
step
-stop
sysinfo
undo
unfreeze
update
where
window
*/
// this is really fugly but for christ sake why did anyone use it?!
MCIERROR WINAPI fake_mciSendStringA(LPCTSTR cmd, LPTSTR ret, UINT cchReturn, HANDLE hwndCallback)
{
dprintf("MCI-SendStringA: %s\n", cmd);
// Change string to lower-case
char *cmdbuf = strdup(cmd); // Prevents cmd readonly error
for (int i = 0; cmdbuf[i]; i++) {
cmdbuf[i] = tolower(cmdbuf[i]);
}
// Explode string into tokens
dprintf("Splitting string \"%s\" into tokens:\n", cmdbuf);
char * com;
com = strtok(cmdbuf, " ,.-");
// -- Implement Commands --
// OPEN
if (com && strcmp(com, "open") == 0) { // TODO:
return 0;
}
// SET
if (com && strcmp(com, "set") == 0) {
com = strtok(NULL, " ,.-"); // Get next token
if(com){ // TODO: FIX: Accept everything. This may bring unexpected behaviour
com = strtok(NULL, " ,.-"); // Get next token
// TIME
if (com && strcmp(com, "time") == 0) {
com = strtok(NULL, " ,.-"); // Get next token
// FORMAT
if (com && strcmp(com, "format") == 0) {
com = strtok(NULL, " ,.-"); // Get next token
static MCI_SET_PARMS parms;
// MILLISECONDS
if (com && strcmp(com, "milliseconds") == 0) {
parms.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
fake_mciSendCommandA(MAGIC_DEVICEID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parms);
return 0;
}
// MSF
if (com && strcmp(com, "msf") == 0) {
parms.dwTimeFormat = MCI_FORMAT_MSF;
fake_mciSendCommandA(MAGIC_DEVICEID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parms);
return 0;
}
// TMSF
if (com && strcmp(com, "tmsf") == 0) {
parms.dwTimeFormat = MCI_FORMAT_TMSF;
fake_mciSendCommandA(MAGIC_DEVICEID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD_PTR)&parms);
return 0;
}
}
}
}
// Accept all other commands
return 0;
}
// STATUS
if (com && strcmp(com, "status") == 0) {
com = strtok(NULL, " ,.-"); // Get next token
if(com){ // TODO: FIX: Accept everything. This may bring unexpected behaviour
com = strtok(NULL, " ,.-"); // Get next token
MCI_STATUS_PARMS parms;
// LENGTH
if (com && strcmp(com, "length") == 0) {
parms.dwItem = MCI_STATUS_LENGTH;
com = strtok(NULL, " ,.-"); // Get next token
// TRACK
if (com && strcmp(com, "track") == 0) {
com = strtok(NULL, " ,.-"); // Get next token (TRACK NUMBER)
// (INT) TRACK NUMBER
if(com){ // TODO: Check if this is an INTEGER (Number)
parms.dwTrack = atoi(com);
fake_mciSendCommandA(MAGIC_DEVICEID, MCI_STATUS, MCI_STATUS_ITEM, (DWORD_PTR)&parms);
itoa(parms.dwReturn, ret, 10); // Response
return 0;
}
}
return 0;
}
// POSITION
if (com && strcmp(com, "position") == 0) {
parms.dwItem = MCI_STATUS_POSITION;
com = strtok(NULL, " ,.-"); // Get next token
// TRACK
if (com && strcmp(com, "track") == 0) {
com = strtok(NULL, " ,.-"); // Get next token (TRACK NUMBER)
// (INT) TRACK NUMBER
if(com){ // TODO: Check if this is an INTEGER (Number)
parms.dwTrack = atoi(com);
fake_mciSendCommandA(MAGIC_DEVICEID, MCI_STATUS, MCI_STATUS_ITEM|MCI_TRACK, (DWORD_PTR)&parms);
itoa(parms.dwReturn, ret, 10); // Response
return 0;
}
}
return 0;
}
// NUMBER
if (com && strcmp(com, "number") == 0) {
com = strtok(NULL, " ,.-"); // Get next token
// OF
if (com && strcmp(com, "of") == 0) {
com = strtok(NULL, " ,.-"); // Get next token
// TRACKS
if (com && strcmp(com, "tracks") == 0) {
itoa(numTracks, ret, 10); // Response
return 0;
}
}
return 0;
}
}
// Accept all other commands
return 0;
}
// PLAY
if (com && strcmp(com, "play") == 0) {
com = strtok(NULL, " ,.-"); // Get next token
if(com){ // TODO: FIX: Accept everything. This may bring unexpected behaviour
com = strtok(NULL, " ,.-"); // Get next token
// FROM
if (com && strcmp(com, "from") == 0) {
com = strtok(NULL, " ,.-"); // Get next token (FROM POS (INT))
// (INT) From Time
if(com){ // TODO: Check if number is INTEGER
int posFrom = atoi(com);// Parse Integer
com = strtok(NULL, " ,.-"); // Get next token
// TO
if (com && strcmp(com, "to") == 0) {
com = strtok(NULL, " ,.-"); // Get next token (TO POS (INT)))
// (INT) To Time
if(com){
int posTo = atoi(com); // Parse Integer
static MCI_PLAY_PARMS parms;
parms.dwFrom = posFrom;
parms.dwTo = posTo;
fake_mciSendCommandA(MAGIC_DEVICEID, MCI_PLAY, MCI_FROM|MCI_TO, (DWORD_PTR)&parms);
//free(posFrom); // ???
//free(posTo); // ???
return 0;
}
}else{
// No TO position specified
static MCI_PLAY_PARMS parms;
parms.dwFrom = posFrom;
fake_mciSendCommandA(MAGIC_DEVICEID, MCI_PLAY, MCI_FROM, (DWORD_PTR)&parms);
return 0;
}
}
}
}
// Accept all other commands
return 0;
}
// STOP
if (com && strcmp(com, "stop") == 0) {
// TODO: No support for ALIASES
fake_mciSendCommandA(MAGIC_DEVICEID, MCI_STOP, 0, (DWORD_PTR)NULL);
return 0;
}
// CLOSE
if (com && strcmp(com, "close") == 0) {
// TODO: No support for ALIASES
fake_mciSendCommandA(MAGIC_DEVICEID, MCI_CLOSE, 0, (DWORD_PTR)NULL);
return 0;
}
// TODO: Unfinished. Dunno what this does..
if (strstr(cmd, "sysinfo")){
strcpy(ret, "cd");
return 0;
}
/* This could be useful if this would be 100% implemented */
// return MCIERR_UNRECOGNIZED_COMMAND;
return 0;
}
UINT WINAPI fake_auxGetNumDevs()
{
dprintf("fake_auxGetNumDevs()\r\n");
return 1;
}
MMRESULT WINAPI fake_auxGetDevCapsA(UINT_PTR uDeviceID, LPAUXCAPS lpCaps, UINT cbCaps)
{
dprintf("fake_auxGetDevCapsA(uDeviceID=%08X, lpCaps=%p, cbCaps=%08X\n", uDeviceID, lpCaps, cbCaps);
lpCaps->wMid = 2 /*MM_CREATIVE*/;
lpCaps->wPid = 401 /*MM_CREATIVE_AUX_CD*/;
lpCaps->vDriverVersion = 1;
strcpy(lpCaps->szPname, "ogg-winmm virtual CD");
lpCaps->wTechnology = AUXCAPS_CDAUDIO;
lpCaps->dwSupport = AUXCAPS_VOLUME;
return MMSYSERR_NOERROR;
}
MMRESULT WINAPI fake_auxGetVolume(UINT uDeviceID, LPDWORD lpdwVolume)
{
dprintf("fake_auxGetVolume(uDeviceId=%08X, lpdwVolume=%p)\r\n", uDeviceID, lpdwVolume);
*lpdwVolume = 0x00000000;
return MMSYSERR_NOERROR;
}
MMRESULT WINAPI fake_auxSetVolume(UINT uDeviceID, DWORD dwVolume)
{
static DWORD oldVolume = -1;
char cmdbuf[256];
dprintf("fake_auxSetVolume(uDeviceId=%08X, dwVolume=%08X)\r\n", uDeviceID, dwVolume);
if (dwVolume == oldVolume)
{
return MMSYSERR_NOERROR;
}
oldVolume = dwVolume;
unsigned short left = LOWORD(dwVolume);
unsigned short right = HIWORD(dwVolume);
dprintf(" left : %ud (%04X)\n", left, left);
dprintf(" right: %ud (%04X)\n", right, right);
plr_volume((left / 65535.0f) * 100);
return MMSYSERR_NOERROR;
}