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
3131# endif
3232#endif
3333
34+ #include < string>
35+ #include < unordered_map>
36+
3437#include " mapi/mapi.h"
3538
3639START_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
90103private:
91104 PluginExporter fPlugin ;
105+ std::unordered_map<std::string, uint> fParamMap ;
92106
93107 void updateParameterOutputsAndTriggers ()
94108 {
@@ -113,53 +127,43 @@ class PluginMAPI
113127// --------------------------------------------------------------------------------------------------------------------
114128
115129MAPI_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
134138MAPI_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
143147MAPI_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
149153MAPI_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
155159MAPI_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
161165MAPI_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}
0 commit comments