Mercurial > hg > pub > prymula > com
comparison DPF-Prymula-audioplugins/dpf/distrho/src/DistrhoUtils.cpp @ 3:84e66ea83026
DPF-Prymula-audioplugins-0.231015-2
author | prymula <prymula76@outlook.com> |
---|---|
date | Mon, 16 Oct 2023 21:53:34 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:cf2cb71d31dd | 3:84e66ea83026 |
---|---|
1 /* | |
2 * DISTRHO Plugin Framework (DPF) | |
3 * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com> | |
4 * | |
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with | |
6 * or without fee is hereby granted, provided that the above copyright notice and this | |
7 * permission notice appear in all copies. | |
8 * | |
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD | |
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | |
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 */ | |
16 | |
17 #ifndef DISTRHO_IS_STANDALONE | |
18 # error Wrong build configuration | |
19 #endif | |
20 | |
21 #include "../extra/String.hpp" | |
22 #include "../DistrhoStandaloneUtils.hpp" | |
23 | |
24 #ifdef DISTRHO_OS_WINDOWS | |
25 # include <windows.h> | |
26 #else | |
27 # ifndef STATIC_BUILD | |
28 # include <dlfcn.h> | |
29 # endif | |
30 # include <limits.h> | |
31 # include <stdlib.h> | |
32 #endif | |
33 | |
34 #ifdef DISTRHO_OS_WINDOWS | |
35 # if DISTRHO_IS_STANDALONE || defined(STATIC_BUILD) | |
36 static constexpr const HINSTANCE hInstance = nullptr; | |
37 # else | |
38 static HINSTANCE hInstance = nullptr; | |
39 | |
40 DISTRHO_PLUGIN_EXPORT | |
41 BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID) | |
42 { | |
43 if (reason == DLL_PROCESS_ATTACH) | |
44 hInstance = hInst; | |
45 return 1; | |
46 } | |
47 # endif | |
48 #endif | |
49 | |
50 START_NAMESPACE_DISTRHO | |
51 | |
52 // ----------------------------------------------------------------------- | |
53 | |
54 const char* getBinaryFilename() | |
55 { | |
56 static String filename; | |
57 | |
58 #ifndef STATIC_BUILD | |
59 if (filename.isNotEmpty()) | |
60 return filename; | |
61 | |
62 #ifdef DISTRHO_OS_WINDOWS | |
63 CHAR filenameBuf[MAX_PATH]; | |
64 filenameBuf[0] = '\0'; | |
65 GetModuleFileNameA(hInstance, filenameBuf, sizeof(filenameBuf)); | |
66 filename = filenameBuf; | |
67 #else | |
68 Dl_info info; | |
69 dladdr((void*)getBinaryFilename, &info); | |
70 char filenameBuf[PATH_MAX]; | |
71 filename = realpath(info.dli_fname, filenameBuf); | |
72 #endif | |
73 #endif | |
74 | |
75 return filename; | |
76 } | |
77 | |
78 const char* getPluginFormatName() noexcept | |
79 { | |
80 #if defined(DISTRHO_PLUGIN_TARGET_CARLA) | |
81 return "Carla"; | |
82 #elif defined(DISTRHO_PLUGIN_TARGET_JACK) | |
83 #if defined(DISTRHO_OS_WASM) | |
84 return "Wasm/Standalone"; | |
85 #elif defined(HAVE_JACK) | |
86 return "JACK/Standalone"; | |
87 #else | |
88 return "Standalone"; | |
89 #endif | |
90 #elif defined(DISTRHO_PLUGIN_TARGET_LADSPA) | |
91 return "LADSPA"; | |
92 #elif defined(DISTRHO_PLUGIN_TARGET_DSSI) | |
93 return "DSSI"; | |
94 #elif defined(DISTRHO_PLUGIN_TARGET_LV2) | |
95 return "LV2"; | |
96 #elif defined(DISTRHO_PLUGIN_TARGET_VST2) | |
97 return "VST2"; | |
98 #elif defined(DISTRHO_PLUGIN_TARGET_VST3) | |
99 return "VST3"; | |
100 #elif defined(DISTRHO_PLUGIN_TARGET_CLAP) | |
101 return "CLAP"; | |
102 #elif defined(DISTRHO_PLUGIN_TARGET_STATIC) && defined(DISTRHO_PLUGIN_TARGET_STATIC_NAME) | |
103 return DISTRHO_PLUGIN_TARGET_STATIC_NAME; | |
104 #else | |
105 return "Unknown"; | |
106 #endif | |
107 } | |
108 | |
109 const char* getResourcePath(const char* const bundlePath) noexcept | |
110 { | |
111 DISTRHO_SAFE_ASSERT_RETURN(bundlePath != nullptr, nullptr); | |
112 | |
113 #if defined(DISTRHO_PLUGIN_TARGET_JACK) || defined(DISTRHO_PLUGIN_TARGET_VST2) || defined(DISTRHO_PLUGIN_TARGET_CLAP) | |
114 static String resourcePath; | |
115 | |
116 if (resourcePath.isEmpty()) | |
117 { | |
118 resourcePath = bundlePath; | |
119 #ifdef DISTRHO_OS_MAC | |
120 resourcePath += "/Contents/Resources"; | |
121 #else | |
122 resourcePath += DISTRHO_OS_SEP_STR "resources"; | |
123 #endif | |
124 } | |
125 | |
126 return resourcePath.buffer(); | |
127 #elif defined(DISTRHO_PLUGIN_TARGET_LV2) | |
128 static String resourcePath; | |
129 | |
130 if (resourcePath.isEmpty()) | |
131 { | |
132 resourcePath = bundlePath; | |
133 resourcePath += DISTRHO_OS_SEP_STR "resources"; | |
134 } | |
135 | |
136 return resourcePath.buffer(); | |
137 #elif defined(DISTRHO_PLUGIN_TARGET_VST3) | |
138 static String resourcePath; | |
139 | |
140 if (resourcePath.isEmpty()) | |
141 { | |
142 resourcePath = bundlePath; | |
143 resourcePath += "/Contents/Resources"; | |
144 } | |
145 | |
146 return resourcePath.buffer(); | |
147 #endif | |
148 | |
149 return nullptr; | |
150 } | |
151 | |
152 #ifndef DISTRHO_PLUGIN_TARGET_JACK | |
153 // all these are null for non-standalone targets | |
154 bool isUsingNativeAudio() noexcept { return false; } | |
155 bool supportsAudioInput() { return false; } | |
156 bool supportsBufferSizeChanges() { return false; } | |
157 bool supportsMIDI() { return false; } | |
158 bool isAudioInputEnabled() { return false; } | |
159 bool isMIDIEnabled() { return false; } | |
160 uint getBufferSize() { return 0; } | |
161 bool requestAudioInput() { return false; } | |
162 bool requestBufferSizeChange(uint) { return false; } | |
163 bool requestMIDI() { return false; } | |
164 #endif | |
165 | |
166 // ----------------------------------------------------------------------- | |
167 | |
168 END_NAMESPACE_DISTRHO |