Recent

Author Topic: help with the bass library  (Read 17914 times)

Neprofi

  • Full Member
  • ***
  • Posts: 174
help with the bass library
« on: June 03, 2015, 07:45:19 am »
Hello everyone! the question is how! I use the Bass library! punched various functions, tasks looked examples, and zero sense all the time the same problem with streaming sound, I have to play through the list of sounds in mp3 format! the other bug all the time on these lines! watch code:::

procedure EndTrackHandler(handle: HSYNC; channel, data: DWORD; user: Pointer); stdcall;
begin
  Form1.CurRepeat:=Form1.CurRepeat+1;
  Form1.Stop;
  if Form1.CurRepeat>=Form1.RepeatCount then
    Form1.Next;
  if Form1.CurRepeat<Form1.RepeatCount then
    Form1.play;
end;
 
procedure TForm1.Play;
var s:string;
begin
  UpdateCurRepeat;
  s:= ExtractFilePath(ParamStr(0))+ FList[FCurTrack];
  Fstream:= Bass_streamcreatefile(false, PChar(s),0,0,BASS_UNICODE or BASS_STREAM_AUTOFREE);
  BASS_ChannelSetSync(FStream, BASS_SYNC_END,0, EndTrackHandler,nil); //this term all the time this error
unit1.pas(215,49) Error: Wrong number of parameters specified for call to "EndTrackHandler"
  Bass_channelplay(Fstream,false);
end;

If anyone has faced this error could you describe to me please((( I 4 months can do to fix it! if not hard please help! Waiting for an answer as hi Thanks to All who help!

Neprofi

  • Full Member
  • ***
  • Posts: 174
Re: help with the bass library
« Reply #1 on: June 03, 2015, 01:04:13 pm »
Clearly not who will not help(((( I knew it well and Lazarus, not what is not good probably! programmers help!

rvk

  • Hero Member
  • *****
  • Posts: 6886
Re: help with the bass library
« Reply #2 on: June 03, 2015, 01:32:50 pm »
Clearly not who will not help(((( I knew it well and Lazarus, not what is not good probably! programmers help!
My guess is your question was put a bit difficult to read.

But the error you're getting is due to using a wrong parameter-sort in your call.

In {$mode delphi} you can use this call the way you do (without converting EndTrackHandler to a procedure-parameter). But in {$mode objfpc} (which you probably have in the top of your unit) you need to use @EndTrackHandler.

So
Code: [Select]
BASS_ChannelSetSync(FStream, BASS_SYNC_END,0, @EndTrackHandler,nil);

Neprofi

  • Full Member
  • ***
  • Posts: 174
Re: help with the bass library
« Reply #3 on: June 03, 2015, 02:37:33 pm »
BASS_ChannelSetSync(FStream, BASS_SYNC_END,0, @EndTrackHandler,nil); wow he swallowed it cheers))) thank you and may have helped but I can't play and can project skeen and I fix it where I don't correct what did they fix)))) I would be very grateful))))

rvk

  • Hero Member
  • *****
  • Posts: 6886
Re: help with the bass library
« Reply #4 on: June 03, 2015, 03:12:26 pm »
... and may have helped but I can't play and can project skeen and I fix it where I don't correct what did they fix)))) I would be very grateful))))
Again, I can't quite make head or tails of this question. Understandable if English is not your native language but communication is difficult in that case.

You might want to rephrase it in you native language (giving us the language too so we can run it through Google Translate) or you can run your question through Google Translate yourself.

If your code in the first post (fixed with my suggestion) still doesn't play, maybe we need more of your code. Did you initialize Bass correctly?


Neprofi

  • Full Member
  • ***
  • Posts: 174
Re: help with the bass library
« Reply #5 on: June 03, 2015, 03:30:39 pm »
OK! here is the project completely!
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
   Windows,SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, ComCtrls, bass, types;
