unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,printers,
  Spectrum, ComCtrls, Menus, ExtCtrls, Buttons, CheckLst;//, Epina.SDL.fourier, OleServer, ExcelXP;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    F1: TMenuItem;
    Exit1: TMenuItem;
    Options1: TMenuItem;
    OpenDialog1: TOpenDialog;
    Label11: TLabel;
    Panel1: TPanel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Label37: TLabel;
    Button3: TButton;
    Panel2: TPanel;
    StatusBar1: TStatusBar;
    Help1: TMenuItem;
    About1: TMenuItem;
    SpeedButton5: TSpeedButton;
    Button2: TButton;
    GroupBox1: TGroupBox;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    SaveDialog1: TSaveDialog;
    CheckBox10: TCheckBox;
    Label6: TLabel;
    Button4: TButton;
    PageControl3: TPageControl;
    TabSheet8: TTabSheet;
    Label38: TLabel;
    Label39: TLabel;
    Label40: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    Edit1: TEdit;
    Edit2: TEdit;
    TabSheet9: TTabSheet;
    GroupBox3: TGroupBox;
    Label42: TLabel;
    CheckBox14: TCheckBox;
    CheckBox15: TCheckBox;
    CheckBox16: TCheckBox;
    CheckBox17: TCheckBox;
    CheckBox18: TCheckBox;
    CheckBox11: TCheckBox;
    CheckBox12: TCheckBox;
    TabSheet10: TTabSheet;
    Label44: TLabel;
    Label45: TLabel;
    RadioGroup6: TRadioGroup;
    GroupBox4: TGroupBox;
    CheckBox24: TCheckBox;
    CheckBox25: TCheckBox;
    CheckBox26: TCheckBox;
    CheckBox6: TCheckBox;
    Edit13: TEdit;
    Edit14: TEdit;
    TabSheet11: TTabSheet;
    TabSheet12: TTabSheet;
    RadioGroup8: TRadioGroup;
    RadioGroup9: TRadioGroup;
    RadioGroup10: TRadioGroup;
    Panel3: TPanel;
    Label8: TLabel;
    Label9: TLabel;
    Label49: TLabel;
    Label53: TLabel;
    Label54: TLabel;
    RadioGroup2: TRadioGroup;
    Label57: TLabel;
    Label58: TLabel;
    ComboBoxEx1: TComboBoxEx;
    SpeedButton4: TSpeedButton;
    Edit12: TEdit;
    Label41: TLabel;
    Panel5: TPanel;
    Label72: TLabel;
    Label73: TLabel;
    Label71: TLabel;
    Label74: TLabel;
    Label75: TLabel;
    Edit5: TEdit;
    Label76: TLabel;
    Panel4: TPanel;
    Run1: TMenuItem;
    Label90: TLabel;
    CheckBox60: TCheckBox;
    Label50: TLabel;
    ProgressBar1: TProgressBar;
    Label91: TLabel;
    Button5: TButton;
    Edit24: TEdit;
    Label92: TLabel;
    Label93: TLabel;
    Label94: TLabel;
    Label95: TLabel;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox48: TCheckBox;
    CheckBox44: TCheckBox;
    CheckBox43: TCheckBox;
    CheckBox42: TCheckBox;
    CheckBox41: TCheckBox;
    CheckBox45: TCheckBox;
    CheckBox40: TCheckBox;
    CheckBox46: TCheckBox;
    CheckBox47: TCheckBox;
    CheckBox49: TCheckBox;
    Label4: TLabel;
    CheckBox5: TCheckBox;
    CheckBox57: TCheckBox;
    RadioGroup7: TRadioGroup;
    Label47: TLabel;
    Edit15: TEdit;
    Edit16: TEdit;
    CheckBox4: TCheckBox;
    Label3: TLabel;
    Label43: TLabel;
    Label59: TLabel;
    Label5: TLabel;
    Panel6: TPanel;
    Label60: TLabel;
    Label61: TLabel;
    Label62: TLabel;
    Label63: TLabel;
    GroupBox2: TGroupBox;
    Label51: TLabel;
    Label52: TLabel;
    Label55: TLabel;
    Label56: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Label10: TLabel;
    RadioGroup3: TRadioGroup;
    Label46: TLabel;
    Label64: TLabel;
    GroupBox5: TGroupBox;
    Label48: TLabel;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    RadioGroup4: TRadioGroup;
    CheckBox38: TCheckBox;
    CheckBox37: TCheckBox;
    CheckBox36: TCheckBox;
    CheckBox35: TCheckBox;
    CheckBox34: TCheckBox;
    CheckBox33: TCheckBox;
    CheckBox32: TCheckBox;
    CheckBox31: TCheckBox;
    CheckBox30: TCheckBox;
    Label7: TLabel;
    CheckBox29: TCheckBox;
    Label65: TLabel;
    Button15: TButton;
    Label66: TLabel;
    Button16: TButton;
    Button17: TButton;
    Label67: TLabel;
    Label68: TLabel;
    Label69: TLabel;
    Label70: TLabel;
    CheckBox39: TCheckBox;
    Label77: TLabel;
    procedure Button17Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure Edit12Exit(Sender: TObject);
    procedure CheckBox48Click(Sender: TObject);
    procedure CheckBox47Click(Sender: TObject);
    procedure CheckBox46Click(Sender: TObject);
    procedure CheckBox45Click(Sender: TObject);
    procedure CheckBox44Click(Sender: TObject);
    procedure CheckBox43Click(Sender: TObject);
    procedure CheckBox41Click(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure CheckBox29Click(Sender: TObject);
    procedure CheckBox39Click(Sender: TObject);
    procedure CheckBox38Click(Sender: TObject);
    procedure CheckBox37Click(Sender: TObject);
    procedure CheckBox36Click(Sender: TObject);
    procedure CheckBox35Click(Sender: TObject);
    procedure CheckBox34Click(Sender: TObject);
    procedure CheckBox33Click(Sender: TObject);
    procedure CheckBox31Click(Sender: TObject);
    procedure CheckBox30Click(Sender: TObject);
    procedure RadioGroup4Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure CheckBox49Click(Sender: TObject);
    procedure Edit7Exit(Sender: TObject);
    procedure Edit7Change(Sender: TObject);
    procedure Edit6Change(Sender: TObject);
    procedure Edit4Change(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure Edit10Exit(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit15Exit(Sender: TObject);
    procedure Edit9Exit(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure CheckBox32Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure CheckBox42Click(Sender: TObject);
    procedure CheckBox5Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure CheckBox6Click(Sender: TObject);
    procedure Edit24Exit(Sender: TObject);
    procedure Edit24Change(Sender: TObject);
    procedure CheckBox40Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Label70Click(Sender: TObject);
    procedure GroupBox2Click(Sender: TObject);
    procedure Edit5Exit(Sender: TObject);
    procedure Edit5Change(Sender: TObject);
    procedure Edit11Change(Sender: TObject);
    procedure CheckBox57Click(Sender: TObject);
    procedure TabSheet8ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
    procedure RadioGroup2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure CheckBox10Click(Sender: TObject);
    procedure CheckBox7Click(Sender: TObject);
    procedure CheckBox8Click(Sender: TObject);
    procedure RadioGroup7Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure Edit10KeyPress(Sender: TObject; var Key: Char);
    procedure About1Click(Sender: TObject);
    procedure Options1Click(Sender: TObject);
    procedure RadioGroup8Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Edit1Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
   procedure WMVScroll(var Msg :TMessage); message WM_VSCROLL;
   procedure WMHScroll(var Msg :TMessage); message WM_HSCROLL;
  public
    { Public declarations }
  end;
function setAnalysisCheck(const viz:boolean; out PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC:boolean):dword;
procedure SuspendOrHibernate(ASuspend,AForce:Boolean);
Procedure multiMeanList;
procedure RAMallocate;
procedure showButtons;

var
                                   Form1 : TForm1;
                         mmcPS,F1Check13 : boolean;
                                  OscRep : boolean=false;
  PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC : boolean;
                              standOnOff : boolean=false;
                                finished : boolean=false;
procedure editChange(edit:tedit);

implementation

{$R *.dfm}

uses Welcome,disco,common,fft,newSpectrum,visualization,grafiti4,spectanalisier,porto,Drawings;

procedure Tform1.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;
 oscRep:=true
end;
//------------------------
procedure Tform1.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;
   oscRep:=true
end;
var F0mess:boolean=false;//to prevent message repeating

procedure hideButtons;
 //hide buttons steering main wav oscillogram show
 begin
  with form1 do
   begin
    groupBox5.Visible:=false;
   end;
 end;{hideButtons}

 procedure showButtons;
 //hide buttons steering main wav oscillogram show
 begin
  with form1 do
   begin
    groupBox5.Visible:=true;
   end;
 end;{showButtons}

procedure TForm1.FormCreate(Sender: TObject);
var s1,s2:string;
begin
 with screen do if (Width<>1920) or (height<>1080) then
  if MessageDlg('The interface of the program was prepared for the 1680x1050 screen resolution!'#13#10+
  'Your screen parameters are: '+intToStr(width)+'x'+intToStr(height)+'.'#13#10+
  'Try to change your graphic card parameters to these values.'#13#10'Change the "vertScrollBar.Range" and the'+
  ' "HorzScrollBar.Range" to adapt the scrolling ranges to other resolution'#13#10+
  'Command "Repaint frames" in the step mode can help if you can''t to do this and graphs are going out of their frames.',
   mtInformation,[mbIgnore,mbAbort],0)=mrAbort then halt;
 left:=0; top:=0;
 vertScrollBar.Range:=1050; vertScrollBar.Position:=0;
 HorzScrollBar.Range:=1680; HorzScrollBar.Position:=0;

 F1Check13:=false;     frameNbr:=1;
 comboboxex1.Items.Assign(printer.printers);
 setDefaults;
 form1.WindowState:=wsMaximized;
 case RadioGroup8.itemIndex of
   0,1:RadioGroup9.Enabled:=false
  else RadioGroup9.Enabled:=true
 end;
 button5.Enabled:=false;
 button9.Enabled:=false;
 button10.Enabled:=false;
 button13.Enabled:=false;
 panel3.Visible:=RadioGroup8.itemIndex=0;
 button4.Visible:=false;
 edit1.Hint:='Read out from disc.'#13#10'Reading from a port, not implemented.';
 edit1.Text:=FloatToStrF(rate,ffFixed,8,1);
 jumpNbrSamples:=round(jump*(rate/1000));  //inicjalizacja w FormCreate
 Edit2.Text:=intToStr(jumpNbrSamples);
 Edit9.Text:=intToStr(count);
 //cpstrPoint:=high(cpstrPoint);
 //edit12.Text:=intToStr(cpstrPoint);
 checkBox15.Checked:=true;
 checkBox16.Checked:=true;
 checkBox39.Enabled:=false;
 CheckBox49.hint:='Choose the bundle output with the "'+radiogroup4.Caption +'" radiogroup';
 checkbox57.Checked:=true;
 checkbox57.hint:='It switches off records of results to output streams,'#13#10'however does not switch off other'+
             ' output check boxes.'#13#10'It allows for easy return to a chosen set of strams sent to the output';
 checkbox60.hint:='Works only with "VER_PLATFORM_WIN32_NT" OS version';
 edit2.Hint:='The parameter "jump" derivate';
 edit9.Hint:='Windows width reading';
 edit10.hint:='Co ile milisekund'#13#10'(przeliczane na próbki)'#13#10'ma się przesuwać okno analizujące';
 edit11.hint:='Podać max częstotliwość podstawową F0max'#13#10'(ma znaczenie tylko dla wykresów).'#13#10+
             'Od wartości częstotliwości Fmax będzie zależeć liczba próbek'#13#10+
             'zawartych w wyświetlanym odcinku oscylogramu. Przyjmuje się 4 punkty na okres Fmax'#13#10+
             'Podając dużą Fmax uzyskujemy więc większe rozciągnięcie oscylogramu.'#13#10+
             'Parametr ten nie ma żadnego wpływu na analizę FFT.';
 groupBox1.Enabled:=false; //analyses mode
 label9.hint:='Acoustic speech signal';
 label9.caption:=waveFilePath;
 fileDateSize(waveFilePath,s1,s2); form1.label54.caption:=s1; form1.label50.caption:=s2;
 label3.caption:=cathFilePath;
 labelsClear([1..37]);
 fileDateSize(cathFilePath,s1,s2); form1.label59.caption:=s1; form1.label43.caption:=s2;
 label46.top:=panel2.top+panel2.Height-canvas.Font.Size-5; label46.left:=panel2.left+52;  //top+height-canvas.Font.Size
 label58.Visible:=false;
 label60.Caption:='';
 label61.Caption:=GaussSearchFilePath;
 label65.top:=panel2.top+panel2.Height+8; label65.left:=label46.left;
 label66.top:=label65.top;  label66.left:=panel2.Left+panel2.Width-20;
 label72.Caption:=outRecordFilePath;
 label91.caption:='';
 label93.Caption:=ReportFilePath;
 fileDateSize(outRecordFilePath,s1,s2); form1.label75.caption:=s1; form1.label74.caption:=s2;application.ProcessMessages;
 fileDateSize(ReportFilePath,s1,s2); form1.label95.caption:=s1; form1.label94.caption:=s2;application.ProcessMessages;
 fileDateSize(GaussSearchFilePath,s1,s2); form1.label63.caption:=s1; form1.label62.caption:=s2;application.ProcessMessages;
 label6.Caption:='';
 Label57.Visible:=False;
 Label90.Caption:='';
 Label90.Caption:='Click "'+button3.Caption+'" to start wave signal preview';
 PageControl3.ActivePageIndex:=0;
 Panel2.Visible:=False;
 panel2.Left:=16+5*form1.Canvas.font.Size-form1.Left+2;
 panel2.width:=form1.Width-10-panel2.Left;
 Panel4.Visible:=false;
 radioGroup2.Hint:='Performs filtering in spectrum domain (applies to spectrum module).'+
              #13#0'Curve equation: y(ln(f))=10 exp{-sqr(ln((i*rate/count)/fc))/v)}'+
              #13#10'where:'+
              #13#10'v=sqr(ln(4000/300))/ln(10) - variance'+
              #13#10'f - frequency'+
              #13#10'fc - central frequency (f argmax)'+
              #13#10'rate - sampling rate'+
              #13#10'count - fft points nbr'+
              #13#10'i*rate/count - current frequency'+
              #13#10'Note. Filter is actualized to proper form after reading parameters of signal data';
 radioGroup3.Enabled:=false;
 RadioGroup3.ItemIndex:=RadioGroup7.ItemIndex;
 radioGroup8.Hint:='disc/AC converter/outer generator';
 RadioGroup10.Hint:='Format Wave - data with 44-byte header Wave, range +-32000,'#13#10'Word - obsolete, with 265-byte description header, range +-32000.';
 hideButtons;
 oscRep:=false;
end;{TForm1.FormCreate}

procedure TForm1.Button1Click(Sender: TObject);    //start old version
begin
beep;
InitWrite;
 if
  (application.messageBox('Close program immediately?','Program closing',MB_YESNO)=IDYES)
 then halt
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
screen.cursor:=-2;
MainProgram
end;

Procedure multiMeanList;
 var k:word;
 Begin
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++ reHistory RAM allocation (05052014, taken from "spectrAnalyser")
   k:=0;                            //----------------------------------------------
    frameNbrArr[k]:=frameNbr;
    frameNbr0Arr[k]:=frameNbrArr[k];
    setLength(reHistoryArr,NbrOfMultiMean+1);          // : array of Thistory;         //for multi CCR processing
    setLength(reHistoryArr[k],frameNbrArr[k],count div 2+1);
    k:=1;                            //----------------------------------------------
    frameNbrArr[k]:=7;
    frameNbr0Arr[k]:=frameNbrArr[k];
    setLength(reHistoryArr[k],frameNbrArr[k],count div 2+1);
    for k:=2 to NbrOfMultiMean do    //----------------------------------------------
     begin
      frameNbrArr[k]:=3*k;
      frameNbr0Arr[k]:=frameNbrArr[k];
      setLength(reHistoryArr[k],frameNbrArr[k],count div 2+1);    // : array of Thistory;         //for multi CCR processing
     end;
  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  End;{multiMeanList}

procedure RAMallocate;
 var k:word;
 Begin
  cp:=count div 2; sqrCount:=count*count;
  if form1.CheckBox6.Checked then count_cp:=cp else count_cp:=count;       //wyświetlać połowę liczby punktów (03052014, aby zainicjować frame, aby dataBlockLengt>0)
  setLength(melIdx,cp+1);
  setLength(melFreq,cp+1);
  SetLength(reHistory,frameNbr,cp+1);
  rehist:=high(reHistory[0]);   //debug
  setLength(filter,cp+1);
  setLength(Yzero,count);
  setLength(cosar,count); setLength(sinar,count);
  setLength(windowWeights,count);
  setLength(xr,count); setLength(xr0,count);setLength(yi,count);
  setLength(index_mix,count); setLength(indexSort,count);
  setLength(reMeanVectorArr,NbrOfMultiMean+1,count);               // : array of array of double; 02052014 taken from setAnalysisCheck
  setLength(outputRecord.streamArray,nbrOfStreams,count div 2+1);   //allocate memory to the stream array (03052014, for windows width change to work)
  outPutRecordInit(outputRecord,nbrOfStreams,count div 2+1);
  setLength(reIns,count);
  setLength(ImIns,count);
  setLength(angle,count);
  setLength(virt_vect,count); setLength(tmp_virt_vect,count);   //30042025
  slidesRecordInit;                                               //(03052014, for windows width change to work) because members of this recor are registered always independetly of that whether they are outputed or not
  setLength(reTmp,count);
  setLength(ImTmp,count);
  setLength(tmpArr,count);
  setLength(frameNbrArr,NbrOfMultiMean+1);     //05052014, taken from "setAnalysisCheck"
  setLength(frameNbr0Arr,NbrOfMultiMean+1);    //05052014, taken from "setAnalysisCheck" : array of integer;          //for multi CCR processing
  multiMeanList;
  //FramesRepaint(count_cp); 05122022
  if count<=cpstrPoint then cpstrPoint:=count-1;
  form1.Edit12.Text:=intToStr(cpstrPoint);
  form2.Edit2.Text:=intToStr(cpstrPoint);
  angleTemp:=high(angle);           //debug
 End;{RAMallocate}

procedure TForm1.Edit1Change(Sender: TObject);
begin
try
count:=strToInt(edit9.Text);
RAMallocate;
except
end;
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
 try
 if key=#13 then
  begin
   count:=strToInt(edit9.Text);
   RAMallocate;
  end;
 except
 end;
end;

procedure EnDis(onOff:boolean);
 begin
  with form1 do
   begin
    Button3.Enabled:=onOff;
    Button2.Enabled:=onOff;
    Edit5.Enabled:=onOff;
   end;
 end;{EnDis}

procedure SuspendOrHibernate(ASuspend,AForce:Boolean);
 var
   iVersionInfo : TOSVersionInfo;
   iToken       : cardinal;
   iPriveleg    : TTokenPrivileges;
   iaresult     : cardinal;
 begin
   FillChar (iPriveleg, SizeOf (iPriveleg), #0);
   iVersionInfo.dwOSVersionInfoSize:= SizeOf(TOSVersionInfo);
   GetVersionEx(iVersionInfo);
   if iVersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT then
    begin
    // Win32Check(OpenProcessToken (GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, iToken));
   //  Win32Check(LookupPrivilegeValue (NIL,'SeShutdownPrivilege',iPriveleg.Privileges[0].Luid));
     iPriveleg.PrivilegeCount:= 1;
     iPriveleg.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED;
     Win32Check(AdjustTokenPrivileges(iToken,False,iPriveleg,Sizeof(iPriveleg),iPriveleg,iaresult));
   end;
  Win32Check(SetSystemPowerState(ASuspend,AForce));
 end;

 procedure oscillButtons(TF:boolean);
  begin
    exitWave:=not TF;
   with form1 do
    begin
   Button6.Enabled:=TF;
   Button7.Enabled:=TF;
   Button8.Enabled:=TF;
   Button9.Enabled:=TF;
   Button10.Enabled:=TF;
   Button11.Enabled:=TF;
   Button12.Enabled:=TF;
   Button13.Enabled:=TF;
   Button16.Enabled:=TF;
   Button17.Enabled:=TF;
   Button14.Enabled:=TF;
   Button15.Enabled:=TF;
    end
  end;{oscillButtons}

procedure TForm1.Button3Click(Sender: TObject);   //"Step Analysis (Run)
var s1,s2,callChain:string;
begin
 callChain:='>Button3Click="Step Analysis (Run)';
 form1.Label90.Caption:='';
 progressBar1.Position:=0;; label91.Caption:='';
 oscillButtons(true);
 InitRead;
 Form2.Edit2.Text:=Form1.Edit12.Text;
 EnDis(false);
 form2.CheckBox61.Checked:=true;
 form2.CheckBox73.Checked:=true;
 spectrAnalyser(nbrOfData,savedRec,prevSliceNbr,callChain);
 fileDateSize(outRecordFilePath,s1,s2);
 form1.label75.caption:=s1;
 form1.label74.caption:=s2;
 application.ProcessMessages;
 EnDis(true);
 showMessage('Program finished!'#13#10'Unlock the "'+form2.Button1.Caption+'" button and click it now');
end;

procedure TForm1.RadioGroup8Click(Sender: TObject);
begin
 case RadioGroup8.itemIndex of
  0,1:begin RadioGroup9.Enabled:=false; RadioGroup10.Enabled:=true end
  else begin RadioGroup9.Enabled:=true; RadioGroup10.Enabled:=false end;
 end;
 panel3.Visible:=RadioGroup8.itemIndex=0;
end;

procedure TForm1.Options1Click(Sender: TObject);
begin
with form1.PageControl3 do Visible:=not Visible;
end;

procedure TForm1.About1Click(Sender: TObject);
begin
form3.show;
welcome.WelcomeTo
end;

procedure edit10process;
var z:extended;
 begin
  with form1 do
  begin
   if not TryStrToFloat(edit10.Text,z) then
    begin
     showMessage('Text "'+edit10.Text+'" is not a number!'#13#10'Correct it (may be you have used point instead of comma (or vice versa, depending on locales)).'#13#10'We take 5 as default');
     edit10.Text:=floatToStrF(jump,ffFixed,6,3);
    end
   else jump:=z;
  jumpNbrSamples:=round(jump*(rate/1000));
  edit10.text:= floatToStrF(jumpNbrSamples*1000/rate,ffFixed,6,4);
  form1.Edit2.Text:=intToStr(jumpNbrSamples);
  form2.Edit1.Text:=form1.Edit2.Text;
 end;{with}
 end;{edit10process}

procedure TForm1.Edit10KeyPress(Sender: TObject; var Key: Char);
//Określić liczbę próbek na jump i wpisać ją do okienka edycyjnego edit2
begin //--------------jump w ms- odczyt z okienka i aktualizacja parametrów pochodnych -----------------
 if key<>#13 then exit;
 edit10process;
end;

procedure TForm1.SpeedButton5Click(Sender: TObject);
begin
halt
end;

procedure TForm1.RadioGroup7Click(Sender: TObject);
begin
 winNbr:=RadioGroup7.ItemIndex;
 form2.RadioGroup7.ItemIndex:=winNbr; form2.RadioGroup3.ItemIndex:=winNbr;
 gaussStdev:=strToInt(form2.Edit4.Text)/gaussScaler; rectFill:=strToInt(form2.Edit7.Text) mod (count div 2);
 WindowsWeights(winNbr,gaussStDev,windowWeights,weightMean,count);
 //WindowsWeights(const wn_nr:byte; const gaussStdev:single; out weights:array of double;out mean:extended;
 //                   const count:longint);
end;

procedure TForm1.CheckBox8Click(Sender: TObject);
begin
 CheckBox7.Checked:=not CheckBox8.Checked;
 form2.CheckBox2.Checked:=CheckBox8.Checked;
 form2.CheckBox1.Checked:=true;
 if CheckBox8.Checked then  button3.Caption:='Step analysis'
 else  button3.Caption:='Continuos analysis';
 form1.checkbox57.enabled:=false;
 form1.RadioGroup7.Enabled:=false;
 //form1.edit12.Enabled:=false;
 form1.edit15.Enabled:=false;
 form1.edit16.Enabled:=false;
 with form2 do
  begin
   Button2.Enabled :=checkBox2.Checked;
   Button4.Enabled :=checkBox2.Checked;
   Button5.Enabled :=checkBox2.Checked;
  end;
end;

procedure TForm1.CheckBox7Click(Sender: TObject);
begin
 CheckBox8.Checked:=not CheckBox7.Checked;
 form2.CheckBox2.Checked:=not CheckBox7.Checked;
  if CheckBox7.Checked then  button3.Caption:='Continuos analysis'
 else  button3.Caption:='Step analysis';
 form1.checkbox57.enabled:=false;
 form1.RadioGroup7.Enabled:=false;
 //form1.edit12.Enabled:=false;
 form1.edit15.Enabled:=false;
 form1.edit16.Enabled:=false;
 with form2 do
  begin
   Button2.Enabled :=checkBox2.Checked;
   Button4.Enabled :=checkBox2.Checked;
   Button5.Enabled :=checkBox2.Checked;
  end;
 manager:=#0;       //aby wyjść z pętli wykonywania krokowego (z oczekiwania na kliknięcie Back|Next)
end;

procedure TForm1.CheckBox10Click(Sender: TObject);
begin   //show graphics
 form2.CheckBox1.Checked:=form1.CheckBox10.Checked;
end;

procedure editChange(edit:tedit);
 var i:integer;
begin   i:=cpstrPoint;
  tryStrToInt(edit.Text,i);
  cpstrPoint:=i;  //220219                                         Q0
 if cpstrPoint>COUNT div 2-1 then
   begin
    cpstrPoint:=count div 2-1;
    edit.Text:=intToStr(cpstrPoint);
    end;
    if cpstrPoint<1 then
   begin
    cpstrPoint:= 1;
    edit.Text:=intToStr(cpstrPoint);
    end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
Form2.Edit2.Text:=Form1.Edit12.Text;
button4.Visible:=false;
form2.Show;
end;

procedure TForm1.RadioGroup2Click(Sender: TObject);
begin
with form1 do panel4.Width:=round(form2.Panel4.Width*panel4.Height/form2.panel4.height);
computeFilter;
if form1.RadioGroup2.ItemIndex=0 then modul:=modul_NpdBrms
else modul:=filter_modul_NpdBrms;
form2.RadioGroup2.ItemIndex:=form1.RadioGroup2.ItemIndex
end;

procedure TForm1.TabSheet8ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
var i,j:integer;
begin
with form1.PageControl3, form1.PageControl3.Canvas,panel4  do
 begin
  i:=left-2;J:=top-2;
  rectangle(i,j,i+30,j+30);  application.ProcessMessages;
 form1.PageControl3.Canvas.rectangle(0, 0,50,50);                    application.ProcessMessages;
 form1.TabSheet8.PageControl.Canvas.rectangle(20, 20,50,50);           application.ProcessMessages;
 end;
application.ProcessMessages;
end;

procedure TForm1.CheckBox57Click(Sender: TObject);  //save chosen streams
begin
beep;
if not windowsSearching then
showMessage('Mind what you are doing!'#13#10'Check off the "'+form1.checkBox57.Caption +
'" box causes, that no output stream will be saved. You can revert, chosen "output" checks still remain "ON".'+
#13#10'Uważaj co robisz!'#13#10'Wyłączenie spowoduje, że nie będą zapisywane wyniki analiz spektralnych.');
label58.Visible:=not checkbox57.Checked;
end;

procedure TForm1.Edit11Change(Sender: TObject);   //F0max
begin
beep
end;

procedure TForm1.Edit5Change(Sender: TObject);
var z :single;
begin
if tryStrToFloat(edit5.Text,z) then melBasis:=z
else showMessage(edit5.Text+' is not a number!');
end;

procedure TForm1.Edit5Exit(Sender: TObject);
begin
edit5.Text:=floatToStr(melBasis);
end;


procedure TForm1.GroupBox2Click(Sender: TObject);
begin
 pagecontrol3.ActivePageIndex:=3;
end;

procedure realInput(var nbr:single);
 begin
  nbr:=high(smallInt)/nbr;
 end;

procedure TForm1.Label70Click(Sender: TObject);
begin
pagecontrol3.ActivePageIndex:=3;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
 breakLoad:=True;
end;

procedure TForm1.Edit24Change(Sender: TObject);
var k:word;
begin
 form2.Edit24.Enabled:=true;   //nbr of frames in averaging
  if tryStrToInt(Edit24.Text,frameNbr) then
   if frameNbr>0 then
    form2.Edit24.Text:=form1.Edit24.Text
   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!');
 frameNbrArr[0]:=frameNbr;
end;

procedure TForm1.Edit24Exit(Sender: TObject);
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
end;

procedure TForm1.CheckBox6Click(Sender: TObject);  //show only a half points
begin
Form2.CheckBox23.checked:=CheckBox6.checked;       //f2.check23= sPS, f1.check6=
form2.CheckBox2.Checked:=true;                     //in order pgm could step in the "stepManager" to call "repaint" to rescale drawings (aby pgm mógł wejść do managera celem wołania "Repaint" celem przeskalowania wykresów)
manager:='V';//FrameRepaint;
end;

procedure analysisChecksSetting(const PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC:boolean);
 Begin
  with form1 do
   begin
   //----------------------------------Form1."Analysis" checbox settings-----------------------
      checkBox14.Checked:=PS;             //PS
      checkBox16.Checked:=sPS;            //sPS
      checkBox17.Checked:=cPS;            //cPS
      checkBox18.Checked:=vPS;            //vPS
      checkBox11.Checked:=msPS;           //msPS
      checkBox15.Checked:=PC;             //PC
      checkBox1.Checked :=cPC;            //cPC
      checkBox2.Checked :=vPC;            //vPC
      checkBox12.Checked:=mPC;            //mPC
      checkBox3.Checked :=mmcPS;          //mmcPS
      //----------------------------------------------------Form2."Analysis" checbox settings (visual page)---------------
      //---"Analysis"(Form2)-----"Analysis"(Form1)---
      form2.CheckBox46.Checked:=checkBox14.Checked;         //PS    .
      form2.CheckBox47.Checked:=checkBox16.Checked;         //sPS    .
      form2.CheckBox50.Checked:=checkBox17.Checked;         //cPS     .
      form2.CheckBox53.Checked:=checkBox17.Checked;         //cPS angle  ??
      form2.CheckBox49.Checked:=checkBox18.Checked;         //vPS      .
      form2.CheckBox52.Checked:=checkBox18.Checked;         //vPS angle  ??
      form2.CheckBox48.Checked:=checkBox11.Checked;         //msPS      .
      form2.CheckBox55.Checked:=checkBox15.Checked;         //PC        .
      form2.CheckBox54.Checked:=checkBox15.Checked;         //PC  angle  ??
      form2.CheckBox56.Checked:=checkBox12.Checked;         //mPC     .
      form2.CheckBox57.Checked:=checkBox2.Checked;          //vPC    .
      form2.CheckBox58.Checked:=checkBox1.Checked;          //cPC    .
      form2.CheckBox59.Checked:=checkBox3.Checked;          //mmcPS  .
     end{with}
 End;{AnalysisChecksSetting}

function setAnalysisCheck(const viz:boolean; out PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC:boolean):dword;
 {
Needed analyses turn on (Synchro analiz w zależności od potrzeb wizualizacji i wyjść)
 }
  var  logos:boolean;
   Begin
    result:=maxDword;
    logos:=form2.CheckBox1.Checked;  //checkbox1=show graphs
    with form1 do   //=======attention, the order of evaluations is important! ========================
     begin          //Analysis-Out-(form1)-------visualisation graph (form2) Aligning form2
            PS:=checkBox40.Checked or form2.checkBox9.Checked  and logos;                                  //PS
           aPS:=checkBox4.Checked  or form2.checkBox26.Checked and logos;                                  //aPS (phase)
           cPS:=checkBox42.Checked or (form2.checkBox13.Checked or form2.CheckBox22.Checked) and logos;    //cPS
           vPS:=checkBox43.Checked or (form2.checkBox12.Checked or form2.CheckBox21.Checked) and logos;    //vPS
          msPS:=checkBox44.Checked or (form2.checkBox11.Checked or form2.CheckBox20.Checked) and logos;    //melsPS
            PC:=checkBox45.Checked or form2.checkBox14.Checked and logos;                                  //PC
           cPC:=checkBox46.Checked or (form2.checkBox17.Checked or form2.CheckBox97.Checked) and logos;    //cPC        f1.check46=output/cPC,   f2.check17=cPC chart
           vPC:=checkBox47.Checked or (form2.checkBox16.Checked or form2.CheckBox64.Checked) and logos;    //vPC
           mPC:=checkBox48.Checked or (form2.checkBox15.Checked or form2.CheckBox63.Checked) and logos;    //mPC
           sPS:=checkBox41.Checked or (form2.checkBox10.Checked or form2.CheckBox19.Checked) and logos;                   //sPS
         mmcPS:=checkBox49.Checked;//or form2.checkBox17.Checked and logos;  //multi_cPC; f1.check49=output/mmcPS, f2.check17=cPC chart
      //------------------------------------------------------------------------------interactions
        sPS:=sPS or mPC or msPS;
        mPC:=mPC  or msPS;
        vPC:=vPC  or vPS;
        cPC:=cPC  or vPC or cPS;
         PC:=PC   or cPC or mPC or sPS or vPS or mmcPS or form2.CheckBox81.Checked; //or force F0 calc.;
         if (PC=false) and (form2.CheckBox81.Checked=False) then
          if messageDlg('Fundamental frequency (F0) will NOT be evaluated from now. Click "Yes" if you like to keep it on'#13'If "Yes" the "'+
           form2.CheckBox94.caption+'" will be turned on to see the effect.'#13'Turn it off to speed up computations',mtWarning, [mbYes, mbNo],1)=mrYes
          then begin form2.CheckBox94.Checked:=True;PC:=true end
          else if not form2.CheckBox81.Enabled then showMessage('Turn off the "'+form2.checkBox25.caption+'" to turn off the "'+form2.checkBox81.caption+'".');
         PS:=PS   or PC  or aPS;
      AnalysisChecksSetting(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);
     end;
    setLength(frameNbrArr,NbrOfMultiMean+1);
    setLength(frameNbr0Arr,NbrOfMultiMean+1);    // : array of integer;          //for multi CCR processing
    setLength(reHistoryArr,NbrOfMultiMean+1);    // : array of Thistory;         //for multi CCR processing
    setLength(reMeanVectorArr,NbrOfMultiMean+1,count); // : array of array of double;
    if form1.CheckBox3.Checked then maxFrameNbr:=maxFrameNbr0 else maxFrameNbr:=frameNbr;   //check3 - "multiMean" analysis
    if not PC then
     begin
      showMessage('Fundamental frequency (F0) will NOT be evaluated from now.'#13#10+
      'This is only when cepstrum is computed for visualisation or for output of a stream,'+
      'which recquires carrying out the cepstrum computing.'#13#10+
      'To the output record will be written some constant - last found F0.'#13#10+
      'Turn on the "'+form2.CheckBox81.Caption+'" to enforce calculation it.');
      F0Mess:=true;
      form2.CheckBox81.Enabled:=true; form2.CheckBox2.Checked:=true;
     end
    else
     if F0mess then  with form2 do
      begin
       showMessage('Fundamental frequency (F0) WILL be evaluated from now.'#13#10'Remember: the "'+
       button2.Caption+'" or "'+button11.Caption+'" operation will not repair break gaps emergent'+  //Back, Go to
       ' due to your options; this would recquire start analysis  from scratch');
       F0mess:=false;
      end;
    if spcSave and not viz then  whatToSave(not spcSave);   //15122024   if - 16122024;  it is a must, to substitute manager:='E' from OutCheckSynchro
   End; {setAnalysisCheck}

procedure TForm1.CheckBox40Click(Sender: TObject);  // Out1: PS
begin
 Edit24.Enabled:=true;//frame nbr
 if Edit24.Enabled then Edit24.Text:=IntToStr(frameNbr)
 else Edit24.Text:='XXXX';
 checkBox30.Enabled:=checkBox40.Checked;
 //if not checkBox40.Checked then checkBox30.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Synchro analiz w zależności od potrzeb wizualizacji i wyjść
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
 if finished then begin ShowMessage('Program terminated'); halt end;    //19022025 to disable erronous finishing
 if (width+20<screen.Width) or (height+40<screen.height) then
  showMessage('At least one parameter of windows height (='+intTostr(height)+') or the windows width (='+intToStr(width)+')'+
   #13'is smaller than actualal screen parameter, i.e. than the screen high (='+intTostr(screen.Height)+') or than the screen width (='+intToStr(screen.Width)+'.'+
   #13'Click the right top system button to expand the picture to full screen');
 count:=strToInt(Edit9.Text);
 fft_par(Edit9,form2.Edit5);
 form1.edit15.text:=intToStr(rectFill);
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Synchro analiz w zależności od potrzeb wizualizacji i wyjść
 computeFilter;
 WindowsWeights(winNbr,gaussStDev,windowWeights,weightMean,count);
end;

procedure TForm1.CheckBox5Click(Sender: TObject);   //OUT0: Input Window and also for: OUT2: Angle PS, OUT3: sPS, OUT5: vPS, OUT6: msPS, OUT7: PC, OUT8: cPC, OUT9: vPC, OUT10: mPC, OUT11: mmcPS
begin
 checkBox29.Enabled:=checkBox5.Checked;
 if not checkBox5.Checked then checkBox29.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Synchro analiz w zależności od potrzeb wizualizacji i wyjść
end;

procedure TForm1.CheckBox42Click(Sender: TObject);  //OUT4: cPS
begin
(*
 if not form1.checkbox42.Checked then
  begin
   form2.CheckBox45.Checked:=false;  //mmcPS
   form1.CheckBox49.Checked:=false;  //mmcPS
  end;
  *)
 checkBox32.Enabled:=checkBox42.Checked;
 //if not checkBox42.Checked then checkBox32.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Synchro analiz w zależności od potrzeb wizualizacji i wyjść
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
 button9.Enabled:=true;
 button10.Enabled:=true;
 button13.Enabled:=true;
 nextWave:=true;
 wholeWave:=false;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
 wholeWave:=not wholeWave;
 button9.Enabled:=true;
 button10.Enabled:=true;
 button13.Enabled:=true;
end;

procedure TForm1.Button8Click(Sender: TObject);  //exit
begin
 oscillButtons(false);
 button5.Enabled:=true;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
 backWave:=true;
 wholeWave:=false;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);

 procedure labelColor(labelx:Tlabel);
  var color:Tcolor;
  Begin
   Color:=Canvas.Pixels[myCursorPos.x,myCursorPos.y];
   labelx.Color:=color;
   if (color=clBlue) or (color=clGreen) or (color=clOlive)or (color=clPurple) or (color=clBlack) then labelx.font.Color:=clWhite
   else labelx.font.Color:=clblack;
   if color=clBlack then labelx.font.Color:=clWhite;
  End;{labelColor}

 var labelx:Tlabel;
 Begin // ----------------------- TForm1.FormMouseMove -------------------
  GetCursorPos(myCursorPos);
   with myCursorPos do label60.Caption:='(x, y)=('+intToStr(x)+', '+intToStr(y)+')'; //for debug prp
  try
  with form1,myCursorPos do
   Begin
    y:=y-form1.Top-44-4;//8;            //pozycja kursora musi być pomniejszona 0 22 prawdopodobnie, bo Cursor pos wskazuje pozycję na ekranie; 22, to szerokość caption.form2
    x:=x-form1.Left-4;//8;              //j.w., +8, bo wykrywane w programie form2.top=-8, a form2.left=-8   dla W7, ale -4 dla W10
    if (x>=panel4.Left) and(x<=panel4.Left+panel4.Width) and (y>=panel4.top) and (y<=panel4.Top +panel4.Height) then
     begin
      labelx:=label57;
      labelColor(labelx);
      x:=round((x-panel4.Left)/f1wspx4);
      label57.Caption:='('+intToStr(x)+', '+intToStr(y)+')= ('+floatToStrF(x*rate/count,ffFixed,8,0)+'Hz, '+floatToStrF((-(y-f1centr4)/f1wspy4+2.9+0.96),ffFixed,8,3)+')'; //+2.9 not explained yet
     end
    else

    if (x>=panel2.Left-3) and(x<=panel2.Left+panel2.Width) and (y>=panel2.top) and (y<=panel2.Top +panel2.Height) then
     begin
      labelx:=label46;
      labelColor(labelx);
      x:=round((x-panel2.Left)/f1wspx2);
      label46.Caption:='('+intToStr(x+startOsc)+'pts, '+intToStr(-y+f1Centr2)+'pts)= ('+
       floatToStrF((x+startOsc)/rate,ffFixed,8,3)+'s, '+floatToStrF((-(y-f1centr2)/f1wspy2),ffFixed,8,3)+'mV)'; //+2.9 not explained yet //06072017, there was: '+floatToStrF((-(y-centr1)/wspy1),ffFixed,8,3)+')';
     end
    else

     if  (x>=panel6.Left) and(x<=panel6.Left+panel6.Width) and (y>=panel6.top) and (y<=panel6.Top +panel6.Height) then
     begin
      labelx:=label5;
      labelColor(labelx);
      x:=round((x-panel6.Left)/f1wspx6);
      label5.Caption:='('+intToStr(x)+', '+intToStr(y)+')= ('+floatToStrF(1000*x/rate,ffFixed,8,0)+'ms, '+
       floatToStrF((-(y-f1centr6/1000-panel6.top-panel6.height)/f1wspy6),ffFixed,8,3)+')';
      // floatToStrF((-(y-f1centr4)/f1wspy4+2.9+0.96),ffFixed,8,3)+')'; //+2.9 not explained yet
     end

    else
     begin
     label57.caption:='Filters shape';
     label57.top:=panel4.top-16;
     label5.caption:='Weighting windows shape';
     label5.top:=panel4.top-16
    end;
   End;{with}
  except
   (*ShowMessage('Some error occured in procedure interpreting cursor position on a graph "'+labelx.Caption+'" area.'+
                #13#10'You can ignore it, just move mouse cursor to some other position.');*)
  end;
 End; {TForm1.FormMouseMove}

procedure TForm1.Edit9Exit(Sender: TObject);
begin
 try
  fft_par(Edit9,form2.Edit5);//RAMallocate;
  form1.edit15.text:=intToStr(rectFill);
  form2.edit7.Text:=intToStr(rectFill);
  timeBack:=true;
 except
  showMessage('There is something wrong with the "'+form1.Edit9.Text+'". correct it');
 end;
end;

procedure TForm1.Edit15Exit(Sender: TObject);
begin
 try
  rectFill:=strToint(form1.edit15.text) mod (count div 2) -1;
  form1.edit15.text:=intToStr(rectFill);
  form2.Edit7.Text:=form1.edit15.text;
 except
  ShowMessage(form1.edit15.text+' is not an integer!, try again.');
 end;
end;

procedure TForm1.Edit2Change(Sender: TObject);
var i:integer;
begin
 if tryStrToInt(edit2.text,i) then form1.edit10.text:=floatToStrF(1000*i/rate,ffFixed,6,3)
 else Edit2.Text:=intToStr(jumpNbrSamples);
end;

procedure TForm1.Edit10Exit(Sender: TObject);
begin
 edit10Process;
end;

procedure TForm1.Edit3Change(Sender: TObject);
begin
 cathNameArr[1]:=edit3.text;
end;

procedure TForm1.Edit4Change(Sender: TObject);
begin
  cathNameArr[2]:=edit4.text;
end;

procedure TForm1.Edit6Change(Sender: TObject);
begin
 cathNameArr[3]:=edit6.text;
end;

procedure TForm1.Edit7Change(Sender: TObject);
begin
cathNameArr[4]:=edit7.text;
end;

procedure TForm1.Edit7Exit(Sender: TObject);
begin
 initWrite;
 with form2 do
  begin
   label64.caption:=cathNameArr[1];
   label66.caption:=cathNameArr[2];
   label70.caption:=cathNameArr[3];
   label5.caption:=cathNameArr[4];
  end;
end;

procedure multiMeanCheckOff;
 Begin
  with form1 do
   begin
    //cPS                       cPC
    checkbox42.checked:=false;  checkbox46.checked:=false;
    checkbox42.enabled:=false;  checkbox46.enabled:=false;
    //vPC                       vPS
    checkbox47.checked:=false;  checkbox43.checked:=false;
    checkbox47.enabled:=false;  checkbox43.enabled:=false;
   end;
 End;{multiMeanCheckOff}

 procedure OutChecksEnabler;
  Begin
   with form1 do
    begin
   //input                    PS                         aPS
    checkbox5.enabled:=true;  checkbox40.enabled:=true; checkbox4.enabled:=true;
  //sPS                       mPS                        PC
    checkbox41.enabled:=true; checkbox44.enabled:=true; checkbox45.enabled:=true;
  //mPC                        cPS                        cPC
    checkbox48.enabled:=true; checkbox42.enabled:=true; checkbox46.enabled:=true;
  //vPC                       vPS
    checkbox47.enabled:=true; checkbox43.enabled:=true;
   end{with}
 End;{procedure OutChecksEnabler}

procedure TForm1.CheckBox49Click(Sender: TObject);
Begin //output check boxes on form1, decide, which mean boundle will be outputed
 checkBox49.Caption:='11. Multi Mean (mm'+radiogroup4.Items[radiogroup4.itemIndex]+')';
 with form1 do
  if checkbox49.Checked then
   begin
   //input                    PS                        aPS
    checkbox5.checked:=false; checkbox40.checked:=false;checkbox4.checked:=false;
    checkbox5.enabled:=false; checkbox40.enabled:=false;checkbox4.enabled:=false;
   //sPS                      mPS                        PC
    checkbox41.checked:=false;checkbox44.checked:=false;checkbox45.checked:=false;
    checkbox41.enabled:=false;checkbox44.enabled:=false;checkbox45.enabled:=false;
   //mPC
    checkbox48.checked:=false;
    checkbox48.enabled:=false;
    multiMeanCheckOff;
   end;{if}
 edit24.Text:='3';

 //checkBox39.Enabled:=checkBox49.Checked;
 //if not checkBox49.Checked then checkBox39.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Synchro analiz w zależności od potrzeb wizualizacji i wyjść
  case form1.radiogroup4.ItemIndex of
  0, 1:begin bundleRange:=PSrange;bundlePanel:=3 end;
  2, 3:begin bundleRange:=PCrange;bundlePanel:=4 end;
 end;{case, range}
 case form1.radiogroup4.ItemIndex of
  0, 2:bundleColor:=streamsGraphColors[5];//clYellow;
  1, 3:bundleColor:=streamsGraphColors[4]//clGreen;
 end;{case color}
 radiogroup4.Visible:=checkbox49.Checked;
 radiogroup4.enabled:=checkbox49.enabled;
// if button3.Enabled then button3.SetFocus; 04122023
 if not checkBox49.Checked then OutChecksEnabler;
 showMessage('You can add (or remove) other streams to output on the next, "visual" window');
end;{CheckBox49Click}

procedure TForm1.Button10Click(Sender: TObject);
begin
 begWave:=true;
 wholeWave:=false;
 button9.Enabled:=false;   //"Back"
 button10.Enabled:=false; //"begin"
 button13.Enabled:=false;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
 decWspx1:=true;
 wholeWave:=false;
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
 incWspx1:=true;
 wholeWave:=false;
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
 back10:=true;
 wholeWave:=false;
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
 button9.Enabled:=true;
 button10.Enabled:=true;
 button13.Enabled:=true;
 next10:=true;
 wholeWave:=false;
end;

function DollarInsert(s:string):string;
 Begin
  insert('$',s,pos('.',s)+1);
  result:=s;
 End;{DollarInsert}

 function DollarDelete(s:string):string;
  Begin
   delete(s,pos('$',s),1);
   result:=s
  End;

 procedure dollarInOutSynchr(checkStnd,checkOut,checkSynchr:TcheckBox);
 Begin
   with checkOut do
    if checked and checkStnd.Checked then
     Caption:= DollarInsert(Caption)
    else
     Caption:= DollarDelete(Caption);
  checkSynchr.checked:=checkStnd.Checked;
 End {dollarInOutSynchr};

 (*
if form1.checkBox30.Checked then
  with form2.CheckBox32 do Caption:= DollarInsert(Caption)
 else
  with form2.CheckBox32 do Caption:= DollarDelete(Caption);//'$' else form2.CheckBox32.Caption:='';
 form2.CheckBox84.Checked:=CheckBox30.Checked;
 *)

procedure TForm1.RadioGroup4Click(Sender: TObject);
begin
 multiMeanCheckOff;
 case form1.radiogroup4.ItemIndex of
  0, 1:begin bundleRange:=PSrange;bundlePanel:=3 end;
  2, 3:begin bundleRange:=PCrange;bundlePanel:=4 end;
 end;{case, range}
 case form1.radiogroup4.ItemIndex of
  0, 2:bundleColor:=streamsGraphColors[5];//clYellow;
  1, 3:bundleColor:=streamsGraphColors[4]//clGreen;
 end;{case color}
 form2.radiogroup4.ItemIndex:=form1.radiogroup4.ItemIndex;
 form2.radiogroup4.Enabled:=form2.CheckBox45.Enabled;
// if button3.canFocus then button3.SetFocus;    //enabled - canFocus 07122023
 form1.radiogroup4.Enabled:=false;
 checkBox49.Caption:='11. Multi Mean (mm'+radiogroup4.Items[radiogroup4.itemIndex]+')';
 if form2.checkbox24.Checked   then    //block message when is operated from form2.radio4
  if checkBox49.Checked then showMessage('Switch OFF/ON the "'+checkBox49.Caption+'" to change this choice');
end;{RadioGroup4Click}

  //--------------standardise, then form2 ouotput checkboxes = $----------------------------
procedure TForm1.CheckBox30Click(Sender: TObject);
begin
 dollarInOutSynchr(form1.checkBox30,form2.CheckBox32,form2.CheckBox84);
 (*
 if form1.checkBox30.Checked then
  with form2.CheckBox32 do Caption:= DollarInsert(Caption)
 else
  with form2.CheckBox32 do Caption:= DollarDelete(Caption);//'$' else form2.CheckBox32.Caption:='';
 form2.CheckBox84.Checked:=CheckBox30.Checked;
 *)
end;

procedure TForm1.CheckBox31Click(Sender: TObject);
begin
 dollarInOutSynchr(form1.checkBox31,form2.CheckBox33,form2.CheckBox85);
 (*if form1.checkBox31.Checked then  form2.CheckBox33.Caption:='$' else form2.CheckBox33.Caption:='';
 form2.CheckBox85.Checked:=CheckBox31.Checked; *)
end;

procedure TForm1.CheckBox32Click(Sender: TObject);
begin
 //checkBox39.Checked:=checkBox32.Checked;
 dollarInOutSynchr(form1.checkBox32,form2.CheckBox36,form2.CheckBox88);
 (*if form1.checkBox32.Checked then  form2.CheckBox36.Caption:='$' else form2.CheckBox36.Caption:='';
 form2.CheckBox88.Checked:=CheckBox32.Checked;  *)
end;
procedure TForm1.CheckBox33Click(Sender: TObject);
begin
 dollarInOutSynchr(form1.checkBox33,form2.CheckBox35,form2.CheckBox87);
(* if form1.checkBox33.Checked then  form2.CheckBox35.Caption:='$' else form2.CheckBox35.Caption:='';
 form2.CheckBox87.Checked:=CheckBox33.Checked; *)
end;

procedure TForm1.CheckBox34Click(Sender: TObject);
begin
 dollarInOutSynchr(form1.checkBox34,form2.CheckBox34,form2.CheckBox86);
(* if form1.checkBox34.Checked then  form2.CheckBox34.Caption:='$' else form2.CheckBox34.Caption:='';
 form2.CheckBox86.Checked:=CheckBox34.Checked;  *)
end;

procedure TForm1.CheckBox35Click(Sender: TObject);
begin
 dollarInOutSynchr(form1.checkBox35,form2.CheckBox41,form2.CheckBox89);
(* if form1.checkBox35.Checked then  form2.CheckBox41.Caption:='$' else form2.CheckBox41.Caption:='';
 form2.CheckBox89.Checked:=CheckBox35.Checked;  *)
end;

procedure TForm1.CheckBox36Click(Sender: TObject);
begin
 dollarInOutSynchr(form1.checkBox36,form2.CheckBox44,form2.CheckBox92);
 (*if form1.checkBox36.Checked then  form2.CheckBox44.Caption:='$' else form2.CheckBox44.Caption:='';
 form2.CheckBox92.Checked:=CheckBox36.Checked; *)
end;

procedure TForm1.CheckBox37Click(Sender: TObject);
begin
 dollarInOutSynchr(form1.checkBox37,form2.CheckBox43,form2.CheckBox91);
 (*if form1.checkBox37.Checked then  form2.CheckBox43.Caption:='$' else form2.CheckBox43.Caption:='';
 form2.CheckBox91.Checked:=CheckBox37.Checked; *)
end;

procedure TForm1.CheckBox38Click(Sender: TObject);
begin
 dollarInOutSynchr(form1.checkBox38,form2.CheckBox42,form2.CheckBox90);
 (*if form1.checkBox38.Checked then  form2.CheckBox42.Caption:='$' else form2.CheckBox42.Caption:='';
 form2.CheckBox90.Checked:=CheckBox38.Checked; *)
end;

procedure TForm1.CheckBox39Click(Sender: TObject);
begin
 dollarInOutSynchr(form1.checkBox39,form2.CheckBox45,form2.CheckBox93);
 //if form1.checkBox39.Checked then  form2.CheckBox45.Caption:='$'+form2.CheckBox45.Caption else form2.CheckBox45.Caption:=form1.CheckBox49.caption;
(* form2.CheckBox93.Checked:=CheckBox39.Checked;*)
end;

procedure TForm1.CheckBox29Click(Sender: TObject);
begin  //input signal portion to output
 dollarInOutSynchr(form1.checkBox29,form2.CheckBox31,form2.CheckBox82);
end;

procedure TForm1.CheckBox4Click(Sender: TObject);
begin  //aPS OUT
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Needed analyses turn on  (Synchro analiz w zależności od potrzeb wizualizacji i wyjść)
end;

procedure TForm1.CheckBox41Click(Sender: TObject);
begin
 checkBox31.Enabled:=checkBox41.Checked;
 //if not checkBox41.Checked then checkBox31.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Needed analyses turn on  (Synchro analiz w zależności od potrzeb wizualizacji i wyjść)
end;

procedure TForm1.CheckBox43Click(Sender: TObject);
begin    //vPS OUT
 checkBox33.Enabled:=checkBox43.Checked;
 //if not checkBox43.Checked then checkBox33.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Needed analyses turn on  (Synchro analiz w zależności od potrzeb wizualizacji i wyjść)
end;

procedure TForm1.CheckBox44Click(Sender: TObject);
begin
 checkBox34.Enabled:=checkBox44.Checked;
 //if not checkBox44.Checked then checkBox34.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Needed analyses turn on  (Synchro analiz w zależności od potrzeb wizualizacji i wyjść)
end;

procedure TForm1.CheckBox45Click(Sender: TObject);
begin
 checkBox35.Enabled:=checkBox45.Checked;
 //if not checkBox45.Checked then checkBox35.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Needed analyses turn on  (Synchro analiz w zależności od potrzeb wizualizacji i wyjść)
end;

procedure TForm1.CheckBox46Click(Sender: TObject);
begin
 checkBox36.Enabled:=checkBox46.Checked;
 //if not checkBox46.Checked then checkBox36.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Needed analyses turn on  (Synchro analiz w zależności od potrzeb wizualizacji i wyjść)
end;

procedure TForm1.CheckBox47Click(Sender: TObject);
begin
 checkBox37.Enabled:=checkBox47.Checked;
 //if not checkBox47.Checked then checkBox37.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Needed analyses turn on  (Synchro analiz w zależności od potrzeb wizualizacji i wyjść)
end;

procedure TForm1.CheckBox48Click(Sender: TObject);
begin
 checkBox38.Enabled:=checkBox48.Checked;
 //if not checkBox48.Checked then checkBox38.Checked:=false;
 OutCheckBoxesChecking;
 setAnalysisCheck(false,PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);   // Needed analyses turn on  (Synchro analiz w zależności od potrzeb wizualizacji i wyjść)
end;

procedure TForm1.Edit12Exit(Sender: TObject);
begin
 unit1.editChange(Edit12);
 manager:='R'
end;

procedure TForm1.FormResize(Sender: TObject);
begin
 application.ProcessMessages;
 form1.Panel2.Width:=form1.width-form1.Panel2.left-40; //-60
 OscRep:=true
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
 OscRep:=true
end;

procedure TForm1.Button16Click(Sender: TObject);
begin
 back1:=true;
 wholeWave:=false;
end;

procedure TForm1.Button17Click(Sender: TObject);
begin
 button9.Enabled:=true;
 button10.Enabled:=true;
 button13.Enabled:=true;
 next1:=true;
 wholeWave:=false;
end;

Initialization

end.


 25012025
(*
 function setAnalysisCheck(const viz:boolean; out PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC:boolean):dword;
 {
Needed analyses turn on (Synchro analiz w zależności od potrzeb wizualizacji i wyjść)
 }
  var  logos:boolean;
   Begin
    result:=maxDword;
    logos:=form2.CheckBox1.Checked;  //checkbox1=show graphs
    with form1 do   //=======attention, the order of evaluations is important! ========================
     begin          //Analysis-Out-(form1)-------visualisation graph (form2) Aligning form2
            PS:=checkBox40.Checked or form2.checkBox9.Checked  and logos;                                  //PS
           aPS:=checkBox4.Checked  or form2.checkBox26.Checked and logos;                                  //aPS (phase)
           cPS:=checkBox42.Checked or (form2.checkBox13.Checked or form2.CheckBox22.Checked) and logos;    //cPS
           vPS:=checkBox43.Checked or (form2.checkBox12.Checked or form2.CheckBox21.Checked) and logos;    //vPS
          msPS:=checkBox44.Checked or (form2.checkBox11.Checked or form2.CheckBox20.Checked) and logos;    //melsPS
            PC:=checkBox45.Checked or form2.checkBox14.Checked and logos;                                  //PC
           cPC:=checkBox46.Checked or (form2.checkBox17.Checked or form2.CheckBox97.Checked) and logos;    //cPC        f1.check46=output/cPC,   f2.check17=cPC chart
           vPC:=checkBox47.Checked or (form2.checkBox16.Checked or form2.CheckBox64.Checked) and logos;    //vPC
           mPC:=checkBox48.Checked or (form2.checkBox15.Checked or form2.CheckBox63.Checked) and logos;    //mPC
           sPS:=checkBox41.Checked or (form2.checkBox10.Checked or form2.CheckBox19.Checked) and logos;                   //sPS
         mmcPS:=checkBox49.Checked;//or form2.checkBox17.Checked and logos;  //multi_cPC; f1.check49=output/mmcPS, f2.check17=cPC chart
      //------------------------------------------------------------------------------interactions
        sPS:=sPS or mPC or msPS;
        mPC:=mPC  or msPS;
        vPC:=vPC  or vPS;
        cPC:=cPC  or vPC or cPS;
         PC:=PC   or cPC or mPC or sPS or vPS or mmcPS or form2.CheckBox81.Checked; //or force F0 calc.;
         PS:=PS   or PC  or aPS;
      AnalysisChecksSetting(PS,sPS,cPS,vPS,msPS,aPS,PC,cPC,vPC,mPC);
     end;
    setLength(frameNbrArr,NbrOfMultiMean+1);
    setLength(frameNbr0Arr,NbrOfMultiMean+1);    // : array of integer;          //for multi CCR processing
    setLength(reHistoryArr,NbrOfMultiMean+1);    // : array of Thistory;         //for multi CCR processing
    setLength(reMeanVectorArr,NbrOfMultiMean+1,count); // : array of array of double;
    if form1.CheckBox3.Checked then maxFrameNbr:=maxFrameNbr0 else maxFrameNbr:=frameNbr;   //check3 - "multiMean" analysis
    if not PC then
     begin
      showMessage('Fundamental frequency (F0) will NOT be evaluated from now.'#13#10+
      'This is only when cepstrum is computed for visualisation or for output of a stream,'+
      'which recquires carrying out the cepstrum computing.'#13#10+
      'To the output record will be written some constant - last found F0.'#13#10+
      'Turn on the "'+form2.CheckBox81.Caption+'" to enforce calculation it.');
      F0Mess:=true;
      form2.CheckBox81.Enabled:=true;
     end
    else
     if F0mess then  with form2 do
      begin
       showMessage('Fundamental frequency (F0) WILL be evaluated from now.'#13#10'Remember: the "'+
       button2.Caption+'" or "'+button11.Caption+'" operation will not repair break gaps emergent'+  //Back, Go to
       ' due to your options; this would recquire start analysis  from scratch');
       F0mess:=false;
      end;
    if spcSave and not viz then  whatToSave(not spcSave);   //15122024   if - 16122024;  it is a must, to substitute manager:='E' from OutCheckSynchro
   End; {setAnalysisCheck}   *)
