Skip to content

Commit 7bdc3f8

Browse files
committed
Change MAPI to use symbol instead of indices, other tweaks
Signed-off-by: falkTX <falktx@falktx.com>
1 parent aa26798 commit 7bdc3f8

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

distrho/src/DistrhoPluginMAPI.cpp

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* DISTRHO Plugin Framework (DPF)
3-
* Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
3+
* Copyright (C) 2012-2026 Filipe Coelho <falktx@falktx.com>
44
*
55
* Permission to use, copy, modify, and/or distribute this software for any purpose with
66
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -31,6 +31,9 @@
3131
# endif
3232
#endif
3333

34+
#include <string>
35+
#include <unordered_map>
36+
3437
#include "mapi/mapi.h"
3538

3639
START_NAMESPACE_DISTRHO
@@ -43,6 +46,9 @@ class PluginMAPI
4346
PluginMAPI()
4447
: fPlugin(nullptr, nullptr, nullptr, nullptr)
4548
{
49+
for (uint32_t i = 0, count = fPlugin.getParameterCount(); i < count; ++i)
50+
fParamMap[fPlugin.getParameterSymbol(i).buffer()] = i;
51+
4652
fPlugin.activate();
4753
}
4854

@@ -53,7 +59,7 @@ class PluginMAPI
5359

5460
// ----------------------------------------------------------------------------------------------------------------
5561

56-
void process(const float* const* ins, float** outs, unsigned int frames)
62+
void process(const float* const* const ins, float** const outs, const uint frames)
5763
{
5864
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
5965
fPlugin.run(const_cast<const float**>(ins), outs, frames, nullptr, 0);
@@ -64,20 +70,27 @@ class PluginMAPI
6470
updateParameterOutputsAndTriggers();
6571
}
6672

67-
float getParameter(unsigned int index) const
73+
float getParameter(const char* const symbol) const
6874
{
69-
return fPlugin.getParameterValue(index);
75+
const std::unordered_map<std::string, uint>::const_iterator it = fParamMap.find(symbol);
76+
DISTRHO_SAFE_ASSERT_RETURN(it != fParamMap.end(), 0.f);
77+
78+
return fPlugin.getParameterValue(it->second);
7079
}
7180

72-
void setParameter(unsigned int index, float value)
81+
void setParameter(const char* const symbol, float value)
7382
{
83+
const std::unordered_map<std::string, uint>::const_iterator it = fParamMap.find(symbol);
84+
DISTRHO_SAFE_ASSERT_RETURN(it != fParamMap.end(),);
85+
86+
const uint32_t index = it->second;
7487
fPlugin.setParameterValue(index, fPlugin.getParameterRanges(index).getFixedValue(value));
7588
}
7689

