Lazarus

Installation => Windows (32/64) => Topic started by: paul_H on March 12, 2006, 11:18:24 am

Title: Compiling a .dll
Post by: paul_H on March 12, 2006, 11:18:24 am
I'm trying to compile a VST plugin (.dll) that I wrote using Delphi. Up to now, with various help in these pages (thanks), I managed to successfully compile, using essentially my original delphi code (with very minor changes). Great!

Except, my VST host doesn't recognize the .dll and reports 'dispatcher not found'.

I have a feeling that this may be related to the configuration of the project or compiler/linker (because all my units are compiled successfully without errors (some hints mind you)).

Also, when I start from a new Library project and simply compile, Lazarus produces a .exe file instead of a .dll. This seems counter intuitive. Does Lazarus, by default, always produce a .exe even when compiling a .dll?

Any insight into these matters will be appreciated.

There is a whole world of eager VST developers out there that would love to be able to develop in pascal and also be able to build for Linux and Mac (myself included).
Title: Compiling a .dll
Post by: mschnell on March 13, 2006, 03:59:57 pm
Sorry, I can't help with the problem :( .

Does your VST plugin done in Delphi actually work ?

I suppose your intention is to port it to Linux ?

What  VST host in Linux do you intend to use ?

-Michael
Title: Compiling a .dll
Post by: duncanparsons on March 13, 2006, 04:24:42 pm
VST and Delphi go very well together.

I'm just embarking on doing a similar thing to Paul.. From what I can see the problem relates to how the cdecl directive is handled. Delphi makes code which works flawlessly - however FPC doesn't appear to. Searching the forae here suggests that this is not an isolated case.

The VST spec required cdecl, and all hosts will be expecting this. However, the function which VST dlls export takes one parameter, and returns a value indicating success. It may be that for FPC we might be able to get away with 'stdcall' or 'pascal', tho' I doubt it...

