LMMS
Loading...
Searching...
No Matches
base.h
Go to the documentation of this file.
1/*
2 * travesty, pure C VST3-compatible interface
3 * Copyright (C) 2021-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#pragma once
18
19#include <stdbool.h>
20#include <stdint.h>
21#include <string.h>
22
26
27#if !defined(__cplusplus) && !defined(constexpr)
28# define constexpr
29#endif
30
34
36
37typedef int16_t v3_str_128[128];
39
41
45
46typedef uint8_t v3_tuid[16];
47
48static inline
49bool v3_tuid_match(const v3_tuid a, const v3_tuid b)
50{
51 return memcmp(a, b, sizeof(v3_tuid)) == 0;
52}
53
54#if defined(_WIN32)
55# define V3_COM_COMPAT 1
56# define V3_API __stdcall
57#else
58# define V3_COM_COMPAT 0
59# define V3_API
60#endif
61
62#if V3_COM_COMPAT
63enum {
64 _V3_SIGNEDNESS = -1,
65 V3_NO_INTERFACE = 0x80004002L,
66 V3_OK = 0,
67 V3_TRUE = 0,
68 V3_FALSE = 1,
69 V3_INVALID_ARG = 0x80070057L,
70 V3_NOT_IMPLEMENTED = 0x80004001L,
71 V3_INTERNAL_ERR = 0x80004005L,
72 V3_NOT_INITIALIZED = 0x8000FFFFL,
73 V3_NOMEM = 0x8007000EL
74};
75
76# define V3_ID(a, b, c, d) { \
77 ((a) & 0x000000FF), \
78 ((a) & 0x0000FF00) >> 8, \
79 ((a) & 0x00FF0000) >> 16, \
80 ((a) & 0xFF000000) >> 24, \
81 \
82 ((b) & 0x00FF0000) >> 16, \
83 ((b) & 0xFF000000) >> 24, \
84 ((b) & 0x000000FF), \
85 ((b) & 0x0000FF00) >> 8, \
86 \
87 ((c) & 0xFF000000) >> 24, \
88 ((c) & 0x00FF0000) >> 16, \
89 ((c) & 0x0000FF00) >> 8, \
90 ((c) & 0x000000FF), \
91 \
92 ((d) & 0xFF000000) >> 24, \
93 ((d) & 0x00FF0000) >> 16, \
94 ((d) & 0x0000FF00) >> 8, \
95 ((d) & 0x000000FF), \
96}
97
98#else // V3_COM_COMPAT
99enum {
109};
110
111# define V3_ID(a, b, c, d) { \
112 ((a) & 0xFF000000) >> 24, \
113 ((a) & 0x00FF0000) >> 16, \
114 ((a) & 0x0000FF00) >> 8, \
115 ((a) & 0x000000FF), \
116 \
117 ((b) & 0xFF000000) >> 24, \
118 ((b) & 0x00FF0000) >> 16, \
119 ((b) & 0x0000FF00) >> 8, \
120 ((b) & 0x000000FF), \
121 \
122 ((c) & 0xFF000000) >> 24, \
123 ((c) & 0x00FF0000) >> 16, \
124 ((c) & 0x0000FF00) >> 8, \
125 ((c) & 0x000000FF), \
126 \
127 ((d) & 0xFF000000) >> 24, \
128 ((d) & 0x00FF0000) >> 16, \
129 ((d) & 0x0000FF00) >> 8, \
130 ((d) & 0x000000FF), \
131}
132#endif // V3_COM_COMPAT
133
134#define V3_ID_COPY(iid) \
135 { iid[0], iid[1], iid[ 2], iid[ 3], iid[ 4], iid[ 5], iid[ 6], iid[ 7], \
136 iid[8], iid[9], iid[10], iid[11], iid[12], iid[13], iid[14], iid[15] }
137
141
143 v3_result (V3_API* query_interface)(void* self, const v3_tuid iid, void** obj);
144 uint32_t (V3_API* ref)(void* self);
145 uint32_t (V3_API* unref)(void* self);
146};
147
148static constexpr const v3_tuid v3_funknown_iid =
149 V3_ID(0x00000000, 0x00000000, 0xC0000000, 0x00000046);
150
154
156#ifndef __cplusplus
157 struct v3_funknown;
158#endif
159 v3_result (V3_API* initialize)(void* self, struct v3_funknown** context);
160 v3_result (V3_API* terminate)(void* self);
161};
162
163static constexpr const v3_tuid v3_plugin_base_iid =
164 V3_ID(0x22888DDB, 0x156E45AE, 0x8358B348, 0x08190625);
165
166#ifdef __cplusplus
167
178
179template<class T> static inline
180constexpr T* v3_cpp_obj(T** obj)
181{
186 return static_cast<T*>(static_cast<void*>(static_cast<uint8_t*>(static_cast<void*>(*obj)) + sizeof(void*)*3));
187}
188
192
193template<class T, class M> static inline
194v3_result v3_cpp_obj_query_interface(T** obj, const v3_tuid iid, M*** obj2)
195{
196 return static_cast<v3_funknown*>(static_cast<void*>(*obj))->query_interface(obj, iid, (void**)obj2);
197}
198
199template<class T> static inline
200uint32_t v3_cpp_obj_ref(T** obj)
201{
202 return static_cast<v3_funknown*>(static_cast<void*>(*obj))->ref(obj);
203}
204
205template<class T> static inline
206uint32_t v3_cpp_obj_unref(T** obj)
207{
208 return static_cast<v3_funknown*>(static_cast<void*>(*obj))->unref(obj);
209}
210
211template<class T> static inline
212v3_result v3_cpp_obj_initialize(T** obj, v3_funknown** context)
213{
214 return static_cast<v3_plugin_base*>(
215 static_cast<void*>(static_cast<uint8_t*>(static_cast<void*>(*obj)) + sizeof(void*)*3))->initialize(obj, context);
216}
217
218template<class T> static inline
219v3_result v3_cpp_obj_terminate(T** obj)
220{
221 return static_cast<v3_plugin_base*>(
222 static_cast<void*>(static_cast<uint8_t*>(static_cast<void*>(*obj)) + sizeof(void*)*3))->terminate(obj);
223}
224
225#endif
#define V3_ID(a, b, c, d)
Definition base.h:111
uint32_t v3_param_id
Definition base.h:40
#define V3_API
Definition base.h:59
static constexpr const v3_tuid v3_funknown_iid
Definition base.h:148
static constexpr const v3_tuid v3_plugin_base_iid
Definition base.h:163
static bool v3_tuid_match(const v3_tuid a, const v3_tuid b)
Definition base.h:49
int16_t v3_str_128[128]
Definition base.h:37
int32_t v3_result
Definition base.h:35
uint8_t v3_bool
Definition base.h:38
uint8_t v3_tuid[16]
Definition base.h:46
@ V3_NOMEM
Definition base.h:108
@ V3_NO_INTERFACE
Definition base.h:100
@ V3_TRUE
Definition base.h:102
@ V3_NOT_IMPLEMENTED
Definition base.h:105
@ V3_NOT_INITIALIZED
Definition base.h:107
@ V3_FALSE
Definition base.h:103
@ V3_INTERNAL_ERR
Definition base.h:106
@ V3_INVALID_ARG
Definition base.h:104
@ V3_OK
Definition base.h:101
uint8_t a
Definition Spc_Cpu.h:141
int int32_t
Definition mid.cpp:97
unsigned int uint32_t
Definition mid.cpp:100
short int16_t
Definition mid.cpp:96
unsigned char uint8_t
Definition mid.cpp:98
#define M
Definition nseel-cfunc.c:37
Definition base.h:142
const v3_tuid iid
Definition base.h:143
const v3_tuid void ** obj
Definition base.h:143
uint32_t(V3_API *unref)(void *self)
uint32_t(V3_API *ref)(void *self)
Definition base.h:155
struct v3_funknown ** context
Definition base.h:159
v3_result(V3_API *terminate)(void *self)
b
Definition crypt.c:628