1 /**
2 FL Plugin client package. This module is the public API.
3 
4 Copyright: Guillaume Piolat 2023.
5 License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6 */
7 module dplug.flp;
8 
9 // Fruity Loops Plug-in format.
10 
11 version(FLP):
12 
13 import dplug.core.nogc;
14 import dplug.core.runtime;
15 import dplug.flp.types;
16 import dplug.flp.client;
17 
18  
19 // Main entry point for FLP plugins.
20 template FLPEntryPoint(alias ClientClass)
21 {
22     static immutable enum create_plugin_instance =
23         "export extern(C) void* CreatePlugInstance(void* Host, size_t Tag) nothrow @nogc" ~
24         "{" ~
25         "    return CreatePlugInstance_templated!" ~ ClientClass.stringof ~ "(Host, Tag);" ~
26         "}\n";
27 
28     const char[] FLPEntryPoint = create_plugin_instance;
29 }
30 
31 // Templated helper.
32 void* CreatePlugInstance_templated(ClientClass)(void* Host, size_t Tag)
33 {
34     TPluginTag tag = Tag;
35     TFruityPlugHost pHost = cast(TFruityPlugHost) Host;
36 
37     if (pHost is null)
38         return null;
39 
40     ScopedForeignCallback!(false, true) scopedCallback;
41     scopedCallback.enter();
42 
43     ClientClass client = mallocNew!ClientClass();
44 
45     bool err;
46     FLPCLient plugin = mallocNew!FLPCLient(pHost, tag, client, &err);
47 
48     if (err)
49     {
50         destroyFree(client);
51         return null;
52     }
53 
54     return cast(void*) plugin;
55 }