0

I want to know a way of consuming the VST3 SDK from Python. In its essence, the VST3 architecture mimics COM.

My end goal is using the GetPluginFactory exported by a VST3 plugin in Python. This function returns a pointer to a C++ virtual class. I am not sure how this even works across different compilers, because C++ doesn't have a standardized ABI.

A host and plugin then communicate with each other by querying available "interfaces". I want to know how I can implement the host part in Python. I have used ctypes to mimic a virtual class via a Structure, but it doesn't work and useless, since a class has a vtable member and I am not sure how a C++ class looks like in C.

SWIG keeps popping up when I try to search for a solution. So is SWIG, the way to go? If yes, how?

I don't have any code, because all I tried till now results in memory violation errors.

demberto
  • 489
  • 5
  • 15
  • On any given platform, C++ absolutely does have a standardized ABI, at least for virtual class interfaces. That's what allows COM and CORBA to work. The first thing in an object is a vtable, which is just a list of function pointers, each of which accepts the object as its first parameter. – Tim Roberts Feb 08 '22 at 18:25
  • @TimRoberts These virtual classes aren't completely virtual, they do have a GUID stored in them, although I am not entirely sure its accessible over the DLL boundary – demberto Feb 08 '22 at 18:33
  • If a virtual class contains state, it follows the vtable pointer(s). – Tim Roberts Feb 08 '22 at 18:40
  • What exactly is a virtual class? I could guess what you mean, but still, I haven't heard that term in the context of C++. – Ulrich Eckhardt Feb 08 '22 at 21:29
  • @UlrichEckhardt virtual class in this context is like a COM interface. In VST3, every virtual class (interface) derives off of `FUnknown` (similar to COM `IUnknown`). VST3 doesn't use the COM architecture as it is cross platform at all and many people are confused about this as well. – demberto Feb 09 '22 at 18:51
  • @TimRoberts And how might I access this vtable? I found [this](https://bytes.com/topic/c/answers/942922-virtual-pointer-accessing-vtable-class-inside-program), is this it? – demberto Feb 09 '22 at 18:56
  • 1
    If you have the address of an object, the first thing at that address is the vtable pointer. Any member variables follow that pointer. https://shaharmike.com/cpp/vtable-part2/ – Tim Roberts Feb 09 '22 at 19:05
  • @TimRoberts that's really helpful. Pointer magic! – demberto Feb 09 '22 at 19:37
  • 1
    I have started to make a small repository of swig examples. The interfaces that I wrap here could be useful for you. https://github.com/JensMunkHansen/swig-examples/tree/main/python/abstract_cpp – Jens Munk Feb 12 '22 at 19:14

0 Answers0