Skip to content

Commit

Permalink
Rework how AU macros are defined, use it for other formats
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Feb 24, 2024
1 parent b7a4dad commit 96c14af
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 150 deletions.
14 changes: 6 additions & 8 deletions distrho/DistrhoInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,20 +675,18 @@ START_NAMESPACE_DISTRHO
#define DISTRHO_PLUGIN_AU_TYPE aufx

/**
The AudioUnit subtype for a plugin.@n
This is a 4-character symbol which identifies a plugin.@n
It must be unique within a manufacturer's plugins, but different manufacturers can use the same subtype.
A 4-character symbol that identifies a brand or manufacturer, with at least one non-lower case character.@n
Plugins from the same brand should use the same symbol.
@note This macro is required when building AU plugins
*/
#define DISTRHO_PLUGIN_AU_SUBTYPE test
#define DISTRHO_PLUGIN_BRAND_ID Dstr

/**
The AudioUnit manufacturer for a plugin.@n
This is a 4-character symbol with at least one non-lower case character.@n
Plugins from the same brand/maker should use the same symbol.
A 4-character symbol which identifies a plugin.@n
It must be unique within at least a set of plugins from the brand.
@note This macro is required when building AU plugins
*/
#define DISTRHO_PLUGIN_AU_MANUFACTURER Dstr
#define DISTRHO_PLUGIN_UNIQUE_ID test

/**
Custom LV2 category for the plugin.@n
Expand Down
11 changes: 10 additions & 1 deletion distrho/DistrhoPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,19 @@ class Plugin

/**
Get the plugin unique Id.@n
This value is used by LADSPA, DSSI, VST2, VST3 and AU plugin formats.
This value is used by LADSPA, DSSI, VST2, VST3 and AUv2 plugin formats.@n
@note It is preferred that you set DISTRHO_PLUGIN_UNIQUE_ID macro instead of overriding this call,
as that is required for AUv2 plugins anyhow.
@see d_cconst()
*/
#ifdef DISTRHO_PLUGIN_UNIQUE_ID
virtual int64_t getUniqueId() const
{
return d_cconst(STRINGIFY(DISTRHO_PLUGIN_UNIQUE_ID));
}
#else
virtual int64_t getUniqueId() const = 0;
#endif

/* --------------------------------------------------------------------------------------------------------
* Init */
Expand Down
12 changes: 9 additions & 3 deletions distrho/DistrhoUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ inline float round(float __x)
# define M_PI 3.14159265358979323846
#endif

#define DISTRHO_MACRO_AS_STRING_VALUE(MACRO) #MACRO
#define DISTRHO_MACRO_AS_STRING(MACRO) DISTRHO_MACRO_AS_STRING_VALUE(MACRO)

/* --------------------------------------------------------------------------------------------------------------------
* misc functions */

Expand All @@ -77,6 +74,15 @@ int64_t d_cconst(const uint8_t a, const uint8_t b, const uint8_t c, const uint8_
return (a << 24) | (b << 16) | (c << 8) | (d << 0);
}

/**
Return a 32-bit number from 4 ASCII characters.
*/
static inline constexpr
uint32_t d_cconst(const char str[4])
{
return (str[0] << 24) | (str[1] << 16) | (str[2] << 8) | str[3];
}

/**
Return an hexadecimal representation of a MAJ.MIN.MICRO version number.
*/
Expand Down
3 changes: 3 additions & 0 deletions distrho/src/DistrhoDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ private: \

/* Useful macros */
#define ARRAY_SIZE(ARRAY) (sizeof(ARRAY)/sizeof(ARRAY[0]))
#define STRINGIFY2(s) #s
#define STRINGIFY(s) STRINGIFY2(s)

/* Useful typedefs */
typedef unsigned char uchar;
Expand All @@ -223,5 +225,6 @@ typedef unsigned long long int ulonglong;
/* Deprecated macros */
#define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) DISTRHO_DECLARE_NON_COPYABLE(ClassName)
#define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName) DISTRHO_DECLARE_NON_COPYABLE(StructName)
#define DISTRHO_MACRO_AS_STRING(MACRO) STRINGIFY2(MACRO)

#endif // DISTRHO_DEFINES_H_INCLUDED
33 changes: 9 additions & 24 deletions distrho/src/DistrhoPluginAU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
#include <map>
#include <vector>

#ifndef DISTRHO_PLUGIN_AU_SUBTYPE
# error DISTRHO_PLUGIN_AU_SUBTYPE undefined!
#ifndef DISTRHO_PLUGIN_BRAND_ID
# error DISTRHO_PLUGIN_BRAND_ID undefined!
#endif

