-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMCI.ahk
1555 lines (1412 loc) · 43.5 KB
/
MCI.ahk
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
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Title: MCI Library v1.1
Updated in October, 2019
https://autohotkey.com/board/topic/32291-library-mci-v11-playcontrol-media-files/
Group: Overview
This library gives the AutoHotkey developer access to the the Media Control
Interface (MCI) which provides standard commands for playing/controlling
multimedia devices.
Group: Notes
Devices Referenced Within The Documentation:
(start code)
Driver Type Description
------ ---- -----------
MCIAVI avivideo
MCICDA cdaudio CD audio
dat Digital-audio tape player
digitalvideo Digital video in a window (not GDI-based)
MPEGVideo General-purpose media player
other Undefined MCI device
overlay Overlay device (analog video in a window)
scanner Image scanner
MCISEQ sequencer MIDI sequencer
vcr Video-cassette recorder or player
MCIPIONR videodisc Videodisc (Pioneer LaserDisc)
MCIWAVE waveaudio Audio device that plays digitized waveform files
(end)
MCI Installation:
To see a list of MCI devices that have been registered for the computer, go
to the following registry locations...
(start code)
Windows NT4/2000/XP/2003/Vista/7/etc.:
16-bit:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\MCI
32-bit:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\MCI32
Windows 95/98/ME:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\MediaResources\MCI
(end)
To see a list of registered file extensions and the MCI device that has been
assigned to each extension, go the following locations...
(start code)
For Windows NT4/2000/XP/2003/Vista/7/etc., this information is stored in
the following registry location:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\MCI Extensions
For Windows 95/98/ME, this information is stored in the %windir%\win.ini
file in the "MCI Extensions" section.
(end)
Performance:
AutoHotkey automatically loads winmm.dll into memory. There is no need or
advantage to preload this library in order to use the MCI library.
Debugging:
*OutputDebug* statements in the core of some of the functions that only
execute on condition are permanent and are provided to help the developer
find and eliminate errors.
Group: Links
MCI Reference Guide
- <http://msdn.microsoft.com/en-us/library/ms709461(VS.85).aspx>
Group: Credit
The MCI library is an offshoot of the Sound_* and Media_* libraries provided
by *Fincs*.
- <http://www.autohotkey.com/forum/viewtopic.php?t=20666>
- <http://www.autohotkey.com/forum/viewtopic.php?t=22662>
Credit and thanks to *Fincs* for creating and enhancing these libraries
which are a conversion from the AutoIt "Sound.au3" standard library
and to *RazerM* for providing the original "Sound.au3" library.
Notify idea and code from *Sean*
- <http://www.autohotkey.com/forum/viewtopic.php?p=132331#132331>
mciGetErrorString call from *PhiLho*
- <http://www.autohotkey.com/forum/viewtopic.php?p=116011#116011>
Group: Functions
*/
/*
ERROR MESSAGES (MULTIMEDIA MCI CONTROL)
The following table lists the trappable errors for the Multimedia MCI control.
Constant Value Description
mciInvalidProcedureCall 5 Invalid procedure call.
mciInvalidProertyValue 380 invalid property value.
mciSetNotSupported 383 Property is read-only.
mciGetNotSupported 394 Property is write-only.
mciInvalidObjectUse 425 Invalid object use.
mciWrongClipboardFormat 461 Specified format doesn't match format of data.
mciObjectLocked 672 DataObject formats list may not be cleared or expanded outside of the OLEStartDrag event.
mciExpectedArgument 673 Expected at least one argument.
mciRecursiveOleDrag 674 Illegal recursive invocation of OLE drag and drop
mciFormatNotByteArray 675 Non-intrinsic OLE drag and drop formats used with SetData require Byte array data. GetData may return more bytes than were given to SetData.
mciDataNotSetForFormat 676 Requested data was not supplied to the DataObject during the OLESetData event.
mciCantCreateButton 30001 Can't create button
mciCantCreateTimer 30002 Can't create a timer resource
mciUnsupportedFunction 30004 Unsupported function
Below is a list of the MCI error strings and numbers that are related to the Multimedia MCI control.
MCI Error Strings MCI Error Numbers:
MCIERR_BASE = 256
MCIERR_INVALID_DEVICE_ID = 257
MCIERR_UNRECOGNIZED_KEYWORD = 259
MCIERR_UNRECOGNIZED_COMMAND = 261
MCIERR_HARDWARE = 262
MCIERR_INVALID_DEVICE_NAME = 263
MCIERR_OUT_OF_MEMORY = 264
MCIERR_DEVICE_OPEN = 265
MCIERR_CANNOT_LOAD_DRIVER = 266
MCIERR_MISSING_COMMAND_STRING = 267
MCIERR_PARAM_OVERFLOW = 268
MCIERR_MISSING_STRING_ARGUMENT = 269
MCIERR_BAD_INTEGER = 270
MCIERR_PARSER_INTERNAL = 271
MCIERR_DRIVER_INTERNAL = 272
MCIERR_MISSING_PARAMETER = 273
MCIERR_UNSUPPORTED_FUNCTION = 274
MCIERR_FILE_NOT_FOUND = 275
MCIERR_DEVICE_NOT_READY = 276
MCIERR_INTERNAL = 277
MCIERR_DRIVER = 278
MCIERR_CANNOT_USE_ALL = 279
MCIERR_MULTIPLE = 280
MCIERR_EXTENSION_NOT_FOUND = 281
MCIERR_OUTOFRANGE = 282
MCIERR_FLAGS_NOT_COMPATIBLE = 283
MCIERR_FILE_NOT_SAVED = 286
MCIERR_DEVICE_TYPE_REQUIRED = 287
MCIERR_DEVICE_LOCKED = 288
MCIERR_DUPLICATE_ALIAS = 289
MCIERR_BAD_CONSTANT = 290
MCIERR_MUST_USE_SHAREABLE = 291
MCIERR_MISSING_DEVICE_NAME = 292
MCIERR_BAD_TIME_FORMAT = 293
MCIERR_NO_CLOSING_QUOTE = 294
MCIERR_DUPLICATE_FLAGS = 295
MCIERR_INVALID_FILE = 296
MCIERR_NULL_PARAMETER_BLOCK = 297
MCIERR_UNNAMED_RESOURCE = 298
MCIERR_NEW_REQUIRES_ALIAS = 299
MCIERR_NOTIFY_ON_AUTO_OPEN = 300
MCIERR_NO_ELEMENT_ALLOWED = 301
MCIERR_NONAPPLICABLE_FUNCTION = 302
MCIERR_ILLEGAL_FOR_AUTO_OPEN = 303
MCIERR_FILENAME_REQUIRED = 304
MCIERR_EXTRA_CHARACTERS = 305
MCIERR_DEVICE_NOT_INSTALLED = 306
MCIERR_GET_CD = 307
MCIERR_SET_CD = 308
MCIERR_SET_DRIVE = 309
MCIERR_DEVICE_LENGTH = 310
MCIERR_DEVICE_ORD_LENGTH = 311
MCIERR_NO_INTEGER = 312
MCIERR_WAVE_OUTPUTSINUSE = 320
MCIERR_WAVE_SETOUTPUTINUSE = 321
MCIERR_WAVE_INPUTSINUSE = 322
MCIERR_WAVE_SETINPUTINUSE = 323
MCIERR_WAVE_OUTPUTUNSPECIFIED = 324
MCIERR_WAVE_INPUTUNSPECIFIED = 325
MCIERR_WAVE_OUTPUTSUNSUITABLE = 326
MCIERR_WAVE_SETOUTPUTUNSUITABLE = 327
MCIERR_WAVE_INPUTSUNSUITABLE = 328
MCIERR_WAVE_SETINPUTUNSUITABLE = 329
MCIERR_SEQ_DIV_INCOMPATIBLE = 336
MCIERR_SEQ_PORT_INUSE = 337
MCIERR_SEQ_PORT_NONEXISTENT = 338
MCIERR_SEQ_PORT_MAPNODEVICE = 339
MCIERR_SEQ_PORT_MISCERROR = 340
MCIERR_SEQ_TIMER = 341
MCIERR_SEQ_PORTUNSPECIFIED = 342
MCIERR_SEQ_NOMIDIPRESENT = 343
MCIERR_NO_WINDOW = 346
MCIERR_CREATEWINDOW = 347
MCIERR_FILE_READ = 348
MCIERR_FILE_WRITE = 349
MCIERR_CUSTOM_DRIVER_BASE = 512
*/
;-----------------------------
;
; Function: MCI_Close
;
; Description:
;
; Closes the device and any associated resources.
;
; Parameters:
;
; p_lpszDeviceID - Device name or alias.
;
; Returns:
;
; The return code from the <MCI_SendString> function which is 0 if the command
; completed successfully.
;
; Remarks:
;
; For most MCI devices, closing a device usually stops playback but not
; always. If unsure of the device, consider stopping the device before
; closing it.
;
;------------------------------------------------------------------------------
MCI_Close(p_lpszDeviceID) {
Static MM_MCINOTIFY:=0x03B9
;-- Close device
l_Return:=MCI_SendString("close " . p_lpszDeviceID . " wait")
;-- Turn off monitoring of MM_MCINOTIFY message?
if OnMessage(MM_MCINOTIFY)="MCI_Notify"
{
;-- Don't process unless all MCI devices are closed
MCI_SendString("sysinfo all quantity open",l_OpenMCIDevices)
if (l_OpenMCIDevices=0)
;-- Disable monitoring
OnMessage(MM_MCINOTIFY,"")
}
Return l_Return
}
;-----------------------------
;
; Function: MCI_CurrentTrack
;
; Description:
;
; Identifies the current track.
;
; Parameters:
;
; p_lpszDeviceID - Device name or alias.
;
; Returns:
;
; The current track. Note: The MCISEQ sequencer returns 1.
;
;------------------------------------------------------------------------------
MCI_CurrentTrack(p_lpszDeviceID) {
MCI_SendString("status " . p_lpszDeviceID . " current track",l_lpszReturnString)
Return l_lpszReturnString
}
;-----------------------------
;
; Function: MCI_DeviceType
;
; Description:
;
; Identifies the device type name.
;
; Parameters:
;
; p_lpszDeviceID - Device name or alias.
;
; Returns:
;
; A device type name, which can be one of the following...
;
; (start code)
; cdaudio
; dat
; digitalvideo
; other
; overlay
; scanner
; sequencer
; vcr
; videodisc
; waveaudio
; (end)
;
;------------------------------------------------------------------------------
MCI_DeviceType(p_lpszDeviceID) {
MCI_SendString("capability " . p_lpszDeviceID . " device type",l_lpszReturnString)
Return l_lpszReturnString
}
;-----------------------------
;
; Function: MCI_Open
;
; Description:
;
; Opens an MCI device and loads the specified file.
;
; Parameters:
;
; p_MediaFile - A multimedia file.
;
; p_Alias - Alias. A name such as media1. [Optional] If blank (the default),
; an alias will automatically be generated.
;
; p_Flags - Flags that determine how the device is opened. [Optional]
;
; Flag Notes:
; Some commonly used flags include...
;
; (start code)
; type {device_type}
; sharable
; (end)
;
; If more than one flag is used, separate each flag/value with a space.
; For example:
;
; (start code)
; type MPEGVideo sharable
; (end)
;
; Additional notes...
;
; - The "wait" flag is automatically added to the end of the command string.
; This flag directs the device to complete the "open" request before
; returning.
;
; - Use the "shareable" flag with care. Per msdn, the "shareable" flag
; "initializes the device or file as shareable. Subsequent attempts to
; open the device or file fail unless you specify "shareable" in both the
; original and subsequent open commands. MCI returns an invalid device
; error if the device is already open and not shareable. The MCISEQ
; sequencer and MCIWAVE devices do not support shared files."
;
; - By default, the MCI device that is opened is determined by the file's
; extension. The "type" flag can be used to 1) override the default
; device that is registered for the file extension or to 2) open a media
; file with a file extension that is not registered as a MCI file
; extension. See the <Notes> section for more information.
;
; - For a complete list of flags and descriptions for the "open" command
; string, see the "MCI Reference Guide" in the <Links> section.
;
; Returns:
;
; The multimedia handle (alias) or 0 (FALSE) to indicate failure. Failure
; will occur with any of the following conditions:
;
; - The media file does not exist.
;
; - The media file's extension is not a regisitered MCI extension. Note:
; This test is only performed if the "type" flag is not specified.
;
; - Non-zero return code from the <MCI_SendString> function.
;
; Remarks:
;
; - Use the <MCI_OpenCDAudio> function to open a CDAudio device.
;
; - After the device has been successfully opened, the time format is set to
; milliseconds which it will remain in effect until it is manually set to
; another value or until the device is closed.
;
;------------------------------------------------------------------------------
MCI_Open(p_MediaFile,p_Alias:="",p_Flags:="", checkFile:=1) {
Static s_Seq:=0
;[==============]
;[ Parameters ]
;[==============]
;-- p_MediaFile
if (p_MediaFile<>"new")
{
;-- Media file exist?
If (checkFile=1)
{
IfNotExist %p_MediaFile%
{
outputdebug,
(ltrim join`s
End Func: %A_ThisFunc%: The media file can't be
found. Return=0
)
Return False
}
}
;-- "Type" flag not defined?
if !InStr(p_Flags," type ")
{
;-- Registered file extension?
SplitPath p_MediaFile,,,l_Extension
;-- Which OS type?
if (A_OSType="WIN32_NT") ;-- Windows NT4/2000/XP/2003/Vista/7/etc.
{
RegRead
,l_Dummy
,HKEY_LOCAL_MACHINE
,SOFTWARE\Microsoft\Windows NT\CurrentVersion\MCI Extensions
,%l_Extension%
} else
{
;-- Windows 95/98/ME
iniRead l_Dummy,%A_WinDir%\win.ini,MCI Extensions,%l_Extension%
}
;-- Not found?
if (!l_Dummy || StrLen(l_Dummy)<2 || l_Dummy="error")
{
outputdebug,
(ltrim join`s
End Func: %A_ThisFunc%: The file extension for this media
file is not registered as a valid MCI extension. Return=0
)
Return False
}
}
;-- Enclose in DQ
p_MediaFile="%p_MediaFile%"
}
;-- Alias
if p_Alias is Space
{
s_Seq++
p_Alias:="MCIFile" . s_Seq
}
;[===============]
;[ Open device ]
;[===============]
l_CmdString:="open "
. p_MediaFile
. " alias "
. p_Alias
. A_Space
. p_Flags
. " wait"
l_Return:=MCI_SendString(l_CmdString)
if l_Return
l_Return:=0
else
l_Return:=p_Alias
;-- Set time format to milliseconds
if l_Return
{
l_CmdString:="set " . p_Alias . " time format milliseconds wait"
MCI_SendString(l_CmdString)
}
;-- Return to sender
Return l_Return
}
;-----------------------------
;
; Function: MCI_OpenCDAudio
;
; Description:
;
; Opens a CDAudio device.
;
; Parameters:
;
; p_Drive - CDROM drive letter. [Optional] If blank (the default), the first
; CDROM drive found is used.
;
; p_Alias - Alias. A name such as media1. [Optional] If blank (the default),
; an alias will automatically be generated.
;
; p_CheckForMedia - Check for media. [Optional] The default is TRUE.
;
; Returns:
;
; The multimedia handle (alias) or 0 to indicate failure. Failure will occur
; with any of the following conditions:
; - The computer does not have a CDROM drive.
; - The specified drive is not CDROM drive.
; - Non-zero return code from the <MCI_SendString> function.
;
; If p_CheckForMedia is TRUE (the default), failure will also occur with
; any of the following conditions:
; - No media was found in the device.
; - Media does not contain audio tracks.
;
; Remarks:
;
; After the device has been successfully opened, the time format is set to
; milliseconds which will remain in effect until it is manually set to another
; value or until the device is closed.
;
;------------------------------------------------------------------------------
MCI_OpenCDAudio(p_Drive="",p_Alias="",p_CheckForMedia=True) {
Static s_Seq:=0
;-- Parameters
p_Drive=%p_Drive% ;-- Autotrim
p_Drive:=SubStr(p_Drive,1,1)
if p_Drive is not Alpha
p_Drive:=""
;-- Drive not specified
if p_Drive is Space
{
;-- Collect list of CDROM drives
DriveGet l_ListOfCDROMDrives,List,CDROM
if l_ListOfCDROMDrives is Space
{
outputdebug,
(ltrim join`s
End Func: %A_ThisFunc%: This PC does not have functioning CDROM
drive. Return=0
)
Return False
}
;-- Assign the first CDROM drive
p_Drive:=SubStr(l_ListOfCDROMDrives,1,1)
}
;-- Is this a CDROM drive?
DriveGet l_DriveType,Type,%p_Drive%:
if (l_DriveType<>"CDROM")
{
outputdebug,
(ltrim join`s
End Func: %A_ThisFunc%: The specified drive (%p_Drive%:) is not
a CDROM drive. Return=0
)
Return False
}
;-- Alias
if p_Alias is Space
{
s_Seq++
p_Alias:="MCICDAudio" . s_Seq
}
;-- Open device
l_CmdString:="open " . p_Drive . ": alias " . p_Alias . " type cdaudio shareable wait"
l_Return:=MCI_SendString(l_CmdString)
if l_Return
l_Return:=0
else
l_Return:=p_Alias
;-- Device is open
if l_Return
{
;-- Set time format to milliseconds
l_CmdString:="set " . p_Alias . " time format milliseconds wait"
MCI_SendString(l_CmdString)
;-- Check for media?
if p_CheckForMedia
{
if not MCI_MediaIsPresent(p_Alias)
{
MCI_Close(p_Alias)
outputdebug,
(ltrim join`s
End Func: %A_ThisFunc%: Media is not present in the
specified drive (%p_Drive%:). Return=0
)
Return False
}
;-- 1st track an audio track?
if not MCI_TrackIsAudio(p_Alias,1)
{
MCI_Close(p_Alias)
outputdebug,
(ltrim join`s
End Func: %A_ThisFunc%: Media in drive %p_Drive%: does not
contain CD Audio tracks. Return=0
)
Return False
}
}
}
Return l_Return
}
;-----------------------------
;
; Function: MCI_Length
;
; Description:
;
; Gets the total length of the media in the current time format.
;
; Parameters:
;
; p_lpszDeviceID - Device name or alias.
;
; p_Track - Track number. [Optional] The default is 0 (no track number).
;
; Returns:
;
; If a track number is not specified (the default), the length of the entire
; entire media is returned. If a track number is specified, only the
; the length of the specified track is returned.
;
;------------------------------------------------------------------------------
MCI_Length(p_lpszDeviceID,p_Track=0) {
;-- Build command string
l_CmdString:="status " . p_lpszDeviceID . " length"
if p_Track
l_CmdString.=" track " . p_Track
;-- Send it!
MCI_SendString(l_CmdString,l_lpszReturnString)
Return l_lpszReturnString
}
;-----------------------------
;
; Function: MCI_MediaIsPresent
;
; Description:
;
; Checks to see if media is present in the device.
;
; Parameters:
;
; p_lpszDeviceID - Device name or alias.
;
; Returns:
;
; TRUE if the media is inserted in the device, otherwise FALSE.
; msdn: Sequencer, video-overlay, digital-video, and waveform-audio devices
; (always) return TRUE.
;
;------------------------------------------------------------------------------
MCI_MediaIsPresent(p_lpszDeviceID) {
l_RC:=MCI_SendString("status " . p_lpszDeviceID . " media present",l_lpszReturnString)
if l_RC ;-- Probably invalid command for the device
Return False
else
Return (l_lpszReturnString="true") ? True:False
}
;-----------------------------
;
; Function: MCI_Notify
;
; Description:
;
; (Internal function. Do not call directly)
;
; This function has 2 responsibilties...
;
; 1) If called by the <MCI_Play> function, wParam contains the name of the
; developer-defined function. This value is assigned to the s_Callback
; static variable for future use.
;
; 2) When called as a result of MM_MCINOTIFY message, this function will call
; the developer-defined function (name stored in the s_Callback static
; variable) sending the MM_MCINOTIFY status flag as the first parameter.
;
; Parameters:
;
; wParam - Function name or a MM_MCINOTIFY flag.
;
; MM_MCINOTIFY flag values are as follows...
;
; (start code)
; MCI_NOTIFY_SUCCESSFUL:=0x1
; The conditions initiating the callback function have been met.
;
; MCI_NOTIFY_SUPERSEDED:=0x2
; The device received another command with the "notify" flag set and
; the current conditions for initiating the callback function have
; been superseded.
;
; MCI_NOTIFY_ABORTED:=0x4
; The device received a command that prevented the current conditions
; for initiating the callback function from being met. If a new
; command interrupts the current command and it also requests
; notification, the device sends this message only and not
; MCI_NOTIFY_SUPERSEDED.
;
; MCI_NOTIFY_FAILURE:=0x8
; A device error occurred while the device was executing the command.
; (end)
;
; lParam - lDevID. This is the identifier of the device initiating the
; callback function. This information is only useful if operating more
; than one MCI device at a time.
;
; Returns:
;
; Per msdn, returns 0 to indicate a successful call.
;
; Remarks:
;
; This function does not complete until the call to the developer-defined
; function has completed. If a MM_MCINOTIFY message is issued while this
; function is running, the message will be treated as unmonitored.
;
;------------------------------------------------------------------------------
MCI_Notify(wParam,lParam,msg,hWnd) {
;;;;; Critical
;-- This will cause MM_MCINOTIFY messages to be buffered rather than
; discared if this function is still running when another MM_MCINOTIFY
; message is sent.
Static s_Callback
;-- Internal call?
if lParam is Space
{
s_Callback:=wParam
return
}
;-- Call developer function
if IsFunc(s_Callback)
%s_Callback%(wParam)
Return 0
}
;-----------------------------
;
; Function: MCI_NumberOfTracks
;
; Description:
;
; Identifies the number of tracks on the media.
;
; Parameters:
;
; p_lpszDeviceID - Device name or alias.
;
; Returns:
;
; The number of tracks on the media.
;
; Remarks:
;
; msdn: The MCISEQ and MCIWAVE devices return 1, as do most VCR devices. The
; MCIPIONR device does not support this flag.
;
;------------------------------------------------------------------------------
MCI_NumberOfTracks(p_lpszDeviceID) {
MCI_SendString("status " . p_lpszDeviceID . " number of tracks",l_lpszReturnString)
Return l_lpszReturnString
}
;----------
;
; Function: MCI_Pause
;
; Description:
;
; Pauses playback or recording.
;
; Parameters:
;
; p_lpszDeviceID - Device name or alias.
;
; Returns:
;
; The return code from the <MCI_SendString> function which is 0 if the command
; completed successfully.
;
; Remarks:
;
; msdn: With the MCICDA, MCISEQ, and MCIPIONR drivers, the pause command works
; the same as the stop command.
;
; Observation: For MCISEQ devices, pause works OK for me.
;
;------------------------------------------------------------------------------
MCI_Pause(p_lpszDeviceID) {
Return MCI_SendString("pause " . p_lpszDeviceID . " wait")
}
;-----------------------------
;
; Function: MCI_Play
;
; Description:
;
; Starts playing a device.
;
; Parameters:
;
; p_lpszDeviceID - Device name or alias.
;
; p_Flags - Flags that determine how the device is played. [Optional] If
; blank, no flags are used.
;
; Flag Notes:
;
; Some commonly used flags include...
;
; (start code)
; from {position}
; to {position}
; (end)
;
; If more than one flag is used, separate each flag/value with a space.
; For example:
;
; (start code)
; from 10144 to 95455
; (end)
;
; Additional notes...
;
; - With the exception of very short sound files (<300 ms), the "wait"
; flag is not recommended. The entire application will be
; non-responsive while the media is being played.
;
; - Do not add the "notify" flag unless you plan to have your script trap
; the MM_MCINOTIFY message outside of this function. The "notify"
; flag is automatically added if the p_Callback parameter contains a
; value.
;
; - For a complete list of flags and descriptions for the "play" command
; string, see the "MCI Reference Guide" in the <Links> section.
;
; p_Callback - Function name that is called when the MM_MCINOTIFY message is
; sent. [Optional] If defined, the "notify" flag is automatically added.
;
; Important: The syntax of this parameter and the associated function is
; critical. If not defined correctly, the script may crash.
;
; The function must have at least one parameter. For example...
;
; (start code)
; MyNotifyFunction(NotifyFlag)
; (end)
;
; Additional parameters are allowed but they must be optional (contain a
; default value). For example:
;
; (start code)
; MyNotifyFunction(NotifyFlag,FirstCall=False,Parm3="ABC")
; (end)
;
; When a notify message is sent, the approriate MM_MCINOTIFY flag is sent
; to the developer-defined function as the first parameter. See the
; <MCI_Notify> function for a description and a list of MM_MCINOTIFY flag
; values.
;
; p_hWndCallback - Handle to a callback window if the p_Callback parameter
; contains a value and/or if the "notify" flag is defined. [Optional] If
; undefined but needed, the handle to default Autohotkey window is used.
;
; Returns:
;
; The return code from the <MCI_SendString> function which is 0 if the command
; completed successfully.
;
;------------------------------------------------------------------------------
MCI_Play(p_lpszDeviceID,p_Flags="",p_Callback="",p_hwndCallback=0) {
Static MM_MCINOTIFY:=0x03B9
;-- Build command string
l_CmdString:="play " . p_lpszDeviceID
if p_Flags
l_CmdString.=A_Space . p_Flags
;-- Notify
p_Callback=%p_Callback% ;-- AutoTrim
if StrLen(p_Callback)
{
l_CmdString.=" notify"
;-- Attach p_Callback to MCI_Notify function
MCI_Notify(p_Callback,"","","")
;-- Monitor for MM_MCINOTIFY message
OnMessage(MM_MCINOTIFY,"MCI_Notify")
;-- Note: If the MM_MCINOTIFY message was monitored elsewhere,
; this statement will override it.
}
;-- Callback handle
if not p_hwndCallback
{
if InStr(A_Space . l_CmdString . A_Space," notify ")
or StrLen(p_Callback)
{
l_DetectHiddenWindows:=A_DetectHiddenWindows
DetectHiddenWindows On
Process Exist
p_hwndCallback:=WinExist("ahk_pid " . ErrorLevel . " ahk_class AutoHotkey")
DetectHiddenWindows %l_DetectHiddenWindows%
}
}
;-- Send it!
Return MCI_SendString(l_CmdString,Dummy,p_hwndCallback)
}
;-----------------------------
;
; Function: MCI_Position
;
; Description:
;
; Identifies the current playback or recording position.
;
; Parameters:
;
; p_lpszDeviceID - Device name or alias.
;
; p_Track - Track number. [Optional] The default is 0 (no track number).
;
; Returns:
;
; The current playback or recording position in the current time format. If
; the p_Track parameter contains a non-zero value, the start position of the
; track relative to entire media is returned.
;
;------------------------------------------------------------------------------
MCI_Position(p_lpszDeviceID,p_Track=0) {
l_CmdString:="status " . p_lpszDeviceID . " position"
if p_Track
l_CmdString.=" track " . p_Track
MCI_SendString(l_CmdString,l_lpszReturnString)
Return l_lpszReturnString
}
;-----------------------------
;
; Function: MCI_Record
;
; Description:
;
; Starts recording.
;
; Parameters:
;
; p_lpszDeviceID - Device name or alias.
;
; p_Flags - Flags that determine how the device operates for recording.
; [Optional] If blank, no flags are used.
;
; Flag Notes:
;
; Some commonly used flags include...
;
; (start code)
; from {position}
; to {position}
; insert
; overwrite
; (end)
;
; If more than one flag is used, separate each flag/value with a space.
; For example:
;
; (start code)
; overwrite from 18122 to 26427
; (end)
;
;
; Additional notes...