type

  { TForm1 }

  TForm1 = class(TForm)
    bPlay: TButton;
    bPrev: TButton;
    bNext: TButton;
    bStop: TButton;
    eRepeatCount: TEdit;
    lbl1: TLabel;
    lblCurRepeat: TLabel;
    lst1: TListBox;
    udRepeatCount: TUpDown;
    procedure bNextClick(Sender: TObject);
    procedure bPlayClick(Sender: TObject);
    procedure bPrevClick(Sender: TObject);
    procedure bStopClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure lst1DblClick(Sender: TObject);
    procedure lst1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect;
      State: TOwnerDrawState);
    procedure udRepeatCountChangingEx(Sender: TObject;
      var AllowChange: Boolean; NewValue: Integer; Direction: TUpDownDirection
      );
  private
    FStream:HSTREAM;
    FRepeatCount:integer;
    FCurRepeat:integer;
    FCurTrack:integer;
    function GetRepeatCount: integer;
    procedure SetRepeatCount(const Value: integer);
    procedure SetCurTrack(const Value: Integer);
    procedure SetCurRepeat(const Value: Integer);
    procedure UpdateCurRepeat;
    procedure ListToListbox;
    { private declarations }
  public
    FList:TStringList;
    function Playing:Boolean;
    procedure Stop;
    procedure Play;
    procedure Prev;
    procedure Next;
    function TrackCount:integer;
    property CurTrack:Integer read FCurTrack write SetCurTrack;
    property RepeatCount:integer read GetRepeatCount write SetRepeatCount;
    property CurRepeat:Integer read FCurRepeat write SetCurRepeat;
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.lst1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
if index=FCurTrack then
lst1.Canvas.Font.Color:=clRed
else
lst1.Canvas.Font.Color:=clWindowText;
lst1.Canvas.TextRect(Rect,rect.Left+3, rect.Top+3, lst1.items[index]);
end;

procedure TForm1.bPlayClick(Sender: TObject);
begin
play;
lst1.Invalidate;
end;

procedure TForm1.bPrevClick(Sender: TObject);
begin
Prev;
Play;
lst1.Invalidate;
end;

procedure TForm1.bStopClick(Sender: TObject);
begin
stop;
lst1.Invalidate;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
if (HIWORD(BASS_GetVersion) <> BASSVERSION) then
begin
MessageBox(0,'An incorrect version of BASS.DLL was loaded',nil,MB_ICONERROR);
Halt;
end;
if not BASS_Init(-1, 44100, 0, Handle, nil) then
raise exception.Create('Error initializing audio!');
FRepeatCount := udRepeatCount.Position;

Flist:=TStringLIST.Create;
Flist.Add('Track1.mp3');
Flist.Add('Track2.mp3');
Flist.Add('Track3.mp3');
ListToListbox();
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
FList.Free;
bass_free;
end;

procedure TForm1.lst1DblClick(Sender: TObject);
begin
if lst1.ItemIndex<>-1 then
CurTrack:=lst1.ItemIndex;
end;

procedure TForm1.bNextClick(Sender: TObject);
begin
next;
Play;
lst1.Invalidate;
end;

procedure TForm1.udRepeatCountChangingEx(Sender: TObject;
  var AllowChange: Boolean; NewValue: Integer; Direction: TUpDownDirection);
begin
FRepeatCount:=NewValue;
end;

function TForm1.GetRepeatCount: integer;
begin
Result := FRepeatCount;
if Result=0 then
result :=1;
end;

procedure TForm1.SetRepeatCount(const Value: integer);
begin
if udRepeatCount.Position<>value then
udRepeatCount.Position:=value;
FRepeatCount := udRepeatCount.Position;
end;

procedure TForm1.SetCurTrack(const Value: Integer);
begin
if (Value>=0)and(Value<TrackCount) then
begin
if Value<>FCurTrack then
begin
Stop;
CurRepeat:=0;
FCurTrack := Value;
end;
end;
lst1.Invalidate;
end;

procedure TForm1.SetCurRepeat(const Value: Integer);
begin
FCurRepeat := Value;
updateCurrepeat;
end;

procedure TForm1.UpdateCurRepeat;
begin
lblCurRepeat.Caption := 'Repeat now: '+inttostr(CurRepeat+1);
end;

procedure TForm1.ListToListbox;
begin
lst1.Items.Assign(FList);
end;

function TForm1.Playing: Boolean;
begin
result := BASS_ChannelIsActive(FStream)<>BASS_ACTIVE_STOPPED;
end;

procedure TForm1.Stop;
begin
if Playing then
BASS_ChannelStop(FStream);
end;

