From aa92833b0aaf9e6bca0dacce54d3232b27fb95a2 Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 26 Dec 2016 22:13:43 +0100 Subject: [PATCH] Cleanup default options for all plugin types --- source/backend/plugin/CarlaPluginBridge.cpp | 2 - source/backend/plugin/CarlaPluginDSSI.cpp | 48 ++++++++---------- .../backend/plugin/CarlaPluginFluidSynth.cpp | 10 +--- source/backend/plugin/CarlaPluginJuce.cpp | 11 ++-- source/backend/plugin/CarlaPluginLADSPA.cpp | 23 ++++----- source/backend/plugin/CarlaPluginLV2.cpp | 44 ++++++++-------- .../plugin/CarlaPluginLinuxSampler.cpp | 2 - source/backend/plugin/CarlaPluginNative.cpp | 50 ++++++++++++------- source/backend/plugin/CarlaPluginVST2.cpp | 37 +++++++++----- 9 files changed, 121 insertions(+), 106 deletions(-) diff --git a/source/backend/plugin/CarlaPluginBridge.cpp b/source/backend/plugin/CarlaPluginBridge.cpp index 78928105c..0803d9359 100644 --- a/source/backend/plugin/CarlaPluginBridge.cpp +++ b/source/backend/plugin/CarlaPluginBridge.cpp @@ -2694,8 +2694,6 @@ public: return false; } - // TODO: set default options - return true; } diff --git a/source/backend/plugin/CarlaPluginDSSI.cpp b/source/backend/plugin/CarlaPluginDSSI.cpp index 5e018bfc5..b1cbafcf9 100644 --- a/source/backend/plugin/CarlaPluginDSSI.cpp +++ b/source/backend/plugin/CarlaPluginDSSI.cpp @@ -417,23 +417,23 @@ public: uint options = 0x0; - if (! fNeedsFixedBuffers) - { - // can't disable fixed buffers if using latency - if (fLatencyIndex == -1) - options |= PLUGIN_OPTION_FIXED_BUFFERS; + // can't disable fixed buffers if using latency + if (fLatencyIndex == -1 && ! fNeedsFixedBuffers) + options |= PLUGIN_OPTION_FIXED_BUFFERS; - // can't disable forced stereo if in rack mode - if (pData->engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK) - pass(); - // if inputs or outputs are just 1, then yes we can force stereo - else if (pData->audioIn.count == 1 || pData->audioOut.count == 1 || fForcedStereoIn || fForcedStereoOut) - options |= PLUGIN_OPTION_FORCE_STEREO; - } + // can't disable forced stereo if in rack mode + if (pData->engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK) + pass(); + // if inputs or outputs are just 1, then yes we can force stereo + else if (pData->audioIn.count == 1 || pData->audioOut.count == 1 || fForcedStereoIn || fForcedStereoOut) + options |= PLUGIN_OPTION_FORCE_STEREO; if (fDssiDescriptor->get_program != nullptr && fDssiDescriptor->select_program != nullptr) options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; + if (fUsesCustomData) + options |= PLUGIN_OPTION_USE_CHUNKS; + if (fDssiDescriptor->run_synth != nullptr) { options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; @@ -443,9 +443,6 @@ public: options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF; } - if (fUsesCustomData) - options |= PLUGIN_OPTION_USE_CHUNKS; - return options; } @@ -2174,8 +2171,8 @@ public: if (fOscData.source == nullptr) { - // if no UI is registered yet only "update" message is valid - CARLA_SAFE_ASSERT_RETURN(std::strcmp(method, "update") == 0,) + // if no UI is registered yet only "configure" and "update" messages are valid + CARLA_SAFE_ASSERT_RETURN(std::strcmp(method, "configure") == 0 || std::strcmp(method, "update") == 0,) } else { @@ -2333,11 +2330,7 @@ public: if (pData->midiprog.current >= 0) { const MidiProgramData& curMidiProg(pData->midiprog.getCurrent()); - - if (getType() == PLUGIN_DSSI) - osc_send_program(fOscData, curMidiProg.bank, curMidiProg.program); - else - osc_send_midi_program(fOscData, curMidiProg.bank, curMidiProg.program); + osc_send_program(fOscData, curMidiProg.bank, curMidiProg.program); } for (uint32_t i=0; i < pData->param.count; ++i) @@ -2651,14 +2644,17 @@ public: /**/ if (fLatencyIndex >= 0 || fNeedsFixedBuffers) pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; - else if (options & PLUGIN_OPTION_FIXED_BUFFERS) + else if (options & PLUGIN_OPTION_FIXED_BUFFERS) pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; /**/ if (pData->engine->getOptions().forceStereo) pData->options |= PLUGIN_OPTION_FORCE_STEREO; - else if (options & PLUGIN_OPTION_FORCE_STEREO) + else if (options & PLUGIN_OPTION_FORCE_STEREO) pData->options |= PLUGIN_OPTION_FORCE_STEREO; + if (fDssiDescriptor->get_program != nullptr && fDssiDescriptor->select_program != nullptr) + pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; + if (fUsesCustomData) pData->options |= PLUGIN_OPTION_USE_CHUNKS; @@ -2669,8 +2665,8 @@ public: pData->options |= PLUGIN_OPTION_SEND_PITCHBEND; pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF; - if (fDssiDescriptor->get_program != nullptr && fDssiDescriptor->select_program != nullptr) - pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; + if (options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) + pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; } return true; diff --git a/source/backend/plugin/CarlaPluginFluidSynth.cpp b/source/backend/plugin/CarlaPluginFluidSynth.cpp index 227186f05..77b7d3534 100644 --- a/source/backend/plugin/CarlaPluginFluidSynth.cpp +++ b/source/backend/plugin/CarlaPluginFluidSynth.cpp @@ -150,8 +150,6 @@ public: uint32_t getParameterScalePointCount(const uint32_t parameterId) const noexcept override { - CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0); - switch (parameterId) { case FluidSynthChorusType: @@ -193,9 +191,6 @@ public: float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept override { - CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f); - CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f); - switch (parameterId) { case FluidSynthChorusType: @@ -1632,11 +1627,10 @@ public: pData->options |= PLUGIN_OPTION_SEND_PITCHBEND; pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF; - // TODO: read some options + if (options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) + pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; return true; - - (void)options; } private: diff --git a/source/backend/plugin/CarlaPluginJuce.cpp b/source/backend/plugin/CarlaPluginJuce.cpp index dee95368e..72fcb0698 100644 --- a/source/backend/plugin/CarlaPluginJuce.cpp +++ b/source/backend/plugin/CarlaPluginJuce.cpp @@ -151,6 +151,9 @@ public: options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; options |= PLUGIN_OPTION_USE_CHUNKS; + if (fInstance->getNumPrograms() > 1) + options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; + if (fInstance->acceptsMidi()) { options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; @@ -1220,7 +1223,7 @@ public: pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; pData->options |= PLUGIN_OPTION_USE_CHUNKS; - if (fDesc.isInstrument) + if (fInstance->getNumPrograms() > 1) pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; if (fInstance->acceptsMidi()) @@ -1229,10 +1232,10 @@ public: pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH; pData->options |= PLUGIN_OPTION_SEND_PITCHBEND; pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF; - } - // TODO: read some options - ignoreUnused(options); + if (options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) + pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; + } return true; } diff --git a/source/backend/plugin/CarlaPluginLADSPA.cpp b/source/backend/plugin/CarlaPluginLADSPA.cpp index ea86c4121..cf340875d 100644 --- a/source/backend/plugin/CarlaPluginLADSPA.cpp +++ b/source/backend/plugin/CarlaPluginLADSPA.cpp @@ -187,19 +187,16 @@ public: { uint options = 0x0; - if (! fNeedsFixedBuffers) - { - // can't disable fixed buffers if using latency - if (fLatencyIndex == -1) - options |= PLUGIN_OPTION_FIXED_BUFFERS; - - // can't disable forced stereo if in rack mode - if (pData->engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK) - pass(); - // if inputs or outputs are just 1, then yes we can force stereo - else if (pData->audioIn.count == 1 || pData->audioOut.count == 1 || fForcedStereoIn || fForcedStereoOut) - options |= PLUGIN_OPTION_FORCE_STEREO; - } + // can't disable fixed buffers if using latency + if (fLatencyIndex == -1 && ! fNeedsFixedBuffers) + options |= PLUGIN_OPTION_FIXED_BUFFERS; + + // can't disable forced stereo if in rack mode + if (pData->engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK) + pass(); + // if inputs or outputs are just 1, then yes we can force stereo + else if (pData->audioIn.count == 1 || pData->audioOut.count == 1 || fForcedStereoIn || fForcedStereoOut) + options |= PLUGIN_OPTION_FORCE_STEREO; return options; } diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index 724cf24f9..73dbfde1f 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -808,28 +808,25 @@ public: uint getOptionsAvailable() const noexcept override { - const bool hasMidiIn(getMidiInCount() > 0); + const uint32_t midiOutCount(getMidiOutCount()); uint options = 0x0; - if (fExt.programs != nullptr) - options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; + // can't disable fixed buffers if using latency or MIDI output + if (fLatencyIndex == -1 && midiOutCount == 0 && ! fNeedsFixedBuffers) + options |= PLUGIN_OPTION_FIXED_BUFFERS; - // can't disable fixed buffers if using latency or MIDI - if (fLatencyIndex >= 0 || hasMidiIn || fNeedsFixedBuffers) + // can't disable forced stereo if in rack mode + if (pData->engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK) pass(); - else - options |= PLUGIN_OPTION_FIXED_BUFFERS; + // if inputs or outputs are just 1, then yes we can force stereo + else if ((pData->audioIn.count == 1 || pData->audioOut.count == 1) && fCanInit2) + options |= PLUGIN_OPTION_FORCE_STEREO; - if (fCanInit2 && pData->engine->getProccessMode() != ENGINE_PROCESS_MODE_CONTINUOUS_RACK) - { - if (pData->options & PLUGIN_OPTION_FORCE_STEREO) - options |= PLUGIN_OPTION_FORCE_STEREO; - else if (pData->audioIn.count <= 1 && pData->audioOut.count <= 1 && (pData->audioIn.count != 0 || pData->audioOut.count != 0)) - options |= PLUGIN_OPTION_FORCE_STEREO; - } + if (fExt.programs != nullptr) + options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; - if (hasMidiIn) + if (midiOutCount != 0) { options |= PLUGIN_OPTION_SEND_PROGRAM_CHANGES; options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; @@ -5020,14 +5017,13 @@ public: // --------------------------------------------------------------- // set default options - pData->options = 0x0; + const uint32_t midiOutCount(getMidiOutCount()); - if (fExt.programs != nullptr && getCategory() == PLUGIN_CATEGORY_SYNTH) - pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; + pData->options = 0x0; - if (fLatencyIndex >= 0 || getMidiInCount() > 0 || fNeedsFixedBuffers) + if (fLatencyIndex >= 0 || midiOutCount != 0 || fNeedsFixedBuffers) pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; - else if (options & PLUGIN_OPTION_FIXED_BUFFERS) + else if (options & PLUGIN_OPTION_FIXED_BUFFERS) pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; if (fCanInit2) @@ -5038,12 +5034,18 @@ public: pData->options |= PLUGIN_OPTION_FORCE_STEREO; } - if (getMidiInCount() > 0) + if (fExt.programs != nullptr) + pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; + + if (midiOutCount != 0) { pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE; pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH; pData->options |= PLUGIN_OPTION_SEND_PITCHBEND; pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF; + + if (options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) + pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; } // --------------------------------------------------------------- diff --git a/source/backend/plugin/CarlaPluginLinuxSampler.cpp b/source/backend/plugin/CarlaPluginLinuxSampler.cpp index 456848b22..541a1630d 100644 --- a/source/backend/plugin/CarlaPluginLinuxSampler.cpp +++ b/source/backend/plugin/CarlaPluginLinuxSampler.cpp @@ -1345,8 +1345,6 @@ public: if (kIsGIG) pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; - // TODO: read some options - return true; (void)options; diff --git a/source/backend/plugin/CarlaPluginNative.cpp b/source/backend/plugin/CarlaPluginNative.cpp index 18c7b7ad2..e494b97b0 100644 --- a/source/backend/plugin/CarlaPluginNative.cpp +++ b/source/backend/plugin/CarlaPluginNative.cpp @@ -330,23 +330,29 @@ public: uint getOptionsAvailable() const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, 0x0); - CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, 0); + CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, 0x0); - // FIXME - try - const bool hasMidiProgs(fDescriptor->get_midi_program_count != nullptr && fDescriptor->get_midi_program_count(fHandle) > 0); + bool hasMidiProgs = false; + + if (fDescriptor->get_midi_program_count != nullptr) + { + try { + hasMidiProgs = fDescriptor->get_midi_program_count(fHandle) > 0; + } catch (...) {} + } uint options = 0x0; - if (getMidiInCount() == 0 && (fDescriptor->hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS) == 0) + // can't disable fixed buffers if using MIDI output + if (getMidiOutCount() == 0 && (fDescriptor->hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS) == 0) options |= PLUGIN_OPTION_FIXED_BUFFERS; - if (pData->engine->getProccessMode() != ENGINE_PROCESS_MODE_CONTINUOUS_RACK) - { - if (pData->options & PLUGIN_OPTION_FORCE_STEREO) - options |= PLUGIN_OPTION_FORCE_STEREO; - else if (pData->audioIn.count <= 1 && pData->audioOut.count <= 1 && (pData->audioIn.count != 0 || pData->audioOut.count != 0)) - options |= PLUGIN_OPTION_FORCE_STEREO; - } + // can't disable forced stereo if in rack mode + if (pData->engine->getProccessMode() == ENGINE_PROCESS_MODE_CONTINUOUS_RACK) + pass(); + // if inputs or outputs are just 1, then yes we can force stereo + else if (pData->audioIn.count == 1 || pData->audioOut.count == 1) + options |= PLUGIN_OPTION_FORCE_STEREO; if (fDescriptor->supports & NATIVE_PLUGIN_SUPPORTS_CONTROL_CHANGES) options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; @@ -2383,11 +2389,18 @@ public: // --------------------------------------------------------------- // set default options - const bool hasMidiProgs(fDescriptor->get_midi_program_count != nullptr && fDescriptor->get_midi_program_count(fHandle) > 0); + bool hasMidiProgs = false; + + if (fDescriptor->get_midi_program_count != nullptr) + { + try { + hasMidiProgs = fDescriptor->get_midi_program_count(fHandle) > 0; + } catch (...) {} + } pData->options = 0x0; - if (getMidiInCount() > 0 || (fDescriptor->hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS) != 0) + if (getMidiOutCount() != 0 || (fDescriptor->hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS) != 0) pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; else if (options & PLUGIN_OPTION_FIXED_BUFFERS) pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; @@ -2406,15 +2419,18 @@ public: if (fDescriptor->supports & NATIVE_PLUGIN_SUPPORTS_ALL_SOUND_OFF) pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF; + if (fDescriptor->supports & NATIVE_PLUGIN_SUPPORTS_CONTROL_CHANGES) + { + if (options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) + pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; + } + if (fDescriptor->supports & NATIVE_PLUGIN_SUPPORTS_PROGRAM_CHANGES) { CARLA_SAFE_ASSERT(! hasMidiProgs); pData->options |= PLUGIN_OPTION_SEND_PROGRAM_CHANGES; - - if (fDescriptor->supports & NATIVE_PLUGIN_SUPPORTS_CONTROL_CHANGES) - pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; } - else if (hasMidiProgs && fDescriptor->category == NATIVE_PLUGIN_CATEGORY_SYNTH) + else if (hasMidiProgs) pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; return true; diff --git a/source/backend/plugin/CarlaPluginVST2.cpp b/source/backend/plugin/CarlaPluginVST2.cpp index e3a2f757c..f3a45b134 100644 --- a/source/backend/plugin/CarlaPluginVST2.cpp +++ b/source/backend/plugin/CarlaPluginVST2.cpp @@ -205,18 +205,21 @@ public: { CARLA_SAFE_ASSERT_RETURN(fEffect != nullptr, 0); + const bool hasMidiOut(hasMidiOutput()); + uint options = 0x0; - options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; + // can't disable fixed buffers if using latency or MIDI output + if (pData->latency.frames == 0 && ! hasMidiOut) + options |= PLUGIN_OPTION_FIXED_BUFFERS; + + if (fEffect->numPrograms > 1) + options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; if (fEffect->flags & effFlagsProgramChunks) options |= PLUGIN_OPTION_USE_CHUNKS; - if (getMidiInCount() == 0) - { - options |= PLUGIN_OPTION_FIXED_BUFFERS; - } - else + if (hasMidiOut) { options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE; @@ -1795,7 +1798,8 @@ protected: case audioMasterGetNumAutomatableParameters: // Deprecated in VST SDK 2.4 - ret = carla_fixedValue(0, static_cast(pData->engine->getOptions().maxParameters), fEffect->numParams); + ret = static_cast(pData->engine->getOptions().maxParameters); + ret = carla_minPositive(ret, fEffect->numParams); break; case audioMasterGetParameterQuantization: @@ -2181,24 +2185,31 @@ public: // --------------------------------------------------------------- // set default options + const bool hasMidiOut(hasMidiOutput()); + pData->options = 0x0; - if (fEffect->flags & effFlagsIsSynth) + if (pData->latency.frames != 0 || hasMidiOut) + pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; + else if (options & PLUGIN_OPTION_FIXED_BUFFERS) + pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; + + if (fEffect->numPrograms > 1) pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; if (fEffect->flags & effFlagsProgramChunks) pData->options |= PLUGIN_OPTION_USE_CHUNKS; - if (hasMidiInput()) + if (hasMidiOut) { - pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; pData->options |= PLUGIN_OPTION_SEND_CHANNEL_PRESSURE; pData->options |= PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH; pData->options |= PLUGIN_OPTION_SEND_PITCHBEND; pData->options |= PLUGIN_OPTION_SEND_ALL_SOUND_OFF; + + if (options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) + pData->options |= PLUGIN_OPTION_SEND_CONTROL_CHANGES; } - else if (options & PLUGIN_OPTION_FIXED_BUFFERS) - pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; return true; @@ -2338,7 +2349,7 @@ private: return 1; case audioMasterGetVendorVersion: - return 0x110; // 1.1.0 + return CARLA_VERSION_HEX; case audioMasterCanDo: CARLA_SAFE_ASSERT_RETURN(ptr != nullptr, 0);