Skip to content

Commit

Permalink
issue #22: provide IMidiMapping interface dynamically, only when CLAP…
Browse files Browse the repository at this point in the history
… supports CLAP_NOTE_DIALECT_MIDI (#61)
  • Loading branch information
defiantnerd authored Aug 27, 2023
1 parent a4a9ce9 commit cbbec73
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
58 changes: 44 additions & 14 deletions src/wrapasvst3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ tresult PLUGIN_API ClapAsVst3::initialize(FUnknown* context)
_plugin = Clap::Plugin::createInstance(*_library, _libraryIndex, this);
}
result = (_plugin->initialize()) ? kResultOk : kResultFalse;
if ( result )
{
_useIMidiMapping = checkMIDIDialectSupport();
}
}
if (_plugin)
{
Expand Down Expand Up @@ -432,6 +436,29 @@ void ClapAsVst3::setupWrapperSpecifics(const clap_plugin_t* plugin)
}
}

bool ClapAsVst3::checkMIDIDialectSupport()
{
// check if the plugin supports noteports and if one of the note ports supports MIDI dialect
auto noteports = _plugin->_ext._noteports;
if (noteports )
{
auto numMIDIInputs = noteports->count(_plugin->_plugin, true);
for (uint32_t i = 0 ; i < numMIDIInputs ; ++i )
{
clap_note_port_info_t info;
if ( noteports->get(_plugin->_plugin,i,true,&info) )
{
if ( info.supported_dialects & CLAP_NOTE_DIALECT_MIDI )
{
return true;
}
}
}
}

return false;
}

void ClapAsVst3::setupAudioBusses(const clap_plugin_t* plugin, const clap_plugin_audio_ports_t* audioports)
{
if (!audioports) return;
Expand Down Expand Up @@ -527,24 +554,27 @@ void ClapAsVst3::setupParameters(const clap_plugin_t* plugin, const clap_plugin_
}
}

// find free tags for IMidiMapping
Vst::ParamID x = 0xb00000;
_IMidiMappingEasy = true;

for (uint8_t channel = 0; channel < _numMidiChannels; channel++)
if ( _useIMidiMapping )
{
for (int i = 0; i < Vst::ControllerNumbers::kCountCtrlNumber; ++i)
// find free tags for IMidiMapping
Vst::ParamID x = 0xb00000;
_IMidiMappingEasy = true;

for (uint8_t channel = 0; channel < _numMidiChannels; channel++)
{
while (parameters.getParameter(x))
for (int i = 0; i < Vst::ControllerNumbers::kCountCtrlNumber; ++i)
{
// if this happens there is a index clash between the parameter ids
// and the ones reserved for the IMidiMapping
_IMidiMappingEasy = false;
x++;
while (parameters.getParameter(x))
{
// if this happens there is a index clash between the parameter ids
// and the ones reserved for the IMidiMapping
_IMidiMappingEasy = false;
x++;
}
auto p = Vst3Parameter::create(0, channel, i, x);
parameters.addParameter(p);
_IMidiMappingIDs[channel][i] = x++;
}
auto p = Vst3Parameter::create(0, channel, i, x);
parameters.addParameter(p);
_IMidiMappingIDs[channel][i] = x++;
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/wrapasvst3.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect
//---Interface--------------------------------------------------------------------------
OBJ_METHODS(ClapAsVst3, SingleComponentEffect)
DEFINE_INTERFACES
DEF_INTERFACE(IMidiMapping)
// since the macro above opens a local function, this code is being executed during QueryInterface() :)
if (::Steinberg::FUnknownPrivate::iidEqual (iid, IMidiMapping::iid))
{
// when queried for the IMididMapping interface, check if the CLAP supports MIDI dialect on the MIDI Input busses and only return IMidiMapping then
if ( _useIMidiMapping ) {
DEF_INTERFACE(IMidiMapping)
}
}
DEF_INTERFACE(INoteExpressionController)
// tresult PLUGIN_API queryInterface(const TUID iid, void** obj) override;
END_DEFINE_INTERFACES(SingleComponentEffect)
Expand Down Expand Up @@ -192,6 +199,8 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect
void onPerformEdit(const clap_event_param_value_t* value) override;
void onEndEdit(clap_id id) override;

// information function to enable/disable the IMIDIMapping interface
bool checkMIDIDialectSupport();
private:
// helper functions
void addAudioBusFrom(const clap_audio_port_info_t* info, bool is_input);
Expand Down Expand Up @@ -222,6 +231,7 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect
util::fixedqueue<queueEvent, 8192> _queueToUI;

// for IMidiMapping
bool _useIMidiMapping = false;
Vst::ParamID _IMidiMappingIDs[16][Vst::ControllerNumbers::kCountCtrlNumber] = { 0 }; // 16 MappingIDs for 16 Channels
bool _IMidiMappingEasy = true;
uint8_t _numMidiChannels = 16;
Expand Down

0 comments on commit cbbec73

Please sign in to comment.