-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pas
2549 lines (2249 loc) · 93.3 KB
/
main.pas
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
{*******************************************************}
{ }
{ Scenarium }
{ Copyright (c) 2024 Kirill Filippenok }
{ Apache License 2.0 }
{ }
{*******************************************************}
unit Main;
{$mode ObjFPC}{$LONGSTRINGS ON}{$RANGECHECKS ON}{$WRITEABLECONST OFF}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, ExtCtrls,
CheckLst, Buttons, StdCtrls, ComCtrls, Types, LCLType, lazUTF8, Themes, Math,
// JSON
fpjson, jsonparser,
// Files
FileUtil,
// Project Units
AboutProject, PlaybackVideo, PlaybackAudio, MonitorConfigure, Settings,
Pocket, UniqueInstance, FileSettings,
// libMPVDelphi
MPVBasePlayer;
type
{ TfMain }
TfMain = class(TForm)
lblCurrentVideoItem: TLabel;
lblVideoTimeTotal: TLabel;
lblVideoTimeCurrent: TLabel;
lblCurrentAudioItem: TLabel;
miVideoSettings: TMenuItem;
miAudioSettings: TMenuItem;
miVideoReloadPlaylist: TMenuItem;
miAudioReloadPlaylist: TMenuItem;
miScenarioReload: TMenuItem;
miVideoDeleteBonds: TMenuItem;
miCloseTab: TMenuItem;
miAudioDeleteBond: TMenuItem;
miAudioAddBond: TMenuItem;
miVideoAddBond: TMenuItem;
miAudioDelete: TMenuItem;
miVideoDelete: TMenuItem;
ppmnTabControl: TPopupMenu;
ppmnAudioPlaylist: TPopupMenu;
ppmnVideoPlaylist: TPopupMenu;
sbtnAudioLinkControlTrackBar: TSpeedButton;
sbtnAudioRepeat: TSpeedButton;
sbtnVideoLinkControlTrackBar: TSpeedButton;
sbtnVideoRepeat: TSpeedButton;
sbtnAudioLinkControlButtons: TSpeedButton;
sbtnVideoLinkControlButtons: TSpeedButton;
sboxAudioBottomExtControls: TScrollBox;
sboxVideoBottomExtControls: TScrollBox;
{ Вкладки }
TabControl: TTabControl;
{ Меню }
MainMenu: TMainMenu;
miScenarioNew: TMenuItem;
miScenarioOpen: TMenuItem;
miScenarioSaveAs: TMenuItem;
miScenarioSave: TMenuItem;
miScenario: TMenuItem;
miScenarioExit: TMenuItem;
Settings: TMenuItem;
Info: TMenuItem;
InfoAboutProgram: TMenuItem;
{ Аудио панель }
panAudio: TPanel;
panAudioControlsTop: TPanel;
panAudioControlsBottom: TPanel;
// Работа со списком
clboxAudioPlaylist: TCheckListBox;
sbtnAudioAdd: TSpeedButton;
sbtnAudioSubtract: TSpeedButton;
sbtnAudioClear: TSpeedButton;
// Воспроизведение
sbtnAudioPlay: TSpeedButton;
sbtnAudioPause: TSpeedButton;
sbtnAudioStop: TSpeedButton;
trbarAudioTime: TTrackBar;
lblAudioTimeCurrent: TLabel;
lblAudioTimeTotal: TLabel;
// Громкость
sbtnAudioVolume: TSpeedButton;
trbarAudioVolume: TTrackBar;
// Таймер
TimerAudio: TTimer;
{ Разделитель }
Splitter: TSplitter;
{ Видео панель }
panVideo: TPanel;
panVideoControlsTop: TPanel;
panVideoControlsBottom: TPanel;
// Работа со списком
clboxVideoPlaylist: TCheckListBox;
sbtnVideoAdd: TSpeedButton;
sbtnVideoSubtract: TSpeedButton;
sbtnVideoClear: TSpeedButton;
// Воспроизведение
sbtnVideoPause: TSpeedButton;
sbtnVideoPlay: TSpeedButton;
sbtnVideoStop: TSpeedButton;
trbarVideoTime: TTrackBar;
// Громкость
sbtnVideoVolume: TSpeedButton;
trbarVideoVolume: TTrackBar;
// Таймер
TimerVideo: TTimer;
// Монитор
sbtnFullyDisplay: TSpeedButton;
sbtnMonitorConfigure: TSpeedButton;
{ Диалоги }
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
UniqueInstance: TUniqueInstance;
procedure clboxAudioPlaylistClick(Sender: TObject);
procedure clboxAudioPlaylistDblClick(Sender: TObject);
procedure clboxAudioPlaylistDragDrop(Sender, Source: TObject; X, Y: Integer
);
procedure clboxAudioPlaylistDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
procedure clboxVideoPlaylistClick(Sender: TObject);
procedure clboxVideoPlaylistDblClick(Sender: TObject);
procedure clboxVideoPlaylistDragDrop(Sender, Source: TObject; X, Y: Integer
);
procedure clboxVideoPlaylistDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
procedure clboxVideoPlaylistItemClick(Sender: TObject; Index: integer);
procedure clboxVideoPlaylistKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure clboxVideoPlaylistMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure clboxVideoPlaylistMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure AddBond(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
procedure FormResize(Sender: TObject);
procedure miAudioDeleteBondClick(Sender: TObject);
procedure miAudioDeleteClick(Sender: TObject);
procedure miAudioSettingsClick(Sender: TObject);
procedure miCloseTabClick(Sender: TObject);
procedure miScenarioReloadClick(Sender: TObject);
procedure miVideoDeleteBondsClick(Sender: TObject);
procedure miVideoDeleteClick(Sender: TObject);
procedure miVideoSettingsClick(Sender: TObject);
procedure panAudioControlsTopMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure ppmnAudioPlaylistPopup(Sender: TObject);
procedure ppmnTabControlPopup(Sender: TObject);
procedure ppmnVideoPlaylistPopup(Sender: TObject);
procedure sboxAudioBottomExtControlsResize(Sender: TObject);
procedure sboxVideoBottomExtControlsResize(Sender: TObject);
procedure sbtnAudioLinkControlTrackBarClick(Sender: TObject);
procedure sbtnAudioPauseClick(Sender: TObject);
procedure sbtnAudioStopClick(Sender: TObject);
procedure sbtnAudioStopMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure sbtnVideoAddClick(Sender: TObject);
procedure sbtnVideoLinkControlButtonsClick(Sender: TObject);
procedure sbtnVideoLinkControlTrackBarClick(Sender: TObject);
procedure sbtnVideoRepeatClick(Sender: TObject);
procedure sbtnVideoStopMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure sbtnVideoVolumeClick(Sender: TObject);
procedure sbtnVideoPlayClick(Sender: TObject);
{ Меню }
procedure miScenarioNewClick(Sender: TObject);
procedure miScenarioOpenClick(Sender: TObject);
procedure miScenarioSaveClick(Sender: TObject);
procedure miScenarioSaveAsClick(Sender: TObject);
procedure miScenarioExitClick(Sender: TObject);
procedure SettingsClick(Sender: TObject);
procedure InfoAboutProgramClick(Sender: TObject);
{ Список файлов }
procedure clboxAudioPlaylistDrawItem(Control: TWinControl;
Index: integer; ARect: TRect; State: TOwnerDrawState); (* Аудио *)
procedure sbtnAudioAddClick(Sender: TObject);
procedure sbtnAudioSubtractClick(Sender: TObject);
procedure sbtnAudioClearClick(Sender: TObject);
procedure clboxVideoPlaylistDrawItem(Control: TWinControl;
Index: integer; ARect: TRect; State: TOwnerDrawState); (* Видео *)
procedure sbtnVideoSubtractClick(Sender: TObject);
procedure sbtnVideoClearClick(Sender: TObject);
{ Воспроизведение }
procedure sbtnAudioPlayClick(Sender: TObject);
procedure sbtnVideoPauseClick(Sender: TObject);
procedure sbtnVideoStopClick(Sender: TObject);
procedure sbtnAudioRepeatClick(Sender: TObject);
procedure sbtnAudioLinkControlButtonsClick(Sender: TObject);
procedure TabControlChange(Sender: TObject);
procedure TabControlChanging(Sender: TObject; var AllowChange: Boolean);
procedure TabControlDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure TabControlDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure TabControlMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure trbarAudioTimeChange(Sender: TObject);
procedure trbarAudioTimeMouseLeave(Sender: TObject);
procedure trbarAudioTimeMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure trbarAudioTimeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
{ Окно воспроизведения (Видео) }
procedure sbtnFullyDisplayClick(Sender: TObject);
procedure sbtnMonitorConfigureClick(Sender: TObject);
{ Громкость (Аудио) }
procedure sbtnAudioVolumeClick(Sender: TObject);
procedure trbarAudioVolumeChange(Sender: TObject);
procedure trbarAudioVolumeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
{ Таймер }
procedure TimerMediaTimer(Sender: TObject);
procedure trbarVideoTimeChange(Sender: TObject);
procedure trbarVideoTimeMouseLeave(Sender: TObject);
procedure trbarVideoTimeMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure trbarVideoTimeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
procedure trbarVideoVolumeChange(Sender: TObject);
procedure trbarVideoVolumeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
procedure UniqueInstanceOtherInstance(Sender: TObject; ParamCount: Integer;
const Parameters: array of String);
private
procedure OpenAndPlayAudio(AItemIndex: Integer);
procedure OpenAndPlayVideo(AItemIndex: Integer);
procedure openScenario(const ScenarioFilePath: String);
procedure setFullyDisplay(ShowPlayback: Boolean);
procedure resetTime(Player: string);
procedure SetElementGlyphs;
procedure LoadScenarioFromJSON(FilePath: String);
procedure BondButtonClick(Sender: TObject);
public
end;
var
fMain: TfMain;
glAudioMute: boolean;
glVideoMute: boolean;
glVideoTrackRewinding: boolean = False;
glAudioTrackRewinding: boolean = False;
glAudioTrackRepeat: boolean = False;
glVideoTrackRepeat: boolean = False;
glCurrentAudioItem: string;
glCurrentAudioItemIndex: Integer;
glCurrentVideoItem: string;
glCurrentVideoItemIndex: Integer;
glCurrentPlaylist: CScenario = NIL;
ScenarioList: CScenarioList;
glAdaptivePanels: Boolean = True;
StateNotify: CStateNotify;
MousePos_TabControl: TPoint;
Popuped_TabControl: Boolean = False;
NewTab_Count: Integer = 0;
LinkPlaybackControlButtons: Boolean = False;
LinkPlaybackControlTrackBar: Boolean = False;
implementation
{$R *.lfm}
function SecsToTimeStr(time_secs: Integer): String;
var
secs, mins: integer;
begin
mins := time_secs div 60;
secs := time_secs mod 60;
if mins < 10 then
Result := '0'
else
Result := '';
Result := Result + IntToStr(mins);
Result := Result + ':';
if secs < 10 then
Result := Result + '0';
Result := Result + IntToStr(secs);
end;
procedure TfMain.BondButtonClick(Sender: TObject);
begin
ShowMessage(
IntToStr(
ScenarioList.Items[TabControl.TabIndex].Bonds.GetInvokingWhereProvoking(
StrToInt(
(Sender as TBitBtn).Name[Length((Sender as TBitBtn).Name)]
)
)
)
+ ' - ' +
clboxVideoPlaylist.Items.Strings[
ScenarioList.Items[TabControl.TabIndex].Bonds.GetInvokingWhereProvoking(
StrToInt(
(Sender as TBitBtn).Name[Length((Sender as TBitBtn).Name)]
)
)
]
);
end;
{ TfMain }
procedure TfMain.FormCreate(Sender: TObject);
begin
SetElementGlyphs();
//ShowMessageFmt('%d', [ParamCount]);
// Двойная буферизация
fMain.DoubleBuffered := True;
panAudio.DoubleBuffered:=True;
panVideo.DoubleBuffered:=True;
// Сценарий
ScenarioList := CScenarioList.Create(True);
// Вкладки
ScenarioList.Add(CScenario.Create);
ScenarioList.Items[0].Name := 'Default';
TabControl.Tabs.Add(ScenarioList.Items[0].Name);
// Заполняем список треков
clboxAudioPlaylist.Items := ScenarioList.Items[0].AudioFileNames; // Аудио
clboxVideoPlaylist.Items := ScenarioList.Items[0].VideoFileNames; // Видео
if ParamCount > 0 then
if FileExists(ParamStr(1)) then
openScenario(ParamStr(1));
{ По умолчанию звук включен }
glAudioMute := False; // Аудио
glVideoMute := False; // Видео
{ Воспроизводимый на данный момент файл }
glCurrentAudioItem := ''; // Аудио
glCurrentAudioItemIndex := -1;
glCurrentVideoItem := ''; // Видео
glCurrentVideoItemIndex := -1;
{ Время устанавливается в нулевое положение }
resetTime('AudioPlayer'); // Аудио
resetTime('VideoPlayer'); // Видео
// Оповещение о состоянии работы с файлом
StateNotify := CStateNotify.Create(fMain);
StateNotify.Parent := fMain;
StateNotify.Width := 250;
StateNotify.Height := 50;
StateNotify.Anchors := [];
StateNotify.AnchorParallel(akLeft, 20, fMain);
StateNotify.AnchorParallel(akBottom, 60, fMain);
StateNotify.Visible := False;
StateNotify.BorderStyle := bsNone;
StateNotify.BevelInner := bvNone;
StateNotify.BevelOuter := bvNone;
StateNotify.ShowTime := 2000;
StateNotify.BringToFront;
end;
procedure TfMain.OpenAndPlayAudio(AItemIndex: Integer);
var IndexBond: Integer;
begin
with fPlaybackAudio do
begin
glCurrentAudioItem := glCurrentPlaylist.AudioFilePaths[AItemIndex];
glCurrentAudioItemIndex := AItemIndex;
lblCurrentAudioItem.Caption := ExtractFileName(glCurrentAudioItem);
audioPlayer.OpenFile(glCurrentAudioItem);
// Время устанавливается в нулевое положение
resetTime('AudioPlayer');
TimerAudio.Enabled := True;
clboxAudioPlaylist.Repaint;
{ Связи }
IndexBond := glCurrentPlaylist.Bonds.IndexOfProvoking(AItemIndex);
if IndexBond <> -1 then
begin
LinkPlaybackControlButtons := True;
setGlyphSpeedButton(sbtnAudioLinkControlButtons, Application.Location + 'icons' + PathDelim + 'link_on.png');
setGlyphSpeedButton(sbtnVideoLinkControlButtons, Application.Location + 'icons' + PathDelim + 'link_on.png');
OpenAndPlayVideo(glCurrentPlaylist.Bonds.GetInvokingWhereProvoking(AItemIndex));
end
else
begin
if LinkPlaybackControlButtons = True then
sbtnAudioLinkControlButtonsClick(fMain);
if LinkPlaybackControlTrackBar = True then
sbtnAudioLinkControlTrackBarClick(fMain);
end;
{ Связи }
// Изменение состояния элементов воспроизведения
setGlyphSpeedButton(sbtnAudioStop, Application.Location + 'icons' + PathDelim + 'stop.png');
setGlyphSpeedButton(sbtnAudioPause, Application.Location + 'icons' + PathDelim + 'pause.png');
setGlyphSpeedButton(sbtnAudioPlay, Application.Location + 'icons' + PathDelim + 'play.png');
end;
end;
procedure TfMain.clboxAudioPlaylistDblClick(Sender: TObject);
begin
if (fPlaybackAudio.audioPlayer = nil) then Exit;
if (clboxAudioPlaylist.Count = 0) then Exit;
if ScenarioList.Items[TabControl.TabIndex].MissingFiles.IndexOf(ScenarioList.Items[TabControl.TabIndex].AudioFilePaths.Strings[clboxAudioPlaylist.ItemIndex]) <> -1 then
begin
ShowMessage('Файл по пути ' + ScenarioList.Items[TabControl.TabIndex].AudioFilePaths.Strings[clboxAudioPlaylist.ItemIndex] + ' отсутствует.');
Exit;
end;
glCurrentPlaylist := ScenarioList.Items[TabControl.TabIndex];
OpenAndPlayAudio(clboxAudioPlaylist.ItemIndex);
end;
procedure TfMain.clboxAudioPlaylistDragDrop(Sender, Source: TObject; X,
Y: Integer);
var clbox : TCheckListBox;
oldIndex, newIndex, i: Integer;
LBitBtn: TBitBtn;
begin
if clboxAudioPlaylist.Count = 0 then
Exit;
clbox := TCheckListBox(Sender);
newIndex := clbox.GetIndexAtXY(X, Y);
oldIndex := clboxAudioPlaylist.ItemIndex;
if newIndex = -1 then // Если перенесли на пустое место
newIndex := clboxAudioPlaylist.Count-1;
if newIndex = oldIndex then Exit; // Проверка на смену позиции
if (Sender <> Source) then Exit;
clboxAudioPlaylist.Items.BeginUpdate;
clboxAudioPlaylist.Items.Move(oldIndex, newIndex); // Передвигаем элемент
ScenarioList.Items[TabControl.TabIndex].AudioFileNames.Move(oldIndex, newIndex);
ScenarioList.Items[TabControl.TabIndex].AudioFilePaths.Move(oldIndex, newIndex);
if oldIndex > newIndex then
begin
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereProvoking(oldIndex, -1);
if fMain.FindComponent('bbtnBondVideo' + IntToStr(oldIndex)) <> NIL then
begin
LBitBtn := ((fMain.FindComponent('bbtnBondVideo' + IntToStr(oldIndex))) as TBitBtn);
FreeAndNil(LBitBtn);
end;
for i := oldIndex-1 downto newIndex do
begin
if i = glCurrentAudioItemIndex then
glCurrentAudioItemIndex := i+1;
if fMain.FindComponent('bbtnBondVideo' + IntToStr(i)) <> NIL then
begin
LBitBtn := ((fMain.FindComponent('bbtnBondVideo' + IntToStr(i))) as TBitBtn);
FreeAndNil(LBitBtn);
end;
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereProvoking(i, i+1);
end;
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereProvoking(-1, newIndex);
if oldIndex = glCurrentAudioItemIndex then
glCurrentAudioItemIndex := newIndex;
end
else
begin
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereProvoking(oldIndex, -1);
if fMain.FindComponent('bbtnBondVideo' + IntToStr(oldIndex)) <> NIL then
begin
LBitBtn := ((fMain.FindComponent('bbtnBondVideo' + IntToStr(oldIndex))) as TBitBtn);
FreeAndNil(LBitBtn);
end;
for i := oldIndex+1 to newIndex do
begin
if i = glCurrentAudioItemIndex then
glCurrentAudioItemIndex := i-1;
if fMain.FindComponent('bbtnBondVideo' + IntToStr(i)) <> NIL then
begin
LBitBtn := ((fMain.FindComponent('bbtnBondVideo' + IntToStr(i))) as TBitBtn);
FreeAndNil(LBitBtn);
end;
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereProvoking(i, i-1);
end;
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereProvoking(-1, newIndex);
if oldIndex = glCurrentAudioItemIndex then
glCurrentAudioItemIndex := newIndex;
end;
clboxAudioPlaylist.Items.EndUpdate;
clboxAudioPlaylist.ItemIndex := newIndex;
clboxAudioPlaylist.ClearSelection;
clboxAudioPlaylist.Selected[newIndex] := True;
end;
procedure TfMain.clboxAudioPlaylistDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
if clboxAudioPlaylist.Count > 0 then
Accept := True;
end;
procedure TfMain.clboxVideoPlaylistClick(Sender: TObject);
begin
//ShowMessageFmt('ItemIndex: %d', [clboxVideoPlaylist.ItemIndex]);
end;
procedure TfMain.clboxAudioPlaylistClick(Sender: TObject);
begin
// !? Выбран ли элемент
if clboxAudioPlaylist.ItemIndex = -1 then
Exit;
// !? Если ли в связях
if not(ScenarioList.Items[TabControl.TabIndex].Bonds.InProvoking(clboxAudioPlaylist.ItemIndex)) then
Exit;
clboxVideoPlaylist.ClearSelection;
clboxVideoPlaylist.Selected[ScenarioList.Items[TabControl.TabIndex].Bonds.GetInvokingWhereProvoking(clboxAudioPlaylist.ItemIndex)] := True;
end;
procedure TfMain.OpenAndPlayVideo(AItemIndex: Integer);
begin
with fPlaybackVideo do
begin
glCurrentVideoItem := glCurrentPlaylist.VideoFilePaths[AItemIndex];
glCurrentVideoItemIndex := AItemIndex;
lblCurrentVideoItem.Caption := ExtractFileName(glCurrentVideoItem);
VideoPlayer.OpenFile(glCurrentVideoItem);
// Время устанавливается в нулевое положение
resetTime('VideoPlayer');
TimerVideo.Enabled := True;
clboxVideoPlaylist.Repaint;
// Изменение состояния элементов воспроизведения
setGlyphSpeedButton(sbtnVideoStop, Application.Location + 'icons' + PathDelim + 'stop.png');
setGlyphSpeedButton(sbtnVideoPause, Application.Location + 'icons' + PathDelim + 'pause.png');
setGlyphSpeedButton(sbtnVideoPlay, Application.Location + 'icons' + PathDelim + 'play.png');
setFullyDisplay(True);
end;
end;
procedure TfMain.openScenario(const ScenarioFilePath: String);
var i: Integer;
bbtnBond: TBitBtn;
begin
try
if ScenarioList.Items[TabControl.TabIndex].Bonds.Count <> 0 then
begin
for i := 0 to ScenarioList.Items[TabControl.TabIndex].Bonds.Count - 1 do
begin
if fMain.FindComponent('bbtnBondVideo' + IntToStr(ScenarioList.Items[TabControl.TabIndex].Bonds.arProvoking[i])) <> NIL then
begin
bbtnBond := (fMain.FindComponent('bbtnBondVideo' + IntToStr(ScenarioList.Items[TabControl.TabIndex].Bonds.arProvoking[i])) as TBitBtn);
FreeAndNil(bbtnBond);
end;
end;
end;
ScenarioList.Add(CScenario.Create);
ScenarioList.Items[TabControl.Tabs.Count].FilePath := ScenarioFilePath;
ScenarioList.Items[TabControl.Tabs.Count].Name := ExtractFileName(ScenarioFilePath);
TabControl.Tabs.Add(ScenarioList.Items[TabControl.Tabs.Count].Name);
TabControl.TabIndex := TabControl.Tabs.Count-1;
LoadScenarioFromJSON(ScenarioFilePath);
if fMain.CanFocus then
fMain.SetFocus;
except
on E: Exception do begin
if ScenarioList.Count > 1 then
begin
FreeAndNil(ScenarioList.Items[ScenarioList.Count-1].AudioFileNames);
FreeAndNil(ScenarioList.Items[ScenarioList.Count-1].AudioFilePaths);
FreeAndNil(ScenarioList.Items[ScenarioList.Count-1].VideoFileNames);
FreeAndNil(ScenarioList.Items[ScenarioList.Count-1].VideoFilePaths);
FreeAndNil(ScenarioList.Items[ScenarioList.Count-1].MissingFiles);
if ScenarioList.Items[ScenarioList.Count-1].Bonds.Count <> 0 then
begin
for i := 0 to ScenarioList.Items[ScenarioList.Count-1].Bonds.Count - 1 do
begin
if fMain.FindComponent('bbtnBondVideo' + IntToStr(ScenarioList.Items[TabControl.TabIndex].Bonds.arProvoking[i])) <> NIL then
begin
bbtnBond := (fMain.FindComponent('bbtnBondVideo' + IntToStr(ScenarioList.Items[TabControl.TabIndex].Bonds.arProvoking[i])) as TBitBtn);
FreeAndNil(bbtnBond);
end;
end;
end;
FreeAndNil(ScenarioList.Items[TabControl.TabIndex].Bonds);
end;
ScenarioList.Remove(ScenarioList.Items[TabControl.TabIndex]);
TabControl.Tabs.Delete(TabControl.TabIndex);
ShowMessage(ScenarioFilePath + ' не является файлом сценария!');
end;
end;
end;
procedure TfMain.clboxVideoPlaylistDblClick(Sender: TObject);
begin
with fPlaybackVideo do
begin
if (fPlaybackVideo.videoPlayer = nil) then Exit;
if (clboxVideoPlaylist.Count = 0) then Exit;
if ScenarioList.Items[TabControl.TabIndex].MissingFiles.IndexOf(ScenarioList.Items[TabControl.TabIndex].VideoFilePaths.Strings[clboxVideoPlaylist.ItemIndex]) <> -1 then
begin
ShowMessage('Файл по пути ' + ScenarioList.Items[TabControl.TabIndex].VideoFilePaths.Strings[clboxVideoPlaylist.ItemIndex] + ' отсутствует.');
Exit;
end;
if LinkPlaybackControlButtons = True then
sbtnAudioLinkControlButtonsClick(fMain);
if LinkPlaybackControlTrackBar = True then
sbtnAudioLinkControlTrackBarClick(fMain);
glCurrentPlaylist := ScenarioList.Items[TabControl.TabIndex];
OpenAndPlayVideo(clboxVideoPlaylist.ItemIndex);
end;
end;
procedure TfMain.clboxVideoPlaylistDragDrop(Sender, Source: TObject; X,
Y: Integer);
var clbox : TCheckListBox;
oldIndex, newIndex, i: Integer;
begin
if clboxVideoPlaylist.Count = 0 then
Exit;
clbox := TCheckListBox(Sender);
newIndex := clbox.GetIndexAtXY(X, Y);
oldIndex := clboxVideoPlaylist.ItemIndex;
if newIndex = -1 then // Если перенесли на пустое место
newIndex := clboxVideoPlaylist.Count-1;
if newIndex = oldIndex then Exit; // Проверка на смену позиции
if (Sender <> Source) then Exit;
clboxAudioPlaylist.Items.BeginUpdate;
clboxVideoPlaylist.Items.Move(oldIndex, newIndex); // Передвигаем крайние
ScenarioList.Items[TabControl.TabIndex].VideoFileNames.Move(oldIndex, newIndex);
ScenarioList.Items[TabControl.TabIndex].VideoFilePaths.Move(oldIndex, newIndex);
if oldIndex > newIndex then
begin
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereInvoking(oldIndex, -1);
for i := oldIndex-1 downto newIndex do
begin
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereInvoking(i, i+1);
end;
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereInvoking(-1, newIndex);
if oldIndex = glCurrentAudioItemIndex then
glCurrentAudioItemIndex := newIndex;
end
else
begin
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereInvoking(oldIndex, -1);
for i := oldIndex+1 to newIndex do
begin
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereInvoking(i, i-1);
end;
ScenarioList.Items[TabControl.TabIndex].Bonds.UpdateWhereInvoking(-1, newIndex);
if oldIndex = glCurrentAudioItemIndex then
glCurrentAudioItemIndex := newIndex;
end;
clboxAudioPlaylist.Items.EndUpdate;
clboxAudioPlaylist.Repaint;
clboxVideoPlaylist.ItemIndex := newIndex;
clboxVideoPlaylist.ClearSelection;
clboxVideoPlaylist.Selected[newIndex] := True;
end;
procedure TfMain.clboxVideoPlaylistDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
if clboxVideoPlaylist.Count > 0 then
Accept := True;
end;
procedure TfMain.clboxVideoPlaylistItemClick(Sender: TObject; Index: integer);
begin
clboxVideoPlaylist.Invalidate;
end;
procedure TfMain.clboxVideoPlaylistKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
clboxVideoPlaylist.Invalidate;
end;
procedure TfMain.clboxVideoPlaylistMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
clboxVideoPlaylist.Invalidate;
end;
procedure TfMain.clboxVideoPlaylistMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if glVideoTrackRewinding = True then
trbarVideoTimeMouseLeave(Sender);
end;
procedure TfMain.FormDestroy(Sender: TObject);
var i: Integer;
bbtnBond: TBitBtn;
begin
if ScenarioList.Items[TabControl.TabIndex].Bonds.Count <> 0 then
begin
for i := 0 to ScenarioList.Items[TabControl.TabIndex].Bonds.Count - 1 do
begin
if fMain.FindComponent('bbtnBondVideo' + IntToStr(ScenarioList.Items[TabControl.TabIndex].Bonds.arProvoking[i])) <> NIL then
begin
bbtnBond := (fMain.FindComponent('bbtnBondVideo' + IntToStr(ScenarioList.Items[TabControl.TabIndex].Bonds.arProvoking[i])) as TBitBtn);
FreeAndNil(bbtnBond);
end;
end;
end;
FreeAndNil(ScenarioList);
end;
procedure TfMain.AddBond(Sender: TObject);
var bbtnFindedVideoBond: TBitBtn;
begin
if clboxAudioPlaylist.ItemIndex = -1 then
begin
ShowMessage('Аудио не выбрано.');
Exit;
end;
if clboxVideoPlaylist.ItemIndex = -1 then
begin
ShowMessage('Видео не выбрано.');
Exit;
end;
if ScenarioList.Items[TabControl.TabIndex].Bonds.InProvoking(clboxAudioPlaylist.ItemIndex) then
begin
ScenarioList.Items[TabControl.TabIndex].Bonds.DeleteWhereProvoking(clboxAudioPlaylist.ItemIndex);
end;
ScenarioList.Items[TabControl.TabIndex].Bonds.Add(clboxAudioPlaylist.ItemIndex, clboxVideoPlaylist.ItemIndex);
if fMain.FindComponent('bbtnBondVideo' + IntToStr(clboxAudioPlaylist.ItemIndex)) <> NIL then
begin
bbtnFindedVideoBond := (fMain.FindComponent('bbtnBondVideo' + IntToStr(clboxAudioPlaylist.ItemIndex)) as TBitBtn);
bbtnFindedVideoBond.Caption := IntToStr(ScenarioList.Items[TabControl.TabIndex].Bonds.arInvoking[ScenarioList.Items[TabControl.TabIndex].Bonds.IndexOfProvoking(clboxAudioPlaylist.ItemIndex)]);
end;
clboxAudioPlaylist.Repaint;
end;
procedure TfMain.FormDropFiles(Sender: TObject; const FileNames: array of string
);
const mrAudio = 21;
mrVideo = 22;
mrSkeep = 23;
mrSkeepAll = 24;
var i: Word;
SkeepAll: Boolean = False;
begin
for i := 0 to Length(FileNames)-1 do
begin
case identifyFileType(FileNames[i]) of
ftAudio:
begin
ScenarioList.Items[TabControl.TabIndex].AudioFilePaths.Add(FileNames[i]);
ScenarioList.Items[TabControl.TabIndex].AudioFileNames.Add(ExtractFileName(FileNames[i]));
end;
ftVideo, ftImage:
begin
ScenarioList.Items[TabControl.TabIndex].VideoFilePaths.Add(FileNames[i]);
ScenarioList.Items[TabControl.TabIndex].VideoFileNames.Add(ExtractFileName(FileNames[i]));
end;
ftUnknown:
begin
if Not(SkeepAll) then
case QuestionDlg('Неизвестный тип файла', 'Тип ' + ExtractFileExt(FileNames[i]) + ' файла ' + ExtractFileName(FileNames[i]) + ' неизвестен. Как воспринимать файл?', mtCustom, [mrAudio, 'Аудио', mrVideo, 'Видео', mrSkeep, 'Пропустить', mrSkeepAll, 'Пропустить все'], '') of
mrAudio:
begin
ScenarioList.Items[TabControl.TabIndex].AudioFilePaths.Add(FileNames[i]);
ScenarioList.Items[TabControl.TabIndex].AudioFileNames.Add(ExtractFileName(FileNames[i]));
end;
mrVideo:
begin
ScenarioList.Items[TabControl.TabIndex].VideoFilePaths.Add(FileNames[i]);
ScenarioList.Items[TabControl.TabIndex].VideoFileNames.Add(ExtractFileName(FileNames[i]));
end;
mrSkeepAll:
SkeepAll := True;
end;
end;
end;
end;
clboxAudioPlaylist.Items := ScenarioList.Items[TabControl.TabIndex].AudioFileNames;
clboxVideoPlaylist.Items := ScenarioList.Items[TabControl.TabIndex].VideoFileNames;
end;
procedure TfMain.FormResize(Sender: TObject);
procedure setRowView;
begin
panAudio.Anchors := [];
panAudio.Visible := False;
panVideo.Anchors := [];
panVideo.Visible := False;
Splitter.Anchors := [];
Splitter.AnchorToNeighbour(akTop, 0, TabControl);
Splitter.AnchorParallel(akBottom, 0, fMain);
Splitter.ResizeAnchor := akLeft;
Splitter.Width := 5;
Splitter.SetSplitterPosition(fMain.Width div 2 - Splitter.Width div 2);
panAudio.AnchorToNeighbour(akTop, 0, TabControl);
panAudio.AnchorParallel(akLeft, 0, fMain);
panAudio.AnchorParallel(akBottom, 0, fMain);
panAudio.AnchorToNeighbour(akRight, 0, Splitter);
panAudio.Visible := True;
panVideo.AnchorToNeighbour(akTop, 0, TabControl);
panVideo.AnchorParallel(akRight, 0, fMain);
panVideo.AnchorParallel(akBottom, 0, fMain);
panVideo.AnchorToNeighbour(akLeft, 0, Splitter);
panVideo.Visible := True;
end;
procedure setColumnView;
begin
panAudio.Anchors := [];
panAudio.Visible := False;
panVideo.Anchors := [];
panVideo.Visible := False;
Splitter.Anchors := [];
Splitter.AnchorParallel(akLeft, 0, fMain);
Splitter.AnchorParallel(akRight, 0, fMain);
Splitter.ResizeAnchor := akTop;
Splitter.Height := 5;
Splitter.SetSplitterPosition((fMain.Height div 2 - Splitter.Height div 2) + TabControl.Height);
panAudio.AnchorToNeighbour(akTop, 0, TabControl);
panAudio.AnchorParallel(akLeft, 0, fMain);
panAudio.AnchorToNeighbour(akBottom, 0, Splitter);
panAudio.AnchorParallel(akRight, 0, fMain);
panAudio.Visible := True;
panVideo.AnchorToNeighbour(akTop, 0, Splitter);
panVideo.AnchorParallel(akRight, 0, fMain);
panVideo.AnchorParallel(akBottom, 0, fMain);
panVideo.AnchorParallel(akLeft, 0, fMain);
panVideo.Visible := True;
end;
begin
if not(glAdaptivePanels) then
Exit;
if fSettings.radgrVisibleVariants.ItemIndex <> 2 then
exit;
if (fMain.Height / fMain.Width) >= 1 then
begin
setColumnView;
end
else
begin
setRowView;
end;
end;
procedure TfMain.miAudioDeleteBondClick(Sender: TObject);
var bbtnFindedVideoBond: TBitBtn;
begin
ScenarioList.Items[TabControl.TabIndex].Bonds.DeleteWhereProvoking(clboxAudioPlaylist.ItemIndex);
if fMain.FindComponent('bbtnBondVideo' + IntToStr(clboxAudioPlaylist.ItemIndex)) <> NIL then
begin
bbtnFindedVideoBond := (fMain.FindComponent('bbtnBondVideo' + IntToStr(clboxAudioPlaylist.ItemIndex)) as TBitBtn);
FreeAndNil(bbtnFindedVideoBond);
end;
clboxAudioPlaylist.Repaint;
end;
procedure TfMain.miAudioDeleteClick(Sender: TObject);
begin
miAudioDeleteBondClick(Self);
sbtnAudioSubtract.Click;
end;
procedure TfMain.miAudioSettingsClick(Sender: TObject);
var AudioExtensions: String = '';
i: Integer;
begin
FileSettings.fFileSettings.edtOldFilePath.Text := ScenarioList.Items[TabControl.TabIndex].AudioFilePaths.Strings[clboxAudioPlaylist.ItemIndex];
for i := Low(Pocket.arrAudioExtensions) to High(Pocket.arrAudioExtensions) do
AudioExtensions := AudioExtensions + '*' + arrAudioExtensions[i] + ';';
FileSettings.fFileSettings.OpenDialog.Filter := 'Audio|' + AudioExtensions + '|All files|*.*';
FileSettings.fFileSettings.ShowModal;
end;
procedure TfMain.miCloseTabClick(Sender: TObject);
var Scenario: CScenario;
i, choose_index: Integer;
bbtnBond: TBitBtn;
begin
if Popuped_TabControl then
begin
choose_index := TabControl.IndexOfTabAt(MousePos_TabControl.X, MousePos_TabControl.Y);
if choose_index = -1 then
choose_index := TabControl.TabIndex;
Popuped_TabControl := False;
end
else
choose_index := TabControl.TabIndex;
Scenario := ScenarioList.Extract(ScenarioList.Items[choose_index]);
TabControl.Tabs.Delete(choose_index);
FreeAndNil(Scenario.AudioFileNames);
FreeAndNil(Scenario.AudioFilePaths);
FreeAndNil(Scenario.VideoFileNames);
FreeAndNil(Scenario.VideoFilePaths);
if Scenario.Bonds.Count <> 0 then
begin
for i := 0 to Scenario.Bonds.Count - 1 do
begin
if fMain.FindComponent('bbtnBondVideo' + IntToStr(Scenario.Bonds.arProvoking[i])) <> NIL then
begin
bbtnBond := (fMain.FindComponent('bbtnBondVideo' + IntToStr(Scenario.Bonds.arProvoking[i])) as TBitBtn);
FreeAndNil(bbtnBond);
end;
end;
end;
FreeAndNil(Scenario.Bonds);
FreeAndNil(Scenario);
clboxAudioPlaylist.Clear;
clboxVideoPlaylist.Clear;
clboxAudioPlaylist.Items := ScenarioList.Items[TabControl.TabIndex].AudioFileNames;
clboxVideoPlaylist.Items := ScenarioList.Items[TabControl.TabIndex].VideoFileNames;
end;
procedure TfMain.miScenarioReloadClick(Sender: TObject);
var i, AudioItemIndex, VideoItemIndex: Integer;
LBitBtn: TBitBtn;
begin
if ScenarioList.Items[TabControl.TabIndex].FilePath = '' then
begin
ScenarioList.Items[TabControl.TabIndex].MissingFiles.Clear;
for i := 0 to clboxAudioPlaylist.Count-1 do
if Not(FileExists(ScenarioList.Items[TabControl.TabIndex].AudioFilePaths.Strings[i])) then
begin
ScenarioList.Items[TabControl.TabIndex].MissingFiles.Add(ScenarioList.Items[TabControl.TabIndex].AudioFilePaths.Strings[i]);
ShowMessage(ScenarioList.Items[TabControl.TabIndex].AudioFilePaths.Strings[i]);
end;
for i := 0 to clboxVideoPlaylist.Count-1 do
if Not(FileExists(ScenarioList.Items[TabControl.TabIndex].VideoFilePaths.Strings[i])) then
ScenarioList.Items[TabControl.TabIndex].MissingFiles.Add(ScenarioList.Items[TabControl.TabIndex].VideoFilePaths.Strings[i]);
clboxAudioPlaylist.Repaint;
clboxVideoPlaylist.Repaint;
StateNotify.State := snReload;
end
else
begin
for i:= 0 to ScenarioList.Items[TabControl.TabIndex].Bonds.Count - 1 do
begin
if fMain.FindComponent('bbtnBondVideo' + IntToStr(ScenarioList.Items[TabControl.TabIndex].Bonds.arProvoking[i])) <> NIL then
begin
LBitBtn := (fMain.FindComponent('bbtnBondVideo' + IntToStr(ScenarioList.Items[TabControl.TabIndex].Bonds.arProvoking[i])) as TBitBtn);
FreeAndNil(LBitBtn);
end;
end;
AudioItemIndex := clboxAudioPlaylist.ItemIndex;
VideoItemIndex := clboxVideoPlaylist.ItemIndex;