Advertisement
altervisi0n

курсач 2 сем

May 24th, 2023
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 28.89 KB | None | 0 0
  1. unit UnitPlay;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils,
  7.   System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
  8.   Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.ComCtrls, Bass, Inifiles,
  9.   Vcl.Buttons,
  10.   System.ImageList, Vcl.ImgList;
  11.  
  12. type
  13.  
  14.   TDrawData = array [0 .. 512] of Single;
  15.   TPlayerMode = (Stop, Play, Paused);
  16.  
  17.   TSoundCloud = class(TForm)
  18.     IndicateGraph: TPaintBox;
  19.     TimeFirstLabel: TLabel;
  20.     TimeLastLabel: TLabel;
  21.     SoundLabel: TLabel;
  22.     BalanceLabel: TLabel;
  23.     ScrollSongBar: TScrollBar;
  24.     SongsList: TListBox;
  25.     OpenDialog1: TOpenDialog;
  26.     Timer1: TTimer;
  27.     SoundBar: TTrackBar;
  28.     BalanceBar: TTrackBar;
  29.     SongNameLabel: TLabel;
  30.     VolumeZeroButton: TBitBtn;
  31.     PlayButton: TBitBtn;
  32.     ImageList1: TImageList;
  33.     PauseButton: TBitBtn;
  34.     BackButton: TBitBtn;
  35.     ForwardButton: TBitBtn;
  36.     StopButton: TBitBtn;
  37.     TrashCanButton: TBitBtn;
  38.     FolderButton: TBitBtn;
  39.     EqualizerButton: TBitBtn;
  40.     MiniViewButton: TBitBtn;
  41.     VolumeTenButton: TBitBtn;
  42.     SettingsAndInfoButton: TBitBtn;
  43.     procedure EqualizerButtonClick(Sender: TObject);
  44.     procedure VolumeZeroButtonClick(Sender: TObject);
  45.     procedure Player;
  46.     procedure FormCreate(Sender: TObject);
  47.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  48.     procedure ScrollSongBarScroll(Sender: TObject; ScrollCode: TScrollCode;
  49.       var ScrollPos: Integer);
  50.     procedure Timer1Timer(Sender: TObject);
  51.     procedure SongsListDblClick(Sender: TObject);
  52.     procedure IndicateGraphPaint(Sender: TObject);
  53.     procedure Draw(HWND: THandle; DrawData: TDrawData; X, Y: Integer);
  54.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  55.     procedure PlayButtonClick(Sender: TObject);
  56.     procedure PauseButtonClick(Sender: TObject);
  57.     procedure BackButtonClick(Sender: TObject);
  58.     procedure ForwardButtonClick(Sender: TObject);
  59.     procedure StopButtonClick(Sender: TObject);
  60.     procedure TrashCanButtonClick(Sender: TObject);
  61.     procedure FolderButtonClick(Sender: TObject);
  62.     procedure MiniViewButtonClick(Sender: TObject);
  63.     procedure ActivateMusicPlayer();
  64.     procedure DeActivateMusicPlayer();
  65.     procedure PlayOrNot();
  66.     procedure VolumeTenButtonClick(Sender: TObject);
  67.     procedure SettingsAndInfoButtonClick(Sender: TObject);
  68.     procedure SondListDrawItem(Control: TWinControl; Index: Integer;
  69.       Rect: TRect; State: TOwnerDrawState);
  70.     procedure CreateCfg;
  71.     procedure CloseCfg;
  72.  
  73.   private
  74.     { Private declarations }
  75.  
  76.   public
  77.     { Public declarations }
  78.  
  79.   end;
  80.  
  81. var
  82.   SoundCloud: TSoundCloud;
  83.   I: Longint; // номер песни
  84.   Filename: string; // имя файла
  85.   Channel: Integer; // сюда сохраняем дескриптор
  86.   Mode: TPlayerMode; // режим
  87.   P: BASS_DX8_PARAMEQ;
  88.   Fx: array [1 .. 10] of Longint;
  89.   // переменные визуализации
  90.   DrawPeaks: array [0 .. 164] of Longint;
  91.   DrawFallOff: array [0 .. 164] of Longint;
  92.   // переменная файла конфигурации
  93.   IniFile: TIniFile;
  94.  
  95. implementation
  96.  
  97. {$R *.dfm}
  98.  
  99. uses
  100.   UnitMini, UnitMix, UnitInformation;
  101.  
  102. procedure TSoundCloud.Draw(HWND: THandle; DrawData: TDrawData; X, Y: Integer);
  103. var
  104.   I, YPos: Longint;
  105.   YVal: Single;
  106. begin
  107.   IndicateGraph.Canvas.Pen.Color := clBlack;
  108.   IndicateGraph.Canvas.Brush.Color := clBlack;
  109.   IndicateGraph.Canvas.Rectangle(0, 0, IndicateGraph.Width,
  110.     IndicateGraph.Height);
  111.   IndicateGraph.Canvas.Pen.Color := clRed;
  112.   for I := 0 to 163 do
  113.   begin
  114.     YVal := Abs(DrawData[I]);
  115.     YPos := Trunc((YVal) * 500);
  116.     if YPos > IndicateGraph.Height then
  117.       YPos := IndicateGraph.Height;
  118.     if YPos >= DrawPeaks[I] then
  119.       DrawPeaks[I] := YPos
  120.     else
  121.       DrawPeaks[I] := DrawPeaks[I] - 1;
  122.     if YPos >= DrawFallOff[I] then
  123.       DrawFallOff[I] := YPos
  124.     else
  125.       DrawFallOff[I] := DrawFallOff[I] - 3;
  126.     IndicateGraph.Canvas.Pen.Color := clYellow;
  127.     IndicateGraph.Canvas.MoveTo(X + I * (3 + 1), Y + IndicateGraph.Height -
  128.       DrawPeaks[I]);
  129.     IndicateGraph.Canvas.LineTo(X + I * (3 + 1) + 3, Y + IndicateGraph.Height -
  130.       DrawPeaks[I]);
  131.     IndicateGraph.Canvas.Pen.Color := clRed;
  132.     IndicateGraph.Canvas.Brush.Color := clRed;
  133.     IndicateGraph.Canvas.Rectangle(X + I * (3 + 1), Y + IndicateGraph.Height -
  134.       DrawFallOff[I], X + I * (3 + 1) + 3, Y + IndicateGraph.Height);
  135.   end;
  136. end;
  137.  
  138. procedure TSoundCloud.PlayButtonClick(Sender: TObject);
  139. begin
  140.   PlayOrNot();
  141.   if Mode = Play then
  142.     exit;
  143.   Player;
  144. end;
  145.  
  146. procedure TSoundCloud.Player;
  147. begin
  148.   if Mode <> Paused then
  149.   begin
  150.     if not FileExists(Filename) then
  151.     begin
  152.       Application.MessageBox('Ошибка воспроизведения файла', 'Ошибка ',
  153.         MB_ICONERROR);
  154.       exit;
  155.     end;
  156.     BASS_ChannelStop(Channel);
  157.     BASS_StreamFree(Channel);
  158.     Channel := BASS_StreamCreateFile(FALSE, PChar(Filename), 0, 0, 0
  159. {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});
  160.     if Channel = 0 then
  161.     begin
  162.       Application.MessageBox('Ошибка воспроизведения файла', 'Ошибка',
  163.         MB_ICONERROR);
  164.       exit;
  165.     end;
  166.   end;
  167.   Fx[1] := BASS_ChannelSetFX(Channel, BASS_FX_DX8_PARAMEQ, 1);
  168.   Fx[2] := BASS_ChannelSetFX(Channel, BASS_FX_DX8_PARAMEQ, 1);
  169.   Fx[3] := BASS_ChannelSetFX(Channel, BASS_FX_DX8_PARAMEQ, 1);
  170.   Fx[4] := BASS_ChannelSetFX(Channel, BASS_FX_DX8_PARAMEQ, 1);
  171.   Fx[5] := BASS_ChannelSetFX(Channel, BASS_FX_DX8_PARAMEQ, 1);
  172.   Fx[6] := BASS_ChannelSetFX(Channel, BASS_FX_DX8_PARAMEQ, 1);
  173.   Fx[7] := BASS_ChannelSetFX(Channel, BASS_FX_DX8_PARAMEQ, 1);
  174.   Fx[8] := BASS_ChannelSetFX(Channel, BASS_FX_DX8_PARAMEQ, 1);
  175.   Fx[9] := BASS_ChannelSetFX(Channel, BASS_FX_DX8_PARAMEQ, 1);
  176.   Fx[10] := BASS_ChannelSetFX(Channel, BASS_FX_DX8_PARAMEQ, 1);
  177.  
  178.   P.fGain := 15 - Mixtape.FirstBar.Position;
  179.   P.fBandwidth := 3;
  180.   P.fCenter := 80;
  181.   BASS_FXSetParameters(Fx[1], @P);
  182.  
  183.   P.fGain := 15 - Mixtape.SecondBar.Position;
  184.   P.fBandwidth := 3;
  185.   P.fCenter := 170;
  186.   BASS_FXSetParameters(Fx[2], @P);
  187.  
  188.   P.fGain := 15 - Mixtape.ThirdBar.Position;
  189.   P.fBandwidth := 3;
  190.   P.fCenter := 310;
  191.   BASS_FXSetParameters(Fx[3], @P);
  192.  
  193.   P.fGain := 15 - Mixtape.FourthBar.Position;
  194.   P.fBandwidth := 3;
  195.   P.fCenter := 600;
  196.   BASS_FXSetParameters(Fx[4], @P);
  197.  
  198.   P.fGain := 15 - Mixtape.FifthBar.Position;
  199.   P.fBandwidth := 3;
  200.   P.fCenter := 1000;
  201.   BASS_FXSetParameters(Fx[5], @P);
  202.  
  203.   P.fGain := 15 - Mixtape.SixthBar.Position;
  204.   P.fBandwidth := 3;
  205.   P.fCenter := 3000;
  206.   BASS_FXSetParameters(Fx[6], @P);
  207.  
  208.   P.fGain := 15 - Mixtape.SeventhBar.Position;
  209.   P.fBandwidth := 3;
  210.   P.fCenter := 6000;
  211.   BASS_FXSetParameters(Fx[7], @P);
  212.  
  213.   P.fGain := 15 - Mixtape.EighthBar.Position;
  214.   P.fBandwidth := 3;
  215.   P.fCenter := 10000;
  216.   BASS_FXSetParameters(Fx[8], @P);
  217.  
  218.   P.fGain := 15 - Mixtape.NinethBar.Position;
  219.   P.fBandwidth := 3;
  220.   P.fCenter := 12000;
  221.   BASS_FXSetParameters(Fx[9], @P);
  222.  
  223.   P.fGain := 15 - Mixtape.TenthBar.Position;
  224.   P.fBandwidth := 3;
  225.   P.fCenter := 14000;
  226.   BASS_FXSetParameters(Fx[10], @P);
  227.  
  228.   if not BASS_ChannelPlay(Channel, FALSE) then
  229.   begin
  230.     Application.MessageBox('Ошибка воспроизведения файла', 'Ошибка',
  231.       MB_ICONERROR);
  232.     exit;
  233.   end;
  234.   ScrollSongBar.Min := 0;
  235.   ScrollSongBar.Max := bass_ChannelGetLength(Channel, 0) - 1;
  236.   SongNameLabel.Caption := ExtractFileName(Filename);
  237.   Mode := Play;
  238.   if (Assigned(MiniLonely)) and (Mode = Play) then
  239.   begin
  240.     MiniLonely.ScrollBar1.Min := ScrollSongBar.Min;
  241.     MiniLonely.ScrollBar1.Max := ScrollSongBar.Max;
  242.     MiniLonely.TrackNameLabel.Caption := SongNameLabel.Caption;
  243.   end;
  244. end;
  245.  
  246. procedure TSoundCloud.ScrollSongBarScroll(Sender: TObject;
  247.   ScrollCode: TScrollCode; var ScrollPos: Integer);
  248. begin
  249.   bass_ChannelSetPosition(Channel, ScrollSongBar.Position, 0);
  250.   if not GetKeyState(VK_LBUTTON) < 0 then
  251.     PauseButton.Click;
  252. end;
  253.  
  254. procedure TSoundCloud.SondListDrawItem(Control: TWinControl; Index: Integer;
  255.   Rect: TRect; State: TOwnerDrawState);
  256. const
  257.   W = 16;
  258.   H = 16;
  259. begin
  260.   with (Control as TListBox).Canvas do
  261.   begin
  262.     FillRect(Rect);
  263.   end;
  264.   with (Control as TListBox).Canvas do
  265.   begin
  266.     Font.Color := clWhite;
  267.     Font.Size := 9;
  268.     Brush.Style := bsClear;
  269.     Brush.Color := clWhite;
  270.     SetBkMode(SongsList.Canvas.Handle, TRANSPARENT);
  271.     TextOut(Rect.Left, Rect.Top, IntToStr(Index + 1) + '. ' +
  272.       ExtractFileName(SongsList.Items[index]));
  273.   end;
  274. end;
  275.  
  276. procedure TSoundCloud.StopButtonClick(Sender: TObject);
  277. begin
  278.   if Mode = Play then
  279.   begin
  280.     BASS_ChannelStop(Channel);
  281.     Mode := Stop;
  282.   end;
  283. end;
  284.  
  285. procedure TSoundCloud.Timer1Timer(Sender: TObject);
  286. var
  287.   FFTFata: TDrawData;
  288.   TrackLen, TrackPos: Double;
  289.   ValPos: Double;
  290.   ValLen: Double;
  291. begin
  292.   if Mode <> Play then
  293.     exit;
  294.   if BASS_ChannelGetPosition(Channel, 0) = bass_ChannelGetLength(Channel, 0)
  295.   then
  296.   begin
  297.     if I < SongsList.Items.Count - 1 then
  298.     begin
  299.       Inc(I);
  300.       Filename := SongsList.Items.Strings[I];
  301.       SongsList.ItemIndex := I;
  302.       Mode := Stop;
  303.       Player;
  304.     end
  305.     else
  306.       exit;
  307.   end;
  308.   BASS_ChannelGetData(Channel, @FFTFata, BASS_DATA_FFT1024);
  309.   Draw(IndicateGraph.Canvas.Handle, FFTFata, 0, -5);
  310.  
  311.   ScrollSongBar.Position := BASS_ChannelGetPosition(Channel, 0);
  312.   MiniLonely.ScrollBar1.Position := ScrollSongBar.Position;
  313.  
  314.   TrackPos := BASS_ChannelBytes2Seconds(Channel,
  315.     BASS_ChannelGetPosition(Channel, 0));
  316.  
  317.   TrackLen := BASS_ChannelBytes2Seconds(Channel,
  318.     bass_ChannelGetLength(Channel, 0));
  319.   ValPos := TrackPos / (24 * 3600);
  320.   ValLen := TrackLen / (24 * 3600);
  321.   TimeFirstLabel.Caption := FormatDateTime('hh:mm:ss', ValPos);
  322.   TimeLastLabel.Caption := FormatDateTime('hh:mm:ss', ValLen);
  323.   BASS_ChannelSetAttribute(Channel, BASS_ATTRIB_VOL, SoundBar.Position / 10);
  324.   BASS_ChannelSetAttribute(Channel, BASS_ATTRIB_PAN, BalanceBar.Position / 5);
  325. end;
  326.  
  327. procedure TSoundCloud.TrashCanButtonClick(Sender: TObject);
  328. begin
  329.   case Application.MessageBox('Вы точно хотите удалить треки?',
  330.     'Предупреждение', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) of
  331.     IDYES:
  332.       begin
  333.         SongsList.Clear;
  334.         DeActivateMusicPlayer();
  335.         BASS_ChannelStop(Channel);
  336.         Mode := Stop;
  337.         Application.MessageBox
  338.           ('Вы очистили плейлист, воспользуйтесь добавлением новых мелодий',
  339.           'Предупреждение', MB_ICONINFORMATION);
  340.       end;
  341.   end;
  342. end;
  343.  
  344. procedure TSoundCloud.BackButtonClick(Sender: TObject);
  345. begin
  346.   PlayOrNot();
  347.   if SongsList.ItemIndex > 0 then
  348.   begin
  349.     Dec(I);
  350.     Filename := SongsList.Items.Strings[I];
  351.     SongsList.ItemIndex := I;
  352.     Mode := Stop;
  353.     Player;
  354.   end
  355.   else
  356.   begin
  357.     BackButton.Enabled := FALSE;
  358.     Application.MessageBox('Это первый трек в вашем плейлисте!', 'Ошибка',
  359.       MB_ICONERROR);
  360.   end;
  361.   StopButton.Click;
  362.   PlayButton.Click;
  363. end;
  364.  
  365. procedure TSoundCloud.VolumeZeroButtonClick(Sender: TObject);
  366. begin
  367.   if Mode = Play then
  368.     SoundBar.Position := 0;
  369. end;
  370.  
  371. procedure TSoundCloud.VolumeTenButtonClick(Sender: TObject);
  372. begin
  373.   if Mode = Play then
  374.     SoundBar.Position := 10;
  375. end;
  376.  
  377. procedure TSoundCloud.SettingsAndInfoButtonClick(Sender: TObject);
  378. begin
  379.   UnitInfo.show;
  380. end;
  381.  
  382. procedure TSoundCloud.MiniViewButtonClick(Sender: TObject);
  383. begin
  384.   if (Mode = Play) or (Mode = Paused) then
  385.   begin
  386.     MiniViewButton.Enabled := True;
  387.     MiniLonely.show;
  388.     SoundCloud.Hide;
  389.     MiniLonely.WindowState := wsNormal;
  390.   end;
  391. end;
  392.  
  393. procedure TSoundCloud.EqualizerButtonClick(Sender: TObject);
  394. begin
  395.   Mixtape.show;
  396. end;
  397.  
  398. procedure TSoundCloud.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  399. begin
  400.   case Application.MessageBox('Вы точно хотите выйти из программы?', 'Выход',
  401.     MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) of
  402.     IDYES:
  403.       CanClose := True;
  404.     IDNO:
  405.       CanClose := FALSE;
  406.   end;
  407. end;
  408.  
  409. procedure TSoundCloud.FolderButtonClick(Sender: TObject);
  410. var
  411.   J: Integer;
  412. begin
  413.   OpenDialog1.Title := 'Выбрать музыку';
  414.   OpenDialog1.Filter := 'mp3|*.mp3';
  415.   if SongsList.Count <> 0 then
  416.     I := SongsList.ItemIndex
  417.   else
  418.     I := 0;
  419.   if not OpenDialog1.Execute then
  420.     exit;
  421.   begin
  422.     for J := 0 to OpenDialog1.Files.Count - 1 do
  423.     begin
  424.       SongsList.Items.Add(OpenDialog1.Files.Strings[J]);
  425.     end;
  426.   end;
  427.   Filename := SongsList.Items.Strings[I];
  428.   SongsList.ItemIndex := I;
  429.  
  430.   PlayOrNot();
  431. end;
  432.  
  433. procedure TSoundCloud.FormClose(Sender: TObject; var Action: TCloseAction);
  434. begin
  435.   CloseCfg;
  436.   Bass_Stop();
  437.   BASS_StreamFree(Channel);
  438.   Bass_Free;
  439. end;
  440.  
  441. procedure TSoundCloud.CloseCfg;
  442. var
  443.   N: Integer;
  444. begin
  445.   IniFile.WriteInteger('Информация о форме', 'Left', Left);
  446.   IniFile.WriteInteger('Информация о форме', 'Top', Top);
  447.   IniFile.WriteInteger('Информация о форме', 'Width', Width);
  448.   IniFile.WriteInteger('Информация о форме', 'Height', Height);
  449.   IniFile.WriteInteger('Громкость', 'SoundBar.position', SoundBar.Position);
  450.   IniFile.WriteInteger('Эквалайзер', 'FirstBar.position',
  451.     Mixtape.FirstBar.Position);
  452.   IniFile.WriteInteger('Эквалайзер', 'SecondBar.position',
  453.     Mixtape.SecondBar.Position);
  454.   IniFile.WriteInteger('Эквалайзер', 'ThirdBar.position',
  455.     Mixtape.ThirdBar.Position);
  456.   IniFile.WriteInteger('Эквалайзер', 'FourthBar.position',
  457.     Mixtape.FourthBar.Position);
  458.   IniFile.WriteInteger('Эквалайзер', 'FifthBar.position',
  459.     Mixtape.FifthBar.Position);
  460.   IniFile.WriteInteger('Эквалайзер', 'SixthBar.position',
  461.     Mixtape.SixthBar.Position);
  462.   IniFile.WriteInteger('Эквалайзер', 'SeventhBar.position',
  463.     Mixtape.SeventhBar.Position);
  464.   IniFile.WriteInteger('Эквалайзер', 'EighthBar.position',
  465.     Mixtape.EighthBar.Position);
  466.   IniFile.WriteInteger('Эквалайзер', 'NinethBar.position',
  467.     Mixtape.NinethBar.Position);
  468.   IniFile.WriteInteger('Эквалайзер', 'TenthBar.position',
  469.     Mixtape.TenthBar.Position);
  470.   IniFile.WriteInteger('Количество треков', 'Треков:', SongsList.Items.Count);
  471.   IniFile.EraseSection('Плейлист');
  472.   for N := 0 to SongsList.Items.Count - 1 do
  473.   begin
  474.     IniFile.WriteString('Плейлист', 'Трек ' + IntToStr(N + 1),
  475.       SongsList.Items.Strings[N]);
  476.   end;
  477.   IniFile.WriteTime('Время', 'Время запуска последней сессии', Time);
  478.   IniFile.Free;
  479. end;
  480.  
  481. procedure TSoundCloud.FormCreate(Sender: TObject);
  482. begin
  483.   SoundBar.Min := 0;
  484.   SoundBar.Max := 10;
  485.   SoundBar.Position := 25;
  486.  
  487.   BalanceBar.Min := -5;
  488.   BalanceBar.Max := 5;
  489.   BalanceBar.Position := 0;
  490.  
  491.   if (HiWord(BASS_GetVersion) <> BASSVERSION) then
  492.   begin
  493.     Application.MessageBox('Не корректная версия BASS.DLL', 'Ошибка',
  494.       MB_ICONERROR);
  495.     exit;
  496.   end;
  497.   if not BASS_Init(-1, 44100, 0, Handle, nil) then
  498.   begin
  499.     Application.MessageBox('Ошибка инициализация аудио', 'Ошибка',
  500.       MB_ICONERROR);
  501.     exit;
  502.   end;
  503.   CreateCfg;
  504. end;
  505.  
  506. procedure TSoundCloud.CreateCfg;
  507. var
  508.   N, Count: Integer;
  509. begin
  510.   IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) +
  511.     'Configuration.ini');
  512.   SoundBar.Position := IniFile.ReadInteger('Громкость', 'SoundBar.position', 5);
  513.   Count := IniFile.ReadInteger('Количество треков', 'Треков:', 0);
  514.   if Count <> 0 then
  515.   begin
  516.     ActivateMusicPlayer();
  517.     for N := 0 to Count - 1 do
  518.       SongsList.Items.Add(IniFile.ReadString('Плейлист',
  519.         'Трек ' + IntToStr(N + 1), 'Ошибка чтения'));
  520.     Filename := SongsList.Items.Strings[0];
  521.     SongsList.ItemIndex := 0;
  522.   end;
  523. end;
  524.  
  525. procedure TSoundCloud.PlayOrNot();
  526. begin
  527.   if SongsList.Items.Count = 0 then
  528.   begin
  529.     DeActivateMusicPlayer();
  530.     Application.MessageBox
  531.       ('Воспользуйтесь загрузкой треков для работы с плеером', 'Ошибка',
  532.       MB_ICONERROR);
  533.   end
  534.   else
  535.     ActivateMusicPlayer();
  536. end;
  537.  
  538. procedure TSoundCloud.ActivateMusicPlayer();
  539. begin
  540.   PauseButton.Enabled := True;
  541.   ForwardButton.Enabled := True;
  542.   BackButton.Enabled := True;
  543.   EqualizerButton.Enabled := True;
  544.   StopButton.Enabled := True;
  545.   PlayButton.Enabled := True;
  546.   MiniViewButton.Enabled := True;
  547.   TrashCanButton.Enabled := True;
  548. end;
  549.  
  550. procedure TSoundCloud.DeActivateMusicPlayer();
  551. begin
  552.   PauseButton.Enabled := FALSE;
  553.   PlayButton.Enabled := FALSE;;
  554.   ForwardButton.Enabled := FALSE;
  555.   BackButton.Enabled := FALSE;
  556.   EqualizerButton.Enabled := FALSE;
  557.   StopButton.Enabled := FALSE;
  558.   MiniViewButton.Enabled := FALSE;
  559.   TrashCanButton.Enabled := FALSE;
  560. end;
  561.  
  562. procedure TSoundCloud.ForwardButtonClick(Sender: TObject);
  563. begin
  564.   PlayOrNot();
  565.   if SongsList.ItemIndex < SongsList.Count - 1 then
  566.   begin
  567.     Inc(I);
  568.     Filename := SongsList.Items.Strings[I];
  569.     SongsList.ItemIndex := I;
  570.     Mode := Stop;
  571.     Player;
  572.   end;
  573.   StopButton.Click;
  574.   PlayButton.Click;
  575. end;
  576.  
  577. procedure TSoundCloud.SongsListDblClick(Sender: TObject);
  578. begin
  579.   I := SongsList.ItemIndex;
  580.   Filename := SongsList.Items.Strings[I];
  581.   UnitInfo.AddMemo(Sender);
  582.   Mode := Stop;
  583.   Player;
  584. end;
  585.  
  586. procedure TSoundCloud.PauseButtonClick(Sender: TObject);
  587. begin
  588.   PlayOrNot();
  589.   if Mode = Play then
  590.   begin
  591.     BASS_ChannelPause(Channel);
  592.     Mode := Paused;
  593.   end;
  594. end;
  595.  
  596. procedure TSoundCloud.IndicateGraphPaint(Sender: TObject);
  597. begin
  598.   IndicateGraph.Canvas.Pen.Color := clBlack;
  599.   IndicateGraph.Canvas.Brush.Color := clBlack;
  600.   IndicateGraph.Canvas.Rectangle(0, 0, IndicateGraph.Width,
  601.     IndicateGraph.Height);
  602. end;
  603.  
  604. end.
  605.  
  606.  
  607.  
  608.  
  609. unit UnitMix;
  610.  
  611. interface
  612.  
  613. uses
  614.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  615.   Dialogs, StdCtrls, ComCtrls, bass, Vcl.ExtCtrls;
  616.  
  617. type
  618.   TMixtape = class(TForm)
  619.     NinethBar: TTrackBar;
  620.     EighthBar: TTrackBar;
  621.     SeventhBar: TTrackBar;
  622.     SixthBar: TTrackBar;
  623.     FifthBar: TTrackBar;
  624.     FourthBar: TTrackBar;
  625.     ThirdBar: TTrackBar;
  626.     SecondBar: TTrackBar;
  627.     FirstBar: TTrackBar;
  628.     TenthBar: TTrackBar;
  629.     Label14: TLabel;
  630.     Label13: TLabel;
  631.     Label12: TLabel;
  632.     Label11: TLabel;
  633.     Label10: TLabel;
  634.     Label9: TLabel;
  635.     Label8: TLabel;
  636.     Label7: TLabel;
  637.     Label6: TLabel;
  638.     Label5: TLabel;
  639.     PaintBox1: TPaintBox;
  640.     PaintBox2: TPaintBox;
  641.     Timer1: TTimer;
  642.     procedure FirstBarChange(Sender: TObject);
  643.     procedure SecondBarChange(Sender: TObject);
  644.     procedure ThirdBarChange(Sender: TObject);
  645.     procedure FourthBarChange(Sender: TObject);
  646.     procedure FifthBarChange(Sender: TObject);
  647.     procedure SixthBarChange(Sender: TObject);
  648.     procedure SeventhBarChange(Sender: TObject);
  649.     procedure EighthBarChange(Sender: TObject);
  650.     procedure NinethBarChange(Sender: TObject);
  651.     procedure TenthBarChange(Sender: TObject);
  652.     procedure FormCreate(Sender: TObject);
  653.     procedure Timer1Timer(Sender: TObject);
  654.   private
  655.     { Private declarations }
  656.   public
  657.     { Public declarations }
  658.   end;
  659.  
  660. var
  661.   Mixtape: TMixtape;
  662.  
  663. implementation
  664.  
  665. {$R *.dfm}
  666.  
  667. uses UnitPlay;
  668.  
  669. procedure TMixtape.FormCreate(Sender: TObject);
  670. begin
  671.   FirstBar.position := IniFile.ReadInteger('Эквалайзер', 'FirstBar.position', 15);
  672.   SecondBar.position := IniFile.ReadInteger('Эквалайзер',
  673.     'SecondBar.position', 15);
  674.   ThirdBar.position := IniFile.ReadInteger('Эквалайзер', 'ThirdBar.position', 15);
  675.   FourthBar.position := IniFile.ReadInteger('Эквалайзер',
  676.     'FourthBar.position', 15);
  677.   FifthBar.position := IniFile.ReadInteger('Эквалайзер', 'FifthBar.position', 15);
  678.   SixthBar.position := IniFile.ReadInteger('Эквалайзер', 'SixthBar.position', 15);
  679.   SeventhBar.position := IniFile.ReadInteger('Эквалайзер',
  680.     'SeventhBar.position', 15);
  681.   EighthBar.position := IniFile.ReadInteger('Эквалайзер',
  682.     'EighthBar.position', 15);
  683.   NinethBar.position := IniFile.ReadInteger('Эквалайзер',
  684.     'NinethBar.position', 15);
  685.   TenthBar.position := IniFile.ReadInteger('Эквалайзер', 'TenthBar.position', 15);
  686. end;
  687.  
  688. procedure TMixtape.EighthBarChange(Sender: TObject);
  689. begin
  690.   BASS_FXGetParameters(fx[8], @p);
  691.   p.fgain := 15 - EighthBar.position;
  692.   BASS_FXSetParameters(fx[8], @p);
  693. end;
  694.  
  695. procedure TMixtape.NinethBarChange(Sender: TObject);
  696. begin
  697.   BASS_FXGetParameters(fx[9], @p);
  698.   p.fgain := 15 - NinethBar.position;
  699.   BASS_FXSetParameters(fx[9], @p);
  700. end;
  701.  
  702. procedure TMixtape.TenthBarChange(Sender: TObject);
  703. begin
  704.   BASS_FXGetParameters(fx[10], @p);
  705.   p.fgain := 15 - TenthBar.position;
  706.   BASS_FXSetParameters(fx[10], @p);
  707. end;
  708.  
  709. procedure TMixtape.FirstBarChange(Sender: TObject);
  710. begin
  711.   BASS_FXGetParameters(fx[1], @p);
  712.   p.fgain := 15 - FirstBar.position;
  713.   BASS_FXSetParameters(fx[1], @p);
  714. end;
  715.  
  716. procedure TMixtape.SecondBarChange(Sender: TObject);
  717. begin
  718.   BASS_FXGetParameters(fx[2], @p);
  719.   p.fgain := 15 - SecondBar.position;
  720.   BASS_FXSetParameters(fx[2], @p);
  721. end;
  722.  
  723. procedure TMixtape.ThirdBarChange(Sender: TObject);
  724. begin
  725.   BASS_FXGetParameters(fx[3], @p);
  726.   p.fgain := 15 - ThirdBar.position;
  727.   BASS_FXSetParameters(fx[3], @p);
  728. end;
  729.  
  730. procedure TMixtape.Timer1Timer(Sender: TObject);
  731. var
  732.   Left, Right, L1, R1: Integer;
  733.   Level: DWORD;
  734. begin
  735.   if BASS_ChannelIsActive(Channel) <> BASS_Active_Playing then
  736.     exit;
  737.   Level := BASS_ChannelGetLevel(Channel);
  738.   Left := LoWord(Level);
  739.   Right := HiWord(Level);
  740.   PaintBox1.Canvas.Brush.Color := clWhite;
  741.   PaintBox1.Canvas.FillRect(PaintBox1.Canvas.ClipRect);
  742.   PaintBox2.Canvas.Brush.Color := clWhite;
  743.   PaintBox2.Canvas.FillRect(PaintBox2.Canvas.ClipRect);
  744.   PaintBox1.Canvas.Brush.Color := clBlack;
  745.   PaintBox2.Canvas.Brush.Color := clBlack;
  746.   PaintBox1.Canvas.Rectangle(0, PaintBox1.Height - L1, PaintBox1.Width,
  747.     PaintBox1.Height);
  748.   PaintBox2.Canvas.Rectangle(0, PaintBox2.Height - R1, PaintBox2.Width,
  749.     PaintBox2.Height);
  750. end;
  751.  
  752. procedure TMixtape.FourthBarChange(Sender: TObject);
  753. begin
  754.   BASS_FXGetParameters(fx[4], @p);
  755.   p.fgain := 15 - FourthBar.position;
  756.   BASS_FXSetParameters(fx[4], @p);
  757. end;
  758.  
  759. procedure TMixtape.FifthBarChange(Sender: TObject);
  760. begin
  761.   BASS_FXGetParameters(fx[5], @p);
  762.   p.fgain := 15 - FifthBar.position;
  763.   BASS_FXSetParameters(fx[5], @p);
  764. end;
  765.  
  766. procedure TMixtape.SixthBarChange(Sender: TObject);
  767. begin
  768.   BASS_FXGetParameters(fx[6], @p);
  769.   p.fgain := 15 - SixthBar.position;
  770.   BASS_FXSetParameters(fx[6], @p);
  771. end;
  772.  
  773. procedure TMixtape.SeventhBarChange(Sender: TObject);
  774. begin
  775.   BASS_FXGetParameters(fx[7], @p);
  776.   p.fgain := 15 - SeventhBar.position;
  777.   BASS_FXSetParameters(fx[7], @p);
  778. end;
  779.  
  780. end.
  781.  
  782.  
  783.  
  784.  
  785. unit UnitMini;
  786.  
  787. interface
  788.  
  789. uses
  790.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  791.   System.Classes, Vcl.Graphics,
  792.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Buttons,
  793.   Bass;
  794.  
  795. type
  796.   TMiniLonely = class(TForm)
  797.     Timer1: TTimer;
  798.     MiniViewButton: TBitBtn;
  799.     PlayButton: TBitBtn;
  800.     NextSongButton: TBitBtn;
  801.     StopButton: TBitBtn;
  802.     PrevSongButton: TBitBtn;
  803.     ScrollBar1: TScrollBar;
  804.     TrackNameLabel: TLabel;
  805.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  806.     procedure FormCreate(Sender: TObject);
  807.     procedure TimerTimer(Sender: TObject);
  808.     procedure MiniViewButtonClick(Sender: TObject);
  809.     procedure StopButtonClick(Sender: TObject);
  810.     procedure PlayButtonClick(Sender: TObject);
  811.     procedure NextSongButtonClick(Sender: TObject);
  812.     procedure PrevSongButtonClick(Sender: TObject);
  813.     procedure FormKeyPress(Sender: TObject; var Key: Char);
  814.     procedure ScrollSongBarScroll(Sender: TObject; ScrollCode: TScrollCode;
  815.       var ScrollPos: Integer);
  816.  
  817.   private
  818.     { Private declarations }
  819.   public
  820.     { Public declarations }
  821.   end;
  822.  
  823. var
  824.   MiniLonely: TMiniLonely;
  825.  
  826. implementation
  827.  
  828. {$R *.dfm}
  829.  
  830. uses
  831.   UnitPlay, UnitMix;
  832.  
  833. procedure TMiniLonely.FormClose(Sender: TObject; var Action: TCloseAction);
  834. begin
  835.   SoundCloud.Show;
  836.   SoundCloud.Position := poDesktopCenter;
  837. end;
  838.  
  839. procedure TMiniLonely.FormCreate(Sender: TObject);
  840. begin
  841.   Top := Screen.WorkAreaRect.Top + 150;
  842.   Left := Screen.WorkAreaRect.Right - Width;
  843.   SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE + SWP_NOMOVE +
  844.     SWP_NOSIZE);
  845.   TrackNameLabel.Caption := SoundCloud.SongNameLabel.Caption;
  846. end;
  847.  
  848. procedure TMiniLonely.TimerTimer(Sender: TObject);
  849. begin
  850.   if MiniLonely.Visible and (Mode = Play) then
  851.   begin
  852.     TrackNameLabel.Caption := SoundCloud.SongNameLabel.Caption;
  853.     PlayButton.Visible := SoundCloud.PlayButton.Visible;
  854.     StopButton.Visible := SoundCloud.StopButton.Visible;
  855.     TrackNameLabel.Caption := ExtractFileName(Filename);
  856.     ScrollBar1.Position := SoundCloud.ScrollSongBar.Position;
  857.   end;
  858. end;
  859.  
  860. procedure TMiniLonely.FormKeyPress(Sender: TObject; var Key: Char);
  861. begin
  862.   if (Key = #32) then
  863.   begin
  864.     if (Mode = Play) then
  865.       SoundCloud.StopButton.Click
  866.     else
  867.       SoundCloud.PlayButton.Click;
  868.   end;
  869.   if Key = #27 then
  870.     MiniLonely.Close;
  871. end;
  872.  
  873. procedure TMiniLonely.MiniViewButtonClick(Sender: TObject);
  874. begin
  875.   MiniLonely.Close;
  876. end;
  877.  
  878. procedure TMiniLonely.ScrollSongBarScroll(Sender: TObject;
  879.   ScrollCode: TScrollCode; var ScrollPos: Integer);
  880. begin
  881.   ScrollBar1.Min := 0;
  882.   ScrollBar1.Max := bass_ChannelGEtLength(UnitPlay.Channel, 0) - 1;
  883.   bass_ChannelSetPosition(UnitPlay.Channel,
  884.     SoundCloud.ScrollSongBar.Position, 0);
  885. end;
  886.  
  887. procedure TMiniLonely.NextSongButtonClick(Sender: TObject);
  888. begin
  889.   SoundCloud.ForwardButton.Click;
  890. end;
  891.  
  892. procedure TMiniLonely.PlayButtonClick(Sender: TObject);
  893. begin
  894.   SoundCloud.PlayButton.Click;
  895. end;
  896.  
  897. procedure TMiniLonely.PrevSongButtonClick(Sender: TObject);
  898. begin
  899.   SoundCloud.BackButton.Click;
  900. end;
  901.  
  902. procedure TMiniLonely.StopButtonClick(Sender: TObject);
  903. begin
  904.   SoundCloud.StopButton.Click;
  905. end;
  906.  
  907. end.
  908.  
  909.  
  910.  
  911.  
  912. unit UnitInformation;
  913.  
  914. interface
  915.  
  916. uses
  917.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  918.   System.Classes, Vcl.Graphics,
  919.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.pngimage, Vcl.ExtCtrls,
  920.   ShellApi, Vcl.StdCtrls, Vcl.Buttons;
  921.  
  922. type
  923.  
  924.   LastTrack = ^Tracks;
  925.  
  926.   Tracks = record
  927.     FilePath: string;
  928.     Next: LastTrack;
  929.   end;
  930.  
  931.   TUnitInfo = class(TForm)
  932.     Image1: TImage;
  933.     Image2: TImage;
  934.     Image3: TImage;
  935.     Image4: TImage;
  936.     Image5: TImage;
  937.     LatestTracksButton: TBitBtn;
  938.     Label1: TLabel;
  939.     procedure Image3Click(Sender: TObject);
  940.     procedure Image4Click(Sender: TObject);
  941.     procedure Image5Click(Sender: TObject);
  942.     procedure Image2Click(Sender: TObject);
  943.     procedure Image1Click(Sender: TObject);
  944.     procedure AddMemo(Sender: TObject);
  945.     procedure WriteToMemo;
  946.     procedure LatestTracksButtonClick(Sender: TObject);
  947.  
  948.  
  949.   private
  950.     { Private declarations }
  951.   public
  952.     { Public declarations }
  953.   end;
  954.  
  955. var
  956.   UnitInfo: TUnitInfo;
  957.   Head: LastTrack;
  958.  
  959. implementation
  960.  
  961. {$R *.dfm}
  962.  
  963. uses
  964.   UnitPlay;
  965.  
  966.  
  967. procedure TUnitInfo.LatestTracksButtonClick(Sender: TObject);
  968. begin
  969.   WriteToMemo();
  970. end;
  971.  
  972. procedure TUnitInfo.Image1Click(Sender: TObject);
  973. begin
  974.   ShellExecute(Handle, 'open', 'https://github.com/antitoxical', Nil,
  975.     Nil, SW_SHOW);
  976. end;
  977.  
  978. procedure TUnitInfo.Image2Click(Sender: TObject);
  979. begin
  980.   ShellExecute(Handle, 'open',
  981.     'https://www.linkedin.com/in/%D0%B4%D0%B0%D0%BD%D0%B8%D0%BB%D0%B0-%D0%B0%D1%81%D0%B5%D0%BF%D0%BA%D0%BE%D0%B2-558147275',
  982.     Nil, Nil, SW_SHOW);
  983. end;
  984.  
  985. procedure TUnitInfo.Image3Click(Sender: TObject);
  986. begin
  987.   ShellExecute(Handle, 'open', 'https://vk.com/antitoxical', Nil, Nil, SW_SHOW);
  988. end;
  989.  
  990. procedure TUnitInfo.Image4Click(Sender: TObject);
  991. begin
  992.   ShellExecute(Handle, 'open', 'https://www.instagram.com/antitoxical', Nil,
  993.     Nil, SW_SHOW);
  994. end;
  995.  
  996. procedure TUnitInfo.Image5Click(Sender: TObject);
  997. begin
  998.   ShellExecute(Handle, 'open', 'https://t.me/altervisi0n', Nil, Nil, SW_SHOW);
  999. end;
  1000.  
  1001. procedure TUnitInfo.AddMemo(Sender: TObject);
  1002. var
  1003.   Curr: LastTrack;
  1004. begin
  1005.   New(Curr);
  1006.   Curr^.FilePath := SoundCloud.SongsList.Items.Strings[I];
  1007.   Curr^.Next := Head;
  1008.   Head := Curr;
  1009. end;
  1010.  
  1011. procedure TUnitInfo.WriteToMemo;
  1012. var
  1013.   Curr: LastTrack;
  1014.   St: string;
  1015. begin
  1016.   St := '';
  1017.   SoundCloud.SongsList.ItemIndex :=0;
  1018.   Curr := Head;
  1019.   while Curr <> NIL do
  1020.   begin
  1021.     SoundCloud.SongsList.ItemIndex := SoundCloud.SongsList.ItemIndex + 1;
  1022.     St := St + Curr^.FilePath + #13;
  1023.     Curr := Curr^.Next;
  1024.   end;
  1025.   if (SoundCloud.SongsList.Count <> 0) and (SoundCloud.SongsList.Count > 1) then
  1026.     ShowMessage('Все треки,проигрываемые в этой сессии:' + #13 + St)
  1027.   else
  1028.     ShowMessage('Треки не проигрывались.');
  1029. end;
  1030.  
  1031. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement