Hi all. I'm looking for some help and tips with Delphi FireMonkey... I wonder if anyone tried to use it for VST plugin developnemt (potentially - Win and Mac VST from one code base).
FireMonkey on Windows relies on GDI+ library. Since VST is a dll, you need to call GDIPlusStartUp() before all other GUI stuff. And it's not the right way to do it from DLL itself, you need host app to do this before and after it uses your DLL.
I cound initialize it from DLL actually, but oh host shutdown it always crashes.
I followed this advice
http://mikevdm.com/BlogEntry/Key/Gdiplu ... steriously
and finally was able to Init and close GDI+ from DLL istelf, but it doesn't feel like a reliable solution to me. Maybe anyone else faced the same problem?
Another problem. When you create a form inside VST dll, it needs to be parented to host's window. Host passes you a window handle (HWND), but with FireMonkey you can't pass Windows handle to a form, only another firemonkey form handle.
Finally I had to change some FMX .pas files, passing window handle via global variable, and finally I could open and close my plugin without crashes... Another dirty fix. Maybe I missed some better way?
Another problem. If I call a menu or popup menu even once, it crashes on shutdown again. The same issue - menus are implemented like forms, and they are created with no parent window. I tried to fox it the same way, didn't work.
Delphi XE FireMonkey & VST Plugins - mission impossible?
- KVRian
- 805 posts since 15 Apr, 2012
-
- KVRist
- 390 posts since 17 Jan, 2005
Jamstix uses Firemonkey since V3.5.
There are many Firemonkey bugs/issues yet to be resolved in XE5. The menu system is one of them. We finally gave up and coded our own. We also could never completely fix the GDI+ init issues. At best it worked for most users but not all (close plugin host crashes). We now have a changed architecture where this doesn't happen anymore but it is complex.
For the HWND issue, all you have to do is translate the FMX handle to a HWND like this:
Windows.SetParent(FmxHandleToHWND(FormHandle),HostWindowHWND);
If you are thinking of using Firemonkey for plugins on OSX, be aware of some serious performance issues with GUI drawing. We had to do custom low-level Cocoa coding and alterations to the FMX event handling to get it to an acceptable level.
There are many Firemonkey bugs/issues yet to be resolved in XE5. The menu system is one of them. We finally gave up and coded our own. We also could never completely fix the GDI+ init issues. At best it worked for most users but not all (close plugin host crashes). We now have a changed architecture where this doesn't happen anymore but it is complex.
For the HWND issue, all you have to do is translate the FMX handle to a HWND like this:
Windows.SetParent(FmxHandleToHWND(FormHandle),HostWindowHWND);
If you are thinking of using Firemonkey for plugins on OSX, be aware of some serious performance issues with GUI drawing. We had to do custom low-level Cocoa coding and alterations to the FMX event handling to get it to an acceptable level.
-
very angry mobster very angry mobster https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=11047
- KVRian
- 611 posts since 15 Dec, 2003 from Melbourne, Australia
I've used VGScene, FireMonkey's predecessor, in a couple small plugins and experimented with FireMonkey in XE2. Both frameworks use GDI+ so have the same issue.
VGScene included some code that allowed GDI+ to be initialised and closed from a DLL. At the time of XE2, Embarcadero's official line was GDI+ had to be initialised & shutdown from the host application. This is not an option when building VST plugins so I used the hack from VGScene with FireMonkey. In my experience this seemed to work but my VGScene plugins aren't used as widely as Jamstix so take that with a grain of salt. (FMX in DLL Hack code)
I've since stopped using FireMonkey. What I saw in XE2 didn't convince me to commit to using it in a plugin. I'm in the midst of building some new VCL controls that can be rendered with an alpha channel using AggPasMod. I was planning to put the code on Github but haven't done it yet.
VGScene included some code that allowed GDI+ to be initialised and closed from a DLL. At the time of XE2, Embarcadero's official line was GDI+ had to be initialised & shutdown from the host application. This is not an option when building VST plugins so I used the hack from VGScene with FireMonkey. In my experience this seemed to work but my VGScene plugins aren't used as widely as Jamstix so take that with a grain of salt. (FMX in DLL Hack code)
I've since stopped using FireMonkey. What I saw in XE2 didn't convince me to commit to using it in a plugin. I'm in the midst of building some new VCL controls that can be rendered with an alpha channel using AggPasMod. I was planning to put the code on Github but haven't done it yet.
This stackoverflow answer shows how to parent a FMX form to a window handle.Another problem. When you create a form inside VST dll, it needs to be parented to host's window. Host passes you a window handle (HWND), but with FireMonkey you can't pass Windows handle to a form, only another firemonkey form handle.
I was able to get things working without changes to any of the FMX source in XE2 but maybe things have changed since then.Finally I had to change some FMX .pas files, passing window handle via global variable, and finally I could open and close my plugin without crashes... Another dirty fix. Maybe I missed some better way?
