1 /*
2 MIT License
3 
4 Copyright (c) 2021 Alexandre BIQUE
5 Copyright (c) 2024 Guillaume PIOLAT
6 
7 Permission is hereby granted,  free of charge, to any person obtaining
8 a copy of  this  software  and  associated  documentation  files  (the
9 "Software"),  to deal in the Software  without restriction,  including
10 without limitation the rights to use, copy,  modify,  merge,  publish,
11 distribute,  sublicense,  and/or sell  copies of the Software,  and to
12 permit persons to whom the Software is furnished to do so,  subject to
13 the following conditions:
14 
15 The  above  copyright  notice  and  this  permission  notice  shall be
16 included  in  all  copies or  substantial  portions of  the  Software.
17 
18 THE SOFTWARE  IS  PROVIDED "AS IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
19 EXPRESS OR IMPLIED,  INCLUDING  BUT NOT  LIMITED TO THE  WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT  SHALL THE AUTHORS  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 CLAIM,  DAMAGES OR OTHER LIABILITY,  WHETHER IN AN ACTION OF CONTRACT,
23 TORT  OR OTHERWISE,  ARISING FROM,  OUT OF OR  IN CONNECTION  WITH THE
24 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26 module dplug.clap;
27 
28 nothrow @nogc:
29 version(CLAP):
30 
31 import dplug.core.nogc;
32 import dplug.core.runtime;
33 
34 import dplug.clap.clapversion;
35 import dplug.clap.types;
36 public import dplug.clap.clapversion;
37 
38 
39 // parts of entry.h and version.h here
40 
41 struct clap_plugin_entry_t 
42 {
43 extern(C) nothrow @nogc:
44     clap_version_t clap_version;
45     bool function(const(char)* plugin_path) init;
46     void function() deinit;
47     const(void)* function(const(char)* factory_id) get_factory;
48 }
49 
50 // Main entry point for CLAP plugins.
51 template CLAPEntryPoint(alias ClientClass)
52 {
53     enum factory_entry =
54         `extern(C) const(void)* clap_factory_entry(const(char)* 
55              factory_id) nothrow @nogc
56         {
57             import dplug.clap.types;
58             return clap_factory_templated!` 
59                 ~ ClientClass.stringof ~ `(factory_id);
60         }`;
61 
62     enum init_entry =
63         `extern(C) bool clap_entry_init(const(char)* plugin_path) 
64          nothrow @nogc { return true; }`;
65 
66     enum deinit_entry =
67         `extern(C) void clap_entry_deinit() nothrow @nogc { }`;
68 
69     enum plugin_entry = 
70         `export extern(C) __gshared clap_plugin_entry_t clap_entry = 
71         clap_plugin_entry_t(CLAP_VERSION, &clap_entry_init, 
72         &clap_entry_deinit, &clap_factory_entry);`;
73 
74     const char[] CLAPEntryPoint = init_entry 
75                                 ~ deinit_entry 
76                                 ~ factory_entry 
77                                 ~ plugin_entry;
78 }
79 
80