unit WisdomBuilder; {$IFDEF FPC} {$MODE Delphi} {$ENDIF} interface uses Classes, SysUtils, Forms, Controls, ExtCtrls, StdCtrls, WDSP, AppTheme, FlatProgressBar; type TWisdomBuildThread = class(TThread) private FDirectory: string; FError: string; protected procedure Execute; override; public constructor Create(const ADirectory: string); property ErrorText: string read FError; end; TWisdomProgressDialog = class(TForm) private FInfoLabel: TLabel; FProgress: TFlatProgressBar; FTimer: TTimer; FThread: TWisdomBuildThread; FPhase: Integer; procedure TimerTick(Sender: TObject); public constructor Create(AOwner: TComponent; AThread: TWisdomBuildThread; const ATheme: TAppTheme); reintroduce; end; implementation constructor TWisdomBuildThread.Create(const ADirectory: string); begin inherited Create(False); FreeOnTerminate := False; FDirectory := ADirectory; FError := ''; end; procedure TWisdomBuildThread.Execute; var DirA: AnsiString; begin try if not Assigned(@WDSPwisdom) then Exit; DirA := AnsiString(FDirectory); WDSPwisdom(PAnsiChar(DirA)); except on E: Exception do FError := E.ClassName + ': ' + E.Message; end; end; constructor TWisdomProgressDialog.Create(AOwner: TComponent; AThread: TWisdomBuildThread; const ATheme: TAppTheme); begin inherited CreateNew(AOwner); FThread := AThread; FPhase := 0; Caption := 'WDSP Wisdom'; Width := 520; Height := 140; Position := poScreenCenter; BorderStyle := bsDialog; BorderIcons := []; Color := ATheme.BG; Font.Name := 'Courier New'; Font.Size := 9; Font.Color := ATheme.Text; FInfoLabel := TLabel.Create(Self); FInfoLabel.Parent := Self; FInfoLabel.SetBounds(16, 16, 480, 40); FInfoLabel.AutoSize := False; FInfoLabel.WordWrap := True; FInfoLabel.Font.Color := ATheme.Text; FInfoLabel.Caption := 'Creating FFTW wisdom for WDSP. This is done once and may take a while on the first run.'; FProgress := TFlatProgressBar.Create(Self); FProgress.Parent := Self; FProgress.SetBounds(16, 72, 480, 22); FProgress.Min := 0; FProgress.Max := 100; FProgress.Position := 0; FProgress.SetAppTheme(ATheme); FTimer := TTimer.Create(Self); FTimer.Interval := 250; FTimer.OnTimer := TimerTick; FTimer.Enabled := True; end; procedure TWisdomProgressDialog.TimerTick(Sender: TObject); var P: PAnsiChar; S: string; begin FPhase := (FPhase + 7) mod 101; FProgress.Position := FPhase; if Assigned(@wisdom_get_status) then begin P := wisdom_get_status; if P <> nil then begin S := Trim(string(AnsiString(P))); if S <> '' then FInfoLabel.Caption := S; end; end; if Assigned(FThread) and FThread.Finished then begin FTimer.Enabled := False; ModalResult := mrOk; end; end; end.