Add initial bits for Qt6 support
[carla.git] / source / modules / distrho / src / DistrhoUtils.cpp
blobaeb7b2b410a32464c530352a8024e42d73595209
1 /*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
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.
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.
17 #ifndef DISTRHO_IS_STANDALONE
18 # error Wrong build configuration
19 #endif
21 #include "../extra/String.hpp"
22 #include "../DistrhoStandaloneUtils.hpp"
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
34 #if defined(DISTRHO_OS_WINDOWS) && !defined(STATIC_BUILD) && !DISTRHO_IS_STANDALONE
35 static HINSTANCE hInstance = nullptr;
37 DISTRHO_PLUGIN_EXPORT
38 BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID)
40 if (reason == DLL_PROCESS_ATTACH)
41 hInstance = hInst;
42 return 1;
44 #endif
46 START_NAMESPACE_DISTRHO
48 // -----------------------------------------------------------------------
50 const char* getBinaryFilename()
52 static String filename;
54 #ifndef STATIC_BUILD
55 if (filename.isNotEmpty())
56 return filename;
58 # ifdef DISTRHO_OS_WINDOWS
59 # if DISTRHO_IS_STANDALONE
60 constexpr const HINSTANCE hInstance = nullptr;
61 # endif
62 CHAR filenameBuf[MAX_PATH];
63 filenameBuf[0] = '\0';
64 GetModuleFileNameA(hInstance, filenameBuf, sizeof(filenameBuf));
65 filename = filenameBuf;
66 # else
67 Dl_info info;
68 dladdr((void*)getBinaryFilename, &info);
69 char filenameBuf[PATH_MAX];
70 filename = realpath(info.dli_fname, filenameBuf);
71 # endif
72 #endif
74 return filename;
77 const char* getPluginFormatName() noexcept
79 #if defined(DISTRHO_PLUGIN_TARGET_CARLA)
80 return "Carla";
81 #elif defined(DISTRHO_PLUGIN_TARGET_JACK)
82 # ifdef DISTRHO_OS_WASM
83 return "Wasm/Standalone";
84 # else
85 return "JACK/Standalone";
86 # endif
87 #elif defined(DISTRHO_PLUGIN_TARGET_LADSPA)
88 return "LADSPA";
89 #elif defined(DISTRHO_PLUGIN_TARGET_DSSI)
90 return "DSSI";
91 #elif defined(DISTRHO_PLUGIN_TARGET_LV2)
92 return "LV2";
93 #elif defined(DISTRHO_PLUGIN_TARGET_VST2)
94 return "VST2";
95 #elif defined(DISTRHO_PLUGIN_TARGET_VST3)
96 return "VST3";
97 #else
98 return "Unknown";
99 #endif
102 const char* getResourcePath(const char* const bundlePath) noexcept
104 DISTRHO_SAFE_ASSERT_RETURN(bundlePath != nullptr, nullptr);
106 #if defined(DISTRHO_PLUGIN_TARGET_JACK) || defined(DISTRHO_PLUGIN_TARGET_VST2)
107 static String resourcePath;
109 if (resourcePath.isEmpty())
111 resourcePath = bundlePath;
112 # ifdef DISTRHO_OS_MAC
113 resourcePath += "/Contents/Resources";
114 # else
115 resourcePath += DISTRHO_OS_SEP_STR "resources";
116 # endif
119 return resourcePath.buffer();
120 #elif defined(DISTRHO_PLUGIN_TARGET_LV2)
121 static String resourcePath;
123 if (resourcePath.isEmpty())
125 resourcePath = bundlePath;
126 resourcePath += DISTRHO_OS_SEP_STR "resources";
129 return resourcePath.buffer();
130 #elif defined(DISTRHO_PLUGIN_TARGET_VST3)
131 static String resourcePath;
133 if (resourcePath.isEmpty())
135 resourcePath = bundlePath;
136 resourcePath += "/Contents/Resources";
139 return resourcePath.buffer();
140 #endif
142 return nullptr;
145 #ifndef DISTRHO_PLUGIN_TARGET_JACK
146 // all these are null for non-standalone targets
147 bool isUsingNativeAudio() noexcept { return false; }
148 bool supportsAudioInput() { return false; }
149 bool supportsBufferSizeChanges() { return false; }
150 bool supportsMIDI() { return false; }
151 bool isAudioInputEnabled() { return false; }
152 bool isMIDIEnabled() { return false; }
153 uint getBufferSize() { return 0; }
154 bool requestAudioInput() { return false; }
155 bool requestBufferSizeChange(uint) { return false; }
156 bool requestMIDI() { return false; }
157 #endif
159 // -----------------------------------------------------------------------
161 END_NAMESPACE_DISTRHO