forked from Ixiko/AHK-libs-and-classes-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsound.ahk
217 lines (194 loc) · 6.7 KB
/
sound.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
;
; AutoHotkey Version: 1.0.47.00
; Language: Anyone
; Author: Fincs <[email protected]>
;
; Script Function:
; Functions to handle multimedia files
;
;===============================================================================
;
; Function Name: Sound_Open
; Description:: Opens a sound file for use with other sound functions
; Parameter(s): File - The sound file
; Alias [optional] - A name such as sound1, if you do not
; specify one it is automatically generated
; Return Value(s): The sound handle or a 0 to indicate failure
; ErrorLevel value: 0 - No Error
; 1 - Open failed
; 2 - File doesn't exist
;
;===============================================================================
Sound_Open(File, Alias=""){
Static SoundNumber = 0
IfNotExist, %File%
{
ErrorLevel = 2
Return 0
}
If Alias =
{
SoundNumber ++
Alias = AutoHotkey%SoundNumber%
}
Loop, %File%
File_Short = %A_LoopFileShortPath%
r := Sound_SendString("open " File_Short " alias " Alias)
If r
{
ErrorLevel = 1
Return 0
}Else{
ErrorLevel = 0
Return %Alias%
}
}
;===============================================================================
;
; Function Name: Sound_Close
; Description:: Closes a sound
; Parameter(s): SoundHandle - Sound handle returned by Sound_Open
; Return Value(s): 1 - Success, 0 - Failure
;
;===============================================================================
Sound_Close(SoundHandle){
r := Sound_SendString("close " SoundHandle)
Return NOT r
}
;===============================================================================
;
; Function Name: Sound_Play
; Description:: Plays a sound from the current position (beginning is the default)
; Parameter(s): SoundHandle - Sound handle returned by Sound_Open
; Wait - If set to 1 the script will wait for the sound to finish before continuing
; - If set to 0 the script will continue while the sound is playing
; Return Value(s): 1 - Success, 0 - Failure
;
;===============================================================================
Sound_Play(SoundHandle, Wait=0){
If(Wait <> 0 AND Wait <> 1)
Return 0
If Wait
r := Sound_SendString("play " SoundHandle " wait")
Else
r := Sound_SendString("play " SoundHandle " from 0") ;play door from 0
Return NOT r
}
;===============================================================================
;
; Function Name: Sound_Stop
; Description:: Stops the sound
; Parameter(s): SoundHandle - Sound handle returned by Sound_Open
; Return Value(s): 1 - Success, 0 - Failure
;
;===============================================================================
Sound_Stop(SoundHandle){
r := Sound_SendString("seek " SoundHandle " to start")
r2 := Sound_SendString("stop " SoundHandle)
If(r AND r2)
{
Return 0
}Else{
Return 1
}
}
;===============================================================================
;
; Function Name: Sound_Pause
; Description:: Pauses the sound
; Parameter(s): SoundHandle - Sound handle returned by Sound_Open
; Return Value(s): 1 - Success, 0 - Failure
;
;===============================================================================
Sound_Pause(SoundHandle){
r := Sound_SendString("pause " SoundHandle)
Return NOT r
}
;===============================================================================
;
; Function Name: Sound_Resume
; Description:: Resumes the sound after being paused
; Parameter(s): SoundHandle - Sound handle returned by Sound_Open
; Return Value(s): 1 - Success, 0 - Failure
;
;===============================================================================
Sound_Resume(SoundHandle){
r := Sound_SendString("resume " SoundHandle)
Return NOT r
}
;===============================================================================
;
; Function Name: Sound_Length
; Description:: Returns the length of the sound
; Parameter(s): SoundHandle - Sound handle returned by Sound_Open
; Return Value(s): Length of the sound - Success
;
;===============================================================================
Sound_Length(SoundHandle){
r := Sound_SendString("set time format miliseconds", 1)
If r
Return 0
r := Sound_SendString("status " SoundHandle " length", 1, 1)
Return %r%
}
;===============================================================================
;
; Function Name: Sound_Seek
; Description:: Seeks the sound to a specified time
; Parameter(s): SoundHandle - Sound handle returned by Sound_Open
; Hour, Min, Sec - Time to seek to
; Return Value(s): 1 - Success, 0 - Failure,
;
;===============================================================================
Sound_Seek(SoundHandle, Hour, Min, Sec){
milli := 0
r := Sound_SendString("set time format milliseconds", 1)
If r
Return 0
milli += Sec * 1000
milli += Min * 1000 * 60
milli += Hour * 1000 * 60 * 60
r := Sound_SendString("seek " SoundHandle " to " milli)
Return NOT r
}
;===============================================================================
;
; Function Name: Sound_Status
; Description:: All devices can return the "not ready", "paused", "playing", and "stopped" values.
; Some devices can return the additional "open", "parked", "recording", and "seeking" values.(MSDN)
; Parameter(s): SoundHandle - Sound handle returned by Sound_Open
; Return Value(s): Sound Status
;
;===============================================================================
Sound_Status(SoundHandle){
Return Sound_SendString("status " SoundHandle " mode", 1, 1)
}
;===============================================================================
;
; Function Name: Sound_Pos
; Description:: Returns the current position of the song
; Parameter(s): SoundHandle - Sound handle returned by Sound_Open
; Return Value(s): Current Position - Success, 0 - Failure
;
;===============================================================================
Sound_Pos(SoundHandle){
r := Sound_SendString("set time format miliseconds", 1)
If r
Return 0
r := Sound_SendString("status " SoundHandle " position", 1, 1)
Return %r%
}
;===============================================================================
Sound_SendString(string, UseSend=0, ReturnTemp=0){
If UseSend
{
VarSetCapacity(stat1, 32, 32)
DllCall("winmm.dll\mciSendStringA", "UInt", &string, "UInt", &stat1, "Int", 32, "Int", 0)
}Else{
DllCall("winmm.dll\mciExecute", "str", string)
}
If(UseSend And ReturnTemp)
Return stat1
Else
Return %ErrorLevel%
}