reading the other posts around (they are few and far between, I get the feeling that cdecl isn't used much...), it seems that this is a known issue, and one that the FPC devs haven't been eager to resolve, alas.

DSP
Title: Compiling a .dll
Post by: Vincent Snijders on March 13, 2006, 04:55:01 pm
Quote from: "duncanparsons"

reading the other posts around (they are few and far between, I get the feeling that cdecl isn't used much...), it seems that this is a known issue, and one that the FPC devs haven't been eager to resolve, alas.

DSP


What is the number of the fpc bug report describing this problem? I don't know if it has a simple test case, but if not, maybe you can create it.
Title: Compiling a .dll
Post by: paul_H on March 13, 2006, 05:37:56 pm
Hi,

I think the problem has more to do with the way that Lazarus is creating .dlls than with the VST details.

I made a small test procedure. It consists of an application written in Lazarus called “test_dll.exe”. This application opens a window with two buttons. One button executes a procedure contained in a .dll written using Lazarus, and the other button executes a similar procedure contained in a .dll written in Delphi.

The code for both .dlls is essentially identical between Lazarus and Delphi. However, the Delphi .dll is successfully executed by the “test_dll.exe” and the Lazarus .dll causes an error.

I make the source code available for test routine and .dlls at this link.

Download DLL_Test.zip (http://home.planet.nl/~harve009/docs/DLL_Test.zip)

Unizip to a temporary directory:

Under Lazarus open the “test_dll.lpi” project and compile.
Under Lazarus open the “mydll.lpi” project and compile.
Under Delphi open the “mydllD.dpr” project and compile.

Double click the “test_dll.exe” and try clicking the buttons.

The Lazarus compiled .dll does not work.

Maybe it's a config item - I don't know.

Complied using Lazarus 0.9.12 Beta.
Title: Compiling a .dll
Post by: duncanparsons on March 13, 2006, 07:11:46 pm
Quote from: "Vincent"
Quote from: "duncanparsons"

reading the other posts around (they are few and far between, I get the feeling that cdecl isn't used much...), it seems that this is a known issue, and one that the FPC devs haven't been eager to resolve, alas.

DSP


What is the number of the fpc bug report describing this problem? I don't know if it has a simple test case, but if not, maybe you can create it.


I searched on the FPC and lazarus sites, and the most pertinent posts seemed to be:

1 (http://community.freepascal.org:10000/lists/fpc-pascal/2005-May/008460.html) which highlights the problem in athread about sockets;

2 (http://www.lazarus.freepascal.org/index.php?name=PNphpBB2&file=viewtopic&t=1038&highlight=cdecl) which says it has a specific problem with cdecl,

and

3 (http://www.lazarus.freepascal.org/index.php?name=PNphpBB2&file=viewtopic&t=1151&highlight=cdecl) relates to scintilla, but it relates pretty well here. I tried paul's test above, and when debugging got the SIGSEGV mentioned in theis post.


This (http://www.lazarus.freepascal.org/index.php?name=PNphpBB2&file=viewtopic&t=461&highlight=cdecl) one is targetting Linux; and there are a number of topic around which have problems with sqlitedb.

Pauls test is interesting, I tried using the standard register, stdcall, and cdecl.. the delphi dll worked each time, but the fpc one always gave the SIGSEGV.. I haven't tried loading the dll using delphi.. has seemed worth it yet. My feeling is that FP should be able to load it's own dlls..

HTH
DSP
Title: Compiling a .dll
Post by: Vincent Snijders on March 13, 2006, 07:34:47 pm
If you want this to be fixed you need to get the attention from the fpc developers. To get their attention, I would advice you do to one of the following:

fpc-pascal (http://lists.freepascal.org/mailman/listinfo/fpc-pascal/) list.

submit a bug report with a small test program at the fpc bug tracker (http://www.freepascal.org/bugs.html).[/list]
Title: Compiling a .dll
Post by: paul_H on March 13, 2006, 10:53:21 pm
In my example from above

Code: [Select]
library mydll;

{$mode objfpc}{$H+}

uses
  Classes,
  SysUtils,
  Windows;

procedure DllMessage; export;
begin
 MessageBox(0,PChar('Hello world from a Lazarus DLL'),PChar('Lazarus'),mb_ok)
end;

exports DllMessage;

begin
end.


WORKS!

Code: [Select]
library mydll;

{$mode objfpc}{$H+}

uses
  Classes,
  SysUtils,
  Dialogs;

procedure DllMessage; export;
begin
 ShowMessage('Hello world from a Lazarus DLL');
end;

exports DllMessage;

begin
end.


Doesn't work!

Some problem with the Dialogs unit in Lazarus?
Title: Compiling a .dll
Post by: Vincent Snijders on March 13, 2006, 10:58:52 pm
Dialogs is LCL. LCL needs to be initialized by using the interfaces unit and calling Application.Initialize.

I don't know if using the LCL in libraries will work, even if you intialized it properly.
Title: Compiling a .dll
Post by: paul_H on March 13, 2006, 11:08:47 pm
Quote from: "Vincent"
Dialogs is LCL. LCL needs to be initialized by using the interfaces unit and calling Application.Initialize.

I don't know if using the LCL in libraries will work, even if you intialized it properly.


I should qualify my first statement a bit more "seems to be a problem with Dialogs when compiling .dlls". Dialogs works fine in an Application.

So, is this a free pascal issue or a Lazarus issue?
Can you suggest a work around?
Title: Compiling a .dll
Post by: paul_H on March 13, 2006, 11:21:52 pm
Code: [Select]
library mydll;

{$mode objfpc}{$H+}

uses
  Interfaces,
  Classes,
  SysUtils,
  Dialogs;

procedure DllMessage; export;
begin
 ShowMessage('Hello world from a Lazarus DLL');
end;

exports DllMessage;

begin
end.  


i.e. adding the Interfaces, seems to work but then the buttons don't respond when I want to close the window.
Title: Compiling a .dll
Post by: Vincent Snijders on March 13, 2006, 11:23:06 pm
You did not add Application.Initialize
Title: Compiling a .dll
Post by: Vincent Snijders on March 13, 2006, 11:24:12 pm
Quote from: "paul_H"

Can you suggest a work around?


Don't use the LCL in your dll, but I don't know if that is acceptable for you.
Title: Compiling a .dll
Post by: paul_H on March 13, 2006, 11:30:20 pm
Quote from: "Vincent"
You did not add Application.Initialize


Where should I put it? I tried between begin and end, but it causes an error. "identifier not found".

P.S. Not using LCL is probably not acceptable in a VST plugin application.
Title: Compiling a .dll
Post by: Vincent Snijders on March 13, 2006, 11:36:50 pm
Quote from: "paul_H"

Where should I put it?

I don't know, I never used the LCL in an DLL.
Quote
I tried between begin and end, but it causes an error. "identifier not found".

The application variable is in the forms unit.
Quote

P.S. Not using LCL is probably not acceptable in a VST plugin application.

What is a VST plugin?
Title: Compiling a .dll
Post by: paul_H on March 13, 2006, 11:44:25 pm
Tried the Forms and Application.Initialize - no luck enabling the buttons.

What is a VST plugin?

In the context of object pascal (Delphi). This is one of the most popular resources.

http://www.tobybear.de/d_template.html

I'm done for tonight.

Thanks for your help so far. :)
Title: Compiling a .dll
Post by: mschnell on March 14, 2006, 12:07:28 pm
Quote from: "duncanparsons"
VST and Delphi go very well together.


GREAT !

Were you actually able to create a VST plugin in Dephi that has a GUI and that sends and receives MIDI and and audio data ?

-Michael
Title: Compiling a .dll
Post by: mschnell on March 14, 2006, 12:21:45 pm
Quote from: "paul_H"
LCL is probably not acceptable in a VST plugin application.


But the Delphi VCL is ?!?!?!?!

-Michael
Title: Compiling a .dll
Post by: Phil on March 14, 2006, 03:27:42 pm
Quote from: "mschnell"
Quote from: "paul_H"
LCL is probably not acceptable in a VST plugin application.


But the Delphi VCL is ?!?!?!?!

-Michael


I believe the issue here is that the LCL just doesn't work in a library. I haven't tested this on OS X or Linux, but it definitely doesn't work with Windows. The library application "runs", but the GUI is completely unresponsive.

With Delphi, not only does the library application run perfectly, but if you pass the main executable's window handle to the DLL and assign it to the DLL's Application.Handle, the DLL form becomes essentially part of the main program's GUI.

Too bad the LCL doesn't support this powerful feature. Should this be posted as a bug?

Does anyone have any experience using LCL in libraries on OS X or Linux?
Title: Compiling a .dll
Post by: duncanparsons on March 14, 2006, 04:43:55 pm
Quote from: "mschnell"
Quote from: "duncanparsons"
VST and Delphi go very well together.


GREAT !

Were you actually able to create a VST plugin in Dephi that has a GUI and that sends and receives MIDI and and audio data ?

-Michael


There are quite a number of Delphi VST plugs around.. I've written a few free plugs available at  BetaBugsAudio (http://www.betabugsaudio.com). I'm mid way through a number of ideas.. the link above for Tobybear is full of delphi audio as well..

it would be great if LCL could be made to work in a dll. It would benefit not just VST, but any plugin writers for any app.

I hope this can be resolved

:)

DSP
Title: Compiling a .dll
Post by: paul_H on March 14, 2006, 05:01:51 pm
Ditto Duncan

Quote from: "paul_H"

P.S. Not using LCL is probably not acceptable in a VST plugin application.


The original quote was as above. It has been miss-quoted in the last few posts.

Quote from: "Phil"
With Delphi, not only does the library application run perfectly, but if you pass the main executable's window handle to the DLL and assign it to the DLL's Application.Handle, the DLL form becomes essentially part of the main program's GUI.


What you describe, I believe, is almost precisely how a VST plug-in is working inside its host application.

LCL is essential for a VST plugin otherwise there is no point to using Pascal (Delphi or Lazarus).

If LCL does not work in a library, as VCL obviously does in Delphi, then this rules Lazarus out as an option for making plugins of any kind that make use of a user interface.

I would tend to suggest, if true, this is either a bug or oversight. I would be happy to see it fixed.
Title: Compiling a .dll
Post by: duncanparsons on March 14, 2006, 06:11:49 pm
Are there other libraries that could be used - gtk, etc?

Would that be an option? What dependecies would that cause?

AFAIK LCL (like the VCL) binds into an file and shouldn't have any other dependencies (VCL packages excluded here). Does gtk have that kind of dependency?

There must be a method by which LCL will fire up..

I'll start to have aproper play now. I'm installing at home as well as at work!

DSP
Title: Compiling a .dll
Post by: felipemdc on March 15, 2006, 02:44:43 am
Quote from: "duncanparsons"
Are there other libraries that could be used - gtk, etc? Would that be an option?


Another option is locate what is the problem with LCL on DLLs. You could try a simple example, like showing a message box and see what is the difference between what LCL does and what VCL does.

Gtk is an option, but be aware that there are some issues with it:

* No RAD (This is irrelevant to a component)

* Only really good on Linux, it´s quite bad on Windows due to bugs and on Mac OS X due to requiring X11 and Fink (read: needs to be compiled from source, cannot be downloaded as binary)

* Hard to use. Beliave me, it´s very hard to use Gtk, it was a pain to write a simple component like TTrayIcon. With Windows API I took 2 hours. With Gtk I took 2 weeks. Add poor documentation to that.

* Your existing VCL code won´t work with it. You will need to rewrite

Qt is much easier to use and much better documented, but is only free for GPL software and is quite expensive.
Title: Compiling a .dll
Post by: felipemdc on March 15, 2006, 02:46:17 am
Quote
AFAIK LCL (like the VCL) binds into an file and shouldn't have any other dependencies (VCL packages excluded here). Does gtk have that kind of dependency?


LCL is linked inside your software and calls a native library to do the work.

Gtk is a external library. (the installer of the runtime has 4MBs on Windows)
Title: Compiling a .dll
Post by: CWBudde on June 19, 2006, 03:45:02 am
Quote from: "Phil"
I believe the issue here is that the LCL just doesn't work in a library. I haven't tested this on OS X or Linux, but it definitely doesn't work with Windows. The library application "runs", but the GUI is completely unresponsive.

With Delphi, not only does the library application run perfectly, but if you pass the main executable's window handle to the DLL and assign it to the DLL's Application.Handle, the DLL form becomes essentially part of the main program's GUI.

Too bad the LCL doesn't support this powerful feature. Should this be posted as a bug?

Does anyone have any experience using LCL in libraries on OS X or Linux?

Any news here? What is the latest information about using LCL in a DLL? Has it been posted as a bug? How about OSX?

I've ported my VST Plugin Wizard to Lazarus, but without the LCL inside a DLL it's nearly worthless. I'd like to contribute some work, but...

Kind regards,

Christian
Title: Compiling a .dll
Post by: CWBudde on June 20, 2006, 05:24:40 pm
If anyone can point me In a direction, than I'd really like to contribute some work. Otherwise it's useless for me (sorry for this bump),

Christian
Title: Compiling a .dll
Post by: felipemdc on June 20, 2006, 05:58:46 pm
You probably should send an e-mail on the mailling list. There are more developers there that can point you to the right direction.
Title: Compiling a .dll
Post by: Phil on June 20, 2006, 11:22:41 pm
Quote from: "CWBudde"

Any news here? What is the latest information about using LCL in a DLL? Has it been posted as a bug? How about OSX?


Recent snapshots of FPC 2.1.1 crash when compiling my libaries, so I can't check to see if there have been any improvements or whether there's any workaround. When they resolve the compiler problem I'll report back.

I don't know if it's been reported as a bug.

I haven't tested it yet on OS X.
Title: Update on using LCL in DLL
Post by: Phil on July 19, 2006, 10:04:52 pm
Quote from: "CWBudde"

Any news here? What is the latest information about using LCL in a DLL? Has it been posted as a bug? How about OSX?


See this bug report for sample code illustrating the problems using an LCL form in a DLL:

  http://www.freepascal.org/mantis/view.php?id=7181

The _only_ case I could find where using an LCL form in a DLL works as expected is as follows:

- Windows only (GTK on OS X just crashes with access violation).
- Call DLL only from console app.
- Compile library with stack checking off (apparent FPC bug).

Sorry I don't have better news.
Title: Re: Update on using LCL in DLL
Post by: CWBudde on July 20, 2006, 06:27:06 pm
Quote from: "Phil"
See this bug report for sample code illustrating the problems using an LCL form in a DLL:

  http://www.freepascal.org/mantis/view.php?id=7181

The _only_ case I could find where using an LCL form in a DLL works as expected is as follows:

- Windows only (GTK on OS X just crashes with access violation).
- Call DLL only from console app.
- Compile library with stack checking off (apparent FPC bug).

Sorry I don't have better news.

The bug report is a good thing, now we need someone who can adress these items. I'd like to do so, but my knowledge of the LCL is very limited and my time likewise.

Thanks,

Christian
Title: Re: Update on using LCL in DLL
Post by: CWBudde on August 07, 2006, 05:47:40 pm
Quote from: "Phil"
See this bug report for sample code illustrating the problems using an LCL form in a DLL:

  http://www.freepascal.org/mantis/view.php?id=7181

I tried to fix the bug by myself an and soon got a clue about what might went wrong here. I need to make some changes to the customforms.inc to be sure, but unfortunately no change will compile. What do I need to include? To compile this file together with the test program.
I already tried to add the whole LCL directory to the compile path, but I got lots of errors, so there must be another way.

Christian
Title: RE: Re: Update on using LCL in DLL
Post by: Vincent Snijders on August 07, 2006, 10:17:27 pm
Revert all the changes you made to setting and make sure all files from previous compile attempts are removed. If you want to test the LCL, you need to compile the complete LCL. Use the Build Lazarus menu option, see wiki (http://wiki.lazarus.freepascal.org/index.php/How_To_Help_Developing_Lazarus#Widgetsets_.28.22interfaces.22.29) for details.
Title: RE: Re: Update on using LCL in DLL
Post by: duncanparsons on September 01, 2008, 03:03:36 pm
I'm having another look at this, so thought I'd give it a bump to see if anyone had any further ideas in the last 2 years :)

I'm looking at perhaps using a callback system where the dll and application know about each other, and the app iterates it's list of 'child applications' telling them to process their messages.. it may help with getting forms communicating but wouldn't solve any more subtle LCL errors in sharing memory, etc. I'm envisioning a C-style thing, rather than something akin to packages - but even then I'm not totally sure it would work; and it would mean implementing changes at the widgetset level.

Any ideas before I start?

DSP
Title: Re: Compiling a .dll
Post by: ZL on December 25, 2008, 01:02:07 pm
duncanparsons, how is your work with this issue going? Any progress?
I'm interested in this issue for coulpe of years too, but didn't post anything because I know I won't be able to contribute to solving it...
Title: Re: Compiling a .dll
Post by: Phil on December 25, 2008, 07:06:12 pm
I've had quite a bit of luck with forms in libraries on OS X/Carbon, but not with Lazarus win32. These same libraries compile and run fine with Delphi, as do non-form DLL's compiled with FPC, so this suggests something wrong in the win32 widgetset.

Here are some of the things I've successfully tested:

- 50,000 line library with multiple forms compiled with Laz 0.9.26/FPC 2.2.2 called from C++/Qt app on Mac. Works identically to its standalone counterpart.

- Same code compiled into a library with Delphi can be called modally or non-modally (the forms, that is) from same C++/Qt app on Windows or even from a .NET app. When compiled with Laz 0.9.26/FPC 2.2.2, Windows is not able even to load the DLL.

Since I have Delphi, I don't need Lazarus on Windows, but it would be great for this to work too. Odd to see Carbon ahead of Windows in this regard.

Thanks.

-Phil
Title: Re: Compiling a .dll
Post by: ZL on December 27, 2008, 01:26:12 am
Phil, thanks for info. But can you load Laz compiled library with Laz compiled executable in Mac (both containint forms)?

If I actually can load library with forms in Mac (so maybe in Linux too?) and if I will be able to load from Laz compiled exe a Delphi dll with forms in Windows it could be at least some kind of solution.
I think I'll try to test it in next month (I hope).

But yes, it would be nice to have Lazarus-only solution :)
Title: Re: Compiling a .dll
Post by: Phil on December 27, 2008, 01:55:35 am
Yes, that works too. You can load the library either by declaring it external or by manually loading and working with the library using LoadLibrary, GetProcAddress and FreeLibrary in the DynLibs unit. For former is simpler to get started with but, as you probably know, you have to put the .dll somewhere that Windows can find it. Doing everything yourself provides more flexibility and allows you to put the library anywhere that your code can find it. This also allows you to handle missing libraries more gracefully - on Windows, it just puts up an error message and quits.

Don't know anything about Linux but I would imagine it's more of a GTK/GTK2 widgetset question than it is a Linux question.

On Windows, if you need to display your Delphi form non-modally (via Show instead of ShowModal) there are issues with some keystrokes not getting sent through to the form (tabbing doesn't work, for example), but there are workarounds by passing the keystrokes through from the host app. If you're using ShowModal, that works fine - apparently a different mechanism is used to detect keystrokes.

Thanks.

-Phil
Title: Re: Compiling a .dll
Post by: PeterX on December 12, 2017, 12:51:36 pm
Just to keep things together .. for people seaching on 'VST Plugins'

http://wiki.freepascal.org/Form_in_DLL
Title: Re: Update on using LCL in DLL
Post by: Thaddy on December 12, 2017, 01:29:43 pm
Quote from: Phil
See this bug report for sample code illustrating the problems using an LCL form in a DLL:

  http://www.freepascal.org/mantis/view.php?id=7181
I tried to fix the bug by myself an and soon got a clue about what might went wrong here. I need to make some changes to the customforms.inc to be sure, but unfortunately no change will compile. What do I need to include? To compile this file together with the test program.
I already tried to add the whole LCL directory to the compile path, but I got lots of errors, so there must be another way.

Christian
You are looking too deep... It is just a matter of alignment which should be 16 in both application and vst.
There is a simple repaint problem that can be solved by, Ahum, Application.ProcessMessages. And make sure the correct handle is in place (The client handle, not the VST), but you know that.

(As an aside: you still did not give me the credits for the reverb -freeverb - translation  O:-) You claim that's your code. It isn't.  I released it as do what you want, but to claim you wrote it it gross. You may have improved on it but I can not see where?
Even my original comments are still in...
The true story is that I wrote the initial VST host code and TobyBear and you improved on it. Fair enough, good job. :D. And the VST basics were layed down by Frederic VanMol )

I am not grumpy, but some original credits should be in place. They aren't.
[edit]
I missed the date, which is 12 years ago. Remark still stands.... (As I remarked 12 years ago....)
Title: Re: Update on using LCL in DLL
Post by: PeterX on December 12, 2017, 01:39:49 pm
There is a simple repaint problem that can be solved by, Ahum, Application.ProcessMessages. And make sure the correct handle is in place (The client handle, not the VST),
I am still not this far.

My plugin compiles and replays the MIDI notes it receives.
But the plugin does not paint ..

http://forum.lazarus.freepascal.org/index.php/topic,39210.msg268729.html#msg268729
Title: Re: Update on using LCL in DLL
Post by: Thaddy on December 12, 2017, 01:43:19 pm
But the plugin does not paint ..
It is a matter of the VST getting the right handle from the main program and an extra processmessages.
I have a small function that sets it in the VST if you want. But it is easy. Do it at load time.
Title: Re: Update on using LCL in DLL
Post by: PeterX on December 23, 2017, 12:38:21 am
But the plugin does not paint ..
It is a matter of the VST getting the right handle from the main program and an extra processmessages.
I have a small function that sets it in the VST if you want. But it is easy. Do it at load time.

To the DLL library file (*.lpr / *.dpr) I added today ..

Code: Pascal  [Select][+][-]
  1. begin
  2.   {$IFDEF FPC}Application.Initialize;{$ENDIF}
  3. end.
  4.  

and now the surface of the VST plugin appears !
(.. after moving the plugin form once ..)
Title: Re: Compiling a .dll
Post by: Thaddy on December 23, 2017, 07:56:39 am
Oh, yes, forgot to mention that. There were a few things more that I do in that function, like masking all floating point exceptions. (Necessary for ms C(++) compiled hosts, do not forget that...)
I also initialize tables there, for LUT's. I think my function example is somewhere on musicdsp. You may also want to examine Christian Budde's examples, these are also for FreePascal AFAIK.
Title: Re: Compiling a .dll
Post by: PeterX on December 23, 2017, 12:05:30 pm
Oh, yes, forgot to mention that.
Oh .. and it took me two weeks now to track down the exception that (now I know ..) occurs on
Code: Pascal  [Select][+][-]
  1.  GUI := TVSTEditorForm.Create(nil);

This ...
Code: Pascal  [Select][+][-]
  1.   {$IFDEF FPC}Application.Initialize;{$ENDIF}
didn't make sense to me in the DLL code, I just played around and compared with code from Form_in_DLL


There were a few things more that I do in that function, like masking all floating point exceptions. (Necessary for ms C(++) compiled hosts, do not forget that...)
I didn't know about that. Maybe it is already done in the example code from VSTPluginwizard1.0 or Delphi ASIO & VST Packages 1.3


You may also want to examine Christian Budde's examples, these are also for FreePascal AFAIK.
The Delphi ASIO & VST Packages 1.3 had no working Lazarus compatible code .. :-(

But I made TestPlugin.dpr  from VSTPluginwizard1.0 compile and run now.
Title: Re: Compiling a .dll
Post by: Thaddy on December 23, 2017, 12:41:43 pm
The ASIO unit most definitely works (at least my original version that pre-dates most others) but only in WIN32.
Title: Re: Compiling a .dll
Post by: PeterX on December 23, 2017, 02:08:54 pm
The ASIO unit most definitely works (at least my original version that pre-dates most others) but only in WIN32.
Do You think it makes sense to use the 64 bit Lazarus ?
I never tried ..
Title: Re: Compiling a .dll
Post by: Thaddy on December 23, 2017, 02:13:57 pm
There are 64bit ASIO drivers, so yes..
Title: Re: Compiling a .dll
Post by: PeterX on December 23, 2017, 04:59:24 pm
There are 64bit ASIO drivers, so yes..
Is the 64 bit ASIO SDK from Steinberg also available as Pascal sources anywhere ?
Title: Re: Compiling a .dll
Post by: avra on December 24, 2017, 11:08:32 pm
Delphi ASIO and VST packages have already been ported to CodeTyphon:
http://www.pilotlogic.com/sitejoom/index.php/113-wiki/ct-packages/audio-and-video/237-pl-asiovst
You can use ct2laz to download CodeTyphon components and examples and convert them to Lazarus.

btw, it would be better to wait a few days for a new version of ct2laz which will be compatible with latest CT 6.30.

EDIT: Somehow instead of adding new message I have modified this old message. Hopefully this message is now reconstructed according to the original.
Title: Re: Compiling a .dll
Post by: PeterX on December 25, 2017, 10:33:47 pm
Delphi ASIO and VST packages have already been ported to CodeTyphon:
http://www.pilotlogic.com/sitejoom/index.php/113-wiki/ct-packages/audio-and-video/237-pl-asiovst
You can use ct2laz to download CodeTyphon components and examples and convert them to Lazarus.

btw, it would be better to wait a few days for a new version of ct2laz which will be compatible with latest CT 6.30.
Thanks a lot for this hint !

I already have a running Delphi host application and plugins.
My problem was to make the plugins compile and run under Lazarus.
Now some of them do work, some less perfect ..
But everything still under 32 bit Lazarus.
Title: Re: Compiling a .dll
Post by: avra on January 01, 2018, 03:22:26 pm
Quote
btw, it would be better to wait a few days for a new version of ct2laz which will be compatible with latest CT 6.30.
New ct2laz is out. It handles latest CT 6.30+ components and examples correctly.  8)
Title: Re: Compiling a .dll
Post by: PeterX on January 01, 2018, 09:37:48 pm
New ct2laz is out. It handles latest CT 6.30+ components and examples correctly.  8)
Thank You, I will look into it !

Do You work on VST plugins or audio software ?
Title: Re: Compiling a .dll
Post by: avra on January 02, 2018, 12:58:29 am
Do You work on VST plugins or audio software ?
No, sorry. I use FFT, IFFT and direct wave synthesis for other purposes, but so far my roads did not cross with VST.
Title: Re: Compiling a .dll
Post by: PeterX on January 04, 2018, 11:38:06 pm
Delphi ASIO and VST packages have already been ported to CodeTyphon:
http://www.pilotlogic.com/sitejoom/index.php/113-wiki/ct-packages/audio-and-video/237-pl-asiovst
You can use ct2laz to download CodeTyphon components and examples and convert them to Lazarus.
Thanks a lot, avra !

The "Delphi ASIO and VST packages" from CodeTyphon does not fully work after converting it with ct2laz.
There is a new Project type called "VST plugin" being created. It throws an error on saving, due to wrong *.ppr instead of *.lpr

And there's no working VST plugin template. But I'm getting closer.
I already have a working example, inside the old ASIO-VST package 1.0
Needs some cleanup, then I will upload it here : http://forum.lazarus.freepascal.org/index.php/topic,39494.0.html
Title: Re: Compiling a .dll
Post by: avra on January 05, 2018, 09:10:02 am
The "Delphi ASIO and VST packages" from CodeTyphon does not fully work after converting it with ct2laz.
There is a new Project type called "VST plugin" being created. It throws an error on saving, due to wrong *.ppr instead of *.lpr
Find file "allAsioVSTRegisterIDE.pas" and replace ppr with lpr in this line:
Code: Pascal  [Select][+][-]
  1. MainFile := AProject.CreateProjectFile('VSTPlugin1.ppr');
Then rebuild Lazarus IDE and report here if the problem was fixed. ct2laz was intended to fix compilation issues, not to fix issues with new project types. Anyway, in case of positive feedback I will update CSV file so this will be fixed and not happen in the future.

And there's no working VST plugin template.
If you have left default options in ct2laz, it would have downloaded and extracted both components (in "typhon" directory) and examples (in "CodeOcean" directory). I found "CodeOcean\pl_ASIOVST\samples\GUI" directory full of examples:
Code: Pascal  [Select][+][-]
  1. AudioDataDisplay\
  2. EQ-Graph\
  3. EQ-Slide\
  4. Fader Test\
  5. Label\
  6. LEDs\
  7. Media Buttons\
  8. Mega Demo\
  9. MidiKeys\
  10. Select Box\
  11. Sphere\
  12. StaticWaveform\
Is that what you're looking for?
Title: Re: Compiling a .dll
Post by: PeterX on January 05, 2018, 11:52:18 am
I found "CodeOcean\pl_ASIOVST\samples\GUI" directory full of examples:
Code: Pascal  [Select][+][-]
  1. AudioDataDisplay\
  2. EQ-Graph\
  3. EQ-Slide\
  4. Fader Test\
  5. ...
  6.  
Is that what you're looking for?

This are test projects only to test GUI objects delivered with the package.

But, no problem, I hope to be able to fix the problems left, in the Code Typhon ASIO-VST 1.3 package.
My TestPlugin from VST-ASIO 1.0 Delphi package works now, with both Delphi 5 and Lazarus 1.8  :D
(.. but currently only under the old 1.0 files)
Title: Re: Compiling a .dll
Post by: PeterX on January 05, 2018, 12:20:08 pm

I was wrong, sorry !

It is  *.lpi  !
Title: Re: Compiling a .dll
Post by: avra on January 05, 2018, 03:44:25 pm
My TestPlugin from VST-ASIO 1.0 Delphi package works now, with both Delphi 5 and Lazarus 1.8  :D
I am glad you worked it out  ;)

Find file "allAsioVSTRegisterIDE.pas" and replace ppr with lpr in this line:
Code: Pascal  [Select][+][-]
  1. MainFile := AProject.CreateProjectFile('VSTPlugin1.ppr');
I was wrong, sorry !
It is  *.lpi  !
Are you sure? PPR is CT counterpart for Lazarus LPR, and I could find PPR mentioned at one place in code as above, but CTPR is CT counterpart for Lazarus LPI and I could not find any part of pl_ASIOVST package code that mentions CTPR.
I think that it is normal that Lazarus asks you to save LPI, but after applying a fix mentioned above and rebuilding IDE, you should be able to save now because PPR is properly replaced with LPR. please try and report.
Title: Re: Compiling a .dll
Post by: PeterX on January 05, 2018, 04:36:46 pm
Are you sure?
If You convert the package yourself to Laz .. (You don't need to become a VST Plugin developer now ..)

When creating a new "VST Plugin" project it's not saved (as designed).
Now try to save the project. With the "preset" *.ppr You get an error message.
("Project-Info-File has same name as main source file" or how to translate the error message to english ..)

Then if You manually change the ending to *.lpi  in the FileSave dialog ..
... it saves the project (it's an XML file) and then the main unit.pas
(and also the main project file, unfortunately as *.ppr)

I saw that instead of *.dpr (like Delphi) or *.lpr  it saves the "library VSTPlugin1;"  as *.ppr

Please see screenshot.
Title: Re: Compiling a .dll
Post by: PeterX on January 05, 2018, 08:47:27 pm
Okay... it IS  *.lpr ....  :-[

Now it works, creating a new VST Plugin project.
Title: Re: Compiling a .dll
Post by: avra on January 06, 2018, 11:08:56 am
I saw that instead of *.dpr (like Delphi) or *.lpr  it saves the "library VSTPlugin1;"  as *.ppr
It shouldn't save ppr if you have changed source as mentioned and rebuilt IDE. Did you rebuild IDE?

Now it works, creating a new VST Plugin project.
It can not magically start working on it's own. What did you do? Did you rebuild IDE or did something else? It is important for me to get proper feedback to know what to add to ct2laz CSV file, and if proposed patch was enough or not.
Title: Re: Compiling a .dll
Post by: PeterX on January 06, 2018, 05:13:02 pm
Okay, now I have three versions of a working plugin.
- ASIO VST 1.0 in Delphi 5
- ASIO VST 1.0 in Lazarus
- ASIO VST 1.3 in Lazarus (pl_ASIOVST)

But things are difficult. In Samplitude Music Studio 2014 32 Bit only the Delphi 5 version works.
In Samplitude Music Studio 2014 64 Bit all three plugins do appear, two do work.
Title: Re: Compiling a .dll
Post by: PeterX on January 06, 2018, 05:18:47 pm
Did you rebuild IDE?
Yes. Everything's okay now. You only need to change this *.ppr to *.lpr in ct2laz.
As I'm working on code in pl_ASIOVST, the package and Lazarus needs rebuilds.


But the code in the template "VST Plugin" ist wrong, at 130:
Code: Pascal  [Select][+][-]
  1.     + 'begin' + le
  2.     + '  Application.Title:=''VST Plugin'';' + le
  3.     + '  Application.CreateForm(TVSTModule1, VSTModule1);' + le
  4.     + '  Application.Run;' + le
  5.     + 'end.';

This is correct:
Code: Pascal  [Select][+][-]
  1. begin
  2.   Application.Initialize;
  3. end.
  4.  
Title: Re: Compiling a .dll
Post by: PeterX on January 06, 2018, 05:22:03 pm
It can not magically start working on it's own. What did you do?
I have the "VST Plugin Analyser.exe" as host.
And Magix Samplitude, and Audacity, and ... for testing.
Title: Re: Compiling a .dll
Post by: avra on January 06, 2018, 08:43:05 pm
Did you rebuild IDE?
Yes. Everything's okay now. You only need to change this *.ppr to *.lpr in ct2laz.
As I'm working on code in pl_ASIOVST, the package and Lazarus needs rebuilds.
I am glad this is clear now so I can add this new rule to CSV file of ct2laz.

But things are difficult. In Samplitude Music Studio 2014 32 Bit only the Delphi 5 version works.
In Samplitude Music Studio 2014 64 Bit all three plugins do appear, two do work.
Well, I do not know if anyone else on Lazarus is familiar with VST plugins. I guess that situation will be better once pl_ASIOVST becomes available from OPM. Until then, your best chance is to report any problem in PilotLogic forum. However, they will surely not support pl_ASIOVST in Lazarus, so you will have to download latest CodeTyphon and try to see if the problems are the same, and if they are report problems to PilotLogic forum. Sometimes you wait forever for a fix, and sometime they are pretty fast like here:
http://www.pilotlogic.com/sitejoom/index.php/forum/audio-and-video-development/3457-the-asio-hosts-both-make-the-ide-crash-immediately
Title: Re: Compiling a .dll
Post by: PeterX on January 06, 2018, 09:19:41 pm
avra,

thanks very much for Your help - I have a working translation to lazarus now from the latest 1.3 ASIO-VST. That's great !

As soon as I am sure this works stable, I would like to share the Plugin Example code
to complete the pl_ASIOVST package. Also some of the GUI object test projects
of pl_ASIOVST package  do crash on runtime. Crashing examples are no good examples ..

I guess that situation will be better once pl_ASIOVST becomes available from OPM.
What's OPM ?  Online Package Manager ?
Title: Re: Compiling a .dll
Post by: balazsszekely on January 06, 2018, 09:27:13 pm
Quote
@PeterX
What's OPM ?  Online Package Manager ?
Yes. ASIOVST is available since last summer in OPM.
Title: Re: Compiling a .dll
Post by: PeterX on January 06, 2018, 11:24:08 pm
Quote
@PeterX
What's OPM ?  Online Package Manager ?
Yes. ASIOVST is available since last summer in OPM.
Sorry, I heard from the "Online Package Manager" the first time ever.
Will this be integrated into the "Install / deinstall Packages" dialog of Laz IDE one day ?

(just found this thread.. )
http://forum.lazarus-ide.org/index.php/topic,34297.1095.html?PHPSESSID=3rket2na8tockjq4svkjl6q1i1
Title: Re: Compiling a .dll
Post by: balazsszekely on January 07, 2018, 07:25:11 am
Quote
@PeterX
Will this be integrated into the "Install / deinstall Packages" dialog of Laz IDE one day ?
It's already integrated, just not installed by default. For more info, please read this: http://wiki.freepascal.org/Online_Package_Manager
Title: Re: Compiling a .dll
Post by: PeterX on January 07, 2018, 02:42:43 pm
It's already integrated, just not installed by default. For more info, please read this: http://wiki.freepascal.org/Online_Package_Manager
Okay, now I know more  :)

I found ASIO-VST on http://packages.lazarus-ide.org/

But there it does not contain the "samples" folder.
And also no example project for a plugin.
And also the "VST Plugin" project invented with the package fails.

As this comes from PilotLogic, I expect there's nobody maintaning the package here for Lazarus ?
How can I contribute changes to the package ?
Title: Re: Compiling a .dll
Post by: avra on January 07, 2018, 02:56:22 pm
I found ASIO-VST on http://packages.lazarus-ide.org/
But there it does not contain the "samples" folder.
It will be fixed once pl_ASIOVST is established in new ct4laz repo and OPM starts using that version.

Quote
And also the "VST Plugin" project invented with the package fails.
As this comes from PilotLogic, I expect there's nobody maintaning the package here for Lazarus ?
How can I contribute changes to the package ?
Already explained:
...your best chance is to report any problem in PilotLogic forum. However, they will surely not support pl_ASIOVST in Lazarus, so you will have to download latest CodeTyphon and try to see if the problems are the same, and if they are report problems to PilotLogic forum. Sometimes you wait forever for a fix, and sometime they are pretty fast like here:
http://www.pilotlogic.com/sitejoom/index.php/forum/audio-and-video-development/3457-the-asio-hosts-both-make-the-ide-crash-immediately
Title: Re: Compiling a .dll
Post by: PeterX on January 10, 2018, 12:12:40 am
...your best chance is to report any problem in PilotLogic forum. ..
Okay, I'll go that way.

I still have some trouble opening the VST plugin in my software.
Reasons not clear, might be alignment problems due to wrong compiler switches.
And in some function declarations "const" is used instead of "by reference" declarations ..
Needs some testing ..

I will create an account there, tomorrow ..
Title: Re: Compiling a .dll
Post by: PeterX on January 11, 2018, 10:46:42 pm
I still have some trouble opening the VST plugin in my software.
Reasons not clear, might be alignment problems due to wrong compiler switches.

VST Plugins loaded in C-style hosts seem to crash, compiled with debug switches on,
especially {$RANGECHECKS ON}, in my case here ..
Now with some debug switches off .. all my three derivates of the example project do compile, and run (!).
TinyPortal © 2005-2018