unit visualization;

interface

uses
  Windows,Messages, SysUtils, math,Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, MPlayer, StdCtrls, Buttons, ComCtrls,formScaler, common, Grids;

type
  TForm2 = class(TForm)
    Panel1: TPanel;
    MediaPlayer1: TMediaPlayer;
    //Label38: TLabel;
    BitBtn1: TBitBtn;
    Button3: TButton;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    Button1: TButton;
    Label12: TLabel;
    Panel7: TPanel;
    Button2: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Label29: TLabel;
    CheckBox2: TCheckBox;
    CheckBox1: TCheckBox;
    Memo1: TMemo;
    Label55: TLabel;
    Label56: TLabel;
    Memo2: TMemo;
    Label57: TLabel;
    Label58: TLabel;
    Label59: TLabel;
    Label60: TLabel;
    Label61: TLabel;
    Label62: TLabel;
    Label63: TLabel;
    Label64: TLabel;
    Label65: TLabel;
    Label66: TLabel;
    Label67: TLabel;
    Label68: TLabel;
    Label70: TLabel;
    Button7: TButton;
    Button8: TButton;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    CheckBox9: TCheckBox;
    CheckBox10: TCheckBox;
    CheckBox11: TCheckBox;
    CheckBox12: TCheckBox;
    CheckBox13: TCheckBox;
    CheckBox14: TCheckBox;
    CheckBox15: TCheckBox;
    CheckBox16: TCheckBox;
    CheckBox17: TCheckBox;
    Panel5: TPanel;
    Button9: TButton;
    CheckBox23: TCheckBox;
    CheckBox26: TCheckBox;
    CheckBox27: TCheckBox;
    CheckBox28: TCheckBox;
    Label1: TLabel;
    CheckBox29: TCheckBox;
    CheckBox31: TCheckBox;
    CheckBox32: TCheckBox;
    CheckBox33: TCheckBox;
    CheckBox34: TCheckBox;
    CheckBox35: TCheckBox;
    CheckBox36: TCheckBox;
    CheckBox37: TCheckBox;
    CheckBox41: TCheckBox;
    CheckBox42: TCheckBox;
    CheckBox43: TCheckBox;
    Label2: TLabel;
    CheckBox44: TCheckBox;
    CheckBox25: TCheckBox;
    CheckBox46: TCheckBox;
    CheckBox47: TCheckBox;
    CheckBox48: TCheckBox;
    CheckBox49: TCheckBox;
    CheckBox50: TCheckBox;
    CheckBox51: TCheckBox;
    CheckBox52: TCheckBox;
    CheckBox53: TCheckBox;
    CheckBox54: TCheckBox;
    CheckBox55: TCheckBox;
    CheckBox56: TCheckBox;
    CheckBox57: TCheckBox;
    CheckBox58: TCheckBox;
    Label3: TLabel;
    CheckBox38: TCheckBox;
    CheckBox39: TCheckBox;
    CheckBox40: TCheckBox;
    CheckBox60: TCheckBox;
    Edit3: TEdit;
    Label4: TLabel;
    GroupBox1: TGroupBox;
    CheckBox18: TCheckBox;
    CheckBox19: TCheckBox;
    CheckBox21: TCheckBox;
    CheckBox22: TCheckBox;
    CheckBox20: TCheckBox;
    Button10: TButton;
    CheckBox45: TCheckBox;
    CheckBox59: TCheckBox;
    Label5: TLabel;
    Label10: TLabel;
    Label13: TLabel;
    RadioGroup2: TRadioGroup;
    RadioGroup1: TRadioGroup;
    Label11: TLabel;
    Label14: TLabel;
    RadioGroup7: TRadioGroup;
    CheckBox24: TCheckBox;
    Edit4: TEdit;
    Label16: TLabel;
    Panel6: TPanel;
    Label71: TLabel;
    Edit2: TEdit;
    Label92: TLabel;
    Edit24: TEdit;
    UpDown1: TUpDown;
    Label8: TLabel;
    Edit1: TEdit;
    CheckBox30: TCheckBox;
    CheckBox3: TCheckBox;
    Label17: TLabel;
    Label21: TLabel;
    Label18: TLabel;
    CheckBox63: TCheckBox;
    CheckBox64: TCheckBox;
    CheckBox65: TCheckBox;
    CheckBox66: TCheckBox;
    Label19: TLabel;
    Panel8: TPanel;
    Panel9: TPanel;
    Label20: TLabel;
    Edit7: TEdit;
    UpDown3: TUpDown;
    GroupBox3: TGroupBox;
    Button12: TButton;
    CheckBox67: TCheckBox;
    CheckBox68: TCheckBox;
    CheckBox69: TCheckBox;
    Edit8: TEdit;
    UpDown5: TUpDown;
    Label22: TLabel;
    Edit9: TEdit;
    Label23: TLabel;
    ProgressBar1: TProgressBar;
    Edit10: TEdit;
    Label24: TLabel;
    CheckBox70: TCheckBox;
    CheckBox71: TCheckBox;
    Edit11: TEdit;
    Label9: TLabel;
    Label15: TLabel;
    Edit12: TEdit;
    Label25: TLabel;
    CheckBox72: TCheckBox;
    Edit5: TEdit;
    Label26: TLabel;
    Edit6: TEdit;
    Label27: TLabel;
    CheckBox61: TCheckBox;
    CheckBox73: TCheckBox;
    CheckBox74: TCheckBox;
    Edit13: TEdit;
    Label28: TLabel;
    Button11: TButton;
    Label30: TLabel;
    CheckBox75: TCheckBox;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Label37: TLabel;
    CheckBox77: TCheckBox;
    CheckBox78: TCheckBox;
    CheckBox79: TCheckBox;
    CheckBox80: TCheckBox;
    Edit14: TEdit;
    Edit15: TEdit;
    Edit16: TEdit;
    Label39: TLabel;
    Label40: TLabel;
    Bevel1: TBevel;
    RadioGroup3: TRadioGroup;
    Label41: TLabel;
    RadioGroup4: TRadioGroup;
    CheckBox81: TCheckBox;
    CheckBox82: TCheckBox;
    GroupBox2: TGroupBox;
    RadioGroup5: TRadioGroup;
    RadioGroup6: TRadioGroup;
    CheckBox83: TCheckBox;
    CheckBox84: TCheckBox;
    CheckBox85: TCheckBox;
    CheckBox86: TCheckBox;
    CheckBox87: TCheckBox;
    CheckBox88: TCheckBox;
    CheckBox89: TCheckBox;
    CheckBox90: TCheckBox;
    CheckBox91: TCheckBox;
    CheckBox92: TCheckBox;
    Label6: TLabel;
    CheckBox94: TCheckBox;
    Label7: TLabel;
    CheckBox95: TCheckBox;
    Button13: TButton;
    Button14: TButton;
    Label38: TLabel;
    Label42: TLabel;
    Button15: TButton;
    Button16: TButton;
    CheckBox93: TCheckBox;
    Button19: TButton;
    Button20: TButton;
    CheckBox62: TCheckBox;
    Button17: TButton;
    CheckBox76: TCheckBox;
    Memo3: TMemo;
    Memo4: TMemo;
    Label43: TLabel;
    Label44: TLabel;
    Label45: TLabel;
    Label46: TLabel;
    Label47: TLabel;
    Label48: TLabel;
    Label49: TLabel;
    Label50: TLabel;
    Label51: TLabel;
    CheckBox96: TCheckBox;
    RadioGroup8: TRadioGroup;
    Button18: TButton;
    StaticText1: TStaticText;
    procedure Button18Click(Sender: TObject);
    procedure CheckBox9Click(Sender: TObject);
    procedure CheckBox17Click(Sender: TObject);
    procedure CheckBox16Click(Sender: TObject);
    procedure CheckBox29Click(Sender: TObject);
    procedure CheckBox28Click(Sender: TObject);
    procedure CheckBox27Click(Sender: TObject);
    procedure CheckBox13Click(Sender: TObject);
    procedure CheckBox12Click(Sender: TObject);
    procedure RadioGroup8Click(Sender: TObject);
    procedure CheckBox96Click(Sender: TObject);
    procedure Memo4Click(Sender: TObject);
    procedure Memo3Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure Edit13KeyPress(Sender: TObject; var Key: Char);
    procedure Edit1Exit(Sender: TObject);
    procedure Button20Click(Sender: TObject);
    procedure Button19Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure CheckBox95Click(Sender: TObject);
    procedure CheckBox82Click(Sender: TObject);
    procedure CheckBox93Click(Sender: TObject);
    procedure CheckBox92Click(Sender: TObject);
    procedure CheckBox91Click(Sender: TObject);
    procedure CheckBox90Click(Sender: TObject);
    procedure CheckBox89Click(Sender: TObject);
    procedure CheckBox88Click(Sender: TObject);
    procedure CheckBox87Click(Sender: TObject);
    procedure CheckBox86Click(Sender: TObject);
    procedure CheckBox85Click(Sender: TObject);
    procedure CheckBox84Click(Sender: TObject);
    procedure CheckBox83Click(Sender: TObject);
    procedure Edit2Exit(Sender: TObject);
    procedure RadioGroup5Click(Sender: TObject);
    procedure CheckBox81Click(Sender: TObject);
    procedure RadioGroup4Click(Sender: TObject);
    procedure Label5MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Label70MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Label66MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Label64MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Label5Click(Sender: TObject);
    procedure Label70Click(Sender: TObject);
    procedure Label66Click(Sender: TObject);
    procedure Label64Click(Sender: TObject);
    procedure Edit16Enter(Sender: TObject);
    procedure Edit15Enter(Sender: TObject);
    procedure Edit14Enter(Sender: TObject);
    procedure Label40Click(Sender: TObject);
    procedure Label39Click(Sender: TObject);
    procedure Edit16Exit(Sender: TObject);
    procedure Edit15Exit(Sender: TObject);
    procedure Edit14Exit(Sender: TObject);
    procedure CheckBox80Click(Sender: TObject);
    procedure CheckBox78Click(Sender: TObject);
    procedure CheckBox77Click(Sender: TObject);
    procedure CheckBox76Click(Sender: TObject);
    procedure Label37Click(Sender: TObject);
    procedure Label36Click(Sender: TObject);
    procedure Edit4Exit(Sender: TObject);
    procedure UpDown3Click(Sender: TObject; Button: TUDBtnType);
    procedure Edit7Exit(Sender: TObject);
    procedure Edit11Enter(Sender: TObject);
    procedure Edit11Exit(Sender: TObject);
    procedure Edit11Change(Sender: TObject);
    procedure CheckBox75Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Memo1Click(Sender: TObject);
    procedure Memo2Click(Sender: TObject);
    procedure Edit13Exit(Sender: TObject);
    procedure Label27Click(Sender: TObject);
    procedure CheckBox74Click(Sender: TObject);
    procedure CheckBox73Click(Sender: TObject);
    procedure Edit6Exit(Sender: TObject);
    procedure Edit5Exit(Sender: TObject);
    procedure CheckBox72Click(Sender: TObject);
    procedure CheckBox69Click(Sender: TObject);
    procedure Edit8Change(Sender: TObject);
    procedure CheckBox2MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure CheckBox2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Button12Click(Sender: TObject);
    procedure CheckBox65Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure CheckBox63Click(Sender: TObject);
    procedure CheckBox30Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
    procedure CheckBox20Click(Sender: TObject);
    procedure CheckBox22Click(Sender: TObject);
    procedure CheckBox21Click(Sender: TObject);
    procedure CheckBox19Click(Sender: TObject);
    procedure CheckBox18Click(Sender: TObject);
    procedure CheckBox62Click(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure UpDown4Click(Sender: TObject; Button: TUDBtnType);
    procedure CheckBox61Click(Sender: TObject);
    procedure Edit4Change(Sender: TObject);
    procedure CheckBox24Click(Sender: TObject);
    procedure CheckBox45Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure CheckBox44Click(Sender: TObject);
    procedure CheckBox43Click(Sender: TObject);
    procedure CheckBox42Click(Sender: TObject);
    procedure CheckBox41Click(Sender: TObject);
    procedure CheckBox37Click(Sender: TObject);
    procedure CheckBox36Click(Sender: TObject);
    procedure CheckBox35Click(Sender: TObject);
    procedure CheckBox34Click(Sender: TObject);
    procedure CheckBox33Click(Sender: TObject);
    procedure CheckBox32Click(Sender: TObject);
    procedure CheckBox31Click(Sender: TObject);
    procedure CheckBox25Click(Sender: TObject);
    procedure CheckBox7Click(Sender: TObject);
    procedure RadioGroup2Click(Sender: TObject);
    procedure RadioGroup7Click(Sender: TObject);
    procedure CheckBox23Click(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure CheckBox6Click(Sender: TObject);
    procedure CheckBox5Click(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure Edit24Enter(Sender: TObject);
    procedure Edit24Exit(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Edit24Change(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
      var DoDefault: Boolean);
  private
    { Private declarations }
   procedure WMVScroll(var Msg :TMessage); message WM_VSCROLL;
   procedure WMHScroll(var Msg :TMessage); message WM_HSCROLL;
  public
    { Public declarations }
  end;
type
TCath=record TcPhon,TcPerson,TcGender:char;TcAge:byte; end;
var
          Form2 : TForm2;
       cathFile : file of Tcath;
           cath : TCath;
f2Radio7Changed : boolean;
    myCursorPos : Tpoint;
  butt12Caption : shortString;
 label18Caption : shortString='"Windows weights spectrum" or "Filter shape"';
  procedure OutCheckBoxesChecking;
implementation

{$R *.dfm}
uses NewSpectrum, Unit1,grafiti4,spectanalisier,commande, Drawings,fft,porto,disco;
var soundStart:boolean = true;
procedure Tform2.WMVScroll(var Msg : TMessage);
begin   //https://www.tek-tips.com/viewthread.cfm?qid=1409264 (thanks to courtesy of zpksoft, see https://groups.google.com/forum/?hl=pl#!topic/pl.comp.lang.delphi/sTQPQcPQcfQ)
  inherited;
  onScroll:=true;manager:='R';//FramesRepaint(count_cp);//
end;
//------------------------
procedure Tform2.WMHScroll(var Msg : TMessage);
begin   //https://www.tek-tips.com/viewthread.cfm?qid=1409264 (thanks to courtesy of zpksoft, see https://groups.google.com/forum/?hl=pl#!topic/pl.comp.lang.delphi/sTQPQcPQcfQ)
  inherited;
  onScroll:=true;manager:='R';//FramesRepaint(count_cp);//
end;

procedure TForm2.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
  var DoDefault: Boolean);
begin
MediaPlayer1.FileName:=waveFilePath;
MediaPlayer1.open;
MediaPlayer1.play
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
 InitWrite;
 if application.messageBox('Break the analysis?'#13#10'Choose rather "Break" button (if you have not done it yet) if you like to save all reults...','FFT',MB_YesNo)=IdYes then halt;
end;

procedure TForm2.Button3Click(Sender: TObject);
begin
 Form1.Edit12.Text:=Form2.Edit2.Text;
 form1.PageControl3.ActivePageIndex:=0;
 form1.button4.Visible:=true;
 form1.Show;
end;

procedure labelsClear_(labelSet:TlabelSet);  //[Arivald 2012]
var ctrl: TLabel;  i,j:Integer;  s:string;
Begin
 with form2 do
 for i := 0 to Panel1.ControlCount-1 do
  if panel1.Controls[i] is Tlabel then
  begin
    ctrl :=Form1.panel1.controls[i] as Tlabel;
    s:=ctrl.Name;
    if TryStrToInt(Copy(s, Length(s) - 1, 2), j) then
    if j in labelSet
    then ctrl.caption:='_';
  end;
End;

procedure OutCheckBoxesChecking;
 Begin  //synchronises the "visual" output with the "start" one
 with Form2 do
  begin //visual-------------start
   checkBox31.Checked:=form1.checkBox5.Checked;   //wav
   checkBox32.Checked:=form1.checkBox40.Checked;  //PS
   checkBox33.Checked:=form1.checkBox41.Checked;  //sPS
   checkBox34.Checked:=form1.checkBox44.Checked;  //msPS
   checkBox35.Checked:=form1.checkBox43.Checked;  //vPS
   checkBox36.Checked:=form1.checkBox42.Checked;  //cPS
   checkBox37.Checked:=form1.checkBox4.Checked;   //aPS
   checkBox41.Checked:=form1.checkBox45.Checked;  //PC
   checkBox42.Checked:=form1.checkBox48.Checked;  //mPC
   checkBox43.Checked:=form1.checkBox47.Checked;  //vPC
   checkBox44.Checked:=form1.checkBox46.Checked;  //cPC
   checkBox45.Checked:=form1.checkBox49.Checked;  //mmcPS
  end;
 End;{OutCheckBoxesChecking}

procedure TForm2.FormCreate(Sender: TObject);
 var i:integer;
Begin

 left:=0; top:=0;
 vertScrollBar.Range:=1050; vertScrollBar.Position:=0;
 HorzScrollBar.Range:=1680; HorzScrollBar.Position:=0;

 harmSpace:=100; harmBiass:=100; harmNbr:=100;
 form2.WindowState:=wsMaximized;
 button2.Hint:='Show previous portion';
 Button2.Enabled:=false;
 button4.Hint:='Show next portion';
 button5.Hint:='Saves current portion and its analysis results to the report file.'#13#10'Note. Chosen during a session portions are gathered in that file'#13#10'one by one in order in which they were chosen.';
 button6.Hint:='Break the analysis';
 button12.Caption:='Search Windows';
 butt12Caption:=button12.Caption;
 button18.Enabled:=false;
 if checkBox2.Checked then checkbox2.Caption:='Stepwise/continuos performance'
 else checkbox2.Caption:='Continuos/stepwise performance';
 checkBox8.Hint:='Weighted signal is here multiplied by averaging period, i.e. 256';
 checkBox11.Hint:='Zakres melowy zosta� rozci�gni�ty tak,'#13#10+
  'aby jego skrajne warto�ci pokrywa�y si� na osi odci�tych wykresu'#13#10+
  'ze skrajnymi warto�ciami cz�stotliwo�ci wyra�onej w hercach';
 checkBox12.Hint:='For averaging constant, i.e. "'+label92.Caption+'", declared in the "'+groupBox1.Caption+'"';
 checkBox23.Checked:=true;
 checkBox24.Checked:=true;         //lock "Diagnostic Box"
 checkBox25.Checked:=true;         //lock Output
 checkBox30.hint:='Check it to eliminate multiplicative signal amplification changes';
 checkBox31.hint:='Note: the wav signal portions stream will contain the only the original form without normalisation or weighting transforms';
 CheckBox45.Enabled:=false;        //mmcPS Out
 CheckBox45.hint:=CheckBox45.hint+#13#10'Unlock the "'+groupBox1.Caption +'" to change the bundle output with the "'+radiogroup4.Caption +'" radiogroup';
 CheckBox59.Enabled:=false;        //mmcPS Analyses
 checkBox61.Caption:='Lock "'+button6.Caption+'"';
 checkBox62.Hint:='Show graphics during averaging actualization when processing parameters are changed';
 checkBox64.Checked:=true;         //reapaintORrepeat (DB)
 checkBox73.Caption:='Lock "'+button1.Caption+'"';
 checkBox74.Caption:='Lock "'+groupBox3.Caption+'"';
 checkBox74.checked:=true;
 checkBox76.Checked:=true;  //Scratch lock
 CheckBox81.Enabled:=false;
 checkBox81.Checked:=false;
 checkBox93.Enabled:=false;
 checkBox94.Checked:=false;
 checkBox96.Caption:='T0 Dash Length change, now='+intToStr(T0dashLength);
 Edit1.Text:=form1.Edit2.Text;
 edit1.Hint:=form1.edit2.Hint;
 Edit2.Text:=form1.Edit12.Text;
 Edit4.Enabled:=true;
 edit4.Visible:=false;
 form2.Edit5.Text:=intToStr(count);
 edit12.hint:='Saves memory usage (limits sounds addresses list (the "IndexRegister" memory allocation)). Too big value can have destructive effect.';
 Edit13.Enabled:=false;
 groupBox3.Enabled:=false;
 KeyPreview:=true;
 label16.Visible:=false;
 label16.Caption:='=dev/'+#13#10+intToStr(gaussScaler);
 label17.Caption:=''; label17.Left:=panel2.Left; label17.top:=panel2.top;
 label18.Visible:=false;
 label18.caption:='';
 label19.Visible:=false;
 label19.caption:='';
 label20.caption:='';
 label20.Visible:=false;
 form2.Label21.Top:=form2.Panel1.Top+form2.Panel1.Height-form2.Label21.Font.Height+11;
 label23.Hint:='Range of standard deviation for Gauss window with scale factor equal to windows width (count).'+
               #13#10'Write lower and upper limit, comma will be treated as a delimitier, only leading spaces are allowed too';
 if trystrToInt(edit1.Text,i) then
  label24.caption:=label24.caption+' ['+intToStr(round(1000*i/rate))+'ms]';
 label27.Left:= edit6.left;
 label27.Caption:='Cepstrum range'#13#10'(click to show|hide)';
 label36.Visible:=false; label37.Visible:=false;
 Label71.Caption:=form1.Label41.Caption;
 labelsClear_([17..24,27,27,30..37,39,40,45..54]);
 panel6.Visible:=false;
 panel9.Visible:=true;
 panel9.SendToBack;
 RadioGroup7.Hint:='Changing window shape will evoke averaging buffers actualization,'#13#10'thus you will observe jump back on the wave signal';
 RadioGroup8.ItemIndex:=2;
 radioGroup8.Enabled:=checkBox2.Checked;
 upDown3.Hint:='Must be less than "'+label26.Caption+'" div 2';
 InitRead;
 form2.RadioGroup7.ItemIndex:=form1.RadioGroup7.ItemIndex;  //zawiesza�o si� w f1.radio7.click 29012014
 form2.RadioGroup3.ItemIndex:=form2.RadioGroup7.ItemIndex;
 radioGroup3.Enabled:=false;
End;{TForm2.FormCreate}

procedure TForm2.BitBtn1Click(Sender: TObject);
begin
 if soundStart then
 begin
  MediaPlayer1.FileName:=waveFilePath;
  MediaPlayer1.open;
  MediaPlayer1.play;
 end
 else
 begin
  MediaPlayer1.Close;
 end;
 soundStart:= not  soundStart;
end;

procedure TForm2.Edit1Change(Sender: TObject);    //Nbr of samples/jump
 var i:longint;
begin
 exit;
 if not trystrToInt(form2.edit1.text,i) then
 showMessage('Error in '+form2.Label8.Caption+'. The '+form2.edit1.text+' is not an integer');
 jumpNbrSamples:=i;   //dodano showMessage j.w., ale przedtem jumpNbrSamples by�o =0!!!, sytuacj� naprawia�o te� dodanie zmiennej po�rednicz�cej k:byte, k:=i; oraz gdy by�o jumpNbrSamples:=k;
 form1.Edit2.Text:=intToStr(jumpNbrSamples);
 label24.caption:='Best part search range'+' ['+intToStr(round(1000*i/rate))+'ms]';
 manager:='t';
 //with form1 do RadioGroup1.items[0]:='od '+intToStr(-strToInt(edit9.Text)+1)+' przesuwanie okna co '+intTostr(jumpNbrSamples)+' pr�bek';
 //with form1 do RadioGroup1.items[0]:='od '+intToStr(-strToInt(edit9.Text)+1)+' przesuwanie okna co '+intTostr(jumpNbrSamples)+' pr�bek';
 //with form1 do RadioGroup1.items[1]:='od '+intToStr(-(strToInt(edit9.Text) div 2)+1)+ ' przesuwanie okna j.w.';
end;

procedure TForm2.CheckBox1Click(Sender: TObject);            //show graphs
begin
Form1.CheckBox10.Checked:=Form2.CheckBox1.Checked;           //f1.check10: show graphics
if not timeBack then CheckBox2.Checked:=CheckBox1.Checked;   //check2: stepwise performance
setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);
if Form2.CheckBox1.Checked then manager:='R';                //26102023 risk!; in order to show current state on the plots
application.processMessages;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin     //back
 manager:='B';
end;

procedure TForm2.Button4Click(Sender: TObject);
begin   //Next
 T0timeBack:=false;
 CheckBox1.Checked:=true;          //Show graphs
 form1.CheckBox57.Enabled:=false;  //save results as "Analysis records"  (zapisuj rekordy jako: "Rekordy analiz")
 form1.RadioGroup7.Enabled:=false; //Windows shape
 form1.edit15.Enabled:=false;      //Windows shape; % wype�nienia prostok�ta
 form1.edit16.Enabled:=false;      //Windows shape; rozmycie (lba odchyle� std)
 spongeShift:=0;
 manager:='N';
end;

procedure TForm2.Button5Click(Sender: TObject);
begin    //save record
manager:='S';
end;

procedure TForm2.Button6Click(Sender: TObject);
begin    //break
form2.CheckBox2.Checked:=true;    //in order to step into the "stepManager" to perform command break (i.e. "C")
form1.CheckBox60.Checked:=false; // do not hibernate comp
form1.Label90.Font.Color:=clRed;
form1.Label90.Caption:='Click "'+form1.Button3.Caption+'" to load wave signal';
InitWrite;
manager:='C';
end;

procedure TForm2.CheckBox2Click(Sender: TObject);
begin                //wykonanie krokowe (Step performance)
 if not checkbox2.Checked then T0timeBack:=false;
 if checkBox2.Checked then checkbox2.Caption:='Stepwise/continuos performance'
 else checkbox2.Caption:='Continuos/stepwise performance';
 Button2.Enabled :=checkBox2.Checked;  //Back
 Button4.Enabled :=checkBox2.Checked;  //Next
 if button4.CanFocus then button4.SetFocus;
 Button11.Enabled :=checkBox2.Checked; //GoTo
 if reportSave then Button5.Enabled :=checkBox2.Checked;  //Save record
 form1.checkbox57.enabled:=false;      //Analysis vPC
 form1.RadioGroup7.Enabled:=false;     //windows shape
 //form1.edit12.Enabled:=false;        //cepstral lifter point
 form1.edit15.Enabled:=false;          //rectangle filling
 form1.edit16.Enabled:=false;          //gauss smear
 if not timeBack then                                                                 //do not lock Diagnostic Box during averaging actualization when windows parameters are changed
   if not checkBox2.Checked and not checkbox24.Checked then checkbox24.Checked:=true; //check2 - step, check24 - lock D.B.
 if not checkBox2.Checked and not checkbox25.Checked and not timeBack then checkbox25.Checked:=true;   //check25 - lock output
 form2.CheckBox62.Enabled:=checkBox2.Checked;
 button17.Enabled:=false; checkBox76.Checked:=true;
 if manager<>'E' then manager:=#0;     //to leave step mode (aby wyj�� z p�tli wykonywania krokowego (z oczekiwania na klikni�cie Back|Next))
 spongeShift:=0;
 radioGroup8.Enabled:=checkBox2.Checked;
end;

procedure TForm2.Edit2Change(Sender: TObject);     //cepstral lifter treshold
begin
unit1.editChange(Edit2);
manager:='t';//'R'  26102023
end;

procedure TForm2.Button7Click(Sender: TObject);
begin   //repeat
 form2.CheckBox1.Checked:=true;
 manager:='r';
end;

procedure TForm2.Edit24Change(Sender: TObject);//nbr of frames in averaging
 var k:word;
  begin
  if tryStrToInt(Edit24.Text,frameNbr) then
    if frameNbr>0 then
     begin
      frameNbrArr[0]:=frameNbr;
      form1.Edit24.Text:=form2.Edit24.Text
     end
    else showMessage('The "'+Edit24.Text+'" in the "'+label92.Caption+'" must be >0!')
   else
   if (Edit24.Text<>'') and (Edit24.Text<>'-') and (Edit24.Text<>'+') then
    showMessage('The "'+Edit24.Text+'" in the "'+label92.Caption+'" is not an integer!');
   if form1.CheckBox3.Checked then  //multimeanPS analysis
    begin
     maxFrameNbr:=0;   //musi by� od�wie�one na wypadek, gdyby frameNbr okaza�o si� najwi�ksze
     for k:=0 to NbrOfMultiMean do if frameNbrArr[k]>maxFrameNbr then maxFrameNbr:=frameNbrArr[k];
    end
   else maxFrameNbr:=frameNbr; //form1.CheckBox3 - multiMean is on
  // if frameNbr>frameNbr0Arr[0] then
   manager:='t';//cofn�� si�, aby uaktualni� bufor historii u�redniania
  end;

procedure TForm2.Button8Click(Sender: TObject);
begin   //repaint
  // odrysowuje ramki okien po ponownym w��czeniu grafiki
  manager:='R';
end;

procedure TForm2.Edit24Exit(Sender: TObject); //frame nbr in averaging
var k:longint;
begin
 if not tryStrToInt(Edit24.Text,k) then    //tu nie modyfikowa� ju� frameNbr1
  begin
   showMessage('The "'+Edit24.Text+'" in the "'+label92.Caption+'" is not an integer!');
   if Edit24.CanFocus then Edit24.SetFocus
  end;
 manager:='F';
end;

procedure TForm2.Edit24Enter(Sender: TObject);
begin
checkbox2.Checked:=true  //stepwise performance
end;

procedure TForm2.CheckBox4Click(Sender: TObject);
begin
 manager:='R';
end;

procedure TForm2.CheckBox5Click(Sender: TObject);
begin
 manager:='R';
end;

procedure TForm2.CheckBox6Click(Sender: TObject);
begin
 if checkBox6.Checked then PCrange:=8*PCrange0 //by�o 5000
 else  PCrange:=PCrange0;                      //by�o 700
  manager:='R';
end;

procedure TForm2.Button9Click(Sender: TObject);
begin
form2Scaler;
end;

procedure TForm2.FormResize(Sender: TObject);
begin
 form2.Panel1.Width:=width-form2.Panel1.left-60;
 manager:='R';//framesRepaint(count_cp);
end;

procedure TForm2.CheckBox23Click(Sender: TObject);
begin
Form1.CheckBox6.checked:=CheckBox23.checked;
end;

procedure TForm2.RadioGroup7Click(Sender: TObject);   //windows shape
begin
// if winNbr<>RadioGroup7.ItemIndex then f2Radio7Changed:=true; blokada 28042014 aby unikn�� 2. wo�ania wag w AnalysisPerformer
 winNbr:=RadioGroup7.ItemIndex;
 form1.RadioGroup7.ItemIndex:=winNbr; form1.RadioGroup3.ItemIndex:=winNbr;
 if winNbr=1 then    //Gauss window
  begin
   label16.Visible:=true; label36.Visible:=true; label37.Visible:=true;
   label16.Caption:='=dev*'+#13#10+intToStr(gaussScaler);
   edit4.Visible:=true;
  end
 else
  begin
   label16.Visible:=false; label36.Visible:=false; label37.Visible:=false;
   edit4.Visible:=false;
  end;
 form2.label19.Visible:=true;
 if not form2.checkbox72.Checked then
 form2.label19.Caption:='Weighting window "'+form2.RadioGroup7.Items[form2.RadioGroup7.itemIndex]+'"';
 edit13.Enabled:=radioGroup7.ItemIndex=1;
 manager:='t';
end;

procedure TForm2.RadioGroup2Click(Sender: TObject);  //filters shape
begin
form2.label18.Visible:=true;
form2.label18.Caption:='Filter shape';
label18Caption:=form2.label18.Caption;
form1.RadioGroup2.ItemIndex:=form2.RadioGroup2.ItemIndex;
form1.RadioGroup2Click(sender);
manager:='t';
end;

procedure panel2Stretch;
 var check82, check83 : boolean;
 Begin
  with form2 do
   begin  //function S
    check82:=checkBox82.Checked or checkBox18.Checked;
    check83:=checkBox83.Checked or checkBox19.Checked;
    if check82 or (not checkBox7.Checked and check83 and not check82)  then  //08122023 block  27012024 unblock
      begin
       panel2Decimals:=3;
       f2Panel2Stretch:= high(smallInt)/10000   //=ca (1.5*totalSignalStDev)
      end
    else
     begin
      panel2Decimals:=0;
      f2Panel2Stretch:= high(smallInt);
     end;
   end{with}
 End;{panel2Stretch}

procedure TForm2.CheckBox7Click(Sender: TObject);     //original signal
begin
 setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);  //Needed analyses turn on
 SaveCheckEnabler(not form2.checkBox25.Checked);
 label7Show;
 panel2Stretch;
 manager:='R';
end;

procedure TForm2.CheckBox25Click(Sender: TObject);//lock output
 var logos:boolean;
begin
 logos:=not form2.CheckBox25.Checked;    //lock output
 if not checkbox25.Checked then checkbox2.Checked:=true;//turn on stepwise analysis when outputs are closed
 with form2 do                //Stepwise|continuos performance
  begin//enable|disable checkboxes 31-45, i.e. visualization.output
   checkbox31.Enabled:=logos; checkbox82.Enabled:=logos; checkbox83.Enabled:=logos;//rare|weighed signal portions
   checkbox32.Enabled:=logos; checkbox84.Enabled:=logos; //PS
   checkbox33.Enabled:=logos; checkbox85.Enabled:=logos; //sPS
   checkbox34.Enabled:=logos; checkbox86.Enabled:=logos; //msPS
   checkbox35.Enabled:=logos; checkbox87.Enabled:=logos; //vPS
   checkbox36.Enabled:=logos; checkbox88.Enabled:=logos; //cPS
   checkbox37.Enabled:=logos;
   checkbox38.Enabled:=false; //avPS
   checkbox39.Enabled:=false; //acPS
   checkbox40.Enabled:=false; //aPC
   checkbox41.Enabled:=logos; checkbox89.Enabled:=logos;  //PC
   checkbox42.Enabled:=logos; checkbox90.Enabled:=logos;  //mPC
   checkbox43.Enabled:=logos; checkbox91.Enabled:=logos;  //vPC
   checkbox44.Enabled:=logos; checkbox92.Enabled:=logos;  //cPC
   checkbox45.Enabled:=logos; {checkbox93.Enabled:=logos; } //multimean Output, multimean normalization, logos=not lock output
   radiogroup4.enabled:=checkbox45.enabled;
   if checkBox25.Checked then CheckBox81.Enabled:=false; //block with the "lock" checkbox81 = "Force F0 calculation"
  end;
 SaveCheckEnabler(logos);
 if standOnOff then     //start from scratch due to standardising changes i.e. f2.checkBox 82-93 or f1.checkBox 29-39
  begin
   standOnOff:=false;
   manager:='E'
  end;
 form2.checkbox62.Checked:=not form2.CheckBox25.Checked;
 Application.ProcessMessages;
 if not checkBox25.Checked then
  showMessage('Any change in the outputs streams content will start analysis from scratch.'#13#10+
  'Nothing, but a report additions, will be saved when the "'+checkBox25.Caption+'" is not checked');
 //spcSave:=checkBox25.Checked;   22012024
end; {CheckBox25Click}

procedure outCheckSynchro(out Check1:TcheckBox; const check2:TcheckBox);
//synchronizes the "output" check boxes from form1 and form2
 Begin
  Check1.Checked :=check2.Checked;
  if not check2.Checked then check2.Caption:='';                                       //change in output streams has happened, begin analysis from scratch
  SaveCheckEnabler(not form2.checkBox25.Checked);
  manager:='E';
 End;{outCheckSynchro}

procedure TForm2.CheckBox31Click(Sender: TObject);
begin
outCheckSynchro(form1.CheckBox5,form2.CheckBox31);
//if not checkBox31.checked then checkBox31.caption:='';
end;

procedure TForm2.CheckBox32Click(Sender: TObject);
begin
outCheckSynchro(form1.CheckBox40,form2.CheckBox32);
//if not checkBox32.checked then checkBox32.caption:='';
end;

procedure TForm2.CheckBox33Click(Sender: TObject);
begin
outCheckSynchro(form1.CheckBox41,form2.CheckBox33);
//if not checkBox33.checked then checkBox33.caption:='';
end;

procedure TForm2.CheckBox34Click(Sender: TObject);
begin
 outCheckSynchro(form1.CheckBox44,form2.CheckBox34); //form1.CheckBox44.Checked:=form2.CheckBox34.Checked;
 //if not checkBox34.checked then checkBox34.caption:='';
end;

procedure TForm2.CheckBox35Click(Sender: TObject);
begin
outCheckSynchro(form1.CheckBox43,form2.CheckBox35);
//if not checkBox35.checked then checkBox35.caption:='';
end;

procedure TForm2.CheckBox36Click(Sender: TObject);
begin
outCheckSynchro(form1.CheckBox42,form2.CheckBox36);
//if not checkBox36.checked then checkBox36.caption:='';
end;

procedure TForm2.CheckBox37Click(Sender: TObject);
begin
outCheckSynchro(form1.CheckBox4,form2.CheckBox37);
//if not checkBox37.checked then checkBox37.caption:='';
end;

procedure TForm2.CheckBox41Click(Sender: TObject);
begin
outCheckSynchro(form1.CheckBox45,CheckBox41);
//if not checkBox41.checked then checkBox41.caption:='';
end;

procedure TForm2.CheckBox42Click(Sender: TObject);
begin
outCheckSynchro(form1.CheckBox48,form2.CheckBox42);
//if not checkBox42.checked then checkBox42.caption:='';
end;

procedure TForm2.CheckBox43Click(Sender: TObject);
begin  //check47 = f1.time varying PC, check43 = vPC
outCheckSynchro(form1.CheckBox47,form2.CheckBox43);
//if not checkBox43.checked then checkBox43.caption:='';
end;

procedure TForm2.CheckBox44Click(Sender: TObject);
begin   //cPC
outCheckSynchro(form1.CheckBox46,form2.CheckBox44);
//if not checkBox44.checked then checkBox44.caption:='';
end;


procedure checkOutOff;
 Begin
  with Form2 do
   begin
    //input     wav             PS                         aPS
     checkbox31.checked:=false; checkbox32.checked:=false; checkbox37.checked:=false;
    //sPS                       mPS                        PC
     checkbox33.checked:=false; checkbox34.checked:=false; checkbox41.checked:=false;
    //mPC                       cPS
     checkbox42.checked:=false; checkbox36.checked:=false;
    //cPC                       vPC                        vPS
     checkbox44.checked:=false; checkbox43.checked:=false; checkbox35.checked:=false;
    end;
 End;{checkOutOff}

procedure TForm2.CheckBox45Click(Sender: TObject);
begin       //mmcPS
 outCheckSynchro(form1.CheckBox49,CheckBox45);
 //if not checkBox45.checked then checkBox45.caption:='';
 if checkbox45.Checked then checkOutOff;  //28112023
 edit24.Text:='3';
 setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);
 case form2.radiogroup4.ItemIndex of
  0: checkbox35.checked:=true; //vPS
  1: checkbox36.checked:=true; //cPS
  2: checkbox43.checked:=true; //vPC
  3: checkbox44.checked:=true; //cPC
 end;{case output}
 application.ProcessMessages; //debug prp
 case form2.radiogroup4.ItemIndex of
  0, 1:begin bundleRange:=PSrange; bundlePanel:=3 end;
  2, 3:begin bundleRange:=PCrange; bundlePanel:=4 end;
 end;{case, range}
 case form2.radiogroup4.ItemIndex of
  0, 2:bundleColor:=streamsGraphColors[5];//clYellow;
  1, 3:bundleColor:=streamsGraphColors[4]//clGreen;
 end;{case color}
 radiogroup4.Visible:=checkbox45.Checked;
 radiogroup4.enabled:=checkbox45.enabled;
 application.ProcessMessages;  //debug prp
 outCheckSynchro(form1.CheckBox49,form2.CheckBox45);
 //if not checkBox45.checked then checkBox45.caption:='';
 checkBox93.Checked:=bundleStand;
 checkBox93.enabled:=checkBox45.checked;
end;{CheckBox45Click}

procedure TForm2.Button10Click(Sender: TObject);
begin
 manager:='H';
end;

procedure TForm2.CheckBox24Click(Sender: TObject);  //lock the Diagnostic Box
begin
 GroupBox1.Enabled:=not checkBox24.Checked;
 if not checkbox24.Checked then checkbox2.Checked:=true;//turn on stepwise analysis when Diagnostic Box became opened
 if not windowsSearching then
 if form2.CheckBox24.Checked then
  if messageDlg('Restart from scratch (due to relocking the "Diagnostic Box")?'#13#10'- it is a must if you have changed the sweeping windows width!',mtWarning,mbYesNo,0)=mrYes then
   begin
    manager:='E'              //start analysis from scratch
   end
  else
 else showMessage('After locking you will be offered to restart analysis from scratch'#13#10'- it is a must if you have changed the sweeping windows width!');
 checkBox75.visible:=not checkBox24.Checked;
 if form2.checkbox24.Checked then
  begin
   form2.checkbox18.Checked:=false;  //Normalize original input signal
   form2.checkbox19.Checked:=false;  //Normalize weighed input signal
   form2.checkbox20.Checked:=false;  //Normalize PS before cepstrum comp.
   form2.checkbox21.Checked:=false;  //-40 dB
   form2.checkbox22.Checked:=false;  //const 60 dB
   form2.checkbox63.Checked:=false;  //const 90 dB
   form2.checkbox80.Checked:=false;  //sinus harmonics
   form2.RadioGroup2.ItemIndex:=0;
  end;
 form2.checkbox62.Checked:=True;     //Averaging Show
 form2.checkbox1.Checked:=True;      //Show graphs
end;

procedure TForm2.Edit4Change(Sender: TObject);   //Gauss windows standard deviation change
begin
 f2Radio7Changed:=true;
 if not checkBox24.Checked then if edit4.CanFocus  then edit4.SetFocus; //if not.. because of error "can not focus on diasabled control..."
 manager:='t';
end;

procedure TForm2.CheckBox61Click(Sender: TObject);
begin
 button6.Enabled:=not checkBox61.Checked;
end;

procedure TForm2.UpDown4Click(Sender: TObject; Button: TUDBtnType);
type TlineColor=array[1..1000] of Tcolor;
var color:Tcolor;

 function getLine(const length:word):TlineColor;
  var  i:word;
  Begin
   for i:=1 to length do getLine[i]:=Canvas.Pixels[myCursorPos.x,myCursorPos.y+i];
  End;

 function putLine(const length:word;line:TlineColor):boolean;
  var  i:word;
  Begin
   for i:=1 to length do setPixel(hdc(0), myCursorPos.x,myCursorPos.y+i,Line[i]);
  End;
var line:tlineColor;
begin
 line:=getLine(form2.Panel4.Height);
  form2.Canvas.Pen.Color:=clOlive;
  form2.Canvas.moveTo(myCursorPos.X,myCursorPos.y);                                           //--------------------ten kolor nie jest aktywowany!
  form2.Canvas.lineTo(myCursorPos.X,myCursorPos.Y+height);
  putLine(form2.Panel4.Height,line);
end;

procedure TForm2.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
 var  graphNbr:byte;
      r : double;
procedure labelColor(labelx:Tlabel);
 var color:Tcolor;
 begin
  Color:=Canvas.Pixels[myCursorPos.x,myCursorPos.y];
  labelx.Color:=color;
  labelx.font.Color:=clblack;
  if color=clBlack then labelx.font.Color:=clWhite;
  application.ProcessMessages;
 end;
var ms,Hz:single;
Begin //----------------------------------------------------- TForm2.FormMouseMove -----------------------------------
 graphNbr:=1;
 GetCursorPos(myCursorPos);
 with form2,myCursorPos do
  begin
   label21.caption:='(x, y)=('+intToStr(x)+', '+intToStr(y)+')';
   y:=y-form2.Top-22-5;//8; 26112022            //the coursor position should be decreased at 22 probably because the cursorPos shows position on a screen; 22 is a height of the caption.form2  (pozycja kursora musi by� pomniejszona 0 22 prawdopodobnie, bo Cursor pos wskazuje pozycj� na ekranie, a 22, to szeroko�� caption.form2)
   x:=x-form2.Left-4;//8; 26112022             //analogously as above (j.w., +8, bo wykrywane w programie (Windows7) form2.top=-8, a form2.left=-8)  and -5, -4 for Windows10
   labelColor(form2.label17);
  try
     if (x<=panel1.Left+panel1.Width) and (y>panel1.top) and (y<=panel1.Top +panel1.Height) then
    begin
     inc(graphNbr); label17.Visible:=true;
     r:=(x-panel1.Left)/wspx1; x:=round(r+0.5); y:=y-panel1.Top; if y<=0 then y:= 1;

     ms:=(rate/1000)*y/(wspy1*count); Hz:=1000/ms;
     label17.top:=panel1.top+panel1.height-16; label17.Left:=panel1.Left+10;  //top must be first evaluated because on the panel2 appeares a patch
     label17.Caption:=floatToStrF(y/(rate*wspy1/1000),ffFixed,8,3)+'ms='+floatToStrF(rate*wspy1/y,ffFixed,8,3)+'Hz';
     label17.Caption:='slice nbr '+intToStr(x+T0sliceNbrGlob)+' = '+floatToStrF((x+T0sliceNbrGlob)*wspx1*JumpNbrSamples/rate,ffFixed,8,2)+'s, '+
     'T0 = '+floatToStrF(ms,ffFixed,8,3)+'ms='+intToStr(round(Hz))+'Hz';  //intToStr(round(1000*wspy1/y))   round(0.1/((wspy1*2*count)/(rate*y)))
    end                                                                            //  round((rate*y)/((wspy1*20*count)))
   else
   if (x<=panel2.Left+panel2.Width) and (y>=panel2.top) and (y<=panel2.Top +panel2.Height) then
    begin
     inc(graphNbr); label17.Visible:=true;
     r:=(x-panel2.Left)/wspx2;
     label17.top:=panel2.top+14; label17.Left:=panel2.Left+10;  //top must be first evaluated because on the panel2 appeares a patch
     label17.Caption:= 'Origins time: '+floatToStrF(r+iGlob,ffFixed,8,0)+' pts, ie '+floatToStrF((r+iGlob)/rate,ffFixed,4,3)+'s;'
      +' locals: time='+floatToStrF(r,ffFixed,8,1)+' pts, i.e. '+floatToStrF(r*1000/rate,ffFixed,8,4)+' ms, ampl.='+
      floatToStrF(-(y-centr2)/wspy2,ffFixed,8,4);// intToStr(round(-(y-centr2)/wspy2));
    end
   else

   if (x<=panel3.Left+panel3.Width) and (y>=panel3.top) and (y<=panel3.Top +panel3.Height) then
    begin
     inc(graphNbr); label17.Visible:=true;
     label17.top:=panel3.top+2; label17.Left:=panel3.Left+10;
     r:=(x-panel3.Left)/wspx3;
     if r/count>0.5 then r:=r-count;       //first half is placed in negative frequency area
     label17.Caption:=intToStr(round(r))+',  '+floatToStrF(r*rate/count,ffFixed,8,0)+'Hz, '+floatToStrF((-(y-centr3)/wspy3),ffFixed,8,2);//intToStr(round(-(y-centr3)/wspy3)); //-panel2.top
     if form2.CheckBox3.Checked then label17.Caption:=label17.Caption+' Np' else label17.Caption:=label17.Caption+' dB';
    end
   else

   if (x<=panel4.Left+panel4.Width) and (y>=panel4.top) and (y<=panel4.Top +panel4.Height) then
    begin
     inc(graphNbr); label17.Visible:=true;
     label17.top:=panel4.top+2;label17.Left:=panel4.Left+10;
     r:=(x-panel4.Left)/wspx4;
     if r>(count div 2) then r:=r-count;      //first half is placed in negative quefrency area
     label17.Caption:=intToStr(x)+' x; '+floatToStrF(r,ffFixed,8,3)+'pt.,  '+floatToStrF(1000*(r)/rate,ffFixed,8,3)+'ms'; //-panel2.top   r-1 041218
     if r>0 then label17.caption:=label17.caption+'='+floatToStrF((rate/r),ffFixed,8,3)+'Hz. ';
     label17.caption:=label17.caption+' Cepstr. ampl.='+floatToStrF((-(y-centr4)/wspy4),ffFixed,8,3);
    end
   else

   if (x<=panel5.Left+panel5.Width) and (y>=panel5.top) and (y<=panel5.Top +panel5.Height) then
    begin
     inc(graphNbr); label17.Visible:=true;
     r:=(x-panel5.Left)/wspx5;
     if r/count>0.5 then r:=r-count;
     label17.Left:=panel5.Left+10; label17.top:=panel5.top+2;
     label17.Caption:=intToStr(round(r))+',  '+floatToStrF(r*rate/count,ffFixed,8,0)+'Hz, '+floatToStrF((-(y-centr5)/wspy5),ffFixed,8,2)+' rad = '+floatToStrF(180*(-(y-centr5)/wspy5)/pi,ffFixed,8,2)+' grad'; //-panel2.top
    end
   else

     if (x>=panel6.Left-2) and(x<=panel6.Left+panel6.Width) and (y>=panel6.top) and (y<=panel6.Top +panel6.Height) then
    begin
     inc(graphNbr);label17.Visible:=false;
     labelColor(form2.label18);
     r:=(x-panel6.Left)/wspx6;
     //label18.Caption:='('+intToStr(x)+', '+intToStr(y)+')= ('+floatToStrF(x*rate/count,ffFixed,8,0)+'Hz, '+floatToStrF((-(y-centr6)/wspy6+2.9+0.96),ffFixed,8,3)+')'; //+2.9 not explained yet
     label18.Caption:='('+intToStr(round(r))+', '+intToStr(y)+')= ('+floatToStrF(r*rate/count,ffFixed,8,0)+'Hz, ';
     r:=(panel6.Height*y)/(wspy6*(-panel6.Height))+1-(panel6.Height*panel6.Top)/(wspy6*(-panel6.Height));
     if form2.CheckBox65.Checked then r:=r-1; //dB
     label18.Caption:=label18.Caption+floatToStrF(r,ffFixed,8,3)+')'; //+2.9 not explained yet  (y/wspy6-panel6.Top-panel6.Height)
     if form2.CheckBox65.Checked then label18.Caption:=label18.Caption+'dB)'
     else label18.Caption:=label18.Caption+')';
    end
   else

   if  (x>=panel8.Left) and(x<=panel8.Left+panel8.Width) and (y>=panel8.top) and (y<=panel8.Top +panel8.Height) then
    begin
     inc(graphNbr); label17.Visible:=false;
     labelColor(form2.label19);
     r:=(x-panel8.Left)/wspx8;
     label19.Caption:='('+intToStr(round(r))+', '+intToStr(y)+')= ('+floatToStrF(1000*r/rate,ffFixed,8,3)+'ms, '+
      floatToStrF((-(y-centr8/1000-panel8.top-panel8.height)/wspy8),ffFixed,8,3)+')';
    end
   else

    begin
    label17.Visible:=false;
    label17.top:=panel2.top+16; label17.Left:=panel2.Left+10; //must be in order not to have patch on the "filter" graph
    label18.Caption:=label18Caption;                         //in order to restore actual graph description, i.e. 'Filters shape'|'Weights spectrum'
    label19.Caption:='Weighting windows shape';
    end;
  except
   (*showMessage('There is some error in procedure "TForm2.FormMouseMove". Check it or turn to the author.'#13#10+
   'Probably some scaling coefficient (i.e. wspx# or wspy#)) of a panel area  being inspected (for the graph nbr '+intTostr(graphNbr)+')  is equal to 0'); ;*)
  end;
  end;{with}
End;{TForm2.FormMouseMove}

procedure TForm2.CheckBox62Click(Sender: TObject);   //augmentx4
begin
// if checkBox62.Checked then PSrange:=PSrange0 div 4
// else PSrange:=PSrange0;
PSrange:=PSrange div 4;
 manager:='R'
end;

 procedure repaintORrepeat;
  begin   //check64="Repaint|Repeat"
   if form2.checkbox64.Checked then manager:='R' else manager:='r';
  end;

procedure TForm2.CheckBox18Click(Sender: TObject);
begin  //Normalize input; Diagnostic box
 manager:='T';//'t'
end;

procedure TForm2.CheckBox19Click(Sender: TObject);
begin    //Normalize weighed input; Diagnostic box
manager:='T';  //'t'
end;

procedure TForm2.CheckBox21Click(Sender: TObject);
begin
 repaintORrepeat;
end;

procedure TForm2.CheckBox22Click(Sender: TObject);
begin
 if checkBox22.Checked then checkbox63.Checked:=false;
 repaintORrepeat;
end;

procedure TForm2.CheckBox20Click(Sender: TObject);
begin //Normalize PS before cepstrum computation (Diagn. box)
 manager:='T';//'t';
end;

procedure TForm2.CheckBox3Click(Sender: TObject);
begin   //Np|dB
 if form2.CheckBox3.Checked then
  begin
   PSrange:=10;
   PCrange:=PCrange0 div 8;
  end
 else
  begin
   PSrange:=PSrange0;
   PCrange:=PCrange0;
  end;
 manager:='e';
end;

procedure TForm2.CheckBox30Click(Sender: TObject);
begin
// cPS vPS sPS[0]:=0; 27102023
manager:='T';    //27102023
end;

procedure TForm2.CheckBox63Click(Sender: TObject);
begin
 if checkBox63.Checked then checkbox22.Checked:=false;
 repaintORrepeat;
end;

procedure TForm2.FormActivate(Sender: TObject);
begin
 if button4.CanFocus then button4.SetFocus;
 computeFilter;
 WindowsWeights(winNbr,gaussStDev,windowWeights,WeightMean,count);
end;

procedure TForm2.CheckBox65Click(Sender: TObject);
begin
 if form2.label18.Caption='Windows weights spectrum' then
  begin
   windowsWeightsSpectrDraw(windowWeights);
  end
 else
  begin
  form2.label18.Caption:='Filters shape';
  filterDraw(filter,form2,form2.panel6,form2.label18,clBlack,wspx6,wspy6,centr6);
  end;
 label18Caption:=label18.Caption;
end;

procedure GaussFileOpen;
 var tmp1,tmp2:pathStr;
 Begin
  GaussSearchFilePath:=fileDir+'\'+FileName+'GaussSearch.txt';
 repeat
{8,save}  gausSave:=whereSave(GaussSearchFilePath,'Save gaussian windows searching results only into eg. "'+fileDir+'\'+fileName+'GaussSearch','txt');
  if gausSave then begin
{9=5}  fileDateSize(GaussSearchFilePath,tmp1,tmp2); form1.label63.caption:=tmp1; form1.label62.caption:=tmp2;application.ProcessMessages;
   form1.label61.Caption:=GaussSearchFilePath;
   assignFile(GaussSearchFile,GaussSearchFilePath);
   rewrite(GaussSearchFile);
   writeln(GaussSearchFile,'Results of analysis of the Gauss weigts window');
   flush(GaussSearchFile);
  end{if}
  else
  if MessageDlg(pchar('[openFiles], Analysis results of the Gauss window search, i.e. "'+GaussSearchFilePath+'" will not be saved, it is a must for the'+
     ' WindowsSearch procedure.'#13#10'You can retry or abort to continue with no saving.'),
      mtWarning,[mbRetry,mbAbort],1)=3  //retry=4, abort=3 yes=6
   then break;
 until gausSave;
 End;

procedure TForm2.Button12Click(Sender: TObject);    //Windows search
begin
 if button12.Caption=butt12Caption then
 begin
  if button4.CanFocus then button4.SetFocus;
  GaussFileOpen;  //28112023
  checkBox74.Checked:=true;   //lock "windows search" groupBox
  checkBox75.visible:=true;
  checkBox75.Checked:=true;
  rectFill:=count div 2 -1;
  form2.edit7.text:=intToStr(rectFill);
  windowsSearch(nbrOfData,true);
  NormCheckBoxesStatesToReport;
  checkBox74.Checked:=false;
 end
 else button12.Caption:=butt12Caption;    //to break this procedure performance (with cooperation with the caption changing in it)
end;

procedure TForm2.CheckBox2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 check2:=CheckBox2.Checked;
end;

procedure TForm2.CheckBox2MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  check2:=CheckBox2.Checked;
end;


procedure TForm2.Edit8Change(Sender: TObject);
begin
 InitWrite;
end;

procedure TForm2.CheckBox69Click(Sender: TObject);
begin
  checkbox70.Visible:=checkBox69.Checked;
end;

procedure TForm2.CheckBox72Click(Sender: TObject);
begin
 if checkbox72.Checked then checkbox78.Checked:=true;
 application.processMessages;
end;

procedure TForm2.Edit5Exit(Sender: TObject);
begin  //windows width
 try
  fft_par(Edit5,form1.Edit9); //compute adequate fft parameters (i.e. weights, sin, cos arrays, RAM allocations etc.)
  timeBack:=true;
 except
 end;
end;

procedure TForm2.Edit6Exit(Sender: TObject);
begin
 pcRange0:=PCrange;
 try
 pcRange:=strToInt(edit6.text);
 manager:='R';
 application.ProcessMessages;
 except
  on Exception : EConvertError do
  ShowMessage(Exception.Message);
 end;
end;

procedure TForm2.CheckBox73Click(Sender: TObject);
begin
button1.Enabled:=not checkBox73.Checked;
end;

procedure TForm2.CheckBox74Click(Sender: TObject);
begin
GroupBox3.Enabled:=not checkBox74.Checked;
end;

procedure TForm2.Label27Click(Sender: TObject);
begin
 edit6.Visible:= not edit6.Visible;
 with edit6 do
 if edit6.Visible then
  begin
   Text := floatToStrF(PCrange,ffFixed,10,2);
   label27.Left:= left+width+3;
   label27.Caption:='Click e.g.'#13#10+'"'+button8.Caption+'"'#13#10'to execute'
  end
  else
   begin
   label27.Left:= left;
   label27.caption:='Cepstrum range'#13#10'(click to show|hide)'
  end;
end;

procedure TForm2.Edit13Exit(Sender: TObject);
begin    //gauss scaler
 try
  gaussScaler:=strToint(edit13.Text);
  gaussStdev:=strToInt(form2.Edit4.Text)/gaussScaler;
  if winNbr=1 then WindowsWeights(winNbr,gaussStDev,windowWeights,WeightMean,count);
  label16.Caption:='=dev*'+#13#10+intToStr(gaussScaler);
 except
  on Exception : EConvertError do
  ShowMessage(Exception.Message);
 end;
 manager:='t'
end;

function TaskBarHeight:integer;
  var R: TRect;
begin
  SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);
  result:=Screen.Height - R.Bottom + R.Top;
 // ShowMessage(IntToStr(result));
end;

procedure TForm2.Memo2Click(Sender: TObject);
begin
 if memo2.height=80 then memo2.height:=height-memo2.top-TaskBarHeight else memo2.Height:=80;
 memo2.BringToFront;
end;

procedure TForm2.Memo1Click(Sender: TObject);
begin
 if memo1.height=80 then memo1.height:=height-memo1.top-TaskBarHeight else memo1.Height:=80;
 memo1.BringToFront;
 TaskBarHeight;
end;

procedure TForm2.Button11Click(Sender: TObject);
begin
 manager:='G';
end;

procedure TForm2.CheckBox75Click(Sender: TObject);
begin //show averaging                                                 //26052014
 if timeBack then form2.CheckBox1.Checked:=form2.CheckBox75.Checked;  //check1=show graphs; aby przerwa� show averaging przy wy��czeniu show graphs
 application.processmessages;                                        //if timeBack, bo wy��czenie show graphs gdy program czeka w trybie "step" powoduje prze��czenie si� na tryb continuos i towarzysz�ce zamkni�cie Diagnostic Box
end;

procedure TForm2.Edit11Change(Sender: TObject);   //in Windows search
 begin
  if windowsSearching then exit;
  if tryStrToInt(Edit11.Text,frameNbr) then
     if frameNbr>0 then
      begin
       frameNbrArr[0]:=frameNbr;
       form2.Edit24.Text:=form2.Edit11.Text
      end
     else showMessage('The "'+Edit11.Text+'" in the "'+label9.Caption+'" must be >0!')
    else
    if (Edit11.Text<>'') and (Edit11.Text<>'-') and (Edit11.Text<>'+') then
     showMessage('The "'+Edit11.Text+'" in the "'+label9.Caption+'" is not an integer!');
    maxFrameNbr:=frameNbr;
    manager:='t';//cofn�� si�, aby uaktualni� bufor historii u�redniania
end;

procedure TForm2.Edit11Exit(Sender: TObject);
begin
 if not tryStrToInt(Edit11.Text,k) then    //tu nie modyfikowa� ju� frameNbr1
   begin
    showMessage('The "'+Edit11.Text+'" in the "'+label9.Caption+'" is not an integer!');
    if Edit11.CanFocus  then Edit11.SetFocus
   end;
 manager:='F';
end;

procedure TForm2.Edit11Enter(Sender: TObject);
begin
checkbox2.Checked:=true  //stepwise performance
end;



procedure edit7Changes;
 begin
  f2Radio7Changed:=true;
  rectFill:=strToInt(form2.Edit7.Text) mod (count div 2);
  if rectFill<1 then rectFill:=1;
  form2.edit7.Text:=intToStr(rectFill);
  form1.Edit15.Text:=form2.edit7.Text; rectWinFill:=strTofloat(form1.Edit15.text);
  manager:='t';
 end;

procedure TForm2.Edit7Exit(Sender: TObject);
begin
edit7Changes;
end;

procedure TForm2.UpDown3Click(Sender: TObject; Button: TUDBtnType);
begin
 edit7Changes;
end;

procedure TForm2.Edit4Exit(Sender: TObject);
begin
 f2Radio7Changed:=true;
 manager:='t';
end;

procedure TForm2.Label36Click(Sender: TObject);
begin
 label36.Color:=clred;    Application.ProcessMessages;
 sleep(100);
 gaussStDevUnscalled:=strToInt(edit4.Text);
 inc(gaussStDevUnscalled);
 edit4.Text:=intToStr(gaussStDevUnscalled);
 f2Radio7Changed:=true;    //windows shape  compute and show
 label36.Color:=clyellow;
 manager:='t';
end;

procedure TForm2.Label37Click(Sender: TObject);
begin
 label37.Color:=cllime;   Application.ProcessMessages;
 sleep(100);
 gaussStDevUnscalled:=strToInt(edit4.Text);
 if gaussStDevUnscalled>0 then dec(gaussStDevUnscalled);
 edit4.Text:=intToStr(gaussStDevUnscalled);
 f2Radio7Changed:=true;
 label37.Color:=clyellow;
 manager:='t';
end;

procedure TForm2.CheckBox76Click(Sender: TObject);
begin
(*// if checkBox76.Checked then PSrange:=PSrange0*2
// else PSrange:=PSrange0;
PSrange:=PSrange*2;
 manager:='R'   *)
 button17.enabled:=not checkBox76.checked; //28102023
end;

procedure TForm2.CheckBox77Click(Sender: TObject);
begin
 checkbox72.Checked:=false;
 f2Radio7Changed:=true;    //windows shape  compute and show
 manager:='t';
end;

procedure TForm2.CheckBox78Click(Sender: TObject);
begin
 if checkbox78.Checked then checkbox72.Checked:=true;
 application.processMessages;
end;

procedure TForm2.CheckBox80Click(Sender: TObject);
begin
  if CheckBox80.Checked then
   begin
    edit14.Text:=IntTostr(harmSpace);//'space'
    edit15.Text:=IntTostr(harmBiass);//'biass'
    edit16.Text:=IntTostr(harmNbr);  //'harm nbr'
   end
  else
   begin
    edit14.Text:='space';
    edit15.Text:='biass';
    edit16.Text:='harm nbr';
    edit14.Color:=clLime; edit15.Color:=clLime; edit16.Color:=clLime;
   end;
  edit14.Enabled:=CheckBox80.Checked; edit15.Enabled:=CheckBox80.Checked; edit16.Enabled:=CheckBox80.Checked;
  repaintORrepeat;
end;

procedure TForm2.Edit14Exit(Sender: TObject);
begin
 harmSpace:=strToInt(edit14.Text);
end;

procedure TForm2.Edit15Exit(Sender: TObject);
begin
  harmBiass:=strToInt(edit15.Text);
end;

procedure TForm2.Edit16Exit(Sender: TObject);
begin
 harmNbr:=strToInt(edit16.Text);
 if harmNbr<1 then begin harmNbr:=1; edit16.Text:='1' end;
end;

procedure TForm2.Label39Click(Sender: TObject);
begin
 label39.Color:=clred;    Application.ProcessMessages;
 sleep(100);
 if edit14.color=clRed then  begin harmSpace:=strToInt(edit14.Text); inc(HarmSpace); edit14.Text:=intToStr(HarmSpace) end;  //label inc|dec click does not evoke onExit event !!!
 if edit15.color=clRed then  begin harmBiass:=strToInt(edit15.Text); inc(HarmBiass); edit15.Text:=intToStr(HarmBiass) end;
 if edit16.color=clRed then  begin harmNbr:=strToInt(edit16.Text);     inc(HarmNbr); edit16.Text:=intToStr(HarmNbr)   end;
 label39.Color:=clLime;
 manager:='t';
end;

procedure TForm2.Label40Click(Sender: TObject);
begin
 label40.Color:=clred;    Application.ProcessMessages;
 sleep(100);
 if edit14.color=clRed then begin harmSpace:=strToInt(edit14.Text);                    dec(HarmSpace); edit14.Text:=intToStr(HarmSpace) end;
 if edit15.color=clRed then begin harmBiass:=strToInt(edit15.Text);                    dec(HarmBiass); edit15.Text:=intToStr(HarmBiass) end;
 if edit16.color=clRed then
  begin
   harmNbr:=strToInt(edit16.Text);
   if harmNbr<1 then begin harmNbr:=1; edit16.Text:='1' end;
   if harmNbr>1 then  dec(HarmNbr);
   edit16.Text:=intToStr(HarmNbr)
  end;
 label40.Color:=clLime;
 manager:='t';
end;

procedure TForm2.Edit14Enter(Sender: TObject);
begin
 edit14.Color:=clRed;
 edit15.color:=clLime;edit16.color:=clLime;
end;

procedure TForm2.Edit15Enter(Sender: TObject);
begin
 edit15.Color:=clRed;
 edit14.color:=clLime;edit16.color:=clLime;
end;

procedure TForm2.Edit16Enter(Sender: TObject);
begin
 edit16.Color:=clRed;
 edit14.color:=clLime;edit15.color:=clLime;
end;

procedure TForm2.Label64Click(Sender: TObject);  //----------cath1Name will be changed in the form1.edit3' "OnChange" event
begin
 form1.edit3.Text:=inputBox('enter new name of the cathegory','Cath. 1 Name',cathNameArr[1]);
 label64.Caption:=cathNameArr[1];
 initWrite;
end;

procedure TForm2.Label66Click(Sender: TObject);  //----------cath2Name will be changed in the form1.edit4' "OnChange" event
begin
 form1.edit4.Text:=inputBox('enter new name of the cathegory','Cath. 2 Name',cathNameArr[2]);
 label66.Caption:=cathNameArr[2];
 initWrite;
end;

procedure TForm2.Label70Click(Sender: TObject);  //----------cath3Name will be changed in the form1.edit6' "OnChange" event
begin
 form1.edit6.Text:=inputBox('enter new name of the cathegory','Cath. 3 Name',cathNameArr[3]);
 label70.Caption:=cathNameArr[3];
 initWrite;
end;

procedure TForm2.Label5Click(Sender: TObject);   //----------cath4Name will be changed in the form1.edit7' "OnChange" event
begin
 form1.edit7.Text:=inputBox('enter new name of the cathegory','Cath. 4 Name',cathNameArr[4]);
 label5.Caption:=cathNameArr[4];
 initWrite;
end;

procedure TForm2.Label64MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
 form2.label64.cursor:=crHandPoint;
end;

procedure TForm2.Label66MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
 form2.label66.cursor:=crHandPoint;
end;

procedure TForm2.Label70MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
 form2.label70.cursor:=crHandPoint;
end;

procedure TForm2.Label5MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
 form2.label5.cursor:=crHandPoint;
end;

procedure TForm2.RadioGroup4Click(Sender: TObject);
var i:integer;
begin
  form1.radiogroup4.ItemIndex:=form2.radiogroup4.ItemIndex;
  i:=form2.radiogroup4.Items.count;
  i:=form2.radiogroup4.Items.Capacity;
  case form2.radiogroup4.ItemIndex of
  0: checkbox35.checked:=true; //vPS
  1: checkbox36.checked:=true; //cPS
  2: checkbox43.checked:=true; //vPC
  3: checkbox44.checked:=true; //cPC
  end;{case output}
  case form2.radiogroup4.ItemIndex of
  0, 1:begin bundleRange:=PSrange; bundlePanel:=3 end;
  2, 3:begin bundleRange:=PCrange; bundlePanel:=4 end;
 end;{case, range}
 case form2.radiogroup4.ItemIndex of
  0, 2:bundleColor:=streamsGraphColors[5];//clYellow;
  1, 3:bundleColor:=streamsGraphColors[4]//clGreen;
 end;{case color}
 form1.radiogroup4.Enabled:=form1.CheckBox49.Enabled;
end;

procedure TForm2.CheckBox81Click(Sender: TObject);
begin
 form1.checkbox15.Checked:=checkBox81.checked;
 form2.checkbox55.Checked:=form1.checkbox15.Checked;
 if checkBox81.checked then showMessage('Calculation of F0 will be forced from now') else showMessage('Calculation of F0 will not be forced from now');
end;

procedure TForm2.RadioGroup5Click(Sender: TObject);
 function repStartComp(idx:byte):word;
   begin
    repStartComp:=trunc(power(2,idx-1))*count;
   end; {repStartComp}
begin
(* case radioGroup5.ItemIndex of
  0: begin
      repStart:=0;
      repEnd:=count-1;
     end;
  1: begin
      repStart:=
      count:=
     end;
  2: begin
      count:=
     end;
  3: begin
      count:=
     end;
 end{case}  *)
end;

procedure TForm2.Edit2Exit(Sender: TObject);
begin
 unit1.editChange(Edit2);
 manager:='R'
end; {Edit2Exit}

procedure TForm2.CheckBox82Click(Sender: TObject);
begin   //standardise original signal portion
 form1.CheckBox29.Checked:=checkBox82.Checked;
 label7Show;
 panel2Stretch;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox83Click(Sender: TObject);
begin //form1.CheckBox29.Checked:=checkBox83.Checked;
 label7Show;
 panel2Stretch;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox84Click(Sender: TObject);
begin  //Norm. PS
 form1.CheckBox30.Checked:=checkBox84.Checked;
 if checkBox84.Checked then PSrange:=PSrange0 div 4
 else PSrange:=PSrange0;
 checkBox29.Checked:=not checkBox84.Checked;
 checkBox29.enabled:=not checkBox84.Checked;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox85Click(Sender: TObject);
begin  //Norm. sPS
 form1.CheckBox31.Checked:=checkBox85.Checked;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox86Click(Sender: TObject);
begin //Norm. msPS
 form1.CheckBox34.Checked:=checkBox86.Checked;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox87Click(Sender: TObject);
begin
 form1.CheckBox33.Checked:=checkBox87.Checked;
 checkBox93.Checked:=bundleStand;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox88Click(Sender: TObject);
begin   //norm cPS
 form1.CheckBox32.Checked:=checkBox88.Checked;
 checkBox93.Checked:=bundleStand;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox89Click(Sender: TObject);
begin      //norm PC
 form1.CheckBox35.Checked:=checkBox89.Checked;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox90Click(Sender: TObject);
begin  //Norm. mPC
 form1.CheckBox38.Checked:=checkBox90.Checked;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox91Click(Sender: TObject);
begin  //norm. vPC
 form1.CheckBox37.Checked:=checkBox91.Checked;
 checkBox93.Checked:=bundleStand;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox92Click(Sender: TObject);
begin    //norm. cPC
 form1.CheckBox36.Checked:=checkBox92.Checked;
 checkBox93.Checked:=bundleStand;
 standOnOff:=true;
 manager:='T';
end;

procedure TForm2.CheckBox93Click(Sender: TObject);
begin
 if checkbox45.checked then
   case form2.radiogroup4.ItemIndex of
   0: checkbox87.checked:=checkbox93.checked; //vPS
   1: checkbox88.checked:=checkbox93.checked; //cPS
   2: checkbox91.checked:=checkbox93.checked; //vPC
   3: checkbox92.checked:=checkbox93.checked; //cPC
  end;
 form1.CheckBox39.Checked:=checkBox93.Checked;
 //manager:='R';
 //standOnOff:=true;
end;

procedure TForm2.Button14Click(Sender: TObject);
begin   // /2
 if PSrange<= high(PSrange) div 2 then PSrange:=PSrange*2;
 button19.Caption:= 'Reset '+intToStr(round(PSrange));//PSrange0-0.5));
 checkBox2.Checked:=true;
 manager:='R'
end;

procedure TForm2.Button13Click(Sender: TObject);
begin
 if PSrange>2 then PSrange:=round(PSrange/2);
 button19.Caption:= 'Reset '+intToStr(round(PSrange));//PSrange-0.5));
 checkBox2.Checked:=true;
 manager:='R'
end;

procedure TForm2.Button15Click(Sender: TObject);
begin   //*2
 if PCrange>2 then PCrange:=round(PCrange/2);
 label42.Caption:='Augmentation '+floatToStrF(PCrange0/PCrange,fffixed,10,3);
 button20.Caption:= 'Reset '+intToStr(round(PCrange));//0/PCrange-0.5));
 checkBox2.Checked:=true;
 manager:='R'
end;

procedure TForm2.Button16Click(Sender: TObject);
begin  // /2
 if PCrange<= high(PCrange) div 2 then PCrange:=PCrange*2;
 label42.Caption:='Augmentation '+floatToStrF(PCrange/PCrange0,fffixed,10,3);
 button20.Caption:= 'Reset '+intToStr(round(PCrange));// /PCrange0+0.5));
 checkBox2.Checked:=true;
 manager:='R'
end;

procedure TForm2.Button19Click(Sender: TObject);
begin   //Reset
 PSrange:=PSrange0;
 button19.Caption:= 'Reset '+intToStr(round(PSrange));//0/PSrange));
 checkBox2.Checked:=true;
 manager:='R'
end;

procedure TForm2.Button20Click(Sender: TObject);
begin   //Reset
 PCrange:=PCrange0;
 label42.Caption:='Augmentation '+floatToStrF(PCrange0/PCrange,ffFixed,10,3);
 button20.Caption:= 'Reset '+intToStr(round(PCrange0));///PCrange));
 checkBox2.Checked:=true;
 manager:='R'
end;

procedure TForm2.Edit1Exit(Sender: TObject);
  var i:longint;
 begin
  if not trystrToInt(form2.edit1.text,i) then
  showMessage('Error in '+form2.Label8.Caption+'. The '+form2.edit1.text+' is not an integer');
  jumpNbrSamples:=i;   //dodano showMessage j.w., ale przedtem jumpNbrSamples by�o =0!!!, sytuacj� naprawia�o te� dodanie zmiennej po�rednicz�cej k:byte, k:=i; oraz gdy by�o jumpNbrSamples:=k;
  form1.Edit2.Text:=intToStr(jumpNbrSamples);
  label24.caption:='Best part search range'+' ['+intToStr(round(1000*i/rate))+'ms]';
 end;

procedure TForm2.Edit13KeyPress(Sender: TObject; var Key: Char);
begin
 if key=#13 then Edit13Exit(sender);
end;

procedure TForm2.Button17Click(Sender: TObject);
begin   //scratch
 checkBox1.Checked:=true; //show graphs
 checkBox2.Checked:=true; //step wise
 if messageDlg('Restart from scratch?',mtWarning,mbYesNo,0)=mrYes then
   manager:='Y';
 checkBox76.Checked:=true; // scratch lock
end;

procedure TForm2.Memo3Click(Sender: TObject);
begin
 if memo3.height=80 then memo3.height:=height-memo3.top-TaskBarHeight else memo3.Height:=80;
end;

procedure TForm2.Memo4Click(Sender: TObject);
begin
 if memo4.height=80 then memo4.height:=height-memo4.top-TaskBarHeight else memo4.Height:=80;
end;

procedure TForm2.RadioGroup8Click(Sender: TObject);
begin
 manager:='V';
 Application.ProcessMessages
end;

procedure TForm2.CheckBox12Click(Sender: TObject);
begin   //viz  vPS
 if not CheckBox12.Checked then exit;
 setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);  //Needed analyses turn on
 SaveCheckEnabler(not form2.checkBox25.Checked);
 checkBox2.Checked:=true;
 manager:='T';
end;

procedure TForm2.CheckBox13Click(Sender: TObject);
begin   //viz cPS
  if not CheckBox13.Checked then exit;
 setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);  //Needed analyses turn on
 SaveCheckEnabler(not form2.checkBox25.Checked);
 checkBox2.Checked:=true;
 manager:='T';
end;

procedure TForm2.CheckBox16Click(Sender: TObject);
begin   //viz aPC
 if not CheckBox16.Checked then exit;
 setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);  //Needed analyses turn on
 SaveCheckEnabler(not form2.checkBox25.Checked);
 checkBox2.Checked:=true;
 manager:='T';
end;

procedure TForm2.CheckBox17Click(Sender: TObject);
begin // viz cPC
 if not CheckBox17.Checked then exit;
 setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);  //Needed analyses turn on
 SaveCheckEnabler(not form2.checkBox25.Checked);
 checkBox2.Checked:=true;
 manager:='T';