procedure EndTrackHandler(handle: HSYNC; channel, data: DWORD; user: Pointer); stdcall;
begin
  Form1.CurRepeat:=Form1.CurRepeat+1;
  Form1.Stop;
  if Form1.CurRepeat>=Form1.RepeatCount then
    Form1.Next;
  if Form1.CurRepeat<Form1.RepeatCount then
    Form1.play;
end;

procedure TForm1.Play;
var s:string;
begin
  UpdateCurRepeat;
  s:= ExtractFilePath(ParamStr(0))+ FList[FCurTrack];
  Fstream:= Bass_streamcreatefile(false, PChar(s),0,0,BASS_UNICODE or BASS_STREAM_AUTOFREE);
  BASS_ChannelSetSync(FStream, BASS_SYNC_END,0, @EndTrackHandler,nil);
  Bass_channelplay(Fstream,false);
end;

procedure TForm1.Prev;
begin
CurTrack:=CurTrack-1;
end;

procedure TForm1.Next;
begin
CurTrack:=CurTrack+1;
end;

function TForm1.TrackCount: integer;
begin
result := Flist.Count;
end; end.   

Neprofi

  • Full Member
  • ***
  • Posts: 174
Re: help with the bass library
« Reply #6 on: June 03, 2015, 03:32:06 pm »
can wrong correct me please!

rvk

  • Hero Member
  • *****
  • Posts: 6886
Re: help with the bass library
« Reply #7 on: June 03, 2015, 04:06:46 pm »
Okay... I hope I van explain this clearly and you can understand it...

You have a procedure EndTrackHandler. This handler is called from the bass library and can be in a different thread. So you can't do anything with your variables and forms in that procedure. (It's asking for trouble and your application will crash)

You need to build in some signaling so when the track ends, the EndTrackHandler can signal your form to do the steps you first wanted to do in EndTrackHandler. Your form can do all the things in its own thread without problems.

You can do the following:

Change the EndTrackHandler in this:
Code: [Select]
var
  CallingForm: TForm;  // <---- Set this ABOVE EndTrackHandler

procedure EndTrackHandler(handle: HSYNC; channel, Data: DWORD; user: Pointer); stdcall;
begin
  // signal callingform that the channel has ended
  SendMessage(Callingform.Handle, WM_CHANNEL_END, 0, 0);
end;
Now the only thing EndTrackHandler does is signal the form with a WM_CHANNEL_END.

Now change this above in the form declaration and add the TForm1.WMChannelEnd:
Code: [Select]
const
  WM_CHANNEL_END = WM_USER + 101;

type
    { TForm1 }
    TForm1 = class(TForm)
//...
    private
        { private declarations }
        procedure WMChannelEnd(var Msg: TMessage); message WM_CHANNEL_END;
    public
//...

procedure TForm1.WMChannelEnd(var Msg: TMessage);
begin
  CurRepeat := CurRepeat + 1;
  Stop;
  if CurRepeat >= RepeatCount then Next;
  if CurRepeat < RepeatCount then play;
end;
This will make it so your form can receive the WM_CHANNEL_END and skip to the next track.

Now the only thing you need to do is set the variable CallingForm just above the BASS_ChannelSetSync:
Code: [Select]
     Callingform := Self;
     BASS_ChannelSetSync(MP3stream, BASS_SYNC_END, 0, @EndTrackHandler, nil);

If you're still experiencing trouble after doing this (other than some compile error) you might want to include the complete .lfm besides the .pas file.

Neprofi

  • Full Member
  • ***
  • Posts: 174
Re: help with the bass library
« Reply #8 on: June 03, 2015, 04:43:48 pm »
and can you give me your project to fix??? to throw the code project fully written by me only corrected you!? please please!
So I fixed about what you said!

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
   Windows,SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, ComCtrls, bass, types;
