-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.pas
2962 lines (2701 loc) · 95.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
unit Main;
{$mode objfpc}{$H+}
{____________________________________________________________
| _______________________________________________________ |
| | | |
| | Remote Tool for Frontier Silicon based devices | |
| | (c) 2019 Alexander Feuster (alexander.feuster@web.de) | |
| | https://www.github.com/feuster | |
| |_______________________________________________________| |
|___________________________________________________________}
//define program basics
interface
uses
Classes, SysUtils, FileUtil, Interfaces, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls, ComCtrls, FrontierSiliconAPI,
fphttpclient, IniFiles, StrUtils, SplashScreen, PIN, Name;
type
{ TMainForm }
TMainForm = class(TForm)
ControlFrequencyPanel: TPanel;
ControlDABPanel: TPanel;
EqualizerPanel: TPanel;
EqualizerGroupBox: TGroupBox;
EqualizerTrackBar2: TTrackBar;
ManualEqualizerSettingImage1: TImage;
ManualEqualizerSettingImage2: TImage;
ManualEqualizerSettingLabel4: TLabel;
ManualEqualizerSettingLabel3: TLabel;
ManualEqualizerSettingLabel1: TLabel;
ManualEqualizerSettingLabel2: TLabel;
ManualEqualizerSettingLabel5: TLabel;
ManualEqualizerSettingLabel6: TLabel;
ManualEqualizerSettingLabel7: TLabel;
ManualEqualizerSettingLabel8: TLabel;
PresetAddButton10: TSpeedButton;
PresetAddButton2: TSpeedButton;
PresetAddButton3: TSpeedButton;
PresetAddButton4: TSpeedButton;
PresetAddButton5: TSpeedButton;
PresetAddButton6: TSpeedButton;
PresetAddButton7: TSpeedButton;
PresetAddButton8: TSpeedButton;
PresetAddButton9: TSpeedButton;
PresetNameLabel1: TLabel;
PresetNameLabel10: TLabel;
PresetNameLabel2: TLabel;
PresetNameLabel3: TLabel;
PresetNameLabel4: TLabel;
PresetNameLabel5: TLabel;
PresetNameLabel6: TLabel;
PresetNameLabel7: TLabel;
PresetNameLabel8: TLabel;
PresetNameLabel9: TLabel;
PresetPlayButton10: TSpeedButton;
PresetPlayButton2: TSpeedButton;
PresetPlayButton3: TSpeedButton;
PresetPlayButton4: TSpeedButton;
PresetPlayButton5: TSpeedButton;
PresetPlayButton6: TSpeedButton;
PresetPlayButton7: TSpeedButton;
PresetPlayButton8: TSpeedButton;
PresetPlayButton9: TSpeedButton;
EqualizerRadioGroup: TRadioGroup;
SetPresetPanel: TPanel;
RadioPanel: TPanel;
HighFreqLabel: TLabel;
MidFreqLabel: TLabel;
LowFreqLabel: TLabel;
SleepTimerStateIdleTimer: TIdleTimer;
SleepTimerComboBox: TComboBox;
ControlButtonsPanel1: TPanel;
ControlButtonsPanel2: TPanel;
DebugTimer: TTimer;
IdleTimer: TIdleTimer;
ModeImageList: TImageList;
PlayInfoText: TLabel;
PlayInfoArtist: TLabel;
PlayInfoName: TLabel;
CoverImage: TImage;
NotifyMemo: TMemo;
NavigationListView: TListView;
NavigationTabSheet: TTabSheet;
NavigationPanel: TPanel;
DebugPanel: TPanel;
NotifyTimer: TTimer;
ControlVolumePanel: TPanel;
PlayInfoPanel: TPanel;
PlayButton: TSpeedButton;
PauseButton: TSpeedButton;
PreviousButton: TSpeedButton;
NextButton: TSpeedButton;
PlayPauseButton: TSpeedButton;
PresetsRadioGroup: TRadioGroup;
RadioTabSheet: TTabSheet;
FreqMinusButton: TSpeedButton;
FreqPlusButton: TSpeedButton;
Frequency: TTrackBar;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
PresetPlayButton1: TSpeedButton;
PresetAddButton1: TSpeedButton;
EqualizerTabSheet: TTabSheet;
EqualizerTrackBar1: TTrackBar;
VolumeBarImage: TImage;
VolPlusButton: TSpeedButton;
VolMinusButton: TSpeedButton;
Button1: TButton;
DeviceImage: TImage;
DeviceImageList: TImageList;
DeviceListRefreshButton: TSpeedButton;
DeviceOffImage: TImage;
DeviceListView: TListView;
DeviceBigImageList: TImageList;
DeviceOnImage: TImage;
DeviceMuteImage: TImage;
DeviceMuteOffImage: TImage;
LabelDeviceNameID: TLabel;
LabelDeviceIP: TLabel;
LabelDeviceNetwork: TLabel;
LabelDevicePIN: TLabel;
LabelDeviceSoftware: TLabel;
LogMemo: TMemo;
PageControl1: TPageControl;
DeviceListPanel: TPanel;
DeviceInfoPanel: TPanel;
PageControlPanel: TPanel;
ControlPanel: TPanel;
ModesRadioGroup: TRadioGroup;
ControlMainControlsPanel: TPanel;
StandbyButton: TSpeedButton;
MutingButton: TSpeedButton;
DebugTabSheet: TTabSheet;
ControlTabSheet: TTabSheet;
DeviceListTabSheet: TTabSheet;
Volume: TTrackBar;
ScaleImage: TImage;
procedure ControlButtonsPanel2Resize(Sender: TObject);
procedure ControlFrequencyPanelResize(Sender: TObject);
procedure DeviceMuteImageClick(Sender: TObject);
procedure DeviceMuteOffImageClick(Sender: TObject);
procedure DeviceOffImageClick(Sender: TObject);
procedure DeviceOnImageClick(Sender: TObject);
procedure DeviceListViewDblClick(Sender: TObject);
procedure DeviceListViewResize(Sender: TObject);
procedure EqualizerGroupBoxResize(Sender: TObject);
procedure EqualizerPanelResize(Sender: TObject);
procedure EqualizerRadioGroupSelectionChanged(Sender: TObject);
procedure EqualizerTrackBar1Change(Sender: TObject);
procedure EqualizerTrackBar1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure EqualizerTrackBar2Change(Sender: TObject);
procedure EqualizerTrackBar2MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure PresetAddButton10Click(Sender: TObject);
procedure PresetAddButton1Click(Sender: TObject);
procedure PresetAddButton2Click(Sender: TObject);
procedure PresetAddButton3Click(Sender: TObject);
procedure PresetAddButton4Click(Sender: TObject);
procedure PresetAddButton5Click(Sender: TObject);
procedure PresetAddButton6Click(Sender: TObject);
procedure PresetAddButton7Click(Sender: TObject);
procedure PresetAddButton8Click(Sender: TObject);
procedure PresetAddButton9Click(Sender: TObject);
procedure PresetPlayButton10Click(Sender: TObject);
procedure PresetPlayButton1Click(Sender: TObject);
procedure PresetPlayButton2Click(Sender: TObject);
procedure PresetPlayButton3Click(Sender: TObject);
procedure PresetPlayButton4Click(Sender: TObject);
procedure PresetPlayButton5Click(Sender: TObject);
procedure PresetPlayButton6Click(Sender: TObject);
procedure PresetPlayButton7Click(Sender: TObject);
procedure PresetPlayButton8Click(Sender: TObject);
procedure PresetPlayButton9Click(Sender: TObject);
procedure RadioPanelResize(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FreqMinusButtonClick(Sender: TObject);
procedure FreqPlusButtonClick(Sender: TObject);
procedure FrequencyMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure IdleTimerTimer(Sender: TObject);
procedure LabelDeviceNameIDClick(Sender: TObject);
procedure LabelDeviceNameIDMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure LabelDevicePINClick(Sender: TObject);
procedure LabelDevicePINMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure LabelDeviceSoftwareClick(Sender: TObject);
procedure LabelDeviceSoftwareMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure LogMemoChange(Sender: TObject);
procedure ModesRadioGroupSelectionChanged(Sender: TObject);
procedure NavigationListViewClick(Sender: TObject);
procedure NavigationListViewResize(Sender: TObject);
procedure NotifyMemoChange(Sender: TObject);
procedure DeviceListPanelResize(Sender: TObject);
procedure DeviceInfoPanelResize(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure PageControlPanelResize(Sender: TObject);
procedure ControlPanelResize(Sender: TObject);
procedure ControlMainControlsPanelResize(Sender: TObject);
procedure NavigationPanelResize(Sender: TObject);
procedure DebugPanelResize(Sender: TObject);
procedure PauseButtonClick(Sender: TObject);
procedure PlayButtonClick(Sender: TObject);
procedure PlayInfoPanelResize(Sender: TObject);
procedure PlayPauseButtonClick(Sender: TObject);
procedure PresetsRadioGroupSelectionChanged(Sender: TObject);
procedure PreviousButtonClick(Sender: TObject);
procedure NextButtonClick(Sender: TObject);
procedure SetPresetPanelResize(Sender: TObject);
procedure SleepTimerComboBoxSelect(Sender: TObject);
procedure SleepTimerStateIdleTimerTimer(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure StandbyButtonClick(Sender: TObject);
procedure MutingButtonClick(Sender: TObject);
procedure DebugTimerTimer(Sender: TObject);
procedure NotifyTimerTimer(Sender: TObject);
procedure Lock_Controls;
procedure Unlock_Controls;
procedure CoverImage_Clear;
procedure CoverImage_Load(URL: String);
procedure CoverImage_Show;
procedure Presets_Reset;
procedure Preset_Selected_Update;
procedure Preset_Play(PresetIndex: Integer);
procedure Preset_Add(PresetID: Integer);
procedure Preset_Labels;
procedure ActualDevice_Reset;
procedure DeviceList_Reset;
function DeviceList_Update: Boolean;
function DeviceList_Show: Boolean;
procedure DeviceList_Save;
procedure Device_NetworkStatus;
procedure Device_Selected;
procedure Device_Device_On(const Read_Standby_State: Boolean = true);
procedure Device_Sleeptimer_Time;
procedure Device_Muting_On;
procedure Device_Presets;
procedure Device_Navigation;
procedure Device_PlayInfo;
procedure Device_PlayInfoClear;
procedure Ini_Write;
procedure Ini_Write_Value(Section: String; Ident: String; Value: String);
function Ini_Read_Value(Section: String; Ident: String): String;
procedure DeviceListRefreshButtonClick(Sender: TObject);
procedure VolMinusButtonClick(Sender: TObject);
procedure VolPlusButtonClick(Sender: TObject);
procedure FirstStartSplashscreen;
{$IFDEF PROG_DEBUG}
procedure Log(AddText: String);
{$ENDIF}
procedure VolumeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ControlVolumePanelResize(Sender: TObject);
private
procedure OnExcept(Sender: TObject; E: Exception);
public
end;
type
TNotifyThread = class(TThread)
private
fNotifies: TStringList;
protected
procedure Execute; override;
public
Constructor Create(CreateSuspended : boolean);
procedure GetNotifies;
end;
type
TEqualizer = record
EqualizerList: TStringList;
CustomEqualizer: TStringList;
ActiveEqualizer: Integer;
end;
type
TDevice = record
IP: String;
Name: String;
ID: String;
IconUrl: String;
Icon: TBitmap;
PIN: String;
Device_On: Boolean;
Muting_On: Boolean;
Modes: TStringList;
Mode: Integer;
ModeID: String;
FM_Min: Integer;
FM_Max: Integer;
FM_Steps: Integer;
Equalizer: TEqualizer;
end;
type
TPreset = record
ID: String;
Name: String;
end;
var
MainForm: TMainForm;
ActualDevice: TDevice;
DeviceList: array [0..63] of TDevice;
Presets: array [0..31] of TPreset;
FirstStart: Boolean = true;
NotifyThread: TNotifyThread;
NotifyEnabled: Boolean;
PresetLocked: Boolean;
ModeLocked: Boolean;
SleepTimerLocked: Boolean;
EqualizerLocked: Boolean;
PlayImageFile: String;
const
PINs: array [0..3] of String = ('1234', '1111', '0000', '1337');
STR_Date: String = {$I %DATE%};
{ Simple Encryption Routine:
Number = Index CryptKey for e.g. Index "3" with CryptKey1 = "1"
Simple Decryption Routine:
Number = Index DecryptKey for e.g. crypted Index "1" with DecryptKey1 = "3"
Keychange:
To obfusicate PINs with the same single number for e.g. "1111" the key is alternating between key 1 and 2
Key pair 1 Key pair 2
Crypt Key: 3 7 9 1 8 2 4 5 0 6 8 9 3 7 2 4 1 0 6 5
Decrypt Key: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 }
PINCryptKey1: array [0..9] of String = ( '3', '7', '9', '1', '8', '2', '4', '5', '0', '6');
PINDecryptKey1: array [0..9] of String = ( '8', '3', '5', '0', '6', '7', '9', '1', '4', '2');
PINCryptKey2: array [0..9] of String = ( '8', '9', '3', '7', '2', '4', '1', '0', '6', '5');
PINDecryptKey2: array [0..9] of String = ( '7', '6', '4', '2', '5', '9', '8', '3', '0', '1');
implementation
{$R *.lfm}
{ TMainForm }
{$IFDEF PROG_DEBUG}
procedure TMainForm.Log(AddText: String);
//Debug log
begin
LogMemo.Append(AddText);
end;
{$ENDIF}
procedure TMainForm.OnExcept(Sender: TObject; E: Exception);
//own Exception handler
begin
{$IFDEF PROG_DEBUG}
if E<>NIL then
begin
Log(Sender.UnitName+' -> '+Sender.ToString+' -> '+E.Message);
ShowMessage(Sender.UnitName+' -> '+Sender.ToString+' -> '+E.Message);
end;
{$ELSE}
if E<>NIL then
ShowMessage(Sender.UnitName+' -> '+Sender.ToString+' -> '+E.Message);
{$ENDIF}
if E<>NIL then
E.Free;
end;
constructor TNotifyThread.Create(CreateSuspended : boolean);
//create Notify thread
begin
inherited Create(CreateSuspended); // because this is black box in OOP and can reset inherited to the opposite again...
FreeOnTerminate := True; // better code...
end;
procedure TNotifyThread.GetNotifies;
//read notifies
begin
if fNotifies<>NIL then
MainForm.NotifyMemo.Lines.AddStrings(fNotifies);
end;
procedure TNotifyThread.Execute;
//run Notify thread
begin
if NotifyEnabled=false then
exit;
if fNotifies=NIL then
begin
fNotifies:=TStringList.Create;
fNotifies.Clear;
end;
while (not Terminated) do
begin
//read notifies from device
try
if (ActualDevice.IP<>'') and (ActualDevice.PIN<>'') then
try
fNotifies:=fsapi_Info_GetNotifies(ActualDevice.IP,ActualDevice.PIN);
except
fNotifies.Clear;
end;
finally
if fNotifies.Count>0 then
begin
try
Synchronize(@GetNotifies);
finally
fNotifies.Clear;
end;
end;
end;
end;
end;
function CryptPIN(PIN: String): String;
//Simple Crypt PIN
var
Index: Integer;
begin
Result:='';
for Index:=1 to Length(PIN) do
begin
if Index MOD 2 = 0 then
Result:=Result+PINCryptKey1[StrToInt(PIN[INDEX])]
else
Result:=Result+PINCryptKey2[StrToInt(PIN[INDEX])];
end;
end;
function DeCryptPIN(PIN: String): String;
//Simple Decrypt PIN
var
Index: Integer;
begin
Result:='';
for Index:=1 to Length(PIN) do
begin
if Index MOD 2 = 0 then
Result:=Result+PINDecryptKey1[StrToInt(PIN[INDEX])]
else
Result:=Result+PINDecryptKey2[StrToInt(PIN[INDEX])];
end;
end;
function DoSplit(Data: String; Index: Byte): String;
//Split data fields
var
Buffer: TStringList;
begin
//extract field from data
Buffer:=TStringList.Create;
Buffer.StrictDelimiter:=true;
Buffer.Delimiter:='|';
Buffer.DelimitedText:=Data;
if Index<Buffer.Count then
Result:=Buffer[Index]
else
Result:='';
if Buffer<>NIL then
Buffer.Free;
end;
procedure TMainForm.CoverImage_Clear;
//clear content image
begin
CoverImage.Picture.Clear;
if ActualDevice.Device_On=false then
exit;
//Default pictures
if UpperCase(ActualDevice.ModeID)='DAB' then
begin
ModeImageList.GetBitmap(1,CoverImage.Picture.Bitmap);
PlayImageFile:='DAB';
end
else if UpperCase(ActualDevice.ModeID)='FM' then
begin
ModeImageList.GetBitmap(2,CoverImage.Picture.Bitmap);
PlayImageFile:='FM';
end
else if UpperCase(ActualDevice.ModeID)='IR' then
begin
ModeImageList.GetBitmap(3,CoverImage.Picture.Bitmap);
PlayImageFile:='IR';
end
else if UpperCase(ActualDevice.ModeID)='MP' then
begin
ModeImageList.GetBitmap(4,CoverImage.Picture.Bitmap);
PlayImageFile:='MP';
end
else if UpperCase(ActualDevice.ModeID)='AUXIN' then
begin
ModeImageList.GetBitmap(5,CoverImage.Picture.Bitmap);
PlayImageFile:='AUXIN';
end
else if UpperCase(ActualDevice.ModeID)='DMR' then
begin
ModeImageList.GetBitmap(6,CoverImage.Picture.Bitmap);
PlayImageFile:='DMR';
end
else if UpperCase(ActualDevice.ModeID)='SPOTIFY' then
begin
ModeImageList.GetBitmap(7,CoverImage.Picture.Bitmap);
PlayImageFile:='SPOTIFY';
end
else if UpperCase(ActualDevice.ModeID)='BLUETOOTH' then
begin
ModeImageList.GetBitmap(8,CoverImage.Picture.Bitmap);
PlayImageFile:='BLUETOOTH';
end
else if UpperCase(ActualDevice.ModeID)='AIRABLE_TIDAL' then
begin
ModeImageList.GetBitmap(9,CoverImage.Picture.Bitmap);
PlayImageFile:='TIDAL';
end
else if UpperCase(ActualDevice.ModeID)='AIRABLE_NAPSTER' then
begin
ModeImageList.GetBitmap(10,CoverImage.Picture.Bitmap);
PlayImageFile:='NAPSTER';
end
else if UpperCase(ActualDevice.ModeID)='AIRABLE_DEEZER' then
begin
ModeImageList.GetBitmap(11,CoverImage.Picture.Bitmap);
PlayImageFile:='DEEZER';
end
else if UpperCase(ActualDevice.ModeID)='AIRABLE_QOBUZ' then
begin
ModeImageList.GetBitmap(12,CoverImage.Picture.Bitmap);
PlayImageFile:='QOBUZ';
end
else if UpperCase(ActualDevice.ModeID)='CD' then
begin
ModeImageList.GetBitmap(13,CoverImage.Picture.Bitmap);
PlayImageFile:='CD';
end
else
begin
ModeImageList.GetBitmap(0,CoverImage.Picture.Bitmap);
PlayImageFile:='Default';
end;
{$IFDEF PROG_DEBUG}
if PlayImageFile<>'Default' then
Log('CoverImage_Clear -> '+PlayImageFile)
else
Log('CoverImage_Clear -> '+PlayImageFile+' for mode '+ActualDevice.ModeID);
{$ENDIF}
end;
procedure TMainForm.CoverImage_Load(URL: String);
//load content image
var
HTTPClient: TFPCustomHTTPClient;
GraphicStream: TMemoryStream;
begin
if (URL='') or (ActualDevice.Device_On=false) then
begin
CoverImage_Clear;
exit;
end;
HTTPClient:=TFPCustomHTTPClient.Create(NIL);
GraphicStream:=TMemoryStream.Create;
//download content graphic if available
try
HTTPClient.SimpleGet(URL,GraphicStream);
except
on E:Exception do
begin
GraphicStream.Clear;
end;
end;
if HTTPClient<>NIL then HTTPClient.Free;
if GraphicStream.Size>0 then
begin
GraphicStream.Position:=0;
CoverImage.Picture.Clear;
CoverImage.Picture.LoadFromStream(GraphicStream);
PlayImageFile:=URL;
{$IFDEF PROG_DEBUG}Log('CoverImage_Load -> '+PlayImageFile);{$ENDIF}
end
else
CoverImage_Clear;
end;
procedure TMainForm.CoverImage_Show;
//show content image
begin
if (ActualDevice.IP='') or (ActualDevice.PIN='') then
exit;
CoverImage_Load(fsapi_Info_graphicUri(ActualDevice.IP,ActualDevice.PIN));
end;
procedure TMainForm.VolumeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
//set volume
begin
if (ActualDevice.IP='') or (ActualDevice.PIN='') then
exit;
fsapi_Volume_Set(ActualDevice.IP,ActualDevice.PIN,Volume.Position);
end;
procedure TMainForm.ControlVolumePanelResize(Sender: TObject);
begin
VolMinusButton.Left:=0;
VolMinusButton.Top:=0;
VolMinusButton.Height:=ControlVolumePanel.ClientHeight;
VolMinusButton.Width:=VolMinusButton.Height;
VolPlusButton.Width:=VolMinusButton.Width;
VolPlusButton.Height:=VolMinusButton.Height;
VolPlusButton.Left:=ControlVolumePanel.ClientWidth-VolPlusButton.Width;
VolPlusButton.Top:=VolMinusButton.Top;
Volume.Left:=VolMinusButton.Width;
Volume.Top:=VolMinusButton.Top;
Volume.Width:=ControlVolumePanel.ClientWidth-VolMinusButton.Width-VolPlusButton.Width;
Volume.Height:=30;
VolumeBarImage.Left:=Volume.Left;
VolumeBarImage.Top:=Volume.Height+1;
VolumeBarImage.Width:=Volume.Width;
VolumeBarImage.Height:=ControlVolumePanel.ClientHeight-Volume.Height-2;
end;
procedure TMainForm.Device_Device_On(const Read_Standby_State: Boolean = true);
//check actual device standby state
begin
if (ActualDevice.IP='') or (ActualDevice.PIN='') then
exit;
if Read_Standby_State=true then
ActualDevice.Device_On:=fsapi_Standby_State(ActualDevice.IP,ActualDevice.PIN);
if ActualDevice.Device_On=true then
begin
DeviceOnImage.Visible:=true;
DeviceOffImage.Visible:=false;
SleepTimerComboBox.Visible:=true;
CoverImage_Show;
Device_PlayInfo;
EqualizerTabSheet.TabVisible:=true;
if (UpperCase(ActualDevice.ModeID)='FM') or (UpperCase(ActualDevice.ModeID)='DAB') then
RadioTabSheet.TabVisible:=true
else
RadioTabSheet.TabVisible:=false;
end
else
begin
DeviceOnImage.Visible:=false;
DeviceOffImage.Visible:=true;
SleepTimerComboBox.Visible:=false;
SleepTimerStateIdleTimer.Enabled:=false;
CoverImage_Clear;
Device_PlayInfoClear;
EqualizerTabSheet.TabVisible:=false;
RadioTabSheet.TabVisible:=false;
end;
end;
procedure TMainForm.Device_Sleeptimer_Time;
//check actual sleeptimer time until shutdown
var
TimeUntilShutdown: Integer;
begin
if (ActualDevice.IP='') or (ActualDevice.PIN='') then
exit;
SleepTimerLocked:=true;
TimeUntilShutdown:=fsapi_Sys_GetSleepTimer(ActualDevice.IP,ActualDevice.PIN);
{$IFDEF PROG_DEBUG}
if TimeUntilShutdown=1 then
Log('Sleeptimer -> '+IntToStr(TimeUntilShutdown)+' second left')
else if TimeUntilShutdown>1 then
Log('Sleeptimer -> '+IntToStr(TimeUntilShutdown)+' seconds left')
else
Log('Sleeptimer -> time until shutdown unknown');
{$ENDIF}
if (TimeUntilShutdown div 60>1) then
begin
SleepTimerComboBox.ItemIndex:=(TimeUntilShutdown div 60);
if SleepTimerStateIdleTimer.Enabled=false then
SleepTimerStateIdleTimer.Enabled:=true;
end
else if TimeUntilShutdown=0 then
begin
SleepTimerComboBox.ItemIndex:=0;
SleepTimerStateIdleTimer.Enabled:=false;
end
else
SleepTimerComboBox.ItemIndex:=1;
SleepTimerLocked:=false;
end;
procedure TMainForm.Device_Muting_On;
//check actual device muting state
begin
if (ActualDevice.IP='') or (ActualDevice.PIN='') then
exit;
ActualDevice.Muting_On:=fsapi_Mute_State(ActualDevice.IP,ActualDevice.PIN);
if ActualDevice.Muting_On=true then
begin
DeviceMuteImage.Visible:=true;
DeviceMuteOffImage.Visible:=false;
end
else
begin
DeviceMuteImage.Visible:=false;
DeviceMuteOffImage.Visible:=true;
end;
end;
procedure TMainForm.Device_Presets;
//check presets
var
PresetList: TStringList;
Preset: TStringList;
Index: Integer;
begin
if (ActualDevice.IP='') or (ActualDevice.PIN='') then
exit;
CoverImage_Clear;
Presets_Reset;
PresetsRadioGroup.Items.Clear;
Application.ProcessMessages;
sleep(250);
PresetList:=TStringList.Create;
Preset:=TStringList.Create;
PresetList:=fsapi_Presets_List(ActualDevice.IP,ActualDevice.PIN);
if PresetList.Text='' then
begin
PresetsRadioGroup.Visible:=false;
exit;
end;
for Index:=0 to PresetList.Count-1 do
begin
Preset.StrictDelimiter:=true;
Preset.Delimiter:='|';
Preset.DelimitedText:=PresetList.Strings[Index];
Presets[Index].Name:=Preset[1];
Presets[Index].ID:=Preset[0];
PresetsRadioGroup.Items.Add(Presets[Index].Name);
end;
if PresetsRadioGroup.Items.Count>0 then
begin
if PresetsRadioGroup.Items.Count<4 then
PresetsRadioGroup.ChildSizing.EnlargeVertical:=crsAnchorAligning
else
PresetsRadioGroup.ChildSizing.EnlargeVertical:=crsHomogenousChildResize;
PresetsRadioGroup.Visible:=true;
end
else
begin
PresetsRadioGroup.Visible:=false;
PresetsRadioGroup.Items.Clear;
end;
CoverImage_Show;
Device_PlayInfo;
if PresetList<>NIL then PresetList.Free;
if Preset<>NIL then Preset.Free;
end;
procedure TMainForm.Device_Navigation;
//check navigation
var
Item: TListItem;
NavItems: TStringList;
NavItem: TStringList;
Index: Integer;
begin
if (ActualDevice.IP='') or (ActualDevice.PIN='') then
exit;
NavigationListView.Items.Clear;
Application.ProcessMessages;
sleep(25);
NavItems:=TStringList.Create;
NavItem:=TStringList.Create;
NavItems:=fsapi_Nav_List(ActualDevice.IP,ActualDevice.PIN);
//create default root folder item
Item:=NavigationListView.Items.Add;
Item.Caption:='[Index]';
Item.SubItems.Add('-1');
Item.SubItems.Add('-1');
Item.SubItems.Add('-1');
//add device navigation items
for Index:=0 to NavItems.Count-1 do
begin
NavItem.StrictDelimiter:=true;
NavItem.Delimiter:='|';
NavItem.DelimitedText:=NavItems.Strings[Index];
Item:=NavigationListView.Items.Add;
Item.Caption:=Trim(NavItem[1]); //Name/Caption
Item.SubItems.Add(NavItem[0]); //Index
Item.SubItems.Add(NavItem[2]); //Type
Item.SubItems.Add(NavItem[3]); //SubType
end;
if NavItems<>NIL then NavItems.Free;
if NavItem<>NIL then NavItem.Free;
end;
procedure TMainForm.Device_PlayInfo;
//actualize play info
begin
if (ActualDevice.IP='') or (ActualDevice.PIN='') then
exit;
PlayInfoName.Caption:= fsapi_Info_Name(ActualDevice.IP,ActualDevice.PIN);
PlayInfoArtist.Caption:=fsapi_Info_Artist(ActualDevice.IP,ActualDevice.PIN);
PlayInfoText.Caption:= fsapi_Info_Text(ActualDevice.IP,ActualDevice.PIN);
end;
procedure TMainForm.Device_PlayInfoClear;
//clear play info
begin
if (ActualDevice.IP='') or (ActualDevice.PIN='') then
exit;
PlayInfoName.Caption:='';
PlayInfoArtist.Caption:='';
PlayInfoText.Caption:='';
end;
procedure TMainForm.DeviceInfoPanelResize(Sender: TObject);
//Resize controls on DeviceInfoPanel
var
Index: Integer;
Offset: Integer;
begin
DeviceImage.Top:=(DeviceInfoPanel.ClientHeight-DeviceImage.Height) div 2;
DeviceImage.Left:=DeviceImage.Top;
DeviceOnImage.Top:=DeviceImage.Top+DeviceImage.Height-DeviceOnImage.Height;
DeviceOnImage.Left:=DeviceImage.Left+DeviceImage.Width-DeviceOnImage.Width;
DeviceOffImage.Top:=DeviceOnImage.Top;
DeviceOffImage.Left:=DeviceOnImage.Left;
DeviceMuteImage.Top:=DeviceOnImage.Top;;
DeviceMuteImage.Left:=DeviceImage.Left;
DeviceMuteOffImage.Top:=DeviceOnImage.Top;;
DeviceMuteOffImage.Left:=DeviceImage.Left;
LabelDeviceNameID.Height:=(DeviceImage.Height-(4*2)) div 5;
Offset:=(DeviceInfoPanel.ClientHeight-(5*LabelDeviceNameID.Height)) div 6;
LabelDeviceNameID.Top:=Offset;
LabelDeviceNameID.Left:=DeviceImage.Width+(2*DeviceImage.Left);
LabelDeviceIP.Top:=LabelDeviceNameID.Top+LabelDeviceNameID.Height+Offset;
LabelDeviceIP.Left:=LabelDeviceNameID.Left;
LabelDevicePIN.Top:=LabelDeviceIP.Top+LabelDeviceIP.Height+Offset;
LabelDevicePIN.Left:=LabelDeviceIP.Left;
LabelDeviceNetwork.Top:=LabelDevicePIN.Top+LabelDevicePIN.Height+Offset;
LabelDeviceNetwork.Left:=LabelDeviceNameID.Left;
LabelDeviceSoftware.Top:=LabelDeviceNetwork.Top+LabelDeviceNetwork.Height+Offset;
LabelDeviceSoftware.Left:=LabelDeviceIP.Left;
CoverImage.Top:=DeviceImage.Top;
CoverImage.Width:=DeviceImage.Width;
CoverImage.Height:=DeviceImage.Height;
CoverImage.Left:=DeviceInfoPanel.ClientWidth-CoverImage.Top-CoverImage.Width;
for Index:=0 to DeviceInfoPanel.ControlCount-1 do
begin
if DeviceInfoPanel.Controls[Index].ClassName='TLabel' then
begin
DeviceInfoPanel.Controls[Index].Width:=DeviceInfoPanel.ClientWidth-(2*DeviceInfoPanel.BevelWidth)-DeviceInfoPanel.Controls[Index].Left;
DeviceInfoPanel.Controls[Index].Height:=LabelDeviceNameID.Height;
DeviceInfoPanel.Controls[Index].Font.Height:=DeviceInfoPanel.Controls[Index].Height-2;
end;
end;
end;
procedure TMainForm.PageControl1Change(Sender: TObject);
begin
if PageControl1.PageIndex=2 then
begin
Preset_Selected_Update;
Device_Sleeptimer_Time;
end;
if PageControl1.PageIndex=4 then
begin
if ActualDevice.Equalizer.CustomEqualizer.Count>0 then
begin
ManualEqualizerSettingLabel1.Caption:=DoSplit(ActualDevice.Equalizer.CustomEqualizer.Strings[0],1)+': ';
ManualEqualizerSettingLabel2.Caption:=DoSplit(ActualDevice.Equalizer.CustomEqualizer.Strings[0],0);
ManualEqualizerSettingLabel3.Caption:=DoSplit(ActualDevice.Equalizer.CustomEqualizer.Strings[0],2);
ManualEqualizerSettingLabel4.Caption:=DoSplit(ActualDevice.Equalizer.CustomEqualizer.Strings[0],3);
EqualizerTrackBar1.Position:=fsapi_Equalizer_CustomParam0_Get(ActualDevice.IP,ActualDevice.PIN);
ManualEqualizerSettingLabel2.Caption:=IntToStr(EqualizerTrackBar1.Position);
EqualizerTrackBar1.Min:=StrToInt(ManualEqualizerSettingLabel3.Caption);
EqualizerTrackBar1.Max:=StrToInt(ManualEqualizerSettingLabel4.Caption);
ManualEqualizerSettingLabel5.Caption:=DoSplit(ActualDevice.Equalizer.CustomEqualizer.Strings[1],1)+': ';
ManualEqualizerSettingLabel6.Caption:=DoSplit(ActualDevice.Equalizer.CustomEqualizer.Strings[1],0);
ManualEqualizerSettingLabel7.Caption:=DoSplit(ActualDevice.Equalizer.CustomEqualizer.Strings[1],2);
ManualEqualizerSettingLabel8.Caption:=DoSplit(ActualDevice.Equalizer.CustomEqualizer.Strings[1],3);
EqualizerTrackBar2.Position:=fsapi_Equalizer_CustomParam1_Get(ActualDevice.IP,ActualDevice.PIN);
ManualEqualizerSettingLabel6.Caption:=IntToStr(EqualizerTrackBar2.Position);
EqualizerTrackBar2.Min:=StrToInt(ManualEqualizerSettingLabel7.Caption);
EqualizerTrackBar2.Max:=StrToInt(ManualEqualizerSettingLabel8.Caption);
end;
if EqualizerRadioGroup.ItemIndex=0 then
begin
EqualizerTrackBar1.Enabled:=true;
EqualizerTrackBar2.Enabled:=true;
end
else
begin
EqualizerTrackBar1.Enabled:=false;
EqualizerTrackBar2.Enabled:=false;
end;
end;
if (ActualDevice.IP<>'') and (ActualDevice.PIN<>'') then
begin
if PageControl1.PageIndex=5 then
begin
fsapi_Nav_State(ActualDevice.IP,ActualDevice.PIN,true)
end
else
begin
fsapi_Nav_State(ActualDevice.IP,ActualDevice.PIN,false);
end;
end;
{$IFDEF PROG_DEBUG}
if PageControl1.PageIndex=0 then
LogMemo.SelStart:=Length(LogMemo.Lines.Text)+1;
{$ENDIF}
end;
procedure TMainForm.PageControlPanelResize(Sender: TObject);
begin
PageControl1.Top:=0;
PageControl1.Left:=0;
PageControl1.Width:=MainForm.ClientWidth;
PageControl1.Height:=MainForm.ClientHeight-DeviceInfoPanel.Height-PlayInfoPanel.Height;
end;
procedure TMainForm.ControlPanelResize(Sender: TObject);
begin
ModesRadioGroup.Left:=0;
ModesRadioGroup.Top:=0;
ModesRadioGroup.Width:=165;
ModesRadioGroup.Height:=ControlPanel.ClientHeight;
PresetsRadioGroup.Width:=Round(1.5*ModesRadioGroup.Width);
ControlMainControlsPanel.Top:=ModesRadioGroup.Top;
ControlMainControlsPanel.Left:=ModesRadioGroup.Width;
ControlMainControlsPanel.Height:=ModesRadioGroup.Height;
ControlMainControlsPanel.Width:=ControlPanel.ClientWidth-ModesRadioGroup.Width-PresetsRadioGroup.Width;
PresetsRadioGroup.Top:=ModesRadioGroup.Top;
PresetsRadioGroup.Left:=ControlMainControlsPanel.Left+ControlMainControlsPanel.Width;
PresetsRadioGroup.Height:=ControlPanel.ClientHeight;
end;
procedure TMainForm.ControlMainControlsPanelResize(Sender: TObject);
begin
ControlVolumePanel.Left:=4;
ControlVolumePanel.Top:=4;
ControlVolumePanel.Width:=ControlMainControlsPanel.ClientWidth-8;
ControlButtonsPanel2.ClientHeight:=StandbyButton.Height+SleepTimerComboBox.Height;
ControlButtonsPanel2.Top:=100;
ControlButtonsPanel2.Left:=(ControlMainControlsPanel.ClientWidth-ControlButtonsPanel2.Width) div 2;
ControlButtonsPanel1.Top:=220;
ControlButtonsPanel1.Left:=((ControlMainControlsPanel.ClientWidth-ControlButtonsPanel1.Width) div 2);
end;
procedure TMainForm.NavigationPanelResize(Sender: TObject);
begin
NavigationListView.Top:=0;
NavigationListView.Left:=0;
NavigationListView.Width:=NavigationPanel.ClientWidth;
NavigationListView.Height:=NavigationPanel.ClientHeight;
end;
procedure TMainForm.DebugPanelResize(Sender: TObject);
begin
LogMemo.Top:=0;
LogMemo.Left:=0;
LogMemo.Height:=DebugPanel.ClientHeight;
LogMemo.Width:=(DebugPanel.ClientWidth) * 3 div 4;