-
Notifications
You must be signed in to change notification settings - Fork 0
/
HLMM.ahk
582 lines (462 loc) · 12.9 KB
/
HLMM.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
;Half-Life Meme Maker
;Pandela 2023
#SingleInstance force
#Persistent
#Include ./config/AutoXYWH.ahk ;https://www.autohotkey.com/boards/viewtopic.php?f=6&t=1079
#Include ./config/BigA.ahk
SetTitleMatchMode,2
SetBatchLines,-1
wao := ""
ms := ""
AlreadyRunning := 0
SeekInterval := "0.1"
AudioArray := []
DelayArray := []
FilterArray := []
A := new biga()
px := 0
py := 0
Inactive := 0
counter2 := 0
global VideoLoaded := 0
global isPaused := 0
SetWorkingDir,A_ScriptDir
global customFFplay := 1
ffplayPath := A_ScriptDir "\config\ffplayy.exe"
if (customFFplay = 0) {
ffplayPath := "ffplay"
ffplayName := "ffplay.exe"
}
if (customFFplay = 1) {
SplitPath,ffplayPath,ffplayName
}
FixVideo := 0 ;Convert all frames in video to keyframes
KeyframeInterval := 1 ;Set to 1 to make ALL frames keyframe, this should probably be 1 if you're using the flag above
Process,Close,%ffplayName% ;close background ffplay process if its running
;gui 2:, +LastFound +E0x00010000 ;The ExStyle allows the parent to take focus if it's clicked.
gui 2: color,gray
gui 2: Add, Button, x134 y574 w176 h81 hWndhBtnOk gSkipBackward, <<<===
gui 2: Add, Button, x310 y574 w176 h81 hWndhBtnOk2 gSkipForward, ===>>>
gui 2: Add, Button, x134 y492 w352 h81 hWndhBtnOk3 gStopPlay, Stop/Play
gui 2: Add, Button, x134 y655 w352 h45 hWndhBtnOk4 gNudgeVideo, Nudge
gui 2: Show, w1280 h720, H.L.M.M
gui 2: +Resize
TreeRoot := "C:\Users\Pandela\Downloads\Half-Life 1"
File := A_ScriptDir . "\timestampLog2.txt"
Input := ""
FileDelete,%File% ;delete timestamp log
gosub,MakeTree ;make sound browser window
WinWait,%TreeRoot% ;wait for sound browser
id := WinExist() ;get sound browser window handle
WinGetTitle,Title,ahk_id %id% ;get sound browser title
TreeWindow := WinExist(Title)
HLMMwindow := WinExist("H.L.M.M")
WinGetPos,winX,winY,winW,winH,H.L.M.M
;msgbox % winX " " winY " " winW " " winH
test1 := winW / 2 + 150
test2 := winH / 2 + 30
test3 := winW / 2 - 180
test4 := winH / 2 - 80
test8 := winH + 1
;Embed SoundBrowser inside our gui
DllCall("SetParent", "uint", TreeWindow, "uint", HLMMwindow)
id_2 := WinExist("ahk_id " TreeWindow)
WinSet,Redraw,,%Title%
; Move and resize SoundBrowser window. Note that if SWP_NOSENDCHANGING
; is omitted, it incorrectly readjusts the size of its client area.
DllCall("SetWindowPos", "uint", TreeWindow, "uint", 0
, "int", test1, "int",test2, "int", test3, "int", test4
, "uint", SWP_SHOWWINDOW)
sleep, 500
WinSet,Redraw,,A
WinActivate,H.L.M.M
WinMove,H.L.M.M,,,,,%test8%
FirstRun := 1
WinMaximize,H.L.M.M
DisplayTimestamp()
return
WM_LBUTTONDOWN() {
If (A_Gui)
PostMessage, 0xA1, 2
}
F3::
OpenVideo:
SplitPath,Input,,sourceFolder,,filename2
Process,Close,%ffplayName%
gosub, checkFix
ffplay := "cmd.exe /c " ffplayPath " -hide_banner -seek_interval " SeekInterval " -i " chr(0x22) Input chr(0x22) " 2>> " chr(0x22) File chr(0x22)
run, % ffplay,,Hide,ffplayPID
clipboard := ffplay
WinWait,ahk_class SDL_app
ControlSend,,{Space},ahk_class SDL_app ;pause video initially
sleep, 500
sleep, 50
;Start the timestamp logging
if (AlreadyRunning != 1) {
lt := new CLogTailer(File, Func("NewLine"))
AlreadyRunning := 1
}
HLMMwindow := WinExist("H.L.M.M")
FFPlayWindow := WinExist("ahk_class SDL_app")
; Get size of FFPlay window, excluding caption and borders:
WinGetActiveStats,%FFPlayWindow%,FFPlayW,FFPlayH,x,y
newX := FFPlayW / 2
NewY := FFPlayH / 2
WinMove,ahk_class SDL_app,,%x%,%y%,%NewX%,%NewY%
WinSet, Style, -0x30000,ahk_class SDL_app
DisableCloseButton(FFPlayWindow)
;Embed FFplay inside our gui
DllCall("SetParent", "uint", FFplayWindow, "uint", HLMMwindow)
id_1 := WinExist("ahk_id " FFplayWindow)
;msgbox % px " " py " " pw " " ph
; Move and resize FFPlay window. Note that if SWP_NOSENDCHANGING
; is omitted, it incorrectly readjusts the size of its client area.
DllCall("SetWindowPos", "uint", FFPlayWindow, "uint", 0
, "int", 0, "int",0, "int", newX, "int", NewY
, "uint",SWP_SHOWWINDOW|SWP_NOSENDCHANGING)
if (px != 0) && (FirstRun = 0) {
newX := pW
newY := pH
py := (py - 20)
}
; Move and resize FFPlay window. Note that if SWP_NOSENDCHANGING
; is omitted, it incorrectly readjusts the size of its client area.
DllCall("SetWindowPos", "uint", FFPlayWindow, "uint", 0
, "int", px, "int",py, "int", newX, "int", NewY
, "uint",SWP_SHOWWINDOW|SWP_NOSENDCHANGING)
FirstRun := 0 ;;;;asd
global VideoLoaded := 1
return
NewLine(text){
match := RegExMatch(text,"\d+\.\d+",timestamp)
global ms := ceil((timestamp * 1000))
;This is to prevent the timestamp from being 0, in sacrifice of a few milliseconds in the timeline
if (ms = 0) && (Timestamp != "0.00") && (VideoLoaded = 1) && (isPaused = 1) && (customFFplay = 1) {
ControlSend,,S,H.L.M.M
}
;This is to prevent the timestamp from being 0, in sacrifice of a few milliseconds in the timeline
if (ms = 0) && (Timestamp != "0.00") && (VideoLoaded = 1) && (customFFplay = 0) {
ControlSend,,S,H.L.M.M
}
;Set the current timeline milliseconds in the gui, can optionally be modified
GuiControl,,SoundOffset,%ms%
if (wao = 1) {
ToolTip % "Timestamp: " timestamp "`n ms: " ms "`n" isPaused
}
if (wao = 0) {
ToolTip
}
}
F6::
msgbox % VideoLoaded
return
;https://www.autohotkey.com/boards/viewtopic.php?t=47894#p215692
class CLogTailer {
__New(logfile, callback){
this.file := FileOpen(logfile, "r-d")
this.callback := callback
; Move seek to end of file
this.file.Seek(0, 2)
fn := this.WatchLog.Bind(this)
SetTimer, % fn, 100
}
WatchLog(){
Loop {
p := this.file.Tell()
l := this.file.Length
line := this.file.ReadLine(), "`r`n"
len := StrLen(line)
if (len){
RegExMatch(line, "[\r\n]+", matches)
if (line == matches)
continue
this.callback.Call(Trim(line, "`r`n"))
}
} until (p == l)
}
}
DisplayTimestamp()
{
gosub, displayTS
}
DisplayTS:
loop {
sleep, 200
if WinActive("H.L.M.M") else WinActive("ahk_class SDL_app") {
global wao := 1
}
if !WinActive("H.L.M.M") && !WinActive("ahk_class SDL_app") {
global wao := 0
}
}
return
CheckFix:
SplitPath,Input,,Dir,,Filename
NewFile := Dir "\" Filename . ".mkv"
FixIt := ComSpec " /c ffmpeg -i " Input " -g 10 -bf 0 -crf 20 -y -ac 2 -c:a pcm_u32le -f nut -fflags +genpts " NewFile
if !FileExist(NewFile) && (FixVideo = 1) {
runwait, % FixIt
sleep, 100
global Input := NewFile
}
Return
SkipForward:
if (Inactive = 1) {
WinGet, hWnd2, ID, ahk_id %id_1%
WinActivate,ahk_id %hWnd2%
Inactive := 0
}
Forward(ms)
Return
SkipBackward:
if (Inactive = 1) {
WinGet, hWnd2, ID, ahk_id %id_1%
WinActivate,ahk_id %hWnd2%
Inactive := 0
}
Backward(ms)
Return
StopPlay:
if (Inactive = 1) {
WinGet, hWnd2, ID, ahk_id %id_1%
WinActivate,ahk_id %hWnd2%
Inactive := 0
}
StopAndPlay()
Return
NudgeVideo:
if (Inactive = 1) {
WinGet, hWnd2, ID, ahk_id %id_1%
WinActivate,ahk_id %hWnd2%
Inactive := 0
}
Nudge()
Return
2GuiSize:
WinGetPos,winX,winY,winW,winH,H.L.M.M
test1 := winW / 2 + 150
test2 := winH / 2 + 30
test3 := winW / 2 - 180
test4 := winH / 2 - 80
balls := !balls
if (balls = 1) {
thisX := "x0.0"
thisY := "*y+1.0"
}
if (balls = 0) {
thisX := "x0.0"
thisY := "y0.0"
}
AutoXYWH( thisX " " thisY, hBtnOk)
AutoXYWH( thisX " " thisY, hBtnOk2)
AutoXYWH( thisX " " thisY, hBtnOk3)
AutoXYWH( thisX " " thisY, hBtnOk4)
DllCall("SetWindowPos", "uint", TreeWindow, "uint", 0
, "int", test1, "int",test2, "int", test3, "int",test4
, "uint", SWP_NOACTIVATE|SWP_SHOWWINDOW|SWP_NOSENDCHANGING)
sleep, 20
WinSet,Redraw,,A
WinSet,Redraw,,ahk_id %id_1%
WinActivate,ahk_id %id_1%
return
Forward(ms)
{
ControlSend,,{Right},H.L.M.M
if (isPaused = 0) && (customFFplay = 1) {
sleep, 20
ControlSend,,S,H.L.M.M
sleep, 1
ControlSend,,P,H.L.M.M
}
}
Backward(ms)
{
ControlSend,,{Left},H.L.M.M
if (isPaused = 0) && (customFFplay = 1) {
sleep, 20
ControlSend,,S,H.L.M.M
sleep, 1
ControlSend,,P,H.L.M.M
}
}
StopAndPlay()
{
global isPaused := !isPaused
sleep, 5
ControlSend,,{Space},H.L.M.M
}
Nudge()
{
ControlSend,,S,H.L.M.M
if (customFFplay = 1) {
sleep, 1
ControlSend,,{Space},H.L.M.M
}
}
;PostLeftClick(x, y, hwnd) {
; PostMessage, 0x201, 0x0001, ((y<<16)^x), , ahk_id%hwnd% ;WM_LBUTTONDOWN
; PostMessage, 0x202 , 0, ((y<<16)^x), , ahk_id%hwnd% ;WM_LBUTTONUP
;}
;Audio File browser
#Include ./config/SoundBrowser.ahk
testSound:
if (ReplaceBGM = 1) {
input := newVideo
}
if (KeepSound = 1) {
input := KeepSoundFile
}
AddSounds := ComSpec " /c ffmpeg -i " chr(0x22) input chr(0x22) " "
AddFilters := " -filter_complex " chr(0x22)
Amt := AudioArray.Length()
loop %Amt%
{
AddSounds .= " -i " chr(0x22) AudioArray[A_Index] chr(0x22)
}
loop %Amt%
{
if (FilterArray[A_Index] = "") {
ApplyFilter := ""
}
if (FilterArray[A_Index] != "") {
ApplyFilter := "," FilterArray[A_Index]
}
AddFilters .= "[" A_Index "]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,adelay=" DelayArray[A_Index] "|" DelayArray[A_Index] ApplyFilter "[HL" A_Index "];"
MixStack .= "[HL" A_Index "]"
}
KeepSoundFile := sourceFolder "\output_" counter2 ".mkv"
KeepSoundFileNext := sourceFolder "\output_" counter2+1 ".mkv"
FinalCommand := AddSounds " " AddFilters "[0]" MixStack "amix=" (Amt + 1) ":normalize=false" chr(0x22) " -c:v copy -f nut -c:a pcm_u32le -ac 2 " KeepSoundFileNext " -y && ffplay " KeepSoundFileNext
clipboard := FinalCommand
;msgbox % FinalCommand
runwait % FinalCommand
MixStack := ""
Inactive = 1
return
CurrentSound:
Gui 1:Submit,NoHide
Counter += 1
AudioArray.push(SoundFile)
DelayArray.push(SoundOffset)
FilterArray.push(SoundFilter)
tooltip % AudioArray[Counter] "`n" DelayArray[Counter] " " ms
Inactive = 1
return
StopSound:
SoundPlay,nothing.avi
Inactive = 1
return
ReplaceSound:
WinGet, hWnd2, ID, ahk_id %id_1%
WinGetPos, pX,pY,pW,pH,ahk_id %id_1%
sleep, 100
Gui 1:Submit,NoHide
SkipAmount := 0.5
SoundPlay,nothing.avi
ReplaceBGM := 1
if (SoundFilter != "") {
ApplyFilter := " -af " SoundFilter
}
if (SoundFilter = "") {
ApplyFilter := ""
}
SplitPath,Input,,sourceFolder,,filename2
newVideo := sourceFolder "\" filename2 "_" sound ".mkv"
replaceAudio := ComSpec " /c ffmpeg -i " chr(0x22) Input chr(0x22) " -ss " SkipAmt " -i " chr(0x22) SoundFile chr(0x22) " " ApplyFilter " -c:v copy -map 0:v -map 1:a -f nut -c:a pcm_u32le -ac 2 -shortest -y " newVideo
runwait, % replaceAudio,,Hide
oldInput := input
input := newVideo
AudioArray := []
DelayArray := []
FilterArray := []
Inactive = 1
global VideoLoaded := 0
gosub, OpenVideo
input := oldInput
Return
KeepSound:
WinGet, hWnd2, ID, ahk_id %id_1%
WinGetPos, pX,pY,pW,pH,ahk_id %id_1%
counter2 += 1
KeepSoundFile := sourceFolder "\output_" counter2 ".mkv"
KeepSoundFileNext := sourceFolder "\output_" counter2+1 ".mkv"
input := KeepSoundFile
KeepSound := 1
AudioArray := []
DelayArray := []
FilterArray := []
Inactive = 1
global VideoLoaded := 0
gosub,OpenVideo
Return
RemoveSound:
AudioArray := A.initial(AudioArray)
DelayArray := A.initial(DelayArray)
FilterArray := A.initial(FilterArray)
Inactive = 1
return
2GuiDropFiles:
WinGet, hWnd2, ID, ahk_id %id_1%
WinGetPos, pX,pY,pW,pH,ahk_id %id_1%
Input := A_GuiEvent
global VideoLoaded := 0
gosub,OpenVideo
Return
RemakeTree:
gosub,MakeTree
WinWait,%TreeRoot%
id := WinExist()
WinGetTitle,Title,ahk_id %id%
TreeWindow := WinExist(Title)
HLMMwindow := WinExist("H.L.M.M")
WinGetPos,winX,winY,winW,winH,H.L.M.M
test1 := winW / 2 + 150
test2 := winH / 2 + 30
test3 := winW / 2 - 180
test4 := winH / 2 - 80
test8 := winH + 1
DllCall("SetParent", "uint", TreeWindow, "uint", HLMMwindow)
id_2 := WinExist("ahk_id " TreeWindow)
WinSet,Redraw,,%Title%
DllCall("SetWindowPos", "uint", TreeWindow, "uint", 0
, "int", test1, "int",test2, "int", test3, "int", test4
, "uint", SWP_SHOWWINDOW)
sleep, 500
WinSet,Redraw,,A
return
2GuiClose:
Process,Close,%ffplayName%
ExitApp
#IfWinActive,H.L.M.M
S::Nudge() ;Allow to send S key to nudge video one frame
Q:: ;do nothing, prevents closing ffplay window
P::StopAndPlay()
Space::StopAndPlay()
Left::Backward(ms)
Right::Forward(ms)
#IfWinActive, ahk_class SDL_app
Q:: ;do nothing, prevents closing ffplay window
Esc:: ;do nothing, prevents closing ffplay window
F:: ;do nothing, prevents fullscreen ffplay window
S:: Nudge()
P::StopAndPlay()
Space::StopAndPlay()
Left::Backward(ms)
Right::Forward(ms)
RButton::
loop {
state := GetKeyState("RButton", "P") ; True if Xbutton1 is ON, false otherwise.
SendEvent, {RButton down}
sleep, 1
if (state = 0) {
SendEvent, {RButton up}
if (isPaused = 0) { ; && (customFFplay = 0)
sleep, 1
ControlSend,,S,H.L.M.M
sleep, 1
ControlSend,,P,H.L.M.M
}
break
}
}
return