type

  { TForm1 }

  TForm1 = class(TForm)
    bPlay: TButton;
    bPrev: TButton;
    bNext: TButton;
    bStop: TButton;
    eRepeatCount: TEdit;
    lbl1: TLabel;
    lblCurRepeat: TLabel;
    lst1: TListBox;
    udRepeatCount: TUpDown;
    procedure bNextClick(Sender: TObject);
    procedure bPlayClick(Sender: TObject);
    procedure bPrevClick(Sender: TObject);
    procedure bStopClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure lst1DblClick(Sender: TObject);
    procedure lst1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect;
      State: TOwnerDrawState);
    procedure udRepeatCountChangingEx(Sender: TObject;
      var AllowChange: Boolean; NewValue: Integer; Direction: TUpDownDirection
      );
  private
    FStream:HSTREAM;
    FRepeatCount:integer;
    FCurRepeat:integer;
    FCurTrack:integer;
    function GetRepeatCount: integer;
    procedure SetRepeatCount(const Value: integer);
    procedure SetCurTrack(const Value: Integer);
    procedure SetCurRepeat(const Value: Integer);
    procedure UpdateCurRepeat;
    procedure ListToListbox;
    { private declarations }
  public
    FList:TStringList;
    function Playing:Boolean;
    procedure Stop;
    procedure Play;
    procedure Prev;
    procedure Next;
    function TrackCount:integer;
    property CurTrack:Integer read FCurTrack write SetCurTrack;
    property RepeatCount:integer read GetRepeatCount write SetRepeatCount;
    property CurRepeat:Integer read FCurRepeat write SetCurRepeat;
    procedure WMChannelEnd(var Msg: TMessage);// message WM_CHANNEL_END;
    { public declarations }
  end;
  const
WM_CHANNEL_END = WM_USER + 101;

var
  Form1: TForm1;
  var
CallingForm: TForm;
implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.lst1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
if index=FCurTrack then
lst1.Canvas.Font.Color:=clRed
else
lst1.Canvas.Font.Color:=clWindowText;
lst1.Canvas.TextRect(Rect,rect.Left+3, rect.Top+3, lst1.items[index]);
end;

procedure TForm1.bPlayClick(Sender: TObject);
begin
play;
lst1.Invalidate;
end;

procedure TForm1.bPrevClick(Sender: TObject);
begin
Prev;
Play;
lst1.Invalidate;
end;

procedure TForm1.bStopClick(Sender: TObject);
begin
stop;
lst1.Invalidate;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
if (HIWORD(BASS_GetVersion) <> BASSVERSION) then
begin
MessageBox(0,'An incorrect version of BASS.DLL was loaded',nil,MB_ICONERROR);
Halt;
end;
if not BASS_Init(-1, 44100, 0, Handle, nil) then
raise exception.Create('Error initializing audio!');
FRepeatCount := udRepeatCount.Position;

Flist:=TStringLIST.Create;
Flist.Add('Track1.mp3');
Flist.Add('Track2.mp3');
Flist.Add('Track3.mp3');
ListToListbox();
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
FList.Free;
bass_free;
end;

procedure TForm1.lst1DblClick(Sender: TObject);
begin
if lst1.ItemIndex<>-1 then
CurTrack:=lst1.ItemIndex;
end;

procedure TForm1.bNextClick(Sender: TObject);
begin
next;
Play;
lst1.Invalidate;
end;

procedure TForm1.udRepeatCountChangingEx(Sender: TObject;
  var AllowChange: Boolean; NewValue: Integer; Direction: TUpDownDirection);
begin
FRepeatCount:=NewValue;
end;

function TForm1.GetRepeatCount: integer;
begin
Result := FRepeatCount;
if Result=0 then
result :=1;
end;

procedure TForm1.SetRepeatCount(const Value: integer);
begin
if udRepeatCount.Position<>value then
udRepeatCount.Position:=value;
FRepeatCount := udRepeatCount.Position;
end;

procedure TForm1.SetCurTrack(const Value: Integer);
begin
if (Value>=0)and(Value<TrackCount) then
begin
if Value<>FCurTrack then
begin
Stop;
CurRepeat:=0;
FCurTrack := Value;
end;
end;
lst1.Invalidate;
end;

procedure TForm1.SetCurRepeat(const Value: Integer);
begin
FCurRepeat := Value;
updateCurrepeat;
end;

procedure TForm1.UpdateCurRepeat;
begin
lblCurRepeat.Caption := 'Repeat now: '+inttostr(CurRepeat+1);
end;

procedure TForm1.ListToListbox;
begin
lst1.Items.Assign(FList);
end;

function TForm1.Playing: Boolean;
begin
result := BASS_ChannelIsActive(FStream)<>BASS_ACTIVE_STOPPED;
end;