end;

procedure TForm2.CheckBox27Click(Sender: TObject);
begin  //viz avPS
  if not CheckBox27.Checked then exit;
 setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);  //Needed analyses turn on
 SaveCheckEnabler(not form2.checkBox25.Checked);
 checkBox2.Checked:=true;
 manager:='T';
end;

procedure TForm2.CheckBox28Click(Sender: TObject);
begin    //viz acPS
  if not CheckBox28.Checked then exit;
 setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);  //Needed analyses turn on
 SaveCheckEnabler(not form2.checkBox25.Checked);
 checkBox2.Checked:=true;
 manager:='T';
end;

procedure TForm2.CheckBox29Click(Sender: TObject);
begin  //viz aPC
  if not CheckBox29.Checked then exit;
 setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);  //Needed analyses turn on
 SaveCheckEnabler(not form2.checkBox25.Checked);
 checkBox2.Checked:=true;
 manager:='T';
end;

procedure TForm2.CheckBox95Click(Sender: TObject);
begin   //wide cepstra
 if checkBox95.checked then
  begin
   if not checkBox23.Checked then checkBox23.Checked:=true;
   wspx4:=panel4.Width/cpstrPoint;
    cpstrVizXrange:=cpstrPoint
  end
 else
  begin
   wspx4:=panel4.Width/count_cp;
    cpstrVizXrange:=count_cp
  end;
 manager:='R';
end;

procedure TForm2.CheckBox96Click(Sender: TObject);
begin  //change T0 dash length
 if checkBox96.Checked then T0dashLength:=5
 else T0dashLength:=16;
 Panel9.width:=T0dashLength+2;
 checkBox96.Caption:='T0 Dash Length change, now='+intToStr(T0dashLength);
 checkbox2.Checked:=true;
 application.processMessages;
 manager:='R';
end;

procedure TForm2.CheckBox9Click(Sender: TObject);
begin
 setAnalysisCheck(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);  //Needed analyses turn on
 SaveCheckEnabler(not form2.checkBox25.Checked);
 manager:='R';
end;

procedure TForm2.Button18Click(Sender: TObject);
begin
 if  windowsSearching then
  if messageDlg('Click "Yes" if you like to finish immediately the analysis',mtConfirmation,[mbYes, mbNo],1)=mrYes then
   begin
    Writeln(reportFile,'Windows searching was broken on demand');
    Writeln(GaussSearchFile,'Windows searching was broken on demand');
    flush(reportFile);
    flush(GaussSearchFile);
    halt;
   end;
end;

end.