#ifndef DISTRHO_PLUGIN_AU_MANUFACTURER
# error DISTRHO_PLUGIN_AU_MANUFACTURER undefined!
#ifndef DISTRHO_PLUGIN_UNIQUE_ID
# error DISTRHO_PLUGIN_UNIQUE_ID undefined!
#endif

START_NAMESPACE_DISTRHO
Expand Down Expand Up @@ -167,26 +167,11 @@ static const char* AudioUnitSelector2Str(const SInt16 selector) noexcept
return "[unknown]";
}

static constexpr FourCharCode getFourCharCodeFromString(const char str[4])
{
return (str[0] << 24) + (str[1] << 16) + (str[2] << 8) + str[3];
}

// --------------------------------------------------------------------------------------------------------------------

#define MACRO_STR2(s) #s
#define MACRO_STR(s) MACRO_STR2(s)

static constexpr const char kTypeStr[] = MACRO_STR(DISTRHO_PLUGIN_AU_TYPE);
static constexpr const char kSubTypeStr[] = MACRO_STR(DISTRHO_PLUGIN_AU_SUBTYPE);
static constexpr const char kManufacturerStr[] = MACRO_STR(DISTRHO_PLUGIN_AU_MANUFACTURER);

#undef MACRO_STR
#undef MACRO_STR2

static constexpr const FourCharCode kType = getFourCharCodeFromString(kTypeStr);
static constexpr const FourCharCode kSubType = getFourCharCodeFromString(kSubTypeStr);
static constexpr const FourCharCode kManufacturer = getFourCharCodeFromString(kManufacturerStr);
static constexpr const uint32_t kType = d_cconst(STRINGIFY(DISTRHO_PLUGIN_AU_TYPE));
static constexpr const uint32_t kSubType = d_cconst(STRINGIFY(DISTRHO_PLUGIN_UNIQUE_ID));
static constexpr const uint32_t kManufacturer = d_cconst(STRINGIFY(DISTRHO_PLUGIN_BRAND_ID));

// --------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -811,8 +796,8 @@ class PluginAU
#define MACRO_STR(a, b, c) MACRO_STR2(a, b, c)

info->mCocoaAUViewClass[0] = CFSTR("CocoaAUView_" MACRO_STR(DISTRHO_PLUGIN_AU_TYPE,
DISTRHO_PLUGIN_AU_SUBTYPE,
DISTRHO_PLUGIN_AU_MANUFACTURER));
DISTRHO_PLUGIN_UNIQUE_ID,
DISTRHO_PLUGIN_BRAND_ID));

#undef MACRO_STR
#undef MACRO_STR2
Expand Down
15 changes: 15 additions & 0 deletions distrho/src/DistrhoPluginChecks.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@
# error DISTRHO_PLUGIN_URI undefined!
#endif

// --------------------------------------------------------------------------------------------------------------------
// Check that symbol macros are well defined

#ifdef DISTRHO_PLUGIN_AU_TYPE
static_assert(sizeof(STRINGIFY(DISTRHO_PLUGIN_AU_TYPE)) == 5, "The macro DISTRHO_PLUGIN_AU_TYPE has incorrect length");
#endif

#ifdef DISTRHO_PLUGIN_BRAND_ID
static_assert(sizeof(STRINGIFY(DISTRHO_PLUGIN_BRAND_ID)) == 5, "The macro DISTRHO_PLUGIN_BRAND_ID has incorrect length");
#endif

#ifdef DISTRHO_PLUGIN_UNIQUE_ID
static_assert(sizeof(STRINGIFY(DISTRHO_PLUGIN_UNIQUE_ID)) == 5, "The macro DISTRHO_PLUGIN_UNIQUE_ID has incorrect length");
#endif

// --------------------------------------------------------------------------------------------------------------------
// Define optional macros if not done yet

Expand Down
24 changes: 7 additions & 17 deletions distrho/src/DistrhoPluginExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include "DistrhoPluginInternal.hpp"
#include "../DistrhoPluginUtils.hpp"

#ifndef DISTRHO_PLUGIN_AU_SUBTYPE
# error DISTRHO_PLUGIN_AU_SUBTYPE undefined!
#ifndef DISTRHO_PLUGIN_BRAND_ID
# error DISTRHO_PLUGIN_BRAND_ID undefined!
#endif

#ifndef DISTRHO_PLUGIN_AU_MANUFACTURER
# error DISTRHO_PLUGIN_AU_MANUFACTURER undefined!
#ifndef DISTRHO_PLUGIN_UNIQUE_ID
# error DISTRHO_PLUGIN_UNIQUE_ID undefined!
#endif