procedure TForm1.Stop;
begin
if Playing then
BASS_ChannelStop(FStream);
end;

procedure EndTrackHandler(handle: HSYNC; channel, Data: DWORD; user: Pointer); stdcall;
begin
// signal callingform that the channel has ended
SendMessage(Callingform.Handle, WM_CHANNEL_END, 0, 0);
end;

{procedure EndTrackHandler(handle: HSYNC; channel, data: DWORD; user: Pointer); stdcall;
begin
  Form1.CurRepeat:=Form1.CurRepeat+1;
  Form1.Stop;
  if Form1.CurRepeat>=Form1.RepeatCount then
    Form1.Next;
  if Form1.CurRepeat<Form1.RepeatCount then
    Form1.play;
end;  }

procedure TForm1.Play;
var s:string;
begin
  UpdateCurRepeat;
  s:= ExtractFilePath(ParamStr(0))+ FList[FCurTrack];
  Fstream:= Bass_streamcreatefile(false, PChar(s),0,0,BASS_UNICODE or BASS_STREAM_AUTOFREE);
  Callingform := Self;
     BASS_ChannelSetSync(fstream, BASS_SYNC_END, 0, @EndTrackHandler, nil);
  //BASS_ChannelSetSync(FStream, BASS_SYNC_END,0, @EndTrackHandler,nil);
  Bass_channelplay(Fstream,false);
end;

procedure TForm1.Prev;
begin
CurTrack:=CurTrack-1;
end;

procedure TForm1.Next;
begin
CurTrack:=CurTrack+1;
end;

function TForm1.TrackCount: integer;
begin
result := Flist.Count;
end;

procedure TForm1.WMChannelEnd(var Msg: TMessage);
begin
CurRepeat := CurRepeat + 1;
Stop;
if CurRepeat >= RepeatCount then Next;
if CurRepeat < RepeatCount then play;
end;end.   

rvk

  • Hero Member
  • *****
  • Posts: 6886
Re: help with the bass library
« Reply #9 on: June 03, 2015, 05:08:29 pm »
:) :) You were sooooooo close :)

You needed to put the following ABOVE your form-declaration:
Code: [Select]
const
  WM_CHANNEL_END = WM_USER + 101;
And you commented out the "message WM_CHANNEL_END;" but shouldn't.
So:
Code: [Select]
    procedure WMChannelEnd(var Msg: TMessage); message WM_CHANNEL_END;