77-
void setState(const char* key, const char* value)
90+
void setState(const char* const key, const void* const value)
7891
{
7992
#if DISTRHO_PLUGIN_WANT_STATE
80-
fPlugin.setState(key, value);
93+
fPlugin.setState(key, static_cast<const char*>(value));
8194
#else
8295
// unused
8396
(void)key;
@@ -89,6 +102,7 @@ class PluginMAPI
89102

90103
private:
91104
PluginExporter fPlugin;
105+
std::unordered_map<std::string, uint> fParamMap;
92106

93107
void updateParameterOutputsAndTriggers()
94108
{
@@ -113,53 +127,43 @@ class PluginMAPI
113127
// --------------------------------------------------------------------------------------------------------------------
114128

115129
MAPI_EXPORT
116-
mapi_handle_t mapi_create(unsigned int sample_rate)
130+
mapi_handle_t mapi_create(const uint sample_rate, const uint buffer_size)
117131
{
118-
if (d_nextBufferSize == 0)
119-
{
120-
#if defined(_DARKGLASS_DEVICE_PABLITO)
121-
d_nextBufferSize = 16;
122-
#elif defined(__MOD_DEVICES__)
123-
d_nextBufferSize = 128;
124-
#else
125-
d_nextBufferSize = 2048;
126-
#endif
127-
}
128-
132+
d_nextBufferSize = buffer_size;
129133
d_nextSampleRate = sample_rate;
130134

131135
return new PluginMAPI();
132136
}
133137

134138
MAPI_EXPORT
135-
void mapi_process(mapi_handle_t handle,
136-
const float* const* ins,
137-
float** outs,
138-
unsigned int frames)
139+
void mapi_process(const mapi_handle_t handle,
140+
const float* const* const ins,
141+
float** const outs,
142+
const uint frames)
139143
{
140144
static_cast<PluginMAPI*>(handle)->process(ins, outs, frames);
141145
}
142146

143147
MAPI_EXPORT
144-
float mapi_get_parameter(mapi_handle_t handle, unsigned int index)
148+
float mapi_get_parameter(const mapi_handle_t handle, const char* const symbol)
145149
{
146-
return static_cast<PluginMAPI*>(handle)->getParameter(index);
150+
return static_cast<PluginMAPI*>(handle)->getParameter(symbol);
147151
}
148152

149153
MAPI_EXPORT
150-
void mapi_set_parameter(mapi_handle_t handle, unsigned int index, float value)
154+
void mapi_set_parameter(const mapi_handle_t handle, const char* const symbol, float value)
151155
{
152-
static_cast<PluginMAPI*>(handle)->setParameter(index, value);
156+
static_cast<PluginMAPI*>(handle)->setParameter(symbol, value);
153157
}
154158

155159
MAPI_EXPORT
156-
void mapi_set_state(mapi_handle_t handle, const char* key, const char* value)
160+
void mapi_set_state(const mapi_handle_t handle, const char* const key, const void* const value)
157161
{
158162
static_cast<PluginMAPI*>(handle)->setState(key, value);
159163
}
160164

161165
MAPI_EXPORT
162-
void mapi_destroy(mapi_handle_t handle)
166+
void mapi_destroy(const mapi_handle_t handle)
163167
{
164168
delete static_cast<PluginMAPI*>(handle);
165169
}

distrho/src/mapi/mapi.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Filipe Coelho <falktx@falktx.com>
1+
// Copyright 2025-2026 Filipe Coelho <falktx@falktx.com>
22
// SPDX-License-Identifier: ISC
33

44
#pragma once
@@ -23,10 +23,11 @@ typedef void* mapi_handle_t;
2323
/**
2424
Create an effect.
2525
@param sample_rate Sample rate in Hz to use for the effect.
26+
@param buffer_size Nominal/expected audio buffer size, can be smaller.
2627
@return A handle for the new effect, or NULL if creation failed.
2728
*/
2829
MAPI_EXPORT
29-
mapi_handle_t mapi_create(unsigned int sample_rate);
30+
mapi_handle_t mapi_create(unsigned int sample_rate, unsigned int buffer_size);
3031

3132
/**
3233
Process an effect.
@@ -50,7 +51,7 @@ void mapi_process(mapi_handle_t handle,
5051
@return value A full-ranged value.
5152
*/
5253
MAPI_EXPORT
53-
float mapi_get_parameter(mapi_handle_t handle, unsigned int index);
54+
float mapi_get_parameter(mapi_handle_t handle, const char* symbol);
5455

5556
/**
5657
Set an effect parameter.
@@ -59,16 +60,16 @@ float mapi_get_parameter(mapi_handle_t handle, unsigned int index);
5960
@param value A full-ranged value.
6061
*/
6162
MAPI_EXPORT
62-
void mapi_set_parameter(mapi_handle_t handle, unsigned int index, float value);
63+
void mapi_set_parameter(mapi_handle_t handle, const char* symbol, float value);
6364

6465
/**
6566
Set an effect state, using strings for both key and value.
6667
@param handle A previously created effect.
6768
@param key A known key for this effect, must not be NULL or empty.
68-
@param value A non-NULL value, allowed to be empty.
69+
@param value A non-NULL value.
6970
*/
7071
MAPI_EXPORT
71-
void mapi_set_state(mapi_handle_t handle, const char* key, const char* value);
72+
void mapi_set_state(mapi_handle_t handle, const char* key, const void* value);
7273

7374
/**
7475
Destroy a previously created effect.

0 commit comments

Comments
 (0)