Advertisement
Vladislav8653

xD

May 27th, 2023
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 7.50 KB | None | 0 0
  1. unit MainUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Imaging.pngimage,
  8.   Vcl.StdCtrls, Vcl.Imaging.jpeg, FMX.Media, Vcl.Menus;
  9.  
  10. type
  11.   TWelcomeWindow = class(TForm)
  12.     Logo: TImage;
  13.     SendButton: TButton;
  14.     GetButton: TButton;
  15.     Label1: TLabel;
  16.     ExtendedInfo: TPopupMenu;
  17.     Info: TMainMenu;
  18.     N1: TMenuItem;
  19.     N2: TMenuItem;
  20.     procedure SendButtonClick(Sender: TObject);
  21.     procedure GetButtonClick(Sender: TObject);
  22.   private
  23.     { Private declarations }
  24.   public
  25.     Mic: TAudioCaptureDevice;
  26.   end;
  27.  
  28. var
  29.   WelcomeWindow: TWelcomeWindow;
  30.  
  31. implementation
  32.  
  33. uses SendWindow, GetWindow;
  34.  
  35. {$R *.dfm}
  36.  
  37. procedure TWelcomeWindow.GetButtonClick(Sender: TObject);
  38. begin
  39.     GetParcel.ShowModal;
  40. end;
  41.  
  42. procedure TWelcomeWindow.SendButtonClick(Sender: TObject);
  43. begin
  44.     SendParcel.ShowModal;
  45. end;
  46.  
  47. end.
  48. =================================================================
  49. unit SendWindow;
  50.  
  51. interface
  52.  
  53. uses
  54.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  55.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Bass, Vcl.Menus,
  56.   Vcl.Imaging.jpeg, Vcl.ExtCtrls, Vcl.ComCtrls;
  57.  
  58. type
  59.   TSendParcel = class(TForm)
  60.     InputEdit: TEdit;
  61.     VarOfChose: TComboBox;
  62.     InfoLabel: TLabel;
  63.     TextLabel: TLabel;
  64.     OpenDialog1: TOpenDialog;
  65.     GoButton: TButton;
  66.     Logo: TImage;
  67.     Info: TMainMenu;
  68.     ExtendedInfo: TPopupMenu;
  69.     N1: TMenuItem;
  70.     N2: TMenuItem;
  71.     N3: TMenuItem;
  72.     N4: TMenuItem;
  73.     SaveDialog1: TSaveDialog;
  74.     ProgressBar: TProgressBar;
  75.     procedure VarOfChoseChange(Sender: TObject);
  76.     procedure GoButtonClick(Sender: TObject);
  77.     procedure InputEditChange(Sender: TObject);
  78.     procedure InputEditKeyPress(Sender: TObject; var Key: Char);
  79.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  80.   private
  81.     { Private declarations }
  82.   public
  83.     { Public declarations }
  84.   end;
  85.  
  86. var
  87.   SendParcel: TSendParcel;
  88.   Path: String;
  89.  
  90. implementation
  91.  
  92. {$R *.dfm}
  93.  
  94. uses MainUnit;
  95.  
  96.  
  97. procedure TSendParcel.FormClose(Sender: TObject; var Action: TCloseAction);
  98. begin
  99.     InputEdit.Visible := False;
  100.     TextLabel.Visible := False;
  101.     GoButton.Visible := False;
  102.     GoButton.Enabled := False;
  103.     ProgressBar.Visible := False;
  104.     VarOFChose.ItemIndex := -1;
  105. end;
  106.  
  107. procedure PlaySound (Frequancy : Cardinal);
  108. Const
  109.     Duration = 400;
  110. begin
  111.    Winapi.Windows.Beep(Frequancy, Duration);
  112. end;
  113.  
  114. procedure TSendParcel.GoButtonClick(Sender: TObject);
  115. var
  116.     DataLength, I, MinAsciiCode, Gap, Proc: Integer;
  117.     Data : String;
  118. Const
  119.     MIN_FREQ = 1000;
  120.     STEP = 20;
  121. begin
  122.     Data := InputEdit.Text;
  123.     DataLength := Length(InputEdit.Text);
  124.     MinAsciiCode := Ord(Data[1]);
  125.     For I := Low(Data) to High(Data) - 1 Do
  126.     begin
  127.         If Ord(Data[I+1]) < Ord(Data[I]) then
  128.             MinAsciiCode := Ord(Data[I+1]);
  129.     end;
  130.     ProgressBar.Visible := True;
  131.     For I := Low(Data) to High(Data) Do
  132.     begin
  133.         Gap := Ord(Data[I]) - MinAsciiCode;
  134.         PlaySound(1000 + STEP * Gap);
  135.         Proc := ((I * 100) div DataLength - 1);
  136.         ProgressBar.Position := Proc;
  137.         Application.ProcessMessages;
  138.     end;
  139.     ProgressBar.Position := 100;
  140. end;
  141.  
  142.  
  143. procedure TSendParcel.InputEditChange(Sender: TObject);
  144. begin
  145.     If Length(InputEdit.Text) > 0 then
  146.         GoButton.Enabled := True
  147.     else
  148.         GoButton.Enabled := False;
  149. end;
  150.  
  151. procedure TSendParcel.InputEditKeyPress(Sender: TObject; var Key: Char);
  152. begin
  153.     If (Key = #13) and (GoButton.Enabled) then
  154.         GoButton.Click
  155. end;
  156.  
  157. procedure TSendParcel.VarOfChoseChange(Sender: TObject);
  158. Const
  159.     STR_INPUT = 0;
  160.     IMAGE_INPUT = 1;
  161. begin
  162.     if VarOFChose.ItemIndex = STR_INPUT then
  163.     begin
  164.         InputEdit.Visible := True;
  165.         TextLabel.Visible := True;
  166.         GoButton.Visible := True;
  167.     end;
  168.     if VarOFChose.ItemIndex = IMAGE_INPUT then
  169.     begin
  170.          MessageBox(SendParcel.Handle, Pchar('Дорогой пользователь, функция передачи картинок будет реализована в ближайшем будущем. Спасибо за понимание.'), 'Извинения', MB_ICONINFORMATION);
  171.          VarOfChose.ItemIndex := -1;
  172.     end;
  173. end;
  174.  
  175. end.
  176. =========================================================
  177. unit GetWindow;
  178.  
  179. interface
  180.  
  181. uses
  182.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  183.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, MMSystem,
  184.   Vcl.Imaging.pngimage, Vcl.ExtCtrls, Vcl.Menus, MainUnit, Bass, BassEnc, BassEnc_MP3;
  185.  
  186. type
  187.   TGetParcel = class(TForm)
  188.     RecordButton: TButton;
  189.     StopRecordButton: TButton;
  190.     Logo: TImage;
  191.     ShowResultsButton: TButton;
  192.     MainMenu1: TMainMenu;
  193.     PopupMenu1: TPopupMenu;
  194.     ResultEdit: TEdit;
  195.     PlayButton: TButton;
  196.     procedure FormDestroy(Sender: TObject);
  197.     procedure RecordButtonClick(Sender: TObject);
  198.     procedure StopRecordButtonClick(Sender: TObject);
  199.     procedure PlayButtonClick(Sender: TObject);
  200.     procedure ShowResultsButtonClick(Sender: TObject);
  201.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  202.   private
  203.     { Private declarations }
  204.   public
  205.     { Public declarations }
  206.   end;
  207.  
  208. var
  209.   GetParcel: TGetParcel;
  210.   Channel: HRECORD;
  211.  
  212. implementation
  213.  
  214. {$R *.dfm}
  215.  
  216.  
  217. function RecordingCallback(Handle: HRECORD; buffer: Pointer; length: DWORD; user: Pointer): boolean; stdcall;
  218. begin
  219.     Result := True;
  220. end;
  221.  
  222. procedure ListenSurrounding ();
  223. var
  224.     IsCorrect : Boolean;
  225. begin
  226.     IsCorrect := False;
  227.     if BassEncMP3_IsAvailable and BASS_IsAvailable then
  228.        IsCorrect := True
  229.     else
  230.         MessageBox(GetParcel.Handle, Pchar('Что-то пошло неверным образом..'), 'Извинения', MB_ICONSTOP);
  231.     If IsCorrect then
  232.     begin
  233.         if not BASS_RecordInit(-1) then
  234.             ShowMessage('Cannot start default recording device!')
  235.         else
  236.         begin
  237.             Channel:= BASS_RecordStart(44100, 2, 0, @RecordingCallback, nil);
  238.             if Channel = 0 then
  239.                 ShowMessage('Couldn''t start recording!')
  240.             else
  241.             begin
  242.                 BASS_Encode_MP3_StartFile(Channel, '', BASS_ENCODE_AUTOFREE or BASS_UNICODE, PChar('запись.mp3'));
  243.             end;
  244.         end;
  245.     end;
  246. end;
  247.  
  248. procedure TGetParcel.PlayButtonClick(Sender: TObject);
  249. begin
  250.     BASS_ChannelPlay(Channel,True);
  251. end;
  252.  
  253. procedure TGetParcel.RecordButtonClick(Sender: TObject);
  254. begin
  255.     ListenSurrounding();
  256.     StopRecordButton.Enabled := True;
  257. end;
  258.  
  259. procedure TGetParcel.ShowResultsButtonClick(Sender: TObject);
  260. begin
  261.     ResultEdit.Visible := True;
  262.     ResultEdit.Text := 'Привет мир';
  263. end;
  264.  
  265. procedure TGetParcel.StopRecordButtonClick(Sender: TObject);
  266. begin
  267.     BASS_ChannelStop(Channel);
  268.     BASS_RecordFree;
  269.     PlayButton.Enabled := True;
  270.     ShowResultsButton.Enabled := True;
  271.     RecordButton.Caption := 'Повторить прослушивание';
  272. end;
  273.  
  274. procedure TGetParcel.FormClose(Sender: TObject; var Action: TCloseAction);
  275. begin
  276.     StopRecordButton.Enabled := False;
  277.     PlayButton.Enabled := False;
  278.     ShowResultsButton.Enabled := False;
  279.     ResultEdit.Visible := False;
  280.     ResultEdit.Text := '';
  281. end;
  282.  
  283. procedure TGetParcel.FormDestroy(Sender: TObject);
  284. begin
  285.     BASS_RecordFree;
  286.     BASS_Free;
  287. end;
  288.  
  289. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement