forked from VE3NEA/MorseRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.pas
1160 lines (939 loc) · 27.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
//------------------------------------------------------------------------------
//This Source Code Form is subject to the terms of the Mozilla Public
//License, v. 2.0. If a copy of the MPL was not distributed with this
//file, You can obtain one at http://mozilla.org/MPL/2.0/.
//------------------------------------------------------------------------------
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, SndCustm, SndOut, Contest, Ini, MorseKey, CallLst,
VolmSldr, VolumCtl, StdCtrls, Station, Menus, ExtCtrls, Log, MAth,
ComCtrls, Spin, SndTypes, ShellApi, jpeg, ToolWin, ImgList, Crc32,
WavFile, IniFiles;
const
WM_TBDOWN = WM_USER+1;
type
TMainForm = class(TForm)
AlSoundOut1: TAlSoundOut;
MainMenu1: TMainMenu;
File1: TMenuItem;
Send1: TMenuItem;
CQ1: TMenuItem;
Number1: TMenuItem;
TU1: TMenuItem;
MyCall1: TMenuItem;
HisCall1: TMenuItem;
QSOB41: TMenuItem;
N1: TMenuItem;
AGN1: TMenuItem;
Bevel1: TBevel;
Panel1: TPanel;
Label1: TLabel;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Bevel2: TBevel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Help1: TMenuItem;
Readme1: TMenuItem;
About1: TMenuItem;
N2: TMenuItem;
PaintBox1: TPaintBox;
Panel5: TPanel;
Exit1: TMenuItem;
Panel6: TPanel;
RichEdit1: TRichEdit;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Shape1: TShape;
PopupMenu1: TPopupMenu;
PileupMNU: TMenuItem;
SingleCallsMNU: TMenuItem;
CompetitionMNU: TMenuItem;
N3: TMenuItem;
StopMNU: TMenuItem;
ImageList1: TImageList;
Run1: TMenuItem;
PileUp1: TMenuItem;
SingleCalls1: TMenuItem;
Competition1: TMenuItem;
N4: TMenuItem;
Stop1MNU: TMenuItem;
ViewScoreBoardMNU: TMenuItem;
ViewScoreTable1: TMenuItem;
N5: TMenuItem;
Panel7: TPanel;
Label16: TLabel;
Panel8: TPanel;
Shape2: TShape;
AlWavFile1: TAlWavFile;
Panel9: TPanel;
GroupBox3: TGroupBox;
Label11: TLabel;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
CheckBox6: TCheckBox;
SpinEdit3: TSpinEdit;
GroupBox1: TGroupBox;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label9: TLabel;
Edit4: TEdit;
SpinEdit1: TSpinEdit;
CheckBox1: TCheckBox;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Panel10: TPanel;
Label8: TLabel;
SpinEdit2: TSpinEdit;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
Label10: TLabel;
VolumeSlider1: TVolumeSlider;
Label18: TLabel;
WebPage1: TMenuItem;
Settings1: TMenuItem;
Call1: TMenuItem;
QSK1: TMenuItem;
CWSpeed1: TMenuItem;
N10WPM1: TMenuItem;
N15WPM1: TMenuItem;
N20WPM1: TMenuItem;
N25WPM1: TMenuItem;
N30WPM1: TMenuItem;
N35WPM1: TMenuItem;
N40WPM1: TMenuItem;
N45WPM1: TMenuItem;
N50WPM1: TMenuItem;
N55WPM1: TMenuItem;
N60WPM1: TMenuItem;
CWBandwidth1: TMenuItem;
CWBandwidth2: TMenuItem;
N300Hz1: TMenuItem;
N350Hz1: TMenuItem;
N400Hz1: TMenuItem;
N450Hz1: TMenuItem;
N500Hz1: TMenuItem;
N550Hz1: TMenuItem;
N600Hz1: TMenuItem;
N650Hz1: TMenuItem;
N700Hz1: TMenuItem;
N750Hz1: TMenuItem;
N800Hz1: TMenuItem;
N850Hz1: TMenuItem;
N900Hz1: TMenuItem;
N100Hz1: TMenuItem;
N150Hz1: TMenuItem;
N200Hz1: TMenuItem;
N250Hz1: TMenuItem;
N300Hz2: TMenuItem;
N350Hz2: TMenuItem;
N400Hz2: TMenuItem;
N450Hz2: TMenuItem;
N500Hz2: TMenuItem;
N550Hz2: TMenuItem;
N600Hz2: TMenuItem;
MonLevel1: TMenuItem;
N30dB1: TMenuItem;
N20dB1: TMenuItem;
N10dB1: TMenuItem;
N0dB1: TMenuItem;
N10dB2: TMenuItem;
N6: TMenuItem;
QRN1: TMenuItem;
QRM1: TMenuItem;
QSB1: TMenuItem;
Flutter1: TMenuItem;
LIDS1: TMenuItem;
Activity1: TMenuItem;
N11: TMenuItem;
N21: TMenuItem;
N31: TMenuItem;
N41: TMenuItem;
N51: TMenuItem;
N61: TMenuItem;
N71: TMenuItem;
N81: TMenuItem;
N91: TMenuItem;
N7: TMenuItem;
Duration1: TMenuItem;
N5min1: TMenuItem;
N10min1: TMenuItem;
N15min1: TMenuItem;
N30min1: TMenuItem;
N60min1: TMenuItem;
N90min1: TMenuItem;
N120min1: TMenuItem;
PlayRecordedAudio1: TMenuItem;
N8: TMenuItem;
AudioRecordingEnabled1: TMenuItem;
HSTCompetition1: TMenuItem;
HSTCompetition2: TMenuItem;
Panel11: TPanel;
ListView1: TListView;
Operator1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure AlSoundOut1BufAvailable(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Edit3KeyPress(Sender: TObject; var Key: Char);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit1Enter(Sender: TObject);
procedure SendClick(Sender: TObject);
procedure Edit4Change(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure SpinEdit1Change(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBoxClick(Sender: TObject);
procedure SpinEdit2Change(Sender: TObject);
procedure SpinEdit3Change(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure Readme1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure RunMNUClick(Sender: TObject);
procedure RunBtnClick(Sender: TObject);
procedure ViewScoreBoardMNUClick(Sender: TObject);
procedure ViewScoreTable1Click(Sender: TObject);
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Panel8MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Shape2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Edit2Enter(Sender: TObject);
procedure VolumeSliderDblClick(Sender: TObject);
procedure VolumeSlider1Change(Sender: TObject);
procedure WebPage1Click(Sender: TObject);
procedure Call1Click(Sender: TObject);
procedure QSK1Click(Sender: TObject);
procedure NWPMClick(Sender: TObject);
procedure Pitch1Click(Sender: TObject);
procedure Bw1Click(Sender: TObject);
procedure File1Click(Sender: TObject);
procedure PlayRecordedAudio1Click(Sender: TObject);
procedure AudioRecordingEnabled1Click(Sender: TObject);
procedure SelfMonClick(Sender: TObject);
procedure Settings1Click(Sender: TObject);
procedure LIDS1Click(Sender: TObject);
procedure Activity1Click(Sender: TObject);
procedure Duration1Click(Sender: TObject);
procedure Operator1Click(Sender: TObject);
procedure StopMNUClick(Sender: TObject);
private
MustAdvance: boolean;
procedure ProcessSpace;
procedure SendMsg(Msg: TStationMessage);
procedure ProcessEnter;
procedure EnableCtl(Ctl: TWinControl; AEnable: boolean);
procedure WmTbDown(var Msg: TMessage); message WM_TBDOWN;
procedure SetToolbuttonDown(Toolbutton: TToolbutton; ADown: boolean);
procedure IncRit(dF: integer);
procedure UpdateRitIndicator;
procedure DecSpeed;
procedure IncSpeed;
public
CompetitionMode: boolean;
procedure Run(Value: TRunMode);
procedure WipeBoxes;
procedure PopupScoreWpx;
procedure PopupScoreHst;
procedure Advance;
procedure SetQsk(Value: boolean);
procedure SetMyCall(ACall: string);
procedure SetPitch(PitchNo: integer);
procedure SetBw(BwNo: integer);
procedure ReadCheckboxes;
end;
var
MainForm: TMainForm;
implementation
uses ScoreDlg;
{$R *.DFM}
procedure TMainForm.FormCreate(Sender: TObject);
begin
Randomize;
Tst := TContest.Create;
LoadCallList;
AlSoundOut1.BufCount := 4;
FromIni;
MakeKeyer;
Keyer.Rate := 11025;
Keyer.BufSize := Ini.BufSize;
Panel2.DoubleBuffered := true;
RichEdit1.Align := alClient;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
ToIni;
Tst.Free;
DestroyKeyer;
end;
procedure TMainForm.AlSoundOut1BufAvailable(Sender: TObject);
begin
if AlSoundOut1.Enabled then
try AlSoundOut1.PutData(Tst.GetAudio); except end;
end;
procedure TMainForm.SendClick(Sender: TObject);
var
Msg: TStationMessage;
begin
Msg := TStationMessage((Sender as TComponent).Tag);
SendMsg(Msg);
case Msg of
msgHisCall: CallSent:= true;
msgNR: NrSent:= true;
end;
end;
procedure TMainForm.SendMsg(Msg: TStationMessage);
begin
if Msg = msgHisCall then
begin
if Edit1.Text <> '' then Tst.Me.HisCall := Edit1.Text;
CallSent := true;
end;
if Msg = msgNR then NrSent := true;
Tst.Me.SendMsg(Msg);
end;
procedure TMainForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['A'..'Z', 'a'..'z', '0'..'9', '/', '?', #8]) then Key := #0;
end;
procedure TMainForm.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then Key := #0;
end;
procedure TMainForm.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then Key := #0;
end;
procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
case Key of
{
#13: //^M = ESM
Ini.Esm := not Ini.Esm;
}
#23: //^W = Wipe
WipeBoxes;
#25: //^Y = Edit
;
#27: //Esc = Abort send
begin
if msgHisCall in Tst.Me.Msg then CallSent := false;
if msgNR in Tst.Me.Msg then NrSent := false;
Tst.Me.AbortSend;
end;
';': //<his> <#>
begin
SendMsg(msgHisCall);
SendMsg(msgNr);
end;
'.', '+', '[', ',': //TU & Save
begin
if not CallSent then SendMsg(msgHisCall);
SendMsg(msgTU);
Log.SaveQso;
end;
' ': //next field
ProcessSpace;
'\': // = F1
SendMsg(msgCQ);
else Exit;
end;
Key := #0;
end;
procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_INSERT: //<his> <#>
begin
SendMsg(msgHisCall);
SendMsg(msgNr);
Key := 0;
end;
VK_RETURN: //Save
ProcessEnter;
VK_F11:
WipeBoxes;
87, 119: //Alt-W = Wipe
if GetKeyState(VK_MENU) < 0 then WipeBoxes else Exit;
{
'M': //Alt-M = Auto CW
if GetKeyState(VK_MENU) < 0
then Ini.AutoCw := not Ini.AutoCw
else Exit;
}
VK_UP:
if GetKeyState(VK_CONTROL) >= 0 then IncRit(1)
else if RunMode <> rmHst then SetBw(ComboBox2.ItemIndex+1);
VK_DOWN:
if GetKeyState(VK_CONTROL) >= 0 then IncRit(-1)
else if RunMode <> rmHst then SetBw(ComboBox2.ItemIndex-1);
VK_PRIOR: //PgUp
IncSpeed;
VK_NEXT: //PgDn
DecSpeed;
VK_F9:
if (ssAlt in Shift) or (ssCtrl in Shift) then DecSpeed;
VK_F10:
if (ssAlt in Shift) or (ssCtrl in Shift) then IncSpeed;
else Exit;
end;
Key := 0;
end;
procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_INSERT, VK_RETURN: Key := 0;
end;
end;
procedure TMainForm.ProcessSpace;
begin
MustAdvance := false;
if ActiveControl = Edit1 then
begin
if Edit2.Text = '' then Edit2.Text := '599';
ActiveControl := Edit3;
end
else if ActiveControl = Edit2 then
begin
if Edit2.Text = '' then Edit2.Text := '599';
ActiveControl := Edit3;
end
else
ActiveControl := Edit1;
end;
procedure TMainForm.ProcessEnter;
var
C, N, R: boolean;
begin
MustAdvance := false;
if (GetKeyState(VK_CONTROL) or GetKeyState(VK_SHIFT) or GetKeyState(VK_MENU)) < 0
then begin Log.SaveQso; Exit; end;
//no QSO in progress, send CQ
if Edit1.Text = '' then begin SendMsg(msgCq); Exit; end;
//current state
C := CallSent;
N := NrSent;
R := Edit3.Text <> '';
//send his call if did not send before, or if call changed
if (not C) or ((not N) and (not R)) then SendMsg(msgHisCall);
if not N then SendMsg(msgNR);
if N and not R then SendMsg(msgQm);
if R and (C or N)
then
begin
SendMsg(msgTU);
Log.SaveQso;
end
else
MustAdvance := true;
end;
procedure TMainForm.Edit1Enter(Sender: TObject);
var
P: integer;
begin
P := Pos('?', Edit1.Text);
if P > 1 then
begin Edit1.SelStart := P-1; Edit1.SelLength := 1; end;
end;
procedure TMainForm.IncSpeed;
begin
Wpm := Trunc(Wpm / 5) * 5 + 5;
Wpm := Max(10, Min(120, Wpm));
SpinEdit1.Value := Wpm;
Tst.Me.Wpm := Wpm;
end;
procedure TMainForm.DecSpeed;
begin
Wpm := Ceil(Wpm / 5) * 5 - 5;
Wpm := Max(10, Min(120, Wpm));
SpinEdit1.Value := Wpm;
Tst.Me.Wpm := Wpm;
end;
procedure TMainForm.Edit4Change(Sender: TObject);
begin
SetMyCall(Trim(Edit4.Text));
end;
procedure TMainForm.SetMyCall(ACall: string);
begin
Ini.Call := ACall;
Edit4.Text := ACall;
Tst.Me.MyCall := ACall;
end;
procedure TMainForm.SetPitch(PitchNo: integer);
begin
Ini.Pitch := 300 + PitchNo * 50;
ComboBox1.ItemIndex := PitchNo;
Tst.Modul.CarrierFreq := Ini.Pitch;
end;
procedure TMainForm.SetBw(BwNo: integer);
begin
if (BwNo < 0) or (BwNo >= ComboBox2.Items.Count) then Exit;
Ini.Bandwidth := 100 + BwNo * 50;
ComboBox2.ItemIndex := BwNo;
Tst.Filt.Points := Round(0.7 * 11025 / Ini.BandWidth);
Tst.Filt.GainDb := 10 * Log10(500/Ini.Bandwidth);
Tst.Filt2.Points := Tst.Filt.Points;
Tst.Filt2.GainDb := Tst.Filt.GainDb;
UpdateRitIndicator;
end;
procedure TMainForm.ComboBox2Change(Sender: TObject);
begin
SetBw(ComboBox2.ItemIndex);
end;
procedure TMainForm.ComboBox1Change(Sender: TObject);
begin
SetPitch(ComboBox1.ItemIndex);
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
AlSoundOut1.Enabled := false;
if AlWavFile1.IsOpen then AlWavFile1.Close;
end;
procedure TMainForm.SpinEdit1Change(Sender: TObject);
begin
Ini.Wpm := SpinEdit1.Value;
Tst.Me.Wpm := Ini.Wpm;
end;
procedure TMainForm.CheckBox1Click(Sender: TObject);
begin
SetQsk(CheckBox1.Checked);
ActiveControl := Edit1;
end;
procedure TMainForm.CheckBoxClick(Sender: TObject);
begin
ReadCheckboxes;
ActiveControl := Edit1;
end;
procedure TMainForm.ReadCheckboxes;
begin
Ini.Qrn := CheckBox4.Checked;
Ini.Qrm := CheckBox3.Checked;
Ini.Qsb := CheckBox2.Checked;
Ini.Flutter := CheckBox5.Checked;
Ini.Lids := CheckBox6.Checked;
end;
procedure TMainForm.SpinEdit2Change(Sender: TObject);
begin
Ini.Duration := SpinEdit2.Value;
end;
procedure TMainForm.SpinEdit3Change(Sender: TObject);
begin
Ini.Activity := SpinEdit3.Value;
end;
procedure TMainForm.PaintBox1Paint(Sender: TObject);
begin
Log.PaintHisto;
end;
procedure TMainForm.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TMainForm.WipeBoxes;
begin
Edit1.Text := '';
Edit2.Text := '';
Edit3.Text := '';
ActiveControl := Edit1;
CallSent := false;
NrSent := false;
end;
procedure TMainForm.About1Click(Sender: TObject);
const
Msg = 'CW CONTEST SIMULATOR'#13#13 +
'Copyright © 2004-2006 Alex Shovkoplyas, VE3NEA'#13#13 +
'[email protected]'#13;
begin
Application.MessageBox(Msg, 'Morse Runner 1.68', MB_OK or MB_ICONINFORMATION);
end;
procedure TMainForm.Readme1Click(Sender: TObject);
var
FileName: string;
begin
FileName := ExtractFilePath(ParamStr(0)) + 'readme.txt';
ShellExecute(GetDesktopWindow, 'open', PChar(FileName), '', '', SW_SHOWNORMAL);
end;
procedure TMainForm.Edit1Change(Sender: TObject);
begin
if Edit1.Text = '' then NrSent := false;
if not Tst.Me.UpdateCallInMessage(Edit1.Text)
then CallSent := false;
end;
procedure TMainForm.RunMNUClick(Sender: TObject);
begin
Run(TRunMode((Sender as TComponent).Tag));
end;
procedure TMainForm.Edit2Enter(Sender: TObject);
begin
if Length(Edit2.Text) = 3 then
begin Edit2.SelStart := 1; Edit2.SelLength := 1; end;
end;
procedure TMainForm.EnableCtl(Ctl: TWinControl; AEnable: boolean);
const
Clr: array[boolean] of TColor = (clBtnFace, clWindow);
begin
Ctl.Enabled := AEnable;
if Ctl is TSpinEdit then (Ctl as TSpinEdit).Color := Clr[AEnable]
else if Ctl is TEdit then (Ctl as TEdit).Color := Clr[AEnable];
end;
procedure TMainForm.Run(Value: TRunMode);
const
Title: array[TRunMode] of string =
('', 'Pile-Up', 'Single Calls', 'COMPETITION', 'H S T', 'Custom');
var
BCompet, BStop: boolean;
begin
if Value = Ini.RunMode then Exit;
BStop := Value = rmStop;
BCompet := Value in [rmWpx, rmHst];
RunMode := Value;
//main ctls
EnableCtl(Edit4, BStop);
EnableCtl(SpinEdit2, BStop);
SetToolbuttonDown(ToolButton1, not BStop);
//condition checkboxes
EnableCtl(CheckBox2, not BCompet);
EnableCtl(CheckBox3, not BCompet);
EnableCtl(CheckBox4, not BCompet);
EnableCtl(CheckBox5, not BCompet);
EnableCtl(CheckBox6, not BCompet);
if RunMode = rmWpx then
begin
CheckBox2.Checked := true;
CheckBox3.Checked := true;
CheckBox4.Checked := true;
CheckBox5.Checked := true;
CheckBox6.Checked := true;
SpinEdit2.Value := CompDuration;
end
else if RunMode = rmHst then
begin
CheckBox2.Checked := false;
CheckBox3.Checked := false;
CheckBox4.Checked := false;
CheckBox5.Checked := false;
CheckBox6.Checked := false;
SpinEdit2.Value := CompDuration;
end;
//button menu
PileupMNU.Enabled := BStop;
SingleCallsMNU.Enabled := BStop;
CompetitionMNU.Enabled := BStop;
HSTCompetition1.Enabled := BStop;
StopMNU.Enabled := not BStop;
//main menu
PileUp1.Enabled := BStop;
SingleCalls1.Enabled := BStop;
Competition1.Enabled := BStop;
HSTCompetition2.Enabled := BStop;
Stop1MNU.Enabled := not BStop;
Call1.Enabled := BStop;
Duration1.Enabled := BStop;
QRN1.Enabled := not BCompet;
QRM1.Enabled := not BCompet;
QSB1.Enabled := not BCompet;
Flutter1.Enabled := not BCompet;
Lids1.Enabled := not BCompet;
//hst specific
Activity1.Enabled := Value <> rmHst;
CWBandwidth2.Enabled := Value <> rmHst;
EnableCtl(SpinEdit3, RunMode <> rmHst);
if RunMode = rmHst then SpinEdit3.Value := 4;
EnableCtl(ComboBox2, RunMode <> rmHst);
if RunMode = rmHst then begin ComboBox2.ItemIndex :=10; SetBw(10); end;
if RunMode = rmHst then ListView1.Visible := false
else if RunMode <> rmStop then ListView1.Visible := true;
//mode caption
Panel4.Caption := Title[Value];
if BCompet
then Panel4.Font.Color := clRed else Panel4.Font.Color := clGreen;
if not BStop then
begin
Tst.Me.AbortSend;
Tst.BlockNumber := 0;
Tst.Me.Nr := '1';
Log.Clear;
WipeBoxes;
RichEdit1.Visible := true;
{! ?}Panel5.Update;
end;
if not BStop then IncRit(0);
if BStop
then
begin
if AlWavFile1.IsOpen then AlWavFile1.Close;
end
else
begin
AlWavFile1.FileName := ChangeFileExt(ParamStr(0), '.wav');
if SaveWav then AlWavFile1.OpenWrite;
end;
AlSoundOut1.Enabled := not BStop;
end;
procedure TMainForm.RunBtnClick(Sender: TObject);
begin
if RunMode = rmStop
then Run(rmPileUp)
else Tst.FStopPressed := true;
end;
procedure TMainForm.WmTbDown(var Msg: TMessage);
begin
TToolbutton(Msg.LParam).Down := Boolean(Msg.WParam);
end;
procedure TMainForm.SetToolbuttonDown(Toolbutton: TToolbutton;
ADown: boolean);
begin
Windows.PostMessage(Handle, WM_TBDOWN, Integer(ADown), Integer(Toolbutton));
end;
procedure TMainForm.PopupScoreWpx;
var
S, FName: string;
Score: integer;
begin
S := Format('%s %s %s %s ', [
FormatDateTime('yyyy-mm-dd', Now),
Ini.Call,
ListView1.Items[0].SubItems[1],
ListView1.Items[1].SubItems[1]]);
S := S + '[' + IntToHex(CalculateCRC32(S, $C90C2086), 8) + ']';
FName := ChangeFileExt(ParamStr(0), '.lst');
with TStringList.Create do
try
if FileExists(FName) then LoadFromFile(FName);
Add(S);
SaveToFile(FName);
finally Free; end;
ScoreDialog.Edit1.Text := S;
Score := StrToIntDef(ListView1.Items[2].SubItems[1], 0);
if Score > HiScore
then ScoreDialog.Height := 192
else ScoreDialog.Height := 129;
HiScore := Max(HiScore, Score);
ScoreDialog.ShowModal;
end;
procedure TMainForm.PopupScoreHst;
var
S: string;
FName: TFileName;
begin
S := Format('%s'#9'%s'#9'%s'#9'%s', [
FormatDateTime('yyyy-mm-dd hh:nn', Now),
Ini.Call,
Ini.HamName,
Panel11.Caption]);
FName := ExtractFilePath(ParamStr(0)) + 'HstResults.txt';
with TStringList.Create do
try
if FileExists(FName) then LoadFromFile(FName);
Add(S);
SaveToFile(FName);
finally Free; end;
ShowMessage('HST Score: ' + ListView1.Items[2].SubItems[1]);
end;
procedure OpenWebPage(Url: string);
begin
ShellExecute(GetDesktopWindow, 'open', PChar(Url), '', '', SW_SHOWNORMAL);
end;
procedure TMainForm.ViewScoreBoardMNUClick(Sender: TObject);
begin
OpenWebPage('http://www.dxatlas.com/MorseRunner/MrScore.asp');
end;
procedure TMainForm.ViewScoreTable1Click(Sender: TObject);
var
FName: string;
begin
RichEdit1.Clear;
FName := ChangeFileExt(ParamStr(0), '.lst');
if FileExists(FName)
then RichEdit1.Lines.LoadFromFile(FName)
else RichEdit1.Lines.Add('Your score table is empty');
RichEdit1.Visible := true;
end;
procedure TMainForm.Panel8MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if X < Shape2.Left then IncRit(-1)
else if X > (Shape2.Left + Shape2.Width) then IncRit(1);
end;
procedure TMainForm.Shape2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
IncRit(0);
end;
procedure TMainForm.IncRit(dF: integer);
begin
case dF of
-1: Inc(Ini.Rit, -50);
0: Ini.Rit := 0;
1: Inc(Ini.Rit, 50);
end;
Ini.Rit := Min(500, Max(-500, Ini.Rit));
UpdateRitIndicator;
end;
procedure TMainForm.UpdateRitIndicator;
begin
Shape2.Width := Ini.Bandwidth div 9;
Shape2.Left := ((Panel8.Width - Shape2.Width) div 2) + (Ini.Rit div 9);
end;
procedure TMainForm.Advance;
begin
if not MustAdvance then Exit;
if Edit2.Text = '' then Edit2.Text := '599';
if Pos('?', Edit1.Text) = 0 then ActiveControl := Edit3
else if ActiveControl = Edit1 then Edit1Enter(nil)
else ActiveControl := Edit1;
MustAdvance := false;
end;
procedure TMainForm.VolumeSliderDblClick(Sender: TObject);
begin
with Sender as TVolumeSlider do
begin
Value := 0.75;
OnChange(Sender);
end;