#include <fstream>
Expand All @@ -45,13 +45,6 @@ void generate_au_plist(const PluginExporter& plugin,
const uint32_t minorVersion = (version & 0x00FF00) >> 8;
const uint32_t microVersion = (version & 0x0000FF) >> 0;

#define MACRO_STR2(s) #s
#define MACRO_STR(s) MACRO_STR2(s)

static_assert(sizeof(MACRO_STR(DISTRHO_PLUGIN_AU_TYPE)) == 5, "The macro DISTRHO_PLUGIN_AU_TYPE has incorrect length");
static_assert(sizeof(MACRO_STR(DISTRHO_PLUGIN_AU_SUBTYPE)) == 5, "The macro DISTRHO_PLUGIN_AU_SUBTYPE has incorrect length");
static_assert(sizeof(MACRO_STR(DISTRHO_PLUGIN_AU_MANUFACTURER)) == 5, "The macro DISTRHO_PLUGIN_AU_MANUFACTURER has incorrect length");

outputFile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
outputFile << "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n";
outputFile << "<plist>\n";
Expand Down Expand Up @@ -88,11 +81,11 @@ void generate_au_plist(const PluginExporter& plugin,
outputFile << " <key>factoryFunction</key>\n";
outputFile << " <string>PluginAUFactory</string>\n";
outputFile << " <key>type</key>\n";
outputFile << " <string>" MACRO_STR(DISTRHO_PLUGIN_AU_TYPE) "</string>\n";
outputFile << " <string>" STRINGIFY(DISTRHO_PLUGIN_AU_TYPE) "</string>\n";
outputFile << " <key>subtype</key>\n";
outputFile << " <string>" MACRO_STR(DISTRHO_PLUGIN_AU_SUBTYPE) "</string>\n";
outputFile << " <string>" STRINGIFY(DISTRHO_PLUGIN_UNIQUE_ID) "</string>\n";
outputFile << " <key>manufacturer</key>\n";
outputFile << " <string>" MACRO_STR(DISTRHO_PLUGIN_AU_MANUFACTURER) "</string>\n";
outputFile << " <string>" STRINGIFY(DISTRHO_PLUGIN_BRAND_ID) "</string>\n";
outputFile << " <key>version</key>\n";
outputFile << " <integer>" << version << "</integer>\n";
outputFile << " <key>resourceUsage</key>\n";
Expand All @@ -107,9 +100,6 @@ void generate_au_plist(const PluginExporter& plugin,
outputFile << " </dict>\n";
outputFile << "</plist>\n";

#undef MACRO_STR
#undef MACRO_STR2

outputFile.close();
std::cout << " done!" << std::endl;
}
Expand Down
12 changes: 6 additions & 6 deletions distrho/src/DistrhoUIAU.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
#undef Point
#undef Size

#ifndef DISTRHO_PLUGIN_AU_SUBTYPE
# error DISTRHO_PLUGIN_AU_SUBTYPE undefined!
#ifndef DISTRHO_PLUGIN_BRAND_ID
# error DISTRHO_PLUGIN_BRAND_ID undefined!
#endif

#ifndef DISTRHO_PLUGIN_AU_MANUFACTURER
# error DISTRHO_PLUGIN_AU_MANUFACTURER undefined!
#ifndef DISTRHO_PLUGIN_UNIQUE_ID
# error DISTRHO_PLUGIN_UNIQUE_ID undefined!
#endif

START_NAMESPACE_DISTRHO
Expand Down Expand Up @@ -383,7 +383,7 @@ static void setSizeCallback(void* const ptr, const uint width, const uint height
// --------------------------------------------------------------------------------------------------------------------

#define COCOA_VIEW_CLASS_NAME \
MACRO_NAME(CocoaView_, DISTRHO_PLUGIN_AU_TYPE, _, DISTRHO_PLUGIN_AU_SUBTYPE, _, DISTRHO_PLUGIN_AU_MANUFACTURER)
MACRO_NAME(CocoaView_, DISTRHO_PLUGIN_AU_TYPE, _, DISTRHO_PLUGIN_UNIQUE_ID, _, DISTRHO_PLUGIN_BRAND_ID)

@interface COCOA_VIEW_CLASS_NAME : NSView
{
Expand Down Expand Up @@ -424,7 +424,7 @@ - (BOOL) isFlipped
// --------------------------------------------------------------------------------------------------------------------

#define COCOA_UI_CLASS_NAME \
MACRO_NAME(CocoaAUView_, DISTRHO_PLUGIN_AU_TYPE, _, DISTRHO_PLUGIN_AU_SUBTYPE, _, DISTRHO_PLUGIN_AU_MANUFACTURER)
MACRO_NAME(CocoaAUView_, DISTRHO_PLUGIN_AU_TYPE, _, DISTRHO_PLUGIN_UNIQUE_ID, _, DISTRHO_PLUGIN_BRAND_ID)

@interface COCOA_UI_CLASS_NAME : NSObject<AUCocoaUIBase>
{
Expand Down
11 changes: 1 addition & 10 deletions examples/CairoUI/CairoExamplePlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2019-2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
* Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
Expand Down Expand Up @@ -74,15 +74,6 @@ class CairoExamplePlugin : public Plugin
return d_version(1, 0, 0);
}

/**
Get the plugin unique Id.@n
This value is used by LADSPA, DSSI, VST2 and VST3 plugin formats.
*/
int64_t getUniqueId() const override
{
return d_cconst('d', 'C', 'a', 'i');
}

/**
Initialize the audio port @a index.@n
This function will be called once, shortly after the plugin is created.
Expand Down
16 changes: 8 additions & 8 deletions examples/CairoUI/DistrhoPluginInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/CairoUI"

/**
The AudioUnit subtype for a plugin.
This is a 4-character symbol which identifies a plugin.
It must be unique within a manufacturer's plugins, but different manufacturers can use the same subtype.
The AudioUnit manufacturer for a plugin.
This is a 4-character symbol with at least one non-lower case character.
Plugins from the same brand/maker should use the same symbol.
@note This macro is required when building AU plugins
*/
#define DISTRHO_PLUGIN_AU_SUBTYPE cair
#define DISTRHO_PLUGIN_BRAND_ID Dstr

/**
The AudioUnit manufacturer for a plugin.
This is a 4-character symbol with at least one non-lower case character.
Plugins from the same brand/maker should use the same symbol.
The AudioUnit subtype for a plugin.
This is a 4-character symbol which identifies a plugin.
It must be unique within a manufacturer's plugins, but different manufacturers can use the same subtype.
@note This macro is required when building AU plugins
*/
#define DISTRHO_PLUGIN_AU_MANUFACTURER Dstr
#define DISTRHO_PLUGIN_UNIQUE_ID dCai

/**
The plugin id when exporting in CLAP format, in reverse URI form.
Expand Down
4 changes: 2 additions & 2 deletions examples/Info/DistrhoPluginInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/Info"
#define DISTRHO_PLUGIN_CLAP_ID "studio.kx.distrho.examples.info"

#define DISTRHO_PLUGIN_AU_SUBTYPE info
#define DISTRHO_PLUGIN_AU_MANUFACTURER Dstr
#define DISTRHO_PLUGIN_BRAND_ID Dstr
#define DISTRHO_PLUGIN_UNIQUE_ID dNfo

#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
Expand Down
11 changes: 1 addition & 10 deletions examples/Info/InfoExamplePlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
Expand Down Expand Up @@ -91,15 +91,6 @@ class InfoExamplePlugin : public Plugin
return d_version(1, 0, 0);
}

/**
Get the plugin unique Id.
This value is used by LADSPA, DSSI and VST plugin formats.
*/
int64_t getUniqueId() const override
{
return d_cconst('d', 'N', 'f', 'o');
}

/* --------------------------------------------------------------------------------------------------------
* Init */

Expand Down
6 changes: 3 additions & 3 deletions examples/Meters/DistrhoPluginInfo.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
Expand All @@ -22,8 +22,8 @@
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/Meters"
#define DISTRHO_PLUGIN_CLAP_ID "studio.kx.distrho.examples.meters"

#define DISTRHO_PLUGIN_AU_SUBTYPE mtrs
#define DISTRHO_PLUGIN_AU_MANUFACTURER Dstr
#define DISTRHO_PLUGIN_BRAND_ID Dstr
#define DISTRHO_PLUGIN_UNIQUE_ID dMtr

#define DISTRHO_PLUGIN_HAS_UI 1
#define DISTRHO_PLUGIN_IS_RT_SAFE 1
Expand Down
11 changes: 1 addition & 10 deletions examples/Meters/ExamplePluginMeters.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2018 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
Expand Down Expand Up @@ -89,15 +89,6 @@ class ExamplePluginMeters : public Plugin
return d_version(1, 0, 0);
}

/**
Get the plugin unique Id.@n
This value is used by LADSPA, DSSI, VST2 and VST3 plugin formats.
*/
int64_t getUniqueId() const override
{
return d_cconst('d', 'M', 't', 'r');
}

/* --------------------------------------------------------------------------------------------------------
* Init */

Expand Down
Loading

0 comments on commit 96c14af

Please sign in to comment.