So the complete code becomes:
(B.T.W. it's always handy to put your code around the code-tags)
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Windows, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, ComCtrls, bass, types;

const
  WM_CHANNEL_END = WM_USER + 101;

type

  { TForm1 }

  TForm1 = class(TForm)
    bPlay: TButton;
    bPrev: TButton;
    bNext: TButton;
    bStop: TButton;
    eRepeatCount: TEdit;
    lbl1: TLabel;
    lblCurRepeat: TLabel;
    lst1: TListBox;
    udRepeatCount: TUpDown;
    procedure bNextClick(Sender: TObject);
    procedure bPlayClick(Sender: TObject);
    procedure bPrevClick(Sender: TObject);
    procedure bStopClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure lst1DblClick(Sender: TObject);
    procedure lst1DrawItem(Control: TWinControl; Index: integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure udRepeatCountChangingEx(Sender: TObject; var AllowChange: boolean;
      NewValue: integer; Direction: TUpDownDirection);
  private
    FStream: HSTREAM;
    FRepeatCount: integer;
    FCurRepeat: integer;
    FCurTrack: integer;
    function GetRepeatCount: integer;
    procedure SetRepeatCount(const Value: integer);
    procedure SetCurTrack(const Value: integer);
    procedure SetCurRepeat(const Value: integer);
    procedure UpdateCurRepeat;
    procedure ListToListbox;
    { private declarations }
  public
    FList: TStringList;
    function Playing: boolean;
    procedure Stop;
    procedure Play;
    procedure Prev;
    procedure Next;
    function TrackCount: integer;
    property CurTrack: integer read FCurTrack write SetCurTrack;
    property RepeatCount: integer read GetRepeatCount write SetRepeatCount;
    property CurRepeat: integer read FCurRepeat write SetCurRepeat;
    procedure WMChannelEnd(var Msg: TMessage); message WM_CHANNEL_END;
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

var
  CallingForm: TForm; // no need to put it in the interface. Here is just fine.

procedure EndTrackHandler(handle: HSYNC; channel, Data: DWORD; user: Pointer); stdcall;
begin
  // signal callingform that the channel has ended
  SendMessage(Callingform.Handle, WM_CHANNEL_END, 0, 0);
end;

{ TForm1 }

procedure TForm1.lst1DrawItem(Control: TWinControl; Index: integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  if index = FCurTrack then
    lst1.Canvas.Font.Color := clRed
  else
    lst1.Canvas.Font.Color := clWindowText;
  lst1.Canvas.TextRect(Rect, rect.Left + 3, rect.Top + 3, lst1.items[index]);
end;

procedure TForm1.bPlayClick(Sender: TObject);
begin
  play;
  lst1.Invalidate;
end;

procedure TForm1.bPrevClick(Sender: TObject);
begin
  Prev;
  Play;
  lst1.Invalidate;
end;

procedure TForm1.bStopClick(Sender: TObject);
begin
  stop;
  lst1.Invalidate;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  if (HIWORD(BASS_GetVersion) <> BASSVERSION) then
  begin
    MessageBox(0, 'An incorrect version of BASS.DLL was loaded', nil, MB_ICONERROR);
    Halt;
  end;
  if not BASS_Init(-1, 44100, 0, Handle, nil) then
    raise Exception.Create('Error initializing audio!');
  FRepeatCount := udRepeatCount.Position;

  Flist := TStringList.Create;
  Flist.Add('Track1.mp3');
  Flist.Add('Track2.mp3');
  Flist.Add('Track3.mp3');
  ListToListbox();
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FList.Free;
  bass_free;
end;

procedure TForm1.lst1DblClick(Sender: TObject);
begin
  if lst1.ItemIndex <> -1 then
    CurTrack := lst1.ItemIndex;
end;

procedure TForm1.bNextClick(Sender: TObject);
begin
  Next;
  Play;
  lst1.Invalidate;
end;

procedure TForm1.udRepeatCountChangingEx(Sender: TObject;
  var AllowChange: boolean; NewValue: integer; Direction: TUpDownDirection);
begin
  FRepeatCount := NewValue;
end;

function TForm1.GetRepeatCount: integer;
begin
  Result := FRepeatCount;
  if Result = 0 then
    Result := 1;
end;

procedure TForm1.SetRepeatCount(const Value: integer);
begin
  if udRepeatCount.Position <> Value then
    udRepeatCount.Position := Value;
  FRepeatCount := udRepeatCount.Position;
end;

procedure TForm1.SetCurTrack(const Value: integer);
begin
  if (Value >= 0) and (Value < TrackCount) then
  begin
    if Value <> FCurTrack then
    begin
      Stop;
      CurRepeat := 0;
      FCurTrack := Value;
    end;
  end;
  lst1.Invalidate;
end;

procedure TForm1.SetCurRepeat(const Value: integer);
begin
  FCurRepeat := Value;
  updateCurrepeat;
end;

procedure TForm1.UpdateCurRepeat;
begin
  lblCurRepeat.Caption := 'Repeat now: ' + IntToStr(CurRepeat + 1);
end;

procedure TForm1.ListToListbox;
begin
  lst1.Items.Assign(FList);
end;

function TForm1.Playing: boolean;
begin
  Result := BASS_ChannelIsActive(FStream) <> BASS_ACTIVE_STOPPED;
end;

procedure TForm1.Stop;
begin
  if Playing then
    BASS_ChannelStop(FStream);
end;

procedure TForm1.Play;
var
  s: string;
begin
  UpdateCurRepeat;
  s := ExtractFilePath(ParamStr(0)) + FList[FCurTrack];
  Fstream := Bass_streamcreatefile(False, PChar(s), 0, 0, BASS_UNICODE or
    BASS_STREAM_AUTOFREE);
  Callingform := Self;
  BASS_ChannelSetSync(fstream, BASS_SYNC_END, 0, @EndTrackHandler, nil);
  //BASS_ChannelSetSync(FStream, BASS_SYNC_END,0, @EndTrackHandler,nil);
  Bass_channelplay(Fstream, False);
end;

procedure TForm1.Prev;
begin
  CurTrack := CurTrack - 1;
end;

procedure TForm1.Next;
begin
  CurTrack := CurTrack + 1;
end;

function TForm1.TrackCount: integer;
begin
  Result := Flist.Count;
end;

procedure TForm1.WMChannelEnd(var Msg: TMessage);
begin
  CurRepeat := CurRepeat + 1;
  Stop;
  if CurRepeat >= RepeatCount then
    Next;
  if CurRepeat < RepeatCount then
    play;
end;

end.
« Last Edit: June 03, 2015, 05:10:42 pm by rvk »

Neprofi

  • Full Member
  • ***
  • Posts: 174
Re: help with the bass library
« Reply #10 on: June 03, 2015, 05:36:04 pm »
now did the right thing? the problem is that the song is not playing! as to what to fix or add???? help For earlier thanks!



unit Unit1;

{$mode objfpc}{$H+}

interface

uses
   Windows,SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, ComCtrls, bass, types;

const
WM_CHANNEL_END = WM_USER + 101;

type

  { TForm1 }

  TForm1 = class(TForm)
    bPlay: TButton;
    bPrev: TButton;
    bNext: TButton;
    bStop: TButton;
    eRepeatCount: TEdit;
    lbl1: TLabel;
    lblCurRepeat: TLabel;
    lst1: TListBox;
    udRepeatCount: TUpDown;
    procedure bNextClick(Sender: TObject);
    procedure bPlayClick(Sender: TObject);
    procedure bPrevClick(Sender: TObject);
    procedure bStopClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure lst1DblClick(Sender: TObject);
    procedure lst1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect;
      State: TOwnerDrawState);
    procedure udRepeatCountChangingEx(Sender: TObject;
      var AllowChange: Boolean; NewValue: Integer; Direction: TUpDownDirection
      );
  private
    FStream:HSTREAM;
    FRepeatCount:integer;
    FCurRepeat:integer;
    FCurTrack:integer;
    function GetRepeatCount: integer;
    procedure SetRepeatCount(const Value: integer);
    procedure SetCurTrack(const Value: Integer);
    procedure SetCurRepeat(const Value: Integer);
    procedure UpdateCurRepeat;
    procedure ListToListbox;
    { private declarations }
  public
    FList:TStringList;
    function Playing:Boolean;
    procedure Stop;
    procedure Play;
    procedure Prev;
    procedure Next;
    function TrackCount:integer;
    property CurTrack:Integer read FCurTrack write SetCurTrack;
    property RepeatCount:integer read GetRepeatCount write SetRepeatCount;
    property CurRepeat:Integer read FCurRepeat write SetCurRepeat;
    procedure WMChannelEnd(var Msg: TMessage); message WM_CHANNEL_END;
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}
 var
CallingForm: TForm; // no need to put it in the interface. Here is just fine.

procedure EndTrackHandler(handle: HSYNC; channel, Data: DWORD; user: Pointer); stdcall;
begin
// signal callingform that the channel has ended
SendMessage(Callingform.Handle, WM_CHANNEL_END, 0, 0);
end;
{ TForm1 }

procedure TForm1.lst1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
if index=FCurTrack then
lst1.Canvas.Font.Color:=clRed
else
lst1.Canvas.Font.Color:=clWindowText;
lst1.Canvas.TextRect(Rect,rect.Left+3, rect.Top+3, lst1.items[index]);
end;

procedure TForm1.bPlayClick(Sender: TObject);
begin
play;
lst1.Invalidate;
end;

procedure TForm1.bPrevClick(Sender: TObject);
begin
Prev;
Play;
lst1.Invalidate;
end;

procedure TForm1.bStopClick(Sender: TObject);
begin
stop;
lst1.Invalidate;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
if (HIWORD(BASS_GetVersion) <> BASSVERSION) then
begin
MessageBox(0,'An incorrect version of BASS.DLL was loaded',nil,MB_ICONERROR);
Halt;
end;
if not BASS_Init(-1, 44100, 0, Handle, nil) then
raise exception.Create('Error initializing audio!');
FRepeatCount := udRepeatCount.Position;

Flist:=TStringLIST.Create;
Flist.Add('Track1.mp3');
Flist.Add('Track2.mp3');
Flist.Add('Track3.mp3');
ListToListbox();
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
FList.Free;
bass_free;
end;

procedure TForm1.lst1DblClick(Sender: TObject);
begin
if lst1.ItemIndex<>-1 then
CurTrack:=lst1.ItemIndex;
end;

procedure TForm1.bNextClick(Sender: TObject);
begin
next;
Play;
lst1.Invalidate;
end;

procedure TForm1.udRepeatCountChangingEx(Sender: TObject;
  var AllowChange: Boolean; NewValue: Integer; Direction: TUpDownDirection);
begin
FRepeatCount:=NewValue;
end;

function TForm1.GetRepeatCount: integer;
begin
Result := FRepeatCount;
if Result=0 then
result :=1;
end;

procedure TForm1.SetRepeatCount(const Value: integer);
begin
if udRepeatCount.Position<>value then
udRepeatCount.Position:=value;
FRepeatCount := udRepeatCount.Position;
end;

procedure TForm1.SetCurTrack(const Value: Integer);
begin
if (Value>=0)and(Value<TrackCount) then
begin
if Value<>FCurTrack then
begin
Stop;
CurRepeat:=0;
FCurTrack := Value;
end;
end;
lst1.Invalidate;
end;

procedure TForm1.SetCurRepeat(const Value: Integer);
begin
FCurRepeat := Value;
updateCurrepeat;
end;

procedure TForm1.UpdateCurRepeat;
begin
lblCurRepeat.Caption := 'Repeat now: '+inttostr(CurRepeat+1);
end;

procedure TForm1.ListToListbox;
begin
lst1.Items.Assign(FList);
end;

function TForm1.Playing: Boolean;
begin
result := BASS_ChannelIsActive(FStream)<>BASS_ACTIVE_STOPPED;
end;

procedure TForm1.Stop;
begin
if Playing then
BASS_ChannelStop(FStream);
end;

procedure TForm1.Play;
var s:string;
begin
UpdateCurRepeat;
s:= ExtractFilePath(ParamStr(0))+ FList[FCurTrack];
Fstream:= Bass_streamcreatefile(false, PChar(s),0,0,BASS_UNICODE or BASS_STREAM_AUTOFREE);
Callingform := Self;
BASS_ChannelSetSync(fstream, BASS_SYNC_END, 0, @EndTrackHandler, nil);
Bass_channelplay(Fstream,false);
end;

procedure TForm1.Prev;
begin
CurTrack:=CurTrack-1;
end;

procedure TForm1.Next;
begin
CurTrack:=CurTrack+1;
end;

function TForm1.TrackCount: integer;
begin
result := Flist.Count;
end;

procedure TForm1.WMChannelEnd(var Msg: TMessage);
begin
CurRepeat := CurRepeat + 1;
Stop;
if CurRepeat >= RepeatCount then
Next;
if CurRepeat < RepeatCount then
play;
end;end.

rvk

  • Hero Member
  • *****
  • Posts: 6886
Re: help with the bass library
« Reply #11 on: June 03, 2015, 05:47:34 pm »
now did the right thing? the problem is that the song is not playing! as to what to fix or add???? help For earlier thanks!
In that case I need the complete project. Could you do the following:
Click Project and then "Publish Project".
Choose a new directory and click Ok.
After that zip that directory and attach it to a post here.

If you can't find how to do it you could rename (or copy) unit1.lfm to unit1.txt and attach it to a post.

Neprofi

  • Full Member
  • ***
  • Posts: 174
Re: help with the bass library
« Reply #12 on: June 03, 2015, 06:19:55 pm »
how to add a project to fully describe! I just can't find !

Neprofi

  • Full Member
  • ***
  • Posts: 174
Re: help with the bass library
« Reply #13 on: June 03, 2015, 06:56:52 pm »
I squeezed cut with archive almost all left unit.pas Bass library for Lazarus version 1.4 as I could! help me please it's hard to explain when you do not know the English language.

Neprofi

  • Full Member
  • ***
  • Posts: 174
Re: help with the bass library
« Reply #14 on: June 03, 2015, 07:00:07 pm »
Investments hopefully will see)))

 

TinyPortal © 2005-2018