Recent

Author Topic: Linux bass hell  (Read 4831 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Linux bass hell
« Reply #15 on: July 09, 2020, 05:56:42 pm »
Here it is. I've attached the project as a zip.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, bass;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     procedure FormCreate(Sender: TObject);
  16.   private
  17.  
  18.   public
  19.  
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32. begin
  33.  
  34.   if not BASS_Init(-1, 44100, 0, @Handle, nil) then showMessage ('Error');
  35.  
  36. end;
  37.  
  38. end.
  39.  
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: Linux bass hell
« Reply #16 on: July 09, 2020, 06:20:47 pm »
Hi pcurtis,

Yeah, Windows, not Windows, handles vs pointers...  :)

try:
Code: Pascal  [Select][+][-]
  1.   if not BASS_Init(-1, 44100, 0, Pointer(Handle), nil) then showMessage ('Error');
  2.  
And let us know if that worked for you or not...

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Linux bass hell
« Reply #17 on: July 09, 2020, 06:42:25 pm »
@Tron - It works - Youre the man
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Linux bass hell
« Reply #18 on: July 09, 2020, 07:10:06 pm »
Hi!

I showed the multi-platform code already, but here it is again.
Code: Pascal  [Select][+][-]
  1. procedure BassInit(H: HWND);
  2. begin
  3. {$IFDEF LINUX}
  4. BASS_Init(-1, 44100, 0, @H, nil);
  5. {$ELSE}
  6. BASS_Init(-1, 44100, 0, H, nil); /// !!! Bei Windows ohne Pointer, nur Handle
  7. {$ENDIF}
  8. end;
  9.  

The HWND parameter must be Form1.Handle.

Winni

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Linux bass hell
« Reply #19 on: July 09, 2020, 07:27:44 pm »
I showed the multi-platform code already, but here it is again.
Code: Pascal  [Select][+][-]
  1. procedure BassInit(H: HWND);
  2. begin
  3. {$IFDEF LINUX}
  4. BASS_Init(-1, 44100, 0, @H, nil);
  5. {$ELSE}
  6. BASS_Init(-1, 44100, 0, H, nil); /// !!! Bei Windows ohne Pointer, nur Handle
  7. {$ENDIF}
  8. end;
  9.  
A stupid question: H is a variable on the stack. When Linux requires the address of this variable it will no longer be valid after your BassInit() has been left. Is this a problem for BASS? Does it require the handle only on this occasion?

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: Linux bass hell
« Reply #20 on: July 09, 2020, 07:39:47 pm »
Bass_init simply requires a window handle (HWND).

The person who made/converted the headers simply assumed that when you are not on windows, there is no HWND, rather a pointer, Quite possibly that person was not aware of the existence of other platforms that also uses HWND handles.
Code: Pascal  [Select][+][-]
  1. {$IFDEF MSWINDOWS}
  2. function BASS_Init(device: Integer; freq, flags: DWORD; win: HWND; clsid: PGUID): BOOL; stdcall; external bassdll;
  3. {$ELSE}
  4. function BASS_Init(device: Integer; freq, flags: DWORD; win: Pointer; clsid: Pointer): BOOL; cdecl; external bassdll;
  5. {$ENDIF}
  6.  
If this is considered difficult, then be prepared because the sources of those headers are riddled with this kind of wrongful assumptions which makes your BASS life a little less soundy :)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Linux bass hell
« Reply #21 on: July 09, 2020, 07:55:41 pm »

A stupid question: H is a variable on the stack. When Linux requires the address of this variable it will no longer be valid after your BassInit() has been left. Is this a problem for BASS? Does it require the handle only on this occasion?

The HWND parameter H is only used while the BASS_Init.
It connects the BASS library to your desktop application.
AFAIK it is not used elsewhere in the BASS functions.

Winni

 

TinyPortal © 2005-2018