Tutorial: Making CLAP plugins

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

Majisto wrote: Sun Jul 02, 2023 11:40 am EDIT: Any idea on what's causing the other error? It's something in the definition pluginDescriptor.
What does the problematic line (and preferebly some context around it) look like?

Post

AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.

Code: Select all (#)

static const clap_plugin_descriptor_t pluginDescriptor = {
	.clap_version = CLAP_VERSION_INIT,
	.id = "nakst.HelloCLAP",
	.name = "HelloCLAP",
	.vendor = "nakst",
	.url = "https://nakst.gitlab.io",
	.manual_url = "https://nakst.gitlab.io",
	.support_url = "https://nakst.gitlab.io",
	.version = "1.0.0",
	.description = "The best audio plugin ever.",

	.features = (const char *[]) {
		CLAP_PLUGIN_FEATURE_INSTRUMENT,
		CLAP_PLUGIN_FEATURE_SYNTHESIZER,
		CLAP_PLUGIN_FEATURE_STEREO,
		NULL,
	},
};
It's in the .features part.

Post

Flexible Array Member ill-defined?

Post

Majisto wrote: Sun Jul 02, 2023 11:45 pm

Code: Select all

static const clap_plugin_descriptor_t pluginDescriptor = {
	.clap_version = CLAP_VERSION_INIT,
	.id = "nakst.HelloCLAP",
	.name = "HelloCLAP",
	.vendor = "nakst",
	.url = "https://nakst.gitlab.io",
	.manual_url = "https://nakst.gitlab.io",
	.support_url = "https://nakst.gitlab.io",
	.version = "1.0.0",
	.description = "The best audio plugin ever.",

	.features = (const char *[]) {
		CLAP_PLUGIN_FEATURE_INSTRUMENT,
		CLAP_PLUGIN_FEATURE_SYNTHESIZER,
		CLAP_PLUGIN_FEATURE_STEREO,
		NULL,
	},
};
It's in the .features part.
I'm honestly not sure. It could be the construct is only valid in C(?) even though at least clang does seem to accept it as C++ as well... or it could be a GCC/Clang extension or something like that perhaps?

That said, you should be able to fix this by declaring the array of feature strings as a separate static array and reference that. Not as nice syntax-wise, but produces the same end result.

Post

It might be an MSVC vs gcc vs clang thing. They've always had these little differences and I've occasionally run into them in the past. It's really annoying and why I don't care for working with other people's code.
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better? :(

Post

I see. Thanks, guys!

Post

AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
syntonica wrote: Mon Jul 03, 2023 6:20 am It might be an MSVC vs gcc vs clang thing. They've always had these little differences and I've occasionally run into them in the past. It's really annoying and why I don't care for working with other people's code.
It's definitely a MSVC vs GCC/CLANG thing. The code builds perfectly on Linux and Mac but it doesn't on Windows.

A valid approach to fix this (without creating any global stuff) is to create a function for the initialization:

Code: Select all (#)

const char **features_init();   //function prototype

const char **features_init() {
  static const char *features[] = {
    CLAP_PLUGIN_FEATURE_INSTRUMENT,
    CLAP_PLUGIN_FEATURE_SYNTHESIZER,
    CLAP_PLUGIN_FEATURE_STEREO,
    NULL,
  };
  return features;
}

static const clap_plugin_descriptor_t pluginDescriptor = {
	.clap_version = CLAP_VERSION_INIT,
	.id = "nakst.HelloCLAP",
	.name = "HelloCLAP",
	.vendor = "nakst",
	.url = "https://nakst.gitlab.io",
	.manual_url = "https://nakst.gitlab.io",
	.support_url = "https://nakst.gitlab.io",
	.version = "1.0.0",
	.description = "The best audio plugin ever.",
	.features = features_init()
};
There are also two minor mistakes in the documentation about how to build the plug-in on Windows:

-The correct flag for DLL making on modern versions of the MSVC compiler is /LD, not /DLL.
-The libraries that have to be added to the compiler command line are user32.lib and gdi32.lib (instead of .dll, as stated on the tutorial).

Thus, the correct command to build the example under Windows should be:

Code: Select all (#)

cl /LD /Zi /std:c++20 plugin.cpp user32.lib gdi32.lib
BTW, hello all. This is my very first post on KVR Audio.

Post

Mastropiero wrote: Sun Oct 22, 2023 3:09 pm A valid approach to fix this (without creating any global stuff) is to create a function for the initialization:
Constants declared "static" (ie. local to compilation unit) are not what they mean when they say to avoid globals. Function statics are actually theoretically worse, because initialization is on first call and required to be thread-safe.. though here it's all constants so likely to result in the same code either way.

Globals in general, even true globals, aren't all bad.. it's just that if you use them for stuff that's not truly supposed to be global, or where you might need multiple copies later, things tend to get messy.

Post Reply

Return to “DSP and Plugin Development”