diff --git a/source/backend/CarlaEngine.hpp b/source/backend/CarlaEngine.hpp index 7671591dc..99951d33e 100644 --- a/source/backend/CarlaEngine.hpp +++ b/source/backend/CarlaEngine.hpp @@ -618,13 +618,13 @@ public: * Activate this client.\n * Client must be deactivated before calling this function. */ - virtual void activate(); + virtual void activate() noexcept; /*! * Deactivate this client.\n * Client must be activated before calling this function. */ - virtual void deactivate(); + virtual void deactivate() noexcept; /*! * Check if the client is activated. @@ -920,15 +920,13 @@ public: /*! * TODO. - * \a id must be either 1 or 2. */ - float getInputPeak(const unsigned int pluginId, const bool isLeft) const; + float getInputPeak(const unsigned int pluginId, const bool isLeft) const noexcept; /*! * TODO. - * \a id must be either 1 or 2. */ - float getOutputPeak(const unsigned int pluginId, const bool isLeft) const; + float getOutputPeak(const unsigned int pluginId, const bool isLeft) const noexcept; // ------------------------------------------------------------------- // Callback @@ -936,12 +934,12 @@ public: /*! * TODO. */ - void callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr); + void callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept; /*! * TODO. */ - void setCallback(const EngineCallbackFunc func, void* const ptr); + void setCallback(const EngineCallbackFunc func, void* const ptr) noexcept; #ifndef BUILD_BRIDGE // ------------------------------------------------------------------- @@ -969,17 +967,17 @@ public: /*! * Start playback of the engine transport. */ - virtual void transportPlay(); + virtual void transportPlay() noexcept; /*! * Pause the engine transport. */ - virtual void transportPause(); + virtual void transportPause() noexcept; /*! * Relocate the engine transport to \a frames. */ - virtual void transportRelocate(const uint64_t frame); + virtual void transportRelocate(const uint64_t frame) noexcept; // ------------------------------------------------------------------- // Error handling @@ -1001,7 +999,7 @@ public: * Tell the engine it's about to close.\n * This is used to prevent the engine thread(s) from reactivating. */ - void setAboutToClose(); + void setAboutToClose() noexcept; // ------------------------------------------------------------------- // Options @@ -1029,7 +1027,7 @@ public: /*! * Idle OSC. */ - void idleOsc(); + void idleOsc() const noexcept; /*! * Get OSC TCP server path. @@ -1061,7 +1059,7 @@ public: * Force register a plugin into slot \a id. \n * This is needed so we can receive OSC events for a plugin while it initializes. */ - void registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin); + void registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin) noexcept; // ------------------------------------------------------------------- @@ -1096,7 +1094,7 @@ protected: * Must always be called at the end of audio processing. * \note RT call */ - void runPendingRtEvents(); + void runPendingRtEvents() noexcept; /*! * Set a plugin (stereo) peak values. @@ -1159,55 +1157,55 @@ public: // ------------------------------------------------------------------- // Bridge/Controller OSC stuff - void oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const; - void oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const; - void oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const; - void oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const; - void oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const; - void oscSend_bridge_program_count(const uint32_t count) const; - void oscSend_bridge_midi_program_count(const uint32_t count) const; - void oscSend_bridge_parameter_data(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const char* const name, const char* const unit) const; - void oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const; - void oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const; - void oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const; - void oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const; - void oscSend_bridge_parameter_value(const int32_t index, const float value) const; // may be used for internal params (< 0) - void oscSend_bridge_default_value(const uint32_t index, const float value) const; - void oscSend_bridge_current_program(const int32_t index) const; - void oscSend_bridge_current_midi_program(const int32_t index) const; - void oscSend_bridge_program_name(const uint32_t index, const char* const name) const; - void oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const; - void oscSend_bridge_configure(const char* const key, const char* const value) const; - void oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const; - void oscSend_bridge_set_chunk_data(const char* const chunkFile) const; - void oscSend_bridge_set_peaks() const; + void oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const noexcept; + void oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept; + void oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept; + void oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept; + void oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept; + void oscSend_bridge_program_count(const uint32_t count) const noexcept; + void oscSend_bridge_midi_program_count(const uint32_t count) const noexcept; + void oscSend_bridge_parameter_data(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept; + void oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept; + void oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept; + void oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept; + void oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept; + void oscSend_bridge_parameter_value(const int32_t index, const float value) const noexcept; // may be used for internal params (< 0) + void oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept; + void oscSend_bridge_current_program(const int32_t index) const noexcept; + void oscSend_bridge_current_midi_program(const int32_t index) const noexcept; + void oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept; + void oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept; + void oscSend_bridge_configure(const char* const key, const char* const value) const noexcept; + void oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept; + void oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept; + void oscSend_bridge_set_peaks() const noexcept; #else public: - void oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const; - void oscSend_control_add_plugin_end(const uint pluginId) const; - void oscSend_control_remove_plugin(const uint pluginId) const; - void oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const; - void oscSend_control_set_plugin_info2(const uint pluginId, const char* const realName, const char* const label, const char* const maker, const char* const copyright) const; - void oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const; - void oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const; - void oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const; - void oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const; - void oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const; - void oscSend_control_set_parameter_data(const uint pluginId, const uint32_t index, const ParameterType type, const uint hints, const char* const name, const char* const unit) const; - void oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const; - void oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const; - void oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const; - void oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const; - void oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const; // may be used for internal params (< 0) - void oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const; - void oscSend_control_set_current_program(const uint pluginId, const int32_t index) const; - void oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const; - void oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const; - void oscSend_control_set_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const; - void oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const; - void oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const; - void oscSend_control_set_peaks(const uint pluginId) const; - void oscSend_control_exit() const; + void oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept; + void oscSend_control_add_plugin_end(const uint pluginId) const noexcept; + void oscSend_control_remove_plugin(const uint pluginId) const noexcept; + void oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const noexcept; + void oscSend_control_set_plugin_info2(const uint pluginId, const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept; + void oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept; + void oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept; + void oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept; + void oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept; + void oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept; + void oscSend_control_set_parameter_data(const uint pluginId, const uint32_t index, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept; + void oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const noexcept; + void oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept; + void oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept; + void oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept; + void oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const noexcept; // may be used for internal params (< 0) + void oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept; + void oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept; + void oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept; + void oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept; + void oscSend_control_set_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept; + void oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept; + void oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept; + void oscSend_control_set_peaks(const uint pluginId) const noexcept; + void oscSend_control_exit() const noexcept; #endif CARLA_DECLARE_NON_COPY_CLASS(CarlaEngine) diff --git a/source/backend/CarlaPlugin.hpp b/source/backend/CarlaPlugin.hpp index 8e1ee999e..558dd68de 100644 --- a/source/backend/CarlaPlugin.hpp +++ b/source/backend/CarlaPlugin.hpp @@ -148,19 +148,13 @@ public: /*! * Get the plugin's category (delay, filter, synth, etc). */ - virtual PluginCategory getCategory() const - { - return PLUGIN_CATEGORY_NONE; - } + virtual PluginCategory getCategory() const noexcept; /*! * Get the plugin's native unique Id.\n * May return 0 on plugin types that don't support Ids. */ - virtual long getUniqueId() const - { - return 0; - } + virtual long getUniqueId() const noexcept; /*! * Get the plugin's latency, in sample frames. @@ -199,7 +193,7 @@ public: /*! * Get the number of scalepoints for parameter \a parameterId. */ - virtual uint32_t getParameterScalePointCount(const uint32_t parameterId) const; + virtual uint32_t getParameterScalePointCount(const uint32_t parameterId) const noexcept; /*! * Get the number of programs. @@ -237,31 +231,31 @@ public: /*! * Get the parameter data of \a parameterId. */ - const ParameterData& getParameterData(const uint32_t parameterId) const; + const ParameterData& getParameterData(const uint32_t parameterId) const noexcept; /*! * Get the parameter ranges of \a parameterId. */ - const ParameterRanges& getParameterRanges(const uint32_t parameterId) const; + const ParameterRanges& getParameterRanges(const uint32_t parameterId) const noexcept; /*! * Check if parameter \a parameterId is of output type. */ - bool isParameterOutput(const uint32_t parameterId) const; + bool isParameterOutput(const uint32_t parameterId) const noexcept; /*! * Get the MIDI program at \a index. * * \see getMidiProgramName() */ - const MidiProgramData& getMidiProgramData(const uint32_t index) const; + const MidiProgramData& getMidiProgramData(const uint32_t index) const noexcept; /*! * Get the custom data set at \a index. * * \see getCustomDataCount() and setCustomData() */ - const CustomData& getCustomData(const uint32_t index) const; + const CustomData& getCustomData(const uint32_t index) const noexcept; /*! * Get the complete plugin chunk data into \a dataPtr. @@ -271,7 +265,7 @@ public: * * \see setChunkData() */ - virtual int32_t getChunkData(void** const dataPtr) const; + virtual int32_t getChunkData(void** const dataPtr) const noexcept; // ------------------------------------------------------------------- // Information (per-plugin data) @@ -281,76 +275,76 @@ public: * * \see PluginOptions, getOptions() and setOption() */ - virtual unsigned int getOptionsAvailable() const; + virtual unsigned int getOptionsAvailable() const noexcept; /*! * Get the current parameter value of \a parameterId. */ - virtual float getParameterValue(const uint32_t parameterId) const; + virtual float getParameterValue(const uint32_t parameterId) const noexcept; /*! * Get the scalepoint \a scalePointId value of the parameter \a parameterId. */ - virtual float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const; + virtual float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept; /*! * Get the plugin's label (URI for LV2 plugins). */ - virtual void getLabel(char* const strBuf) const; + virtual void getLabel(char* const strBuf) const noexcept; /*! * Get the plugin's maker. */ - virtual void getMaker(char* const strBuf) const; + virtual void getMaker(char* const strBuf) const noexcept; /*! * Get the plugin's copyright/license. */ - virtual void getCopyright(char* const strBuf) const; + virtual void getCopyright(char* const strBuf) const noexcept; /*! * Get the plugin's (real) name. * * \see getName() and setName() */ - virtual void getRealName(char* const strBuf) const; + virtual void getRealName(char* const strBuf) const noexcept; /*! * Get the name of the parameter \a parameterId. */ - virtual void getParameterName(const uint32_t parameterId, char* const strBuf) const; + virtual void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept; /*! * Get the symbol of the parameter \a parameterId. */ - virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf) const; + virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf) const noexcept; /*! * Get the custom text of the parameter \a parameterId. */ - virtual void getParameterText(const uint32_t parameterId, const float value, char* const strBuf) const; + virtual void getParameterText(const uint32_t parameterId, const float value, char* const strBuf) const noexcept; /*! * Get the unit of the parameter \a parameterId. */ - virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf) const; + virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept; /*! * Get the scalepoint \a scalePointId label of the parameter \a parameterId. */ - virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const; + virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept; /*! * Get the name of the program at \a index. */ - void getProgramName(const uint32_t index, char* const strBuf) const; + void getProgramName(const uint32_t index, char* const strBuf) const noexcept; /*! * Get the name of the MIDI program at \a index. * * \see getMidiProgramInfo() */ - void getMidiProgramName(const uint32_t index, char* const strBuf) const; + void getMidiProgramName(const uint32_t index, char* const strBuf) const noexcept; /*! * Get information about the plugin's parameter count.\n @@ -429,7 +423,7 @@ public: * * \see isEnabled() */ - void setEnabled(const bool yesNo); + void setEnabled(const bool yesNo) noexcept; /*! * Set plugin as active according to \a active. @@ -437,7 +431,7 @@ public: * \param sendOsc Send message change over OSC * \param sendCallback Send message change to registered callback */ - void setActive(const bool active, const bool sendOsc, const bool sendCallback); + void setActive(const bool active, const bool sendOsc, const bool sendCallback) noexcept; #ifndef BUILD_BRIDGE /*! @@ -447,7 +441,7 @@ public: * \param sendOsc Send message change over OSC * \param sendCallback Send message change to registered callback */ - void setDryWet(const float value, const bool sendOsc, const bool sendCallback); + void setDryWet(const float value, const bool sendOsc, const bool sendCallback) noexcept; /*! * Set the plugin's output volume to \a value.\n @@ -456,7 +450,7 @@ public: * \param sendOsc Send message change over OSC * \param sendCallback Send message change to registered callback */ - void setVolume(const float value, const bool sendOsc, const bool sendCallback); + void setVolume(const float value, const bool sendOsc, const bool sendCallback) noexcept; /*! * Set the plugin's output left balance value to \a value.\n @@ -467,7 +461,7 @@ public: * * \note Pure-Stereo plugins only! */ - void setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback); + void setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) noexcept; /*! * Set the plugin's output right balance value to \a value.\n @@ -478,7 +472,7 @@ public: * * \note Pure-Stereo plugins only! */ - void setBalanceRight(const float value, const bool sendOsc, const bool sendCallback); + void setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) noexcept; /*! * Set the plugin's output panning value to \a value.\n @@ -489,7 +483,7 @@ public: * * \note Force-Stereo plugins only! */ - void setPanning(const float value, const bool sendOsc, const bool sendCallback); + void setPanning(const float value, const bool sendOsc, const bool sendCallback) noexcept; #endif /*! @@ -498,7 +492,7 @@ public: * \param sendOsc Send message change over OSC * \param sendCallback Send message change to registered callback */ - virtual void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback); + virtual void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept; // ------------------------------------------------------------------- // Set data (plugin-specific stuff) @@ -514,7 +508,7 @@ public: * * \see getParameterValue() */ - virtual void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback); + virtual void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept; /*! * Set a plugin's parameter value, including internal parameters.\n @@ -527,19 +521,19 @@ public: * \see setBalanceLeft() * \see setBalanceRight() */ - void setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback); + void setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept; /*! * Set parameter's \a parameterId MIDI channel to \a channel.\n * \a channel must be between 0 and 15. */ - void setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback); + void setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback) noexcept; /*! * Set parameter's \a parameterId MIDI CC to \a cc.\n * \a cc must be between 0 and 95 (0x5F), or -1 for invalid. */ - void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback); + void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback) noexcept; /*! * Add a custom data set.\n @@ -576,7 +570,7 @@ public: * \param sendCallback Send message change to registered callback * \param block Block the audio callback */ - virtual void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback); + virtual void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept; /*! * Change the current MIDI plugin program to \a index. @@ -590,13 +584,13 @@ public: * \param sendCallback Send message change to registered callback * \param block Block the audio callback */ - virtual void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback); + virtual void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept; /*! * This is an overloaded call to setMidiProgram().\n * It changes the current MIDI program using \a bank and \a program values instead of index. */ - void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback); + void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept; // ------------------------------------------------------------------- // Set gui stuff @@ -635,12 +629,12 @@ public: /*! * Plugin activate call. */ - virtual void activate(); + virtual void activate() noexcept; /*! * Plugin activate call. */ - virtual void deactivate(); + virtual void deactivate() noexcept; /*! * Plugin process call. @@ -673,12 +667,12 @@ public: * Try to lock the plugin's master mutex. * @param forcedOffline When true, always locks and returns true */ - bool tryLock(const bool forcedOffline); + bool tryLock(const bool forcedOffline) noexcept; /*! * Unlock the plugin's master mutex. */ - void unlock(); + void unlock() noexcept; // ------------------------------------------------------------------- // Plugin buffers @@ -699,7 +693,7 @@ public: /*! * Register this plugin to the engine's OSC client (controller or bridge). */ - void registerToOscClient(); + void registerToOscClient() noexcept; /*! * Update the plugin's internal OSC data according to \a source and \a url.\n @@ -732,7 +726,7 @@ public: /*! * Send all midi notes off to the host callback.\n - * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead (ONLY IF ctrlChannel is valid). + * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead (IFF ctrlChannel is valid). * \note RT call */ void sendMidiAllNotesOffToCallback(); @@ -752,27 +746,27 @@ public: /*! * Tell the UI a parameter has changed. */ - virtual void uiParameterChange(const uint32_t index, const float value); + virtual void uiParameterChange(const uint32_t index, const float value) noexcept; /*! * Tell the UI the current program has changed. */ - virtual void uiProgramChange(const uint32_t index); + virtual void uiProgramChange(const uint32_t index) noexcept; /*! * Tell the UI the current midi program has changed. */ - virtual void uiMidiProgramChange(const uint32_t index); + virtual void uiMidiProgramChange(const uint32_t index) noexcept; /*! * Tell the UI a note has been pressed. */ - virtual void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo); + virtual void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept; /*! * Tell the UI a note has been released. */ - virtual void uiNoteOff(const uint8_t channel, const uint8_t note); + virtual void uiNoteOff(const uint8_t channel, const uint8_t note) noexcept; // ------------------------------------------------------------------- // Helper functions @@ -815,7 +809,7 @@ public: } /*! - * Handy function used and required by CarlaEngine::clonePlugin(). + * Handy function required by CarlaEngine::clonePlugin(). */ virtual const void* getExtraStuff() const noexcept { @@ -831,8 +825,8 @@ public: const char* const label; }; - static size_t getNativePluginCount(); - static const NativePluginDescriptor* getNativePluginDescriptor(const size_t index); + static size_t getNativePluginCount() noexcept; + static const NativePluginDescriptor* getNativePluginDescriptor(const size_t index) noexcept; static CarlaPlugin* newNative(const Initializer& init); static CarlaPlugin* newBridge(const Initializer& init, const BinaryType btype, const PluginType ptype, const char* const bridgeBinary); @@ -871,8 +865,8 @@ protected: class ScopedDisabler { public: - ScopedDisabler(CarlaPlugin* const plugin); - ~ScopedDisabler(); + ScopedDisabler(CarlaPlugin* const plugin) noexcept; + ~ScopedDisabler() noexcept; private: CarlaPlugin* const fPlugin; @@ -889,8 +883,8 @@ protected: class ScopedSingleProcessLocker { public: - ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block); - ~ScopedSingleProcessLocker(); + ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block) noexcept; + ~ScopedSingleProcessLocker() noexcept; private: CarlaPlugin* const fPlugin; diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index f6bd53ac9..859378264 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -730,7 +730,7 @@ CarlaEngineClient::~CarlaEngineClient() carla_debug("CarlaEngineClient::~CarlaEngineClient()"); } -void CarlaEngineClient::activate() +void CarlaEngineClient::activate() noexcept { CARLA_ASSERT(! fActive); carla_debug("CarlaEngineClient::activate()"); @@ -738,7 +738,7 @@ void CarlaEngineClient::activate() fActive = true; } -void CarlaEngineClient::deactivate() +void CarlaEngineClient::deactivate() noexcept { CARLA_ASSERT(fActive); carla_debug("CarlaEngineClient::deactivate()"); @@ -1887,14 +1887,14 @@ const EngineTimeInfo& CarlaEngine::getTimeInfo() const noexcept // ----------------------------------------------------------------------- // Information (peaks) -float CarlaEngine::getInputPeak(const unsigned int pluginId, const bool isLeft) const +float CarlaEngine::getInputPeak(const unsigned int pluginId, const bool isLeft) const noexcept { CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f); return pData->plugins[pluginId].insPeak[isLeft ? 0 : 1]; } -float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft) const +float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft) const noexcept { CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f); @@ -1904,15 +1904,19 @@ float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft) // ----------------------------------------------------------------------- // Callback -void CarlaEngine::callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr) +void CarlaEngine::callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept { carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr); if (pData->callback != nullptr) - pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr); + { + try { + pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr); + } catch(...) {} + } } -void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) +void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) noexcept { carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr); @@ -2117,17 +2121,17 @@ bool CarlaEngine::patchbayRefresh() // ----------------------------------------------------------------------- // Transport -void CarlaEngine::transportPlay() +void CarlaEngine::transportPlay() noexcept { pData->time.playing = true; } -void CarlaEngine::transportPause() +void CarlaEngine::transportPause() noexcept { pData->time.playing = false; } -void CarlaEngine::transportRelocate(const uint64_t frame) +void CarlaEngine::transportRelocate(const uint64_t frame) noexcept { pData->time.frame = frame; } @@ -2137,7 +2141,7 @@ void CarlaEngine::transportRelocate(const uint64_t frame) const char* CarlaEngine::getLastError() const noexcept { - return (const char*)pData->lastError; + return pData->lastError.getBuffer(); } void CarlaEngine::setLastError(const char* const error) const @@ -2145,7 +2149,7 @@ void CarlaEngine::setLastError(const char* const error) const pData->lastError = error; } -void CarlaEngine::setAboutToClose() +void CarlaEngine::setAboutToClose() noexcept { carla_debug("CarlaEngine::setAboutToClose()"); @@ -2266,9 +2270,11 @@ bool CarlaEngine::isOscControlRegistered() const noexcept } #endif -void CarlaEngine::idleOsc() +void CarlaEngine::idleOsc() const noexcept { - pData->osc.idle(); + try { + pData->osc.idle(); + } catch(...) {} } const char* CarlaEngine::getOscServerPathTCP() const noexcept @@ -2296,7 +2302,7 @@ EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexc return isInput ? pData->bufEvents.in : pData->bufEvents.out; } -void CarlaEngine::registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin) +void CarlaEngine::registerEnginePlugin(const unsigned int id, CarlaPlugin* const plugin) noexcept { CARLA_SAFE_ASSERT_RETURN(id == pData->curPluginCount,); carla_debug("CarlaEngine::registerEnginePlugin(%i, %p)", id, plugin); @@ -2350,7 +2356,7 @@ void CarlaEngine::offlineModeChanged(const bool isOffline) } } -void CarlaEngine::runPendingRtEvents() +void CarlaEngine::runPendingRtEvents() noexcept { pData->doNextPluginAction(true); @@ -2378,379 +2384,357 @@ void CarlaEngine::setPluginPeaks(const unsigned int pluginId, float const inPeak // Bridge/Controller OSC stuff #ifdef BUILD_BRIDGE -void CarlaEngine::oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const +void CarlaEngine::oscSend_bridge_plugin_info1(const PluginCategory category, const uint hints, const long uniqueId) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_plugin_info1(%i:%s, %X, %l)", category, PluginCategory2Str(category), hints, uniqueId); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+21]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_plugin_info1"); - lo_send(pData->oscData->target, targetPath, "iih", static_cast(category), static_cast(hints), static_cast(uniqueId)); - } + char targetPath[std::strlen(pData->oscData->path)+21]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_plugin_info1"); + try_lo_send(pData->oscData->target, targetPath, "iih", static_cast(category), static_cast(hints), static_cast(uniqueId)); } -void CarlaEngine::oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const +void CarlaEngine::oscSend_bridge_plugin_info2(const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(maker != nullptr,); CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_plugin_info2(\"%s\", \"%s\", \"%s\", \"%s\")", realName, label, maker, copyright); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+21]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_plugin_info2"); - lo_send(pData->oscData->target, targetPath, "ssss", realName, label, maker, copyright); - } + char targetPath[std::strlen(pData->oscData->path)+21]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_plugin_info2"); + try_lo_send(pData->oscData->target, targetPath, "ssss", realName, label, maker, copyright); } -void CarlaEngine::oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const +void CarlaEngine::oscSend_bridge_audio_count(const uint32_t ins, const uint32_t outs) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_audio_count(%i, %i)", ins, outs); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+20]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_audio_count"); - lo_send(pData->oscData->target, targetPath, "iii", static_cast(ins), static_cast(outs)); - } + char targetPath[std::strlen(pData->oscData->path)+20]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_audio_count"); + try_lo_send(pData->oscData->target, targetPath, "iii", static_cast(ins), static_cast(outs)); } -void CarlaEngine::oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const +void CarlaEngine::oscSend_bridge_midi_count(const uint32_t ins, const uint32_t outs) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_midi_count(%i, %i)", ins, outs); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+19]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_midi_count"); - lo_send(pData->oscData->target, targetPath, "ii", static_cast(ins), static_cast(outs)); - } + char targetPath[std::strlen(pData->oscData->path)+19]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_midi_count"); + try_lo_send(pData->oscData->target, targetPath, "ii", static_cast(ins), static_cast(outs)); } -void CarlaEngine::oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const +void CarlaEngine::oscSend_bridge_parameter_count(const uint32_t ins, const uint32_t outs) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_parameter_count(%i, %i)", ins, outs); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+24]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_parameter_count"); - lo_send(pData->oscData->target, targetPath, "ii", static_cast(ins), static_cast(outs)); - } + char targetPath[std::strlen(pData->oscData->path)+24]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_parameter_count"); + try_lo_send(pData->oscData->target, targetPath, "ii", static_cast(ins), static_cast(outs)); } -void CarlaEngine::oscSend_bridge_program_count(const uint32_t count) const +void CarlaEngine::oscSend_bridge_program_count(const uint32_t count) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_program_count(%i)", count); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+22]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_program_count"); - lo_send(pData->oscData->target, targetPath, "i", static_cast(count)); - } + char targetPath[std::strlen(pData->oscData->path)+22]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_program_count"); + try_lo_send(pData->oscData->target, targetPath, "i", static_cast(count)); } -void CarlaEngine::oscSend_bridge_midi_program_count(const uint32_t count) const +void CarlaEngine::oscSend_bridge_midi_program_count(const uint32_t count) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_midi_program_count(%i)", count); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+27]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_midi_program_count"); - lo_send(pData->oscData->target, targetPath, "i", static_cast(count)); - } + char targetPath[std::strlen(pData->oscData->path)+27]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_midi_program_count"); + try_lo_send(pData->oscData->target, targetPath, "i", static_cast(count)); } -void CarlaEngine::oscSend_bridge_parameter_data(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const char* const name, const char* const unit) const +void CarlaEngine::oscSend_bridge_parameter_data(const uint32_t index, const int32_t rindex, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(unit != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", index, rindex, type, ParameterType2Str(type), hints, name, unit); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+23]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_parameter_data"); - lo_send(pData->oscData->target, targetPath, "iiiiss", static_cast(index), static_cast(rindex), static_cast(type), static_cast(hints), name, unit); - } + char targetPath[std::strlen(pData->oscData->path)+23]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_parameter_data"); + try_lo_send(pData->oscData->target, targetPath, "iiiiss", static_cast(index), static_cast(rindex), static_cast(type), static_cast(hints), name, unit); } -void CarlaEngine::oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const +void CarlaEngine::oscSend_bridge_parameter_ranges1(const uint32_t index, const float def, const float min, const float max) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, def, min, max); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+26]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_parameter_ranges1"); - lo_send(pData->oscData->target, targetPath, "ifff", static_cast(index), def, min, max); - } + char targetPath[std::strlen(pData->oscData->path)+26]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_parameter_ranges1"); + try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast(index), def, min, max); } -void CarlaEngine::oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const +void CarlaEngine::oscSend_bridge_parameter_ranges2(const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_parameter_ranges(%i, %f, %f, %f)", index, step, stepSmall, stepLarge); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+26]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_parameter_ranges2"); - lo_send(pData->oscData->target, targetPath, "ifff", static_cast(index), step, stepSmall, stepLarge); - } + char targetPath[std::strlen(pData->oscData->path)+26]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_parameter_ranges2"); + try_lo_send(pData->oscData->target, targetPath, "ifff", static_cast(index), step, stepSmall, stepLarge); } -void CarlaEngine::oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const +void CarlaEngine::oscSend_bridge_parameter_midi_cc(const uint32_t index, const int16_t cc) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_cc(%i, %i)", index, cc); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+26]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_parameter_midi_cc"); - lo_send(pData->oscData->target, targetPath, "ii", static_cast(index), static_cast(cc)); - } + char targetPath[std::strlen(pData->oscData->path)+26]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_parameter_midi_cc"); + try_lo_send(pData->oscData->target, targetPath, "ii", static_cast(index), static_cast(cc)); } -void CarlaEngine::oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const +void CarlaEngine::oscSend_bridge_parameter_midi_channel(const uint32_t index, const uint8_t channel) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_parameter_midi_channel(%i, %i)", index, channel); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+31]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_parameter_midi_channel"); - lo_send(pData->oscData->target, targetPath, "ii", static_cast(index), static_cast(channel)); - } + char targetPath[std::strlen(pData->oscData->path)+31]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_parameter_midi_channel"); + try_lo_send(pData->oscData->target, targetPath, "ii", static_cast(index), static_cast(channel)); } -void CarlaEngine::oscSend_bridge_parameter_value(const int32_t index, const float value) const +void CarlaEngine::oscSend_bridge_parameter_value(const int32_t index, const float value) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,); carla_debug("CarlaEngine::oscSend_bridge_parameter_value(%i, %f)", index, value); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+24]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_parameter_value"); - lo_send(pData->oscData->target, targetPath, "if", index, value); - } + char targetPath[std::strlen(pData->oscData->path)+24]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_parameter_value"); + try_lo_send(pData->oscData->target, targetPath, "if", index, value); } -void CarlaEngine::oscSend_bridge_default_value(const uint32_t index, const float value) const +void CarlaEngine::oscSend_bridge_default_value(const uint32_t index, const float value) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_default_value(%i, %f)", index, value); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+22]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_default_value"); - lo_send(pData->oscData->target, targetPath, "if", static_cast(index), value); - } + char targetPath[std::strlen(pData->oscData->path)+22]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_default_value"); + try_lo_send(pData->oscData->target, targetPath, "if", static_cast(index), value); } -void CarlaEngine::oscSend_bridge_current_program(const int32_t index) const +void CarlaEngine::oscSend_bridge_current_program(const int32_t index) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_current_program(%i)", index); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+20]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_current_program"); - lo_send(pData->oscData->target, targetPath, "i", index); - } + char targetPath[std::strlen(pData->oscData->path)+20]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_current_program"); + try_lo_send(pData->oscData->target, targetPath, "i", index); } -void CarlaEngine::oscSend_bridge_current_midi_program(const int32_t index) const +void CarlaEngine::oscSend_bridge_current_midi_program(const int32_t index) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_current_midi_program(%i)", index); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+25]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_current_midi_program"); - lo_send(pData->oscData->target, targetPath, "i", index); - } + char targetPath[std::strlen(pData->oscData->path)+25]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_current_midi_program"); + try_lo_send(pData->oscData->target, targetPath, "i", index); } -void CarlaEngine::oscSend_bridge_program_name(const uint32_t index, const char* const name) const +void CarlaEngine::oscSend_bridge_program_name(const uint32_t index, const char* const name) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_program_name(%i, \"%s\")", index, name); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+21]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_program_name"); - lo_send(pData->oscData->target, targetPath, "is", static_cast(index), name); - } + char targetPath[std::strlen(pData->oscData->path)+21]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_program_name"); + try_lo_send(pData->oscData->target, targetPath, "is", static_cast(index), name); } -void CarlaEngine::oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const +void CarlaEngine::oscSend_bridge_midi_program_data(const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(name != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_midi_program_data(%i, %i, %i, \"%s\")", index, bank, program, name); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+26]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_midi_program_data"); - lo_send(pData->oscData->target, targetPath, "iiis", static_cast(index), static_cast(bank), static_cast(program), name); - } + char targetPath[std::strlen(pData->oscData->path)+26]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_midi_program_data"); + try_lo_send(pData->oscData->target, targetPath, "iiis", static_cast(index), static_cast(bank), static_cast(program), name); } -void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value) const +void CarlaEngine::oscSend_bridge_configure(const char* const key, const char* const value) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(value != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_configure(\"%s\", \"%s\")", key, value); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+18]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_configure"); - lo_send(pData->oscData->target, targetPath, "ss", key, value); - } + char targetPath[std::strlen(pData->oscData->path)+18]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_configure"); + try_lo_send(pData->oscData->target, targetPath, "ss", key, value); } -void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const +void CarlaEngine::oscSend_bridge_set_custom_data(const char* const type, const char* const key, const char* const value) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", type, key, value); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+24]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_set_custom_data"); - lo_send(pData->oscData->target, targetPath, "sss", type, key, value); - } + char targetPath[std::strlen(pData->oscData->path)+24]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_set_custom_data"); + try_lo_send(pData->oscData->target, targetPath, "sss", type, key, value); } -void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile) const +void CarlaEngine::oscSend_bridge_set_chunk_data(const char* const chunkFile) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); + CARLA_SAFE_ASSERT_RETURN(chunkFile != nullptr && chunkFile[0] != '\0',); carla_debug("CarlaEngine::oscSend_bridge_set_chunk_data(\"%s\")", chunkFile); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+23]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/bridge_set_chunk_data"); - lo_send(pData->oscData->target, targetPath, "s", chunkFile); - } + char targetPath[std::strlen(pData->oscData->path)+23]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/bridge_set_chunk_data"); + try_lo_send(pData->oscData->target, targetPath, "s", chunkFile); } // TODO? //void oscSend_bridge_set_peaks() const; #else -void CarlaEngine::oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const +void CarlaEngine::oscSend_control_add_plugin_start(const uint pluginId, const char* const pluginName) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(pluginName != nullptr && pluginName[0] != '\0',); carla_debug("CarlaEngine::oscSend_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+18]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/add_plugin_start"); - lo_send(pData->oscData->target, targetPath, "is", static_cast(pluginId), pluginName); - } + char targetPath[std::strlen(pData->oscData->path)+18]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/add_plugin_start"); + try_lo_send(pData->oscData->target, targetPath, "is", static_cast(pluginId), pluginName); } -void CarlaEngine::oscSend_control_add_plugin_end(const uint pluginId) const +void CarlaEngine::oscSend_control_add_plugin_end(const uint pluginId) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); carla_debug("CarlaEngine::oscSend_control_add_plugin_end(%i)", pluginId); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+16]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/add_plugin_end"); - lo_send(pData->oscData->target, targetPath, "i", static_cast(pluginId)); - } + char targetPath[std::strlen(pData->oscData->path)+16]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/add_plugin_end"); + try_lo_send(pData->oscData->target, targetPath, "i", static_cast(pluginId)); } -void CarlaEngine::oscSend_control_remove_plugin(const uint pluginId) const +void CarlaEngine::oscSend_control_remove_plugin(const uint pluginId) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); carla_debug("CarlaEngine::oscSend_control_remove_plugin(%i)", pluginId); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+15]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/remove_plugin"); - lo_send(pData->oscData->target, targetPath, "i", static_cast(pluginId)); - } + char targetPath[std::strlen(pData->oscData->path)+15]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/remove_plugin"); + try_lo_send(pData->oscData->target, targetPath, "i", static_cast(pluginId)); } -void CarlaEngine::oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const +void CarlaEngine::oscSend_control_set_plugin_info1(const uint pluginId, const PluginType type, const PluginCategory category, const uint hints, const long uniqueId) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(type != PLUGIN_NONE,); carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, %i:%s, %i:%s, %X, %l)", pluginId, type, PluginType2Str(type), category, PluginCategory2Str(category), hints, uniqueId); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+18]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_plugin_info1"); - lo_send(pData->oscData->target, targetPath, "iiiih", static_cast(pluginId), static_cast(type), static_cast(category), static_cast(hints), static_cast(uniqueId)); - } + char targetPath[std::strlen(pData->oscData->path)+18]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_plugin_info1"); + try_lo_send(pData->oscData->target, targetPath, "iiiih", static_cast(pluginId), static_cast(type), static_cast(category), static_cast(hints), static_cast(uniqueId)); } -void CarlaEngine::oscSend_control_set_plugin_info2(const uint pluginId, const char* const realName, const char* const label, const char* const maker, const char* const copyright) const +void CarlaEngine::oscSend_control_set_plugin_info2(const uint pluginId, const char* const realName, const char* const label, const char* const maker, const char* const copyright) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(realName != nullptr && realName[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0',); @@ -2758,330 +2742,307 @@ void CarlaEngine::oscSend_control_set_plugin_info2(const uint pluginId, const ch CARLA_SAFE_ASSERT_RETURN(copyright != nullptr,); carla_debug("CarlaEngine::oscSend_control_set_plugin_data(%i, \"%s\", \"%s\", \"%s\", \"%s\")", pluginId, realName, label, maker, copyright); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+18]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_plugin_info2"); - lo_send(pData->oscData->target, targetPath, "issss", static_cast(pluginId), realName, label, maker, copyright); - } + char targetPath[std::strlen(pData->oscData->path)+18]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_plugin_info2"); + try_lo_send(pData->oscData->target, targetPath, "issss", static_cast(pluginId), realName, label, maker, copyright); } -void CarlaEngine::oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const +void CarlaEngine::oscSend_control_set_audio_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); carla_debug("CarlaEngine::oscSend_control_set_audio_count(%i, %i, %i)", pluginId, ins, outs); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+18]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_audio_count"); - lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(ins), static_cast(outs)); - } + char targetPath[std::strlen(pData->oscData->path)+18]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_audio_count"); + try_lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(ins), static_cast(outs)); } -void CarlaEngine::oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const +void CarlaEngine::oscSend_control_set_midi_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); carla_debug("CarlaEngine::oscSend_control_set_midi_count(%i, %i, %i)", pluginId, ins, outs); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+18]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_midi_count"); - lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(ins), static_cast(outs)); - } + char targetPath[std::strlen(pData->oscData->path)+18]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_midi_count"); + try_lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(ins), static_cast(outs)); } -void CarlaEngine::oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const +void CarlaEngine::oscSend_control_set_parameter_count(const uint pluginId, const uint32_t ins, const uint32_t outs) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); carla_debug("CarlaEngine::oscSend_control_set_parameter_count(%i, %i, %i)", pluginId, ins, outs); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+18]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_parameter_count"); - lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(ins), static_cast(outs)); - } + char targetPath[std::strlen(pData->oscData->path)+18]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_parameter_count"); + try_lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(ins), static_cast(outs)); } -void CarlaEngine::oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const +void CarlaEngine::oscSend_control_set_program_count(const uint pluginId, const uint32_t count) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); carla_debug("CarlaEngine::oscSend_control_set_program_count(%i, %i)", pluginId, count); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+19]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_program_count"); - lo_send(pData->oscData->target, targetPath, "ii", static_cast(pluginId), static_cast(count)); - } + char targetPath[std::strlen(pData->oscData->path)+19]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_program_count"); + try_lo_send(pData->oscData->target, targetPath, "ii", static_cast(pluginId), static_cast(count)); } -void CarlaEngine::oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const +void CarlaEngine::oscSend_control_set_midi_program_count(const uint pluginId, const uint32_t count) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); carla_debug("CarlaEngine::oscSend_control_set_midi_program_count(%i, %i)", pluginId, count); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+24]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_midi_program_count"); - lo_send(pData->oscData->target, targetPath, "ii", static_cast(pluginId), static_cast(count)); - } + char targetPath[std::strlen(pData->oscData->path)+24]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_midi_program_count"); + try_lo_send(pData->oscData->target, targetPath, "ii", static_cast(pluginId), static_cast(count)); } -void CarlaEngine::oscSend_control_set_parameter_data(const uint pluginId, const uint32_t index, const ParameterType type, const uint hints, const char* const name, const char* const unit) const +void CarlaEngine::oscSend_control_set_parameter_data(const uint pluginId, const uint32_t index, const ParameterType type, const uint hints, const char* const name, const char* const unit) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(unit != nullptr,); carla_debug("CarlaEngine::oscSend_control_set_parameter_data(%i, %i, %i:%s, %X, \"%s\", \"%s\")", pluginId, index, type, ParameterType2Str(type), hints, name, unit); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+20]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_parameter_data"); - lo_send(pData->oscData->target, targetPath, "iiiiss", static_cast(pluginId), static_cast(index), static_cast(type), static_cast(hints), name, unit); - } + char targetPath[std::strlen(pData->oscData->path)+20]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_parameter_data"); + try_lo_send(pData->oscData->target, targetPath, "iiiiss", static_cast(pluginId), static_cast(index), static_cast(type), static_cast(hints), name, unit); } -void CarlaEngine::oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const +void CarlaEngine::oscSend_control_set_parameter_ranges1(const uint pluginId, const uint32_t index, const float def, const float min, const float max) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(def <= min && def >= max,); CARLA_SAFE_ASSERT_RETURN(min < max,); carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges1(%i, %i, %f, %f, %f)", pluginId, index, def, min, max, def); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+23]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_parameter_ranges1"); - lo_send(pData->oscData->target, targetPath, "iifff", static_cast(pluginId), static_cast(index), def, min, max); - } + char targetPath[std::strlen(pData->oscData->path)+23]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_parameter_ranges1"); + try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast(pluginId), static_cast(index), def, min, max); } -void CarlaEngine::oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const +void CarlaEngine::oscSend_control_set_parameter_ranges2(const uint pluginId, const uint32_t index, const float step, const float stepSmall, const float stepLarge) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(step <= stepSmall && step >= stepLarge,); CARLA_SAFE_ASSERT_RETURN(stepSmall <= stepLarge,); carla_debug("CarlaEngine::oscSend_control_set_parameter_ranges2(%i, %i, %f, %f, %f)", pluginId, index, step, stepSmall, stepLarge); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+23]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_parameter_ranges"); - lo_send(pData->oscData->target, targetPath, "iifff", static_cast(pluginId), static_cast(index), step, stepSmall, stepLarge); - } + char targetPath[std::strlen(pData->oscData->path)+23]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_parameter_ranges"); + try_lo_send(pData->oscData->target, targetPath, "iifff", static_cast(pluginId), static_cast(index), step, stepSmall, stepLarge); } -void CarlaEngine::oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const +void CarlaEngine::oscSend_control_set_parameter_midi_cc(const uint pluginId, const uint32_t index, const int16_t cc) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(cc <= 0x5F,); carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+23]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_parameter_midi_cc"); - lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(index), static_cast(cc)); - } + char targetPath[std::strlen(pData->oscData->path)+23]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_parameter_midi_cc"); + try_lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(index), static_cast(cc)); } -void CarlaEngine::oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const +void CarlaEngine::oscSend_control_set_parameter_midi_channel(const uint pluginId, const uint32_t index, const uint8_t channel) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,); carla_debug("CarlaEngine::oscSend_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+28]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_parameter_midi_channel"); - lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(index), static_cast(channel)); - } + char targetPath[std::strlen(pData->oscData->path)+28]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_parameter_midi_channel"); + try_lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(index), static_cast(channel)); } -void CarlaEngine::oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const +void CarlaEngine::oscSend_control_set_parameter_value(const uint pluginId, const int32_t index, const float value) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(index != PARAMETER_NULL,); carla_debug("CarlaEngine::oscSend_control_set_parameter_value(%i, %i:%s, %f)", pluginId, index, (index < 0) ? InternalParameterIndex2Str(static_cast(index)) : "(none)", value); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+21]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_parameter_value"); - lo_send(pData->oscData->target, targetPath, "iif", static_cast(pluginId), index, value); - } + char targetPath[std::strlen(pData->oscData->path)+21]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_parameter_value"); + try_lo_send(pData->oscData->target, targetPath, "iif", static_cast(pluginId), index, value); } -void CarlaEngine::oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const +void CarlaEngine::oscSend_control_set_default_value(const uint pluginId, const uint32_t index, const float value) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); carla_debug("CarlaEngine::oscSend_control_set_default_value(%i, %i, %f)", pluginId, index, value); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+19]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_default_value"); - lo_send(pData->oscData->target, targetPath, "iif", static_cast(pluginId), static_cast(index), value); - } + char targetPath[std::strlen(pData->oscData->path)+19]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_default_value"); + try_lo_send(pData->oscData->target, targetPath, "iif", static_cast(pluginId), static_cast(index), value); } -void CarlaEngine::oscSend_control_set_current_program(const uint pluginId, const int32_t index) const +void CarlaEngine::oscSend_control_set_current_program(const uint pluginId, const int32_t index) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); carla_debug("CarlaEngine::oscSend_control_set_current_program(%i, %i)", pluginId, index); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+21]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_current_program"); - lo_send(pData->oscData->target, targetPath, "ii", static_cast(pluginId), index); - } + char targetPath[std::strlen(pData->oscData->path)+21]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_current_program"); + try_lo_send(pData->oscData->target, targetPath, "ii", static_cast(pluginId), index); } -void CarlaEngine::oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const +void CarlaEngine::oscSend_control_set_current_midi_program(const uint pluginId, const int32_t index) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); carla_debug("CarlaEngine::oscSend_control_set_current_midi_program(%i, %i)", pluginId, index); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+26]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_current_midi_program"); - lo_send(pData->oscData->target, targetPath, "ii", static_cast(pluginId), index); - } + char targetPath[std::strlen(pData->oscData->path)+26]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_current_midi_program"); + try_lo_send(pData->oscData->target, targetPath, "ii", static_cast(pluginId), index); } -void CarlaEngine::oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const +void CarlaEngine::oscSend_control_set_program_name(const uint pluginId, const uint32_t index, const char* const name) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(name != nullptr,); carla_debug("CarlaEngine::oscSend_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+18]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_program_name"); - lo_send(pData->oscData->target, targetPath, "iis", static_cast(pluginId), static_cast(index), name); - } + char targetPath[std::strlen(pData->oscData->path)+18]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_program_name"); + try_lo_send(pData->oscData->target, targetPath, "iis", static_cast(pluginId), static_cast(index), name); } -void CarlaEngine::oscSend_control_set_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const +void CarlaEngine::oscSend_control_set_midi_program_data(const uint pluginId, const uint32_t index, const uint32_t bank, const uint32_t program, const char* const name) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(name != nullptr,); carla_debug("CarlaEngine::oscSend_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+23]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_midi_program_data"); - lo_send(pData->oscData->target, targetPath, "iiiis", static_cast(pluginId), static_cast(index), static_cast(bank), static_cast(program), name); - } + char targetPath[std::strlen(pData->oscData->path)+23]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_midi_program_data"); + try_lo_send(pData->oscData->target, targetPath, "iiiis", static_cast(pluginId), static_cast(index), static_cast(bank), static_cast(program), name); } -void CarlaEngine::oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const +void CarlaEngine::oscSend_control_note_on(const uint pluginId, const uint8_t channel, const uint8_t note, const uint8_t velo) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,); CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,); CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,); carla_debug("CarlaEngine::oscSend_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+9]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/note_on"); - lo_send(pData->oscData->target, targetPath, "iiii", static_cast(pluginId), static_cast(channel), static_cast(note), static_cast(velo)); - } + char targetPath[std::strlen(pData->oscData->path)+9]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/note_on"); + try_lo_send(pData->oscData->target, targetPath, "iiii", static_cast(pluginId), static_cast(channel), static_cast(note), static_cast(velo)); } -void CarlaEngine::oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const +void CarlaEngine::oscSend_control_note_off(const uint pluginId, const uint8_t channel, const uint8_t note) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,); CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,); carla_debug("CarlaEngine::oscSend_control_note_off(%i, %i, %i)", pluginId, channel, note); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+10]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/note_off"); - lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(channel), static_cast(note)); - } + char targetPath[std::strlen(pData->oscData->path)+10]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/note_off"); + try_lo_send(pData->oscData->target, targetPath, "iii", static_cast(pluginId), static_cast(channel), static_cast(note)); } -void CarlaEngine::oscSend_control_set_peaks(const uint pluginId) const +void CarlaEngine::oscSend_control_set_peaks(const uint pluginId) const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount,); // TODO - try and see if we can get peaks[4] ref const EnginePluginData& epData(pData->plugins[pluginId]); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+11]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/set_peaks"); - lo_send(pData->oscData->target, targetPath, "iffff", static_cast(pluginId), epData.insPeak[0], epData.insPeak[1], epData.outsPeak[0], epData.outsPeak[1]); - } + char targetPath[std::strlen(pData->oscData->path)+11]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/set_peaks"); + try_lo_send(pData->oscData->target, targetPath, "iffff", static_cast(pluginId), epData.insPeak[0], epData.insPeak[1], epData.outsPeak[0], epData.outsPeak[1]); } -void CarlaEngine::oscSend_control_exit() const +void CarlaEngine::oscSend_control_exit() const noexcept { CARLA_SAFE_ASSERT_RETURN(pData->oscData != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->path != nullptr && pData->oscData->path[0] != '\0',); + CARLA_SAFE_ASSERT_RETURN(pData->oscData->target != nullptr,); carla_debug("CarlaEngine::oscSend_control_exit()"); - if (pData->oscData->target != nullptr) - { - char targetPath[std::strlen(pData->oscData->path)+6]; - std::strcpy(targetPath, pData->oscData->path); - std::strcat(targetPath, "/exit"); - lo_send(pData->oscData->target, targetPath, ""); - } + char targetPath[std::strlen(pData->oscData->path)+6]; + std::strcpy(targetPath, pData->oscData->path); + std::strcat(targetPath, "/exit"); + try_lo_send(pData->oscData->target, targetPath, ""); } #endif diff --git a/source/backend/engine/CarlaEngineInternal.hpp b/source/backend/engine/CarlaEngineInternal.hpp index 86f74eeb6..0afe09a93 100644 --- a/source/backend/engine/CarlaEngineInternal.hpp +++ b/source/backend/engine/CarlaEngineInternal.hpp @@ -61,7 +61,7 @@ CARLA_BACKEND_START_NAMESPACE // ----------------------------------------------------------------------- static inline -const char* EngineType2Str(const EngineType type) +const char* EngineType2Str(const EngineType type) noexcept { switch (type) { @@ -84,7 +84,7 @@ const char* EngineType2Str(const EngineType type) } static inline -const char* EnginePortType2Str(const EnginePortType type) +const char* EnginePortType2Str(const EnginePortType type) noexcept { switch (type) { @@ -103,7 +103,7 @@ const char* EnginePortType2Str(const EnginePortType type) } static inline -const char* EngineEventType2Str(const EngineEventType type) +const char* EngineEventType2Str(const EngineEventType type) noexcept { switch (type) { @@ -120,7 +120,7 @@ const char* EngineEventType2Str(const EngineEventType type) } static inline -const char* EngineControlEventType2Str(const EngineControlEventType type) +const char* EngineControlEventType2Str(const EngineControlEventType type) noexcept { switch (type) { @@ -158,10 +158,10 @@ struct EnginePluginData { float insPeak[2]; float outsPeak[2]; - void clear() + void clear() noexcept { plugin = nullptr; - insPeak[0] = insPeak[1] = 0.0f; + insPeak[0] = insPeak[1] = 0.0f; outsPeak[0] = outsPeak[1] = 0.0f; } }; @@ -346,13 +346,13 @@ struct CarlaEngineProtectedData { rack = nullptr; } - ~InternalAudio() + ~InternalAudio() noexcept { CARLA_ASSERT(! isReady); CARLA_ASSERT(rack == nullptr); } - void initPatchbay() + void initPatchbay() noexcept { if (usePatchbay) { @@ -427,7 +427,7 @@ struct CarlaEngineProtectedData { : in(nullptr), out(nullptr) {} - ~InternalEvents() + ~InternalEvents() noexcept { CARLA_ASSERT(in == nullptr); CARLA_ASSERT(out == nullptr); @@ -454,7 +454,7 @@ struct CarlaEngineProtectedData { pluginId(0), value(0) {} - ~NextAction() + ~NextAction() noexcept { CARLA_ASSERT(opcode == kEnginePostActionNull); } @@ -486,7 +486,7 @@ struct CarlaEngineProtectedData { CARLA_DECLARE_NON_COPY_STRUCT(CarlaEngineProtectedData) #endif - ~CarlaEngineProtectedData() + ~CarlaEngineProtectedData() noexcept { CARLA_ASSERT(curPluginCount == 0); CARLA_ASSERT(maxPluginNumber == 0); @@ -494,10 +494,10 @@ struct CarlaEngineProtectedData { CARLA_ASSERT(plugins == nullptr); } - void doPluginRemove() + void doPluginRemove() noexcept { - CARLA_ASSERT(curPluginCount > 0); - CARLA_ASSERT(nextAction.pluginId < curPluginCount); + CARLA_SAFE_ASSERT_RETURN(curPluginCount > 0,); + CARLA_SAFE_ASSERT_RETURN(nextAction.pluginId < curPluginCount,); --curPluginCount; // move all plugins 1 spot backwards @@ -526,17 +526,17 @@ struct CarlaEngineProtectedData { plugins[id].outsPeak[1] = 0.0f; } - void doPluginsSwitch() + void doPluginsSwitch() noexcept { - CARLA_ASSERT(curPluginCount >= 2); + CARLA_SAFE_ASSERT_RETURN(curPluginCount >= 2,); const unsigned int idA(nextAction.pluginId); const unsigned int idB(nextAction.value); - CARLA_ASSERT(idA < curPluginCount); - CARLA_ASSERT(idB < curPluginCount); - CARLA_ASSERT(plugins[idA].plugin != nullptr); - CARLA_ASSERT(plugins[idB].plugin != nullptr); + CARLA_SAFE_ASSERT_RETURN(idA < curPluginCount,); + CARLA_SAFE_ASSERT_RETURN(idB < curPluginCount,); + CARLA_SAFE_ASSERT_RETURN(plugins[idA].plugin != nullptr,); + CARLA_SAFE_ASSERT_RETURN(plugins[idB].plugin != nullptr,); #if 0 std::swap(plugins[idA].plugin, plugins[idB].plugin); @@ -584,12 +584,12 @@ struct CarlaEngineProtectedData { class ScopedActionLock { public: - ScopedActionLock(CarlaEngineProtectedData* const data, const EnginePostAction action, const unsigned int pluginId, const unsigned int value, const bool lockWait) + ScopedActionLock(CarlaEngineProtectedData* const data, const EnginePostAction action, const unsigned int pluginId, const unsigned int value, const bool lockWait) noexcept : fData(data) { fData->nextAction.mutex.lock(); - CARLA_ASSERT(fData->nextAction.opcode == kEnginePostActionNull); + CARLA_SAFE_ASSERT_RETURN(fData->nextAction.opcode == kEnginePostActionNull,); fData->nextAction.opcode = action; fData->nextAction.pluginId = pluginId; diff --git a/source/backend/engine/CarlaEngineJack.cpp b/source/backend/engine/CarlaEngineJack.cpp index 8e21f1efd..17dadc224 100644 --- a/source/backend/engine/CarlaEngineJack.cpp +++ b/source/backend/engine/CarlaEngineJack.cpp @@ -329,7 +329,7 @@ public: jackbridge_client_close(fClient); } - void activate() override + void activate() noexcept override { carla_debug("CarlaEngineJackClient::activate()"); @@ -337,13 +337,15 @@ public: { CARLA_SAFE_ASSERT_RETURN(fClient != nullptr && ! fActive,); - jackbridge_activate(fClient); + try { + jackbridge_activate(fClient); + } catch(...) {} } CarlaEngineClient::activate(); } - void deactivate() override + void deactivate() noexcept override { carla_debug("CarlaEngineJackClient::deactivate()"); @@ -351,7 +353,9 @@ public: { CARLA_SAFE_ASSERT_RETURN(fClient != nullptr && fActive,); - jackbridge_deactivate(fClient); + try { + jackbridge_deactivate(fClient); + } catch(...) {} } CarlaEngineClient::deactivate(); @@ -922,28 +926,43 @@ public: // ------------------------------------------------------------------- // Transport - void transportPlay() override + void transportPlay() noexcept override { if (pData->options.transportMode == ENGINE_TRANSPORT_MODE_INTERNAL) - CarlaEngine::transportPlay(); - else if (fClient != nullptr) - jackbridge_transport_start(fClient); + return CarlaEngine::transportPlay(); + + if (fClient != nullptr) + { + try { + jackbridge_transport_start(fClient); + } catch(...) {} + } } - void transportPause() override + void transportPause() noexcept override { if (pData->options.transportMode == ENGINE_TRANSPORT_MODE_INTERNAL) - CarlaEngine::transportPause(); - else if (fClient != nullptr) - jackbridge_transport_stop(fClient); + return CarlaEngine::transportPause(); + + if (fClient != nullptr) + { + try { + jackbridge_transport_stop(fClient); + } catch(...) {} + } } - void transportRelocate(const uint64_t frame) override + void transportRelocate(const uint64_t frame) noexcept override { if (pData->options.transportMode == ENGINE_TRANSPORT_MODE_INTERNAL) - CarlaEngine::transportRelocate(frame); - else if (fClient != nullptr) - jackbridge_transport_locate(fClient, static_cast(frame)); + return CarlaEngine::transportRelocate(frame); + + if (fClient != nullptr) + { + try { + jackbridge_transport_locate(fClient, static_cast(frame)); + } catch(...) {} + } } #endif diff --git a/source/backend/engine/CarlaEngineOsc.cpp b/source/backend/engine/CarlaEngineOsc.cpp index 7dbf4d1b4..d2fd98655 100644 --- a/source/backend/engine/CarlaEngineOsc.cpp +++ b/source/backend/engine/CarlaEngineOsc.cpp @@ -28,7 +28,7 @@ CARLA_BACKEND_START_NAMESPACE #ifndef BUILD_BRIDGE // ------------------------------------------------------------------- -// Bridge Helper, defined in CarlaPlugin.cpp +// Bridge Helper, defined in BridgePlugin.cpp extern int CarlaPluginSetOscBridgeInfo(CarlaPlugin* const plugin, const PluginBridgeInfoType type, const int argc, const lo_arg* const* const argv, const char* const types); @@ -41,31 +41,31 @@ CarlaEngineOsc::CarlaEngineOsc(CarlaEngine* const engine) fServerTCP(nullptr), fServerUDP(nullptr) { - carla_debug("CarlaEngineOsc::CarlaEngineOsc(%p)", engine); CARLA_ASSERT(engine != nullptr); + carla_debug("CarlaEngineOsc::CarlaEngineOsc(%p)", engine); } CarlaEngineOsc::~CarlaEngineOsc() { - carla_debug("CarlaEngineOsc::~CarlaEngineOsc()"); CARLA_ASSERT(fName.isEmpty()); CARLA_ASSERT(fServerPathTCP.isEmpty()); CARLA_ASSERT(fServerPathUDP.isEmpty()); CARLA_ASSERT(fServerTCP == nullptr); CARLA_ASSERT(fServerUDP == nullptr); + carla_debug("CarlaEngineOsc::~CarlaEngineOsc()"); } // ----------------------------------------------------------------------- void CarlaEngineOsc::init(const char* const name) { + CARLA_SAFE_ASSERT_RETURN(fName.isEmpty(),); + CARLA_SAFE_ASSERT_RETURN(fServerPathTCP.isEmpty(),); + CARLA_SAFE_ASSERT_RETURN(fServerPathUDP.isEmpty(),); + CARLA_SAFE_ASSERT_RETURN(fServerTCP == nullptr,); + CARLA_SAFE_ASSERT_RETURN(fServerUDP == nullptr,); + CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',); carla_debug("CarlaEngineOsc::init(\"%s\")", name); - CARLA_ASSERT(fName.isEmpty()); - CARLA_ASSERT(fServerPathTCP.isEmpty()); - CARLA_ASSERT(fServerPathUDP.isEmpty()); - CARLA_ASSERT(fServerTCP == nullptr); - CARLA_ASSERT(fServerUDP == nullptr); - CARLA_ASSERT(name != nullptr); fName = name; fName.toBasic(); @@ -99,13 +99,13 @@ void CarlaEngineOsc::init(const char* const name) } CARLA_ASSERT(fName.isNotEmpty()); - CARLA_ASSERT(fServerPathTCP.isNotEmpty()); - CARLA_ASSERT(fServerPathUDP.isNotEmpty()); - CARLA_ASSERT(fServerTCP != nullptr); - CARLA_ASSERT(fServerUDP != nullptr); + CARLA_SAFE_ASSERT(fServerPathTCP.isNotEmpty()); + CARLA_SAFE_ASSERT(fServerPathUDP.isNotEmpty()); + CARLA_SAFE_ASSERT(fServerTCP != nullptr); + CARLA_SAFE_ASSERT(fServerUDP != nullptr); } -void CarlaEngineOsc::idle() +void CarlaEngineOsc::idle() const { if (fServerTCP != nullptr) { @@ -120,12 +120,12 @@ void CarlaEngineOsc::idle() void CarlaEngineOsc::close() { - carla_debug("CarlaEngineOsc::close()"); CARLA_ASSERT(fName.isNotEmpty()); - CARLA_ASSERT(fServerPathTCP.isNotEmpty()); - CARLA_ASSERT(fServerPathUDP.isNotEmpty()); - CARLA_ASSERT(fServerTCP != nullptr); - CARLA_ASSERT(fServerUDP != nullptr); + CARLA_SAFE_ASSERT(fServerPathTCP.isNotEmpty()); + CARLA_SAFE_ASSERT(fServerPathUDP.isNotEmpty()); + CARLA_SAFE_ASSERT(fServerTCP != nullptr); + CARLA_SAFE_ASSERT(fServerUDP != nullptr); + carla_debug("CarlaEngineOsc::close()"); fName.clear(); @@ -149,12 +149,6 @@ void CarlaEngineOsc::close() #ifndef BUILD_BRIDGE fControlData.free(); #endif - - CARLA_ASSERT(fName.isEmpty()); - CARLA_ASSERT(fServerPathTCP.isEmpty()); - CARLA_ASSERT(fServerPathUDP.isEmpty()); - CARLA_ASSERT(fServerTCP == nullptr); - CARLA_ASSERT(fServerUDP == nullptr); } // ----------------------------------------------------------------------- @@ -166,24 +160,19 @@ bool isDigit(const char c) int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg) { - CARLA_ASSERT(fName.isNotEmpty()); - CARLA_ASSERT(fServerPathTCP.isNotEmpty()); - CARLA_ASSERT(fServerPathUDP.isNotEmpty()); - CARLA_ASSERT(fServerTCP != nullptr); - CARLA_ASSERT(fServerUDP != nullptr); - CARLA_ASSERT(path != nullptr); + CARLA_SAFE_ASSERT_RETURN(fName.isNotEmpty(), 1); + CARLA_SAFE_ASSERT_RETURN(path != nullptr && path[0] != '\0', 1); carla_debug("CarlaEngineOsc::handleMessage(%s, \"%s\", %i, %p, \"%s\", %p)", bool2str(isTCP), path, argc, argv, types, msg); - if (path == nullptr) + if (isTCP) { - carla_stderr("CarlaEngineOsc::handleMessage() - got invalid path"); - return 1; + CARLA_SAFE_ASSERT_RETURN(fServerPathTCP.isNotEmpty(), 1); + CARLA_SAFE_ASSERT_RETURN(fServerTCP != nullptr, 1); } - - if (fName.isEmpty()) + else { - carla_stderr("CarlaEngineOsc::handleMessage(%s, \"%s\", ...) - received message but client is offline", bool2str(isTCP), path); - return 1; + CARLA_SAFE_ASSERT_RETURN(fServerPathUDP.isNotEmpty(), 1); + CARLA_SAFE_ASSERT_RETURN(fServerUDP != nullptr, 1); } #ifndef BUILD_BRIDGE @@ -199,18 +188,16 @@ int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, cons } #endif - const size_t nameSize = fName.length(); + const size_t nameSize(fName.length()); // Check if message is for this client - if (std::strlen(path) <= nameSize || std::strncmp(path+1, (const char*)fName, nameSize) != 0) + if (std::strlen(path) <= nameSize || std::strncmp(path+1, fName.getBuffer(), nameSize) != 0) { - carla_stderr("CarlaEngineOsc::handleMessage() - message not for this client -> '%s' != '/%s/'", path, (const char*)fName); + carla_stderr("CarlaEngineOsc::handleMessage() - message not for this client -> '%s' != '/%s/'", path, fName.getBuffer()); return 1; } - // Get plugin id from message - // eg, /carla/23/method - + // Get plugin id from path, "/carla/23/method" -> 23 unsigned int pluginId = 0; size_t offset; @@ -220,7 +207,7 @@ int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, cons { if (isDigit(path[nameSize+5])) { - carla_stderr2("CarlaEngineOsc::handleMessage() - invalid plugin id, over 999? (value: \"%s\")", path+nameSize+1); + carla_stderr2("CarlaEngineOsc::handleMessage() - invalid plugin id, over 999? (value: \"%s\")", path+(nameSize+1)); return 1; } else if (isDigit(path[nameSize+4])) @@ -259,7 +246,7 @@ int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, cons } // Get plugin - CarlaPlugin* const plugin = fEngine->getPluginUnchecked(pluginId); + CarlaPlugin* const plugin(fEngine->getPluginUnchecked(pluginId)); if (plugin == nullptr || plugin->getId() != pluginId) { @@ -268,7 +255,8 @@ int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, cons } // Get method from path, "/Carla/i/method" -> "method" - char method[32] = { 0 }; + char method[32]; + carla_zeroChar(method, 32); std::strncpy(method, path + (nameSize + offset), 31); if (method[0] == '\0') @@ -280,7 +268,7 @@ int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, cons // Common OSC methods (DSSI and bridge UIs) if (std::strcmp(method, "update") == 0) { - const lo_address source = lo_message_get_source(msg); + const lo_address source(lo_message_get_source(msg)); return handleMsgUpdate(plugin, argc, argv, types, source); } if (std::strcmp(method, "configure") == 0) @@ -324,7 +312,7 @@ int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, cons return handleMsgNoteOff(plugin, argc, argv, types); // Plugin Bridges - if ((plugin->getHints() & PLUGIN_IS_BRIDGE) > 0 && std::strlen(method) > 11 && std::strncmp(method, "bridge_", 7) == 0) + if ((plugin->getHints() & PLUGIN_IS_BRIDGE) != 0 && std::strlen(method) > 11 && std::strncmp(method, "bridge_", 7) == 0) { if (std::strcmp(method+7, "audio_count") == 0) return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeAudioCount, argc, argv, types); diff --git a/source/backend/engine/CarlaEngineOsc.hpp b/source/backend/engine/CarlaEngineOsc.hpp index 8be102538..b27cc1248 100644 --- a/source/backend/engine/CarlaEngineOsc.hpp +++ b/source/backend/engine/CarlaEngineOsc.hpp @@ -61,7 +61,7 @@ public: ~CarlaEngineOsc(); void init(const char* const name); - void idle(); + void idle() const; void close(); // ------------------------------------------------------------------- diff --git a/source/backend/plugin/BridgePlugin.cpp b/source/backend/plugin/BridgePlugin.cpp index a3ca4c9e6..47bbbeec6 100644 --- a/source/backend/plugin/BridgePlugin.cpp +++ b/source/backend/plugin/BridgePlugin.cpp @@ -212,17 +212,14 @@ struct BridgeControl : public RingBufferControl { bool waitForServer() { - CARLA_ASSERT(data != nullptr); - - if (data == nullptr) - return false; + CARLA_SAFE_ASSERT_RETURN(data != nullptr, false); jackbridge_sem_post(&data->runServer); return jackbridge_sem_timedwait(&data->runClient, 5); } - void writeOpcode(const PluginBridgeOpcode opcode) + void writeOpcode(const PluginBridgeOpcode opcode) noexcept { writeInt(static_cast(opcode)); } @@ -320,7 +317,7 @@ public: return fPluginType; } - PluginCategory getCategory() const override + PluginCategory getCategory() const noexcept override { return fInfo.category; } @@ -346,7 +343,7 @@ public: // ------------------------------------------------------------------- // Information (current data) - int32_t getChunkData(void** const dataPtr) const override + int32_t getChunkData(void** const dataPtr) const noexcept override { CARLA_ASSERT(pData->options & PLUGIN_OPTION_USE_CHUNKS); CARLA_ASSERT(dataPtr != nullptr); @@ -365,7 +362,7 @@ public: // ------------------------------------------------------------------- // Information (per-plugin data) - unsigned int getOptionsAvailable() const override + unsigned int getOptionsAvailable() const noexcept override { unsigned int options = 0x0; @@ -380,41 +377,41 @@ public: return options; } - float getParameterValue(const uint32_t parameterId) const override + float getParameterValue(const uint32_t parameterId) const noexcept override { - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f); return fParams[parameterId].value; } - void getLabel(char* const strBuf) const override + void getLabel(char* const strBuf) const noexcept override { std::strncpy(strBuf, (const char*)fInfo.label, STR_MAX); } - void getMaker(char* const strBuf) const override + void getMaker(char* const strBuf) const noexcept override { std::strncpy(strBuf, (const char*)fInfo.maker, STR_MAX); } - void getCopyright(char* const strBuf) const override + void getCopyright(char* const strBuf) const noexcept override { std::strncpy(strBuf, (const char*)fInfo.copyright, STR_MAX); } - void getRealName(char* const strBuf) const override + void getRealName(char* const strBuf) const noexcept override { std::strncpy(strBuf, (const char*)fInfo.name, STR_MAX); } - void getParameterName(const uint32_t parameterId, char* const strBuf) const override + void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override { CARLA_ASSERT(parameterId < pData->param.count); std::strncpy(strBuf, (const char*)fParams[parameterId].name, STR_MAX); } - void getParameterUnit(const uint32_t parameterId, char* const strBuf) const override + void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept override { CARLA_ASSERT(parameterId < pData->param.count); @@ -452,7 +449,7 @@ public: // ------------------------------------------------------------------- // Set data (plugin-specific stuff) - void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_ASSERT(parameterId < pData->param.count); @@ -477,7 +474,7 @@ public: CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback); } - void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast(pData->prog.count),); @@ -498,7 +495,7 @@ public: CarlaPlugin::setProgram(index, sendGui, sendOsc, sendCallback); } - void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast(pData->midiprog.count),); @@ -709,24 +706,30 @@ public: // ------------------------------------------------------------------- // Plugin processing - void activate() override + void activate() noexcept override { // already locked before fShmControl.writeOpcode(kPluginBridgeOpcodeSetParameter); fShmControl.writeInt(PARAMETER_ACTIVE); fShmControl.writeFloat(1.0f); fShmControl.commitWrite(); - waitForServer(); + + try { + waitForServer(); + } catch(...) {} } - void deactivate() override + void deactivate() noexcept override { // already locked before fShmControl.writeOpcode(kPluginBridgeOpcodeSetParameter); fShmControl.writeInt(PARAMETER_ACTIVE); fShmControl.writeFloat(0.0f); fShmControl.commitWrite(); - waitForServer(); + + try { + waitForServer(); + } catch(...) {} } void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) override diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index 8f831928f..5f3463864 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -261,6 +261,22 @@ const char* CarlaPlugin::getIconName() const noexcept return pData->iconName; } +PluginCategory CarlaPlugin::getCategory() const noexcept +{ + PluginCategory category = PLUGIN_CATEGORY_NONE; + + try { + category = getPluginCategoryFromName(pData->name); + } catch(...) {} + + return category; +} + +long CarlaPlugin::getUniqueId() const noexcept +{ + return 0; +} + uint32_t CarlaPlugin::getLatencyInFrames() const noexcept { return pData->latency; @@ -294,7 +310,7 @@ uint32_t CarlaPlugin::getParameterCount() const noexcept return pData->param.count; } -uint32_t CarlaPlugin::getParameterScalePointCount(const uint32_t parameterId) const +uint32_t CarlaPlugin::getParameterScalePointCount(const uint32_t parameterId) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0); return 0; @@ -328,37 +344,37 @@ int32_t CarlaPlugin::getCurrentMidiProgram() const noexcept return pData->midiprog.current; } -const ParameterData& CarlaPlugin::getParameterData(const uint32_t parameterId) const +const ParameterData& CarlaPlugin::getParameterData(const uint32_t parameterId) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterDataNull); return pData->param.data[parameterId]; } -const ParameterRanges& CarlaPlugin::getParameterRanges(const uint32_t parameterId) const +const ParameterRanges& CarlaPlugin::getParameterRanges(const uint32_t parameterId) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterRangesNull); return pData->param.ranges[parameterId]; } -bool CarlaPlugin::isParameterOutput(const uint32_t parameterId) const +bool CarlaPlugin::isParameterOutput(const uint32_t parameterId) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, false); return (pData->param.data[parameterId].type == PARAMETER_OUTPUT); } -const MidiProgramData& CarlaPlugin::getMidiProgramData(const uint32_t index) const +const MidiProgramData& CarlaPlugin::getMidiProgramData(const uint32_t index) const noexcept { CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count, kMidiProgramDataNull); return pData->midiprog.data[index]; } -const CustomData& CarlaPlugin::getCustomData(const uint32_t index) const +const CustomData& CarlaPlugin::getCustomData(const uint32_t index) const noexcept { CARLA_SAFE_ASSERT_RETURN(index < pData->custom.count(), kCustomDataNull); return pData->custom.getAt(index); } -int32_t CarlaPlugin::getChunkData(void** const dataPtr) const +int32_t CarlaPlugin::getChunkData(void** const dataPtr) const noexcept { CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0); CARLA_ASSERT(false); // this should never happen @@ -368,20 +384,20 @@ int32_t CarlaPlugin::getChunkData(void** const dataPtr) const // ------------------------------------------------------------------- // Information (per-plugin data) -unsigned int CarlaPlugin::getOptionsAvailable() const +unsigned int CarlaPlugin::getOptionsAvailable() const noexcept { CARLA_ASSERT(false); // this should never happen return 0x0; } -float CarlaPlugin::getParameterValue(const uint32_t parameterId) const +float CarlaPlugin::getParameterValue(const uint32_t parameterId) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f); CARLA_ASSERT(false); // this should never happen return 0.0f; } -float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const +float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f); CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f); @@ -389,53 +405,53 @@ float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const return 0.0f; } -void CarlaPlugin::getLabel(char* const strBuf) const +void CarlaPlugin::getLabel(char* const strBuf) const noexcept { strBuf[0] = '\0'; } -void CarlaPlugin::getMaker(char* const strBuf) const +void CarlaPlugin::getMaker(char* const strBuf) const noexcept { strBuf[0] = '\0'; } -void CarlaPlugin::getCopyright(char* const strBuf) const +void CarlaPlugin::getCopyright(char* const strBuf) const noexcept { strBuf[0] = '\0'; } -void CarlaPlugin::getRealName(char* const strBuf) const +void CarlaPlugin::getRealName(char* const strBuf) const noexcept { strBuf[0] = '\0'; } -void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const +void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); CARLA_ASSERT(false); // this should never happen strBuf[0] = '\0'; } -void CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const strBuf) const +void CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const strBuf) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); strBuf[0] = '\0'; } -void CarlaPlugin::getParameterText(const uint32_t parameterId, const float, char* const strBuf) const +void CarlaPlugin::getParameterText(const uint32_t parameterId, const float, char* const strBuf) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); CARLA_ASSERT(false); // this should never happen strBuf[0] = '\0'; } -void CarlaPlugin::getParameterUnit(const uint32_t parameterId, char* const strBuf) const +void CarlaPlugin::getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); strBuf[0] = '\0'; } -void CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const +void CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId),); @@ -443,14 +459,14 @@ void CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const strBuf[0] = '\0'; } -void CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf) const +void CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf) const noexcept { CARLA_SAFE_ASSERT_RETURN(index < pData->prog.count,); CARLA_SAFE_ASSERT_RETURN(pData->prog.names[index] != nullptr,); std::strncpy(strBuf, pData->prog.names[index], STR_MAX); } -void CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf) const +void CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf) const noexcept { CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count,); CARLA_SAFE_ASSERT_RETURN(pData->midiprog.data[index].name != nullptr,); @@ -872,7 +888,10 @@ void CarlaPlugin::setName(const char* const newName) { CARLA_ASSERT(newName != nullptr && newName[0] != '\0'); - pData->name = newName; + if (pData->name != nullptr) + delete[] pData->name; + + pData->name = carla_strdup(newName); } void CarlaPlugin::setOption(const unsigned int option, const bool yesNo) @@ -887,7 +906,7 @@ void CarlaPlugin::setOption(const unsigned int option, const bool yesNo) pData->saveSetting(option, yesNo); } -void CarlaPlugin::setEnabled(const bool yesNo) +void CarlaPlugin::setEnabled(const bool yesNo) noexcept { if (pData->enabled == yesNo) return; @@ -901,7 +920,7 @@ void CarlaPlugin::setEnabled(const bool yesNo) // ------------------------------------------------------------------- // Set data (internal stuff) -void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback) noexcept { #ifndef BUILD_BRIDGE CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT @@ -939,7 +958,7 @@ void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool se } #ifndef BUILD_BRIDGE -void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool sendCallback) noexcept { CARLA_ASSERT(value >= 0.0f && value <= 1.0f); @@ -957,7 +976,7 @@ void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool se pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_DRYWET, 0, fixedValue, nullptr); } -void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool sendCallback) noexcept { CARLA_ASSERT(value >= 0.0f && value <= 1.27f); @@ -975,7 +994,7 @@ void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool se pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_VOLUME, 0, fixedValue, nullptr); } -void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) noexcept { CARLA_ASSERT(value >= -1.0f && value <= 1.0f); @@ -993,7 +1012,7 @@ void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bo pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_BALANCE_LEFT, 0, fixedValue, nullptr); } -void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) noexcept { CARLA_ASSERT(value >= -1.0f && value <= 1.0f); @@ -1011,7 +1030,7 @@ void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const b pData->engine->callback(ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED, pData->id, PARAMETER_BALANCE_RIGHT, 0, fixedValue, nullptr); } -void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool sendCallback) noexcept { CARLA_ASSERT(value >= -1.0f && value <= 1.0f); @@ -1030,7 +1049,7 @@ void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool s } #endif -void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept { #ifndef BUILD_BRIDGE CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT @@ -1065,7 +1084,7 @@ void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const // ------------------------------------------------------------------- // Set data (plugin-specific stuff) -void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept { CARLA_ASSERT(parameterId < pData->param.count); #ifdef BUILD_BRIDGE @@ -1095,7 +1114,7 @@ void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float valu #endif } -void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept { CARLA_ASSERT(rindex > PARAMETER_MAX && rindex != PARAMETER_NULL); @@ -1132,7 +1151,7 @@ void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float } } -void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback) noexcept { CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT CARLA_ASSERT(parameterId < pData->param.count); @@ -1161,7 +1180,7 @@ void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t ch #endif } -void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback) noexcept { CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT CARLA_ASSERT(parameterId < pData->param.count); @@ -1267,7 +1286,7 @@ void CarlaPlugin::setChunkData(const char* const stringData) (void)stringData; } -void CarlaPlugin::setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept { CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast(pData->prog.count),); #ifdef BUILD_BRIDGE @@ -1324,7 +1343,7 @@ void CarlaPlugin::setProgram(const int32_t index, const bool sendGui, const bool #endif } -void CarlaPlugin::setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept { CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast(pData->midiprog.count),); #ifdef BUILD_BRIDGE @@ -1380,7 +1399,7 @@ void CarlaPlugin::setMidiProgram(const int32_t index, const bool sendGui, const #endif } -void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback) +void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept { for (uint32_t i=0; i < pData->midiprog.count; ++i) { @@ -1392,15 +1411,6 @@ void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program // ------------------------------------------------------------------- // Set ui stuff -void CarlaPlugin::showCustomUI(const bool yesNo) -{ - CARLA_ASSERT(false); - return; - - // unused - (void)yesNo; -} - void CarlaPlugin::idle() { if (! pData->enabled) @@ -1420,6 +1430,15 @@ void CarlaPlugin::idle() } } +void CarlaPlugin::showCustomUI(const bool yesNo) +{ + CARLA_ASSERT(false); + return; + + // unused + (void)yesNo; +} + // ------------------------------------------------------------------- // Plugin state @@ -1430,12 +1449,12 @@ void CarlaPlugin::reloadPrograms(const bool) // ------------------------------------------------------------------- // Plugin processing -void CarlaPlugin::activate() +void CarlaPlugin::activate() noexcept { CARLA_ASSERT(! pData->active); } -void CarlaPlugin::deactivate() +void CarlaPlugin::deactivate() noexcept { CARLA_ASSERT(pData->active); } @@ -1452,7 +1471,7 @@ void CarlaPlugin::offlineModeChanged(const bool) { } -bool CarlaPlugin::tryLock(const bool forcedOffline) +bool CarlaPlugin::tryLock(const bool forcedOffline) noexcept { if (forcedOffline) { @@ -1463,7 +1482,7 @@ bool CarlaPlugin::tryLock(const bool forcedOffline) return pData->masterMutex.tryLock(); } -void CarlaPlugin::unlock() +void CarlaPlugin::unlock() noexcept { pData->masterMutex.unlock(); } @@ -1486,7 +1505,7 @@ void CarlaPlugin::clearBuffers() // ------------------------------------------------------------------- // OSC stuff -void CarlaPlugin::registerToOscClient() +void CarlaPlugin::registerToOscClient() noexcept { #ifdef BUILD_BRIDGE if (! pData->engine->isOscBridgeRegistered()) @@ -1947,7 +1966,7 @@ void CarlaPlugin::postRtEventsRun() // ------------------------------------------------------------------- // Post-poned UI Stuff -void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) +void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) noexcept { CARLA_ASSERT(index < getParameterCount()); return; @@ -1957,7 +1976,7 @@ void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) (void)value; } -void CarlaPlugin::uiProgramChange(const uint32_t index) +void CarlaPlugin::uiProgramChange(const uint32_t index) noexcept { CARLA_ASSERT(index < getProgramCount()); return; @@ -1966,7 +1985,7 @@ void CarlaPlugin::uiProgramChange(const uint32_t index) (void)index; } -void CarlaPlugin::uiMidiProgramChange(const uint32_t index) +void CarlaPlugin::uiMidiProgramChange(const uint32_t index) noexcept { CARLA_ASSERT(index < getMidiProgramCount()); return; @@ -1975,7 +1994,7 @@ void CarlaPlugin::uiMidiProgramChange(const uint32_t index) (void)index; } -void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) +void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept { CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); CARLA_ASSERT(note < MAX_MIDI_NOTE); @@ -1988,7 +2007,7 @@ void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint (void)velo; } -void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note) +void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note) noexcept { CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); CARLA_ASSERT(note < MAX_MIDI_NOTE); @@ -2027,7 +2046,7 @@ CarlaEngineAudioPort* CarlaPlugin::getAudioOutPort(const uint32_t index) const n // ------------------------------------------------------------------- // Scoped Disabler -CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) +CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) noexcept : fPlugin(plugin) { CARLA_SAFE_ASSERT_RETURN(plugin != nullptr,); @@ -2044,7 +2063,7 @@ CarlaPlugin::ScopedDisabler::ScopedDisabler(CarlaPlugin* const plugin) plugin->pData->client->deactivate(); } -CarlaPlugin::ScopedDisabler::~ScopedDisabler() +CarlaPlugin::ScopedDisabler::~ScopedDisabler() noexcept { CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,); @@ -2059,7 +2078,7 @@ CarlaPlugin::ScopedDisabler::~ScopedDisabler() // ------------------------------------------------------------------- // Scoped Process Locker -CarlaPlugin::ScopedSingleProcessLocker::ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block) +CarlaPlugin::ScopedSingleProcessLocker::ScopedSingleProcessLocker(CarlaPlugin* const plugin, const bool block) noexcept : fPlugin(plugin), fBlock(block) { @@ -2073,7 +2092,7 @@ CarlaPlugin::ScopedSingleProcessLocker::ScopedSingleProcessLocker(CarlaPlugin* c plugin->pData->singleMutex.lock(); } -CarlaPlugin::ScopedSingleProcessLocker::~ScopedSingleProcessLocker() +CarlaPlugin::ScopedSingleProcessLocker::~ScopedSingleProcessLocker() noexcept { CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); CARLA_SAFE_ASSERT_RETURN(fPlugin->pData != nullptr,); @@ -2090,24 +2109,6 @@ CarlaPlugin::ScopedSingleProcessLocker::~ScopedSingleProcessLocker() fPlugin->pData->singleMutex.unlock(); } -// #ifdef BUILD_BRIDGE -// CarlaPlugin* newFailAsBridge(const CarlaPlugin::Initializer& init) -// { -// init.engine->setLastError("Can't use this in plugin bridges"); -// return nullptr; -// } -// -// CarlaPlugin* CarlaPlugin::newNative(const Initializer& init) { return newFailAsBridge(init); } -// CarlaPlugin* CarlaPlugin::newGIG(const Initializer& init, const bool) { return newFailAsBridge(init); } -// CarlaPlugin* CarlaPlugin::newSF2(const Initializer& init, const bool) { return newFailAsBridge(init); } -// CarlaPlugin* CarlaPlugin::newSFZ(const Initializer& init, const bool) { return newFailAsBridge(init); } -// -// # ifdef WANT_NATIVE -// size_t CarlaPlugin::getNativePluginCount() { return 0; } -// const PluginDescriptor* CarlaPlugin::getNativePluginDescriptor(const size_t) { return nullptr; } -// # endif -// #endif - // ------------------------------------------------------------------- CARLA_BACKEND_END_NAMESPACE diff --git a/source/backend/plugin/DssiPlugin.cpp b/source/backend/plugin/DssiPlugin.cpp index 3182bcd6c..2f290ba36 100644 --- a/source/backend/plugin/DssiPlugin.cpp +++ b/source/backend/plugin/DssiPlugin.cpp @@ -108,17 +108,17 @@ public: return PLUGIN_DSSI; } - PluginCategory getCategory() const override + PluginCategory getCategory() const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr, PLUGIN_CATEGORY_NONE); if (pData->audioIn.count == 0 && pData->audioOut.count > 0 && (fDssiDescriptor->run_synth != nullptr || fDssiDescriptor->run_multiple_synths != nullptr)) return PLUGIN_CATEGORY_SYNTH; - return getPluginCategoryFromName(pData->name); + return CarlaPlugin::getCategory(); } - long getUniqueId() const override + long getUniqueId() const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, 0); @@ -133,7 +133,7 @@ public: // ------------------------------------------------------------------- // Information (current data) - int32_t getChunkData(void** const dataPtr) const override + int32_t getChunkData(void** const dataPtr) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fUsesCustomData, 0); CARLA_SAFE_ASSERT_RETURN(pData->options & PLUGIN_OPTION_USE_CHUNKS, 0); @@ -143,18 +143,20 @@ public: CARLA_SAFE_ASSERT_RETURN(fHandle2 == nullptr, 0); CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0); + int ret = 0; unsigned long dataSize = 0; - if (fDssiDescriptor->get_custom_data(fHandle, dataPtr, &dataSize) != 0) - return static_cast(dataSize); + try { + ret = fDssiDescriptor->get_custom_data(fHandle, dataPtr, &dataSize); + } catch(...) {} - return 0; + return (ret != 0) ? static_cast(dataSize) : 0; } // ------------------------------------------------------------------- // Information (per-plugin data) - unsigned int getOptionsAvailable() const override + unsigned int getOptionsAvailable() const noexcept override { #ifdef __USE_GNU const bool isAmSynth(strcasestr(pData->filename, "amsynth")); @@ -196,7 +198,7 @@ public: return options; } - float getParameterValue(const uint32_t parameterId) const override + float getParameterValue(const uint32_t parameterId) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fParamBuffers != nullptr, 0.0f); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f); @@ -204,7 +206,7 @@ public: return fParamBuffers[parameterId]; } - void getLabel(char* const strBuf) const override + void getLabel(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -214,7 +216,7 @@ public: CarlaPlugin::getLabel(strBuf); } - void getMaker(char* const strBuf) const override + void getMaker(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -224,7 +226,7 @@ public: CarlaPlugin::getMaker(strBuf); } - void getCopyright(char* const strBuf) const override + void getCopyright(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -234,7 +236,7 @@ public: CarlaPlugin::getCopyright(strBuf); } - void getRealName(char* const strBuf) const override + void getRealName(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -244,7 +246,7 @@ public: CarlaPlugin::getRealName(strBuf); } - void getParameterName(const uint32_t parameterId, char* const strBuf) const override + void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); @@ -270,7 +272,7 @@ public: // ------------------------------------------------------------------- // Set data (plugin-specific stuff) - void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_SAFE_ASSERT_RETURN(fParamBuffers != nullptr,); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); @@ -331,7 +333,7 @@ public: fDssiDescriptor->set_custom_data(fHandle, chunk.data(), chunk.size()); } - void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fDssiDescriptor->select_program != nullptr,); @@ -345,10 +347,16 @@ public: const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback)); - fDssiDescriptor->select_program(fHandle, bank, program); + try { + fDssiDescriptor->select_program(fHandle, bank, program); + } catch(...) {} if (fHandle2 != nullptr) - fDssiDescriptor->select_program(fHandle2, bank, program); + { + try { + fDssiDescriptor->select_program(fHandle2, bank, program); + } catch(...) {} + } } CarlaPlugin::setMidiProgram(index, sendGui, sendOsc, sendCallback); @@ -916,31 +924,43 @@ public: // ------------------------------------------------------------------- // Plugin processing - void activate() override + void activate() noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); if (fDescriptor->activate != nullptr) { - fDescriptor->activate(fHandle); + try { + fDescriptor->activate(fHandle); + } catch(...) {} if (fHandle2 != nullptr) - fDescriptor->activate(fHandle2); + { + try { + fDescriptor->activate(fHandle2); + } catch(...) {} + } } } - void deactivate() override + void deactivate() noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); if (fDescriptor->deactivate != nullptr) { - fDescriptor->deactivate(fHandle); + try { + fDescriptor->deactivate(fHandle); + } catch(...) {} if (fHandle2 != nullptr) - fDescriptor->deactivate(fHandle2); + { + try { + fDescriptor->deactivate(fHandle2); + } catch(...) {} + } } } @@ -1692,7 +1712,7 @@ public: // ------------------------------------------------------------------- // Post-poned UI Stuff - void uiParameterChange(const uint32_t index, const float value) override + void uiParameterChange(const uint32_t index, const float value) noexcept override { CARLA_SAFE_ASSERT_RETURN(index < pData->param.count,); @@ -1702,7 +1722,7 @@ public: osc_send_control(pData->osc.data, pData->param.data[index].rindex, value); } - void uiMidiProgramChange(const uint32_t index) override + void uiMidiProgramChange(const uint32_t index) noexcept override { CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count,); @@ -1712,7 +1732,7 @@ public: osc_send_program(pData->osc.data, pData->midiprog.data[index].bank, pData->midiprog.data[index].program); } - void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) override + void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept override { CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,); CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,); @@ -1731,7 +1751,7 @@ public: #endif } - void uiNoteOff(const uint8_t channel, const uint8_t note) override + void uiNoteOff(const uint8_t channel, const uint8_t note) noexcept override { CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,); CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,); diff --git a/source/backend/plugin/FluidSynthPlugin.cpp b/source/backend/plugin/FluidSynthPlugin.cpp index 7951fe4b5..201cc5322 100644 --- a/source/backend/plugin/FluidSynthPlugin.cpp +++ b/source/backend/plugin/FluidSynthPlugin.cpp @@ -131,7 +131,7 @@ public: return PLUGIN_FILE_SF2; } - PluginCategory getCategory() const override + PluginCategory getCategory() const noexcept override { return PLUGIN_CATEGORY_SYNTH; } @@ -139,7 +139,7 @@ public: // ------------------------------------------------------------------- // Information (count) - uint32_t getParameterScalePointCount(const uint32_t parameterId) const override + uint32_t getParameterScalePointCount(const uint32_t parameterId) const noexcept override { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0); @@ -162,7 +162,7 @@ public: // ------------------------------------------------------------------- // Information (per-plugin data) - unsigned int getOptionsAvailable() const override + unsigned int getOptionsAvailable() const noexcept override { unsigned int options = 0x0; @@ -175,14 +175,14 @@ public: return options; } - float getParameterValue(const uint32_t parameterId) const override + float getParameterValue(const uint32_t parameterId) const noexcept override { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f); return fParamBuffers[parameterId]; } - float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const override + 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); @@ -218,7 +218,7 @@ public: } } - void getLabel(char* const strBuf) const override + void getLabel(char* const strBuf) const noexcept override { if (fLabel != nullptr) std::strncpy(strBuf, fLabel, STR_MAX); @@ -226,22 +226,22 @@ public: CarlaPlugin::getLabel(strBuf); } - void getMaker(char* const strBuf) const override + void getMaker(char* const strBuf) const noexcept override { std::strncpy(strBuf, "FluidSynth SF2 engine", STR_MAX); } - void getCopyright(char* const strBuf) const override + void getCopyright(char* const strBuf) const noexcept override { std::strncpy(strBuf, "GNU GPL v2+", STR_MAX); } - void getRealName(char* const strBuf) const override + void getRealName(char* const strBuf) const noexcept override { getLabel(strBuf); } - void getParameterName(const uint32_t parameterId, char* const strBuf) const override + void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); @@ -295,7 +295,7 @@ public: } } - void getParameterUnit(const uint32_t parameterId, char* const strBuf) const override + void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); @@ -313,7 +313,7 @@ public: } } - void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const override + void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId),); @@ -368,7 +368,7 @@ public: // ------------------------------------------------------------------- // Set data (internal stuff) - void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) override + void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept override { if (channel < MAX_MIDI_CHANNELS) pData->midiprog.current = fCurMidiProgs[channel]; @@ -379,7 +379,7 @@ public: // ------------------------------------------------------------------- // Set data (plugin-specific stuff) - void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); @@ -392,18 +392,24 @@ public: switch (parameterId) { case FluidSynthReverbOnOff: - fluid_synth_set_reverb_on(fSynth, (fixedValue > 0.5f) ? 1 : 0); + try { + fluid_synth_set_reverb_on(fSynth, (fixedValue > 0.5f) ? 1 : 0); + } catch(...) {} break; case FluidSynthReverbRoomSize: case FluidSynthReverbDamp: case FluidSynthReverbLevel: case FluidSynthReverbWidth: - fluid_synth_set_reverb(fSynth, fParamBuffers[FluidSynthReverbRoomSize], fParamBuffers[FluidSynthReverbDamp], fParamBuffers[FluidSynthReverbWidth], fParamBuffers[FluidSynthReverbLevel]); + try { + fluid_synth_set_reverb(fSynth, fParamBuffers[FluidSynthReverbRoomSize], fParamBuffers[FluidSynthReverbDamp], fParamBuffers[FluidSynthReverbWidth], fParamBuffers[FluidSynthReverbLevel]); + } catch(...) {} break; case FluidSynthChorusOnOff: - fluid_synth_set_chorus_on(fSynth, (value > 0.5f) ? 1 : 0); + try { + fluid_synth_set_chorus_on(fSynth, (value > 0.5f) ? 1 : 0); + } catch(...) {} break; case FluidSynthChorusNr: @@ -411,16 +417,27 @@ public: case FluidSynthChorusSpeedHz: case FluidSynthChorusDepthMs: case FluidSynthChorusType: - fluid_synth_set_chorus(fSynth, (int)fParamBuffers[FluidSynthChorusNr], fParamBuffers[FluidSynthChorusLevel], fParamBuffers[FluidSynthChorusSpeedHz], fParamBuffers[FluidSynthChorusDepthMs], (int)fParamBuffers[FluidSynthChorusType]); + try { + fluid_synth_set_chorus(fSynth, (int)fParamBuffers[FluidSynthChorusNr], fParamBuffers[FluidSynthChorusLevel], fParamBuffers[FluidSynthChorusSpeedHz], fParamBuffers[FluidSynthChorusDepthMs], (int)fParamBuffers[FluidSynthChorusType]); + } catch(...) {} break; case FluidSynthPolyphony: - fluid_synth_set_polyphony(fSynth, (int)value); + try { + fluid_synth_set_polyphony(fSynth, (int)value); + } catch(...) {} break; case FluidSynthInterpolation: for (int i=0; i < MAX_MIDI_CHANNELS; ++i) - fluid_synth_set_interp_method(fSynth, i, (int)value); + { + try { + fluid_synth_set_interp_method(fSynth, i, (int)value); + } + catch(...) { + break; + } + } break; default: @@ -484,7 +501,7 @@ public: CarlaPlugin::setCustomData(type, key, value, sendGui); } - void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_SAFE_ASSERT_RETURN(fSynth != nullptr,); CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast(pData->midiprog.count),); @@ -496,7 +513,10 @@ public: //const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback)); - fluid_synth_program_select(fSynth, pData->ctrlChannel, fSynthId, bank, program); + try { + fluid_synth_program_select(fSynth, pData->ctrlChannel, fSynthId, bank, program); + } catch(...) {} + fCurMidiProgs[pData->ctrlChannel] = index; } diff --git a/source/backend/plugin/LadspaPlugin.cpp b/source/backend/plugin/LadspaPlugin.cpp index aa8f0f62c..4f24394d1 100644 --- a/source/backend/plugin/LadspaPlugin.cpp +++ b/source/backend/plugin/LadspaPlugin.cpp @@ -92,7 +92,7 @@ public: return PLUGIN_LADSPA; } - PluginCategory getCategory() const override + PluginCategory getCategory() const noexcept override { if (fRdfDescriptor != nullptr) { @@ -127,10 +127,10 @@ public: return PLUGIN_CATEGORY_SYNTH; } - return getPluginCategoryFromName(pData->name); + return CarlaPlugin::getCategory(); } - long getUniqueId() const override + long getUniqueId() const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, 0); @@ -140,7 +140,7 @@ public: // ------------------------------------------------------------------- // Information (count) - uint32_t getParameterScalePointCount(const uint32_t parameterId) const override + uint32_t getParameterScalePointCount(const uint32_t parameterId) const noexcept override { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0); @@ -163,7 +163,7 @@ public: // ------------------------------------------------------------------- // Information (per-plugin data) - unsigned int getOptionsAvailable() const override + unsigned int getOptionsAvailable() const noexcept override { #ifdef __USE_GNU const bool isDssiVst(strcasestr(pData->filename, "dssi-vst")); @@ -189,7 +189,7 @@ public: return options; } - float getParameterValue(const uint32_t parameterId) const override + float getParameterValue(const uint32_t parameterId) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fParamBuffers != nullptr, 0.0f); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f); @@ -197,7 +197,7 @@ public: return fParamBuffers[parameterId]; } - float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const override + float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr, 0.0f); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f); @@ -219,7 +219,7 @@ public: return 0.0f; } - void getLabel(char* const strBuf) const override + void getLabel(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -229,7 +229,7 @@ public: CarlaPlugin::getLabel(strBuf); } - void getMaker(char* const strBuf) const override + void getMaker(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -241,7 +241,7 @@ public: CarlaPlugin::getMaker(strBuf); } - void getCopyright(char* const strBuf) const override + void getCopyright(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -251,7 +251,7 @@ public: CarlaPlugin::getCopyright(strBuf); } - void getRealName(char* const strBuf) const override + void getRealName(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -263,7 +263,7 @@ public: CarlaPlugin::getRealName(strBuf); } - void getParameterName(const uint32_t parameterId, char* const strBuf) const override + void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); @@ -276,7 +276,7 @@ public: CarlaPlugin::getParameterName(parameterId, strBuf); } - void getParameterSymbol(const uint32_t parameterId, char* const strBuf) const override + void getParameterSymbol(const uint32_t parameterId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); @@ -296,7 +296,7 @@ public: CarlaPlugin::getParameterSymbol(parameterId, strBuf); } - void getParameterUnit(const uint32_t parameterId, char* const strBuf) const override + void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); @@ -335,7 +335,7 @@ public: CarlaPlugin::getParameterUnit(parameterId, strBuf); } - void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const override + void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); @@ -375,7 +375,7 @@ public: // ------------------------------------------------------------------- // Set data (plugin-specific stuff) - void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_SAFE_ASSERT_RETURN(fParamBuffers != nullptr,); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); @@ -821,31 +821,43 @@ public: // ------------------------------------------------------------------- // Plugin processing - void activate() override + void activate() noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); if (fDescriptor->activate != nullptr) { - fDescriptor->activate(fHandle); + try { + fDescriptor->activate(fHandle); + } catch(...) {} if (fHandle2 != nullptr) - fDescriptor->activate(fHandle2); + { + try { + fDescriptor->activate(fHandle2); + } catch(...) {} + } } } - void deactivate() override + void deactivate() noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); if (fDescriptor->deactivate != nullptr) { - fDescriptor->deactivate(fHandle); + try { + fDescriptor->deactivate(fHandle); + } catch(...) {} if (fHandle2 != nullptr) - fDescriptor->deactivate(fHandle2); + { + try { + fDescriptor->deactivate(fHandle2); + } catch(...) {} + } } } diff --git a/source/backend/plugin/LinuxSamplerPlugin.cpp b/source/backend/plugin/LinuxSamplerPlugin.cpp index be3a4a22d..e6856cb5e 100644 --- a/source/backend/plugin/LinuxSamplerPlugin.cpp +++ b/source/backend/plugin/LinuxSamplerPlugin.cpp @@ -295,7 +295,7 @@ public: return getPluginTypeFromString(fFormat); } - PluginCategory getCategory() const override + PluginCategory getCategory() const noexcept override { return PLUGIN_CATEGORY_SYNTH; } @@ -313,7 +313,7 @@ public: // ------------------------------------------------------------------- // Information (per-plugin data) - unsigned int getOptionsAvailable() const override + unsigned int getOptionsAvailable() const noexcept override { unsigned int options = 0x0; @@ -326,7 +326,7 @@ public: return options; } - void getLabel(char* const strBuf) const override + void getLabel(char* const strBuf) const noexcept override { if (fLabel != nullptr) std::strncpy(strBuf, fLabel, STR_MAX); @@ -334,7 +334,7 @@ public: CarlaPlugin::getLabel(strBuf); } - void getMaker(char* const strBuf) const override + void getMaker(char* const strBuf) const noexcept override { if (fMaker != nullptr) std::strncpy(strBuf, fMaker, STR_MAX); @@ -342,12 +342,12 @@ public: CarlaPlugin::getMaker(strBuf); } - void getCopyright(char* const strBuf) const override + void getCopyright(char* const strBuf) const noexcept override { getMaker(strBuf); } - void getRealName(char* const strBuf) const override + void getRealName(char* const strBuf) const noexcept override { if (fRealName != nullptr) std::strncpy(strBuf, fRealName, STR_MAX); @@ -372,7 +372,7 @@ public: // ------------------------------------------------------------------- // Set data (internal stuff) - void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) override + void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept override { if (channel < MAX_MIDI_CHANNELS) pData->midiprog.current = fCurMidiProgs[channel]; @@ -445,7 +445,7 @@ public: CarlaPlugin::setCustomData(type, key, value, sendGui); } - void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast(pData->midiprog.count),); @@ -466,7 +466,9 @@ public: } else*/ { - fInstrument->LoadInstrumentInBackground(fInstrumentIds[rIndex], engineChannel); + try { + fInstrument->LoadInstrumentInBackground(fInstrumentIds[rIndex], engineChannel); + } catch(...) {} } fCurMidiProgs[pData->ctrlChannel] = index; diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index dfb7ead99..4165cf649 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -40,313 +40,12 @@ CARLA_BACKEND_START_NAMESPACE } #endif -#if 0 -const unsigned int MAX_EVENT_BUFFER = 8192; // 0x2000 -#endif - -#if 0 -// Extra Plugin Hints -const unsigned int PLUGIN_HAS_EXTENSION_OPTIONS = 0x1000; -const unsigned int PLUGIN_HAS_EXTENSION_PROGRAMS = 0x2000; -const unsigned int PLUGIN_HAS_EXTENSION_STATE = 0x4000; -const unsigned int PLUGIN_HAS_EXTENSION_WORKER = 0x8000; -#endif - // Extra Parameter Hints const unsigned int PARAMETER_IS_STRICT_BOUNDS = 0x1000; const unsigned int PARAMETER_IS_TRIGGER = 0x2000; -#if 0 -// LV2 Event Data/Types -const unsigned int CARLA_EVENT_DATA_ATOM = 0x01; -const unsigned int CARLA_EVENT_DATA_EVENT = 0x02; -const unsigned int CARLA_EVENT_DATA_MIDI_LL = 0x04; -const unsigned int CARLA_EVENT_TYPE_MESSAGE = 0x10; // unused -const unsigned int CARLA_EVENT_TYPE_MIDI = 0x20; -const unsigned int CARLA_EVENT_TYPE_TIME = 0x40; -#endif - -#if 0 -// LV2 URI Map Ids -const uint32_t CARLA_URI_MAP_ID_NULL = 0; -const uint32_t CARLA_URI_MAP_ID_ATOM_BLANK = 1; -const uint32_t CARLA_URI_MAP_ID_ATOM_BOOL = 2; -const uint32_t CARLA_URI_MAP_ID_ATOM_CHUNK = 3; -const uint32_t CARLA_URI_MAP_ID_ATOM_DOUBLE = 4; -const uint32_t CARLA_URI_MAP_ID_ATOM_FLOAT = 5; -const uint32_t CARLA_URI_MAP_ID_ATOM_INT = 6; -const uint32_t CARLA_URI_MAP_ID_ATOM_LITERAL = 7; -const uint32_t CARLA_URI_MAP_ID_ATOM_LONG = 8; -const uint32_t CARLA_URI_MAP_ID_ATOM_PATH = 9; -const uint32_t CARLA_URI_MAP_ID_ATOM_PROPERTY = 10; -const uint32_t CARLA_URI_MAP_ID_ATOM_RESOURCE = 11; -const uint32_t CARLA_URI_MAP_ID_ATOM_SEQUENCE = 12; -const uint32_t CARLA_URI_MAP_ID_ATOM_STRING = 13; -const uint32_t CARLA_URI_MAP_ID_ATOM_TUPLE = 14; -const uint32_t CARLA_URI_MAP_ID_ATOM_URI = 15; -const uint32_t CARLA_URI_MAP_ID_ATOM_URID = 16; -const uint32_t CARLA_URI_MAP_ID_ATOM_VECTOR = 17; -const uint32_t CARLA_URI_MAP_ID_ATOM_TRANSFER_ATOM = 18; -const uint32_t CARLA_URI_MAP_ID_ATOM_TRANSFER_EVENT = 19; -const uint32_t CARLA_URI_MAP_ID_BUF_MAX_LENGTH = 20; -const uint32_t CARLA_URI_MAP_ID_BUF_MIN_LENGTH = 21; -const uint32_t CARLA_URI_MAP_ID_BUF_SEQUENCE_SIZE = 22; -const uint32_t CARLA_URI_MAP_ID_LOG_ERROR = 23; -const uint32_t CARLA_URI_MAP_ID_LOG_NOTE = 24; -const uint32_t CARLA_URI_MAP_ID_LOG_TRACE = 25; -const uint32_t CARLA_URI_MAP_ID_LOG_WARNING = 26; -const uint32_t CARLA_URI_MAP_ID_TIME_POSITION = 27; // base type -const uint32_t CARLA_URI_MAP_ID_TIME_BAR = 28; // values -const uint32_t CARLA_URI_MAP_ID_TIME_BAR_BEAT = 29; -const uint32_t CARLA_URI_MAP_ID_TIME_BEAT = 30; -const uint32_t CARLA_URI_MAP_ID_TIME_BEAT_UNIT = 31; -const uint32_t CARLA_URI_MAP_ID_TIME_BEATS_PER_BAR = 32; -const uint32_t CARLA_URI_MAP_ID_TIME_BEATS_PER_MINUTE = 33; -const uint32_t CARLA_URI_MAP_ID_TIME_FRAME = 34; -const uint32_t CARLA_URI_MAP_ID_TIME_FRAMES_PER_SECOND = 35; -const uint32_t CARLA_URI_MAP_ID_TIME_SPEED = 36; -const uint32_t CARLA_URI_MAP_ID_MIDI_EVENT = 37; -const uint32_t CARLA_URI_MAP_ID_PARAM_SAMPLE_RATE = 38; -const uint32_t CARLA_URI_MAP_ID_COUNT = 39; -#endif - -#if 0 // LV2 Feature Ids -const uint32_t kFeatureIdBufSizeBounded = 0; -const uint32_t kFeatureIdBufSizeFixed = 1; -const uint32_t kFeatureIdBufSizePowerOf2 = 2; -const uint32_t kFeatureIdEvent = 3; -const uint32_t kFeatureIdHardRtCapable = 4; -const uint32_t kFeatureIdInPlaceBroken = 5; -const uint32_t kFeatureIdIsLive = 6; -const uint32_t kFeatureIdLogs = 7; -const uint32_t kFeatureIdOptions = 8; -const uint32_t kFeatureIdPrograms = 9; -const uint32_t kFeatureIdRtMemPool = 10; -const uint32_t kFeatureIdStateMakePath = 11; -const uint32_t kFeatureIdStateMapPath = 12; -const uint32_t kFeatureIdStrictBounds = 13; -const uint32_t kFeatureIdUriMap = 14; -const uint32_t kFeatureIdUridMap = 15; -const uint32_t kFeatureIdUridUnmap = 16; -const uint32_t kFeatureIdWorker = 17; -const uint32_t kFeatureIdUiDataAccess = 18; -const uint32_t kFeatureIdUiInstanceAccess = 19; -const uint32_t kFeatureIdUiIdle = 20; -const uint32_t kFeatureIdUiFixedSize = 21; -const uint32_t kFeatureIdUiMakeResident = 22; -const uint32_t kFeatureIdUiNoUserResize = 23; -const uint32_t kFeatureIdUiParent = 24; -const uint32_t kFeatureIdUiPortMap = 25; -const uint32_t kFeatureIdUiPortSubscribe = 26; -const uint32_t kFeatureIdUiResize = 27; -const uint32_t kFeatureIdUiTouch = 28; -const uint32_t kFeatureIdExternalUi = 29; -const uint32_t kFeatureIdExternalUiOld = 30; -#endif -const uint32_t kFeatureCount = 0 /*31*/; - -#if 0 -enum Lv2PluginGuiType { - PLUGIN_UI_NULL, - PLUGIN_UI_OSC, - PLUGIN_UI_PARENT, - PLUGIN_UI_EXTERNAL -}; -#endif - -#if 0 -struct Lv2EventData { - uint32_t type; - uint32_t rindex; - CarlaEngineEventPort* port; - union { - LV2_Atom_Buffer* atom; - LV2_Event_Buffer* event; - LV2_MIDI* midi; - void* _ptr; // value checking - }; - - Lv2EventData() - : type(0x0), - rindex(0), - port(nullptr), - _ptr(nullptr) {} - - ~Lv2EventData() - { - if (port != nullptr) - { - delete port; - port = nullptr; - } - - const ScopedValueSetter zeroType(type, type, 0x0); - - if (type & CARLA_EVENT_DATA_ATOM) - { - CARLA_SAFE_ASSERT_RETURN(atom != nullptr,); - - std::free(atom); - atom = nullptr; - } - else if (type & CARLA_EVENT_DATA_EVENT) - { - CARLA_SAFE_ASSERT_RETURN(event != nullptr,); - - std::free(event); - event = nullptr; - } - else if (type & CARLA_EVENT_DATA_MIDI_LL) - { - CARLA_SAFE_ASSERT_RETURN(midi != nullptr,) - CARLA_SAFE_ASSERT_RETURN(midi->data != nullptr,); - - delete[] midi->data; - midi->data = nullptr; - - delete midi; - midi = nullptr; - } - - CARLA_ASSERT(_ptr == nullptr); - } - - CARLA_DECLARE_NON_COPY_STRUCT(Lv2EventData) -}; - -struct Lv2PluginEventData { - uint32_t count; - Lv2EventData* data; - Lv2EventData* ctrl; // default port, either this->data[x] or pData->portIn/Out - uint32_t ctrlIndex; - - Lv2PluginEventData() - : count(0), - data(nullptr), - ctrl(nullptr), - ctrlIndex(0) {} - - ~Lv2PluginEventData() - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT(data == nullptr); - CARLA_ASSERT(ctrl == nullptr); - CARLA_ASSERT_INT(ctrlIndex == 0, ctrlIndex); - } - - void createNew(const uint32_t newCount) - { - CARLA_ASSERT_INT(count == 0, count); - CARLA_ASSERT(data == nullptr); - CARLA_ASSERT(ctrl == nullptr); - CARLA_ASSERT_INT(ctrlIndex == 0, ctrlIndex); - CARLA_ASSERT_INT(newCount > 0, newCount); - - if (data != nullptr || newCount == 0) - return; - - data = new Lv2EventData[newCount]; - count = newCount; - } - - void clear() - { - if (data != nullptr) - { - for (uint32_t i=0; i < count; ++i) - { - if (data[i].port != nullptr && ctrl != nullptr && data[i].port == ctrl->port) - data[i].port = nullptr; - } - - delete[] data; - data = nullptr; - } - - count = 0; - - ctrl = nullptr; - ctrlIndex = 0; - } - - void initBuffers() - { - for (uint32_t i=0; i < count; ++i) - { - if (data[i].port != nullptr && (ctrl == nullptr || data[i].port != ctrl->port)) - data[i].port->initBuffer(); - } - } - - CARLA_DECLARE_NON_COPY_STRUCT(Lv2PluginEventData) -}; - -struct Lv2PluginOptions { - enum OptIndex { - MaxBlockLenth = 0, - MinBlockLenth, - SequenceSize, - SampleRate, - Null - }; - - int maxBufferSize; - int minBufferSize; - int sequenceSize; - double sampleRate; - LV2_Options_Option opts[5]; - - Lv2PluginOptions() - : maxBufferSize(0), - minBufferSize(0), - sequenceSize(MAX_EVENT_BUFFER), - sampleRate(0.0) - { - LV2_Options_Option& optMaxBlockLenth(opts[MaxBlockLenth]); - optMaxBlockLenth.context = LV2_OPTIONS_INSTANCE; - optMaxBlockLenth.subject = 0; - optMaxBlockLenth.key = CARLA_URI_MAP_ID_BUF_MAX_LENGTH; - optMaxBlockLenth.size = sizeof(int); - optMaxBlockLenth.type = CARLA_URI_MAP_ID_ATOM_INT; - optMaxBlockLenth.value = &maxBufferSize; - - LV2_Options_Option& optMinBlockLenth(opts[MinBlockLenth]); - optMinBlockLenth.context = LV2_OPTIONS_INSTANCE; - optMinBlockLenth.subject = 0; - optMinBlockLenth.key = CARLA_URI_MAP_ID_BUF_MIN_LENGTH; - optMinBlockLenth.size = sizeof(int); - optMinBlockLenth.type = CARLA_URI_MAP_ID_ATOM_INT; - optMinBlockLenth.value = &minBufferSize; - - LV2_Options_Option& optSequenceSize(opts[SequenceSize]); - optSequenceSize.context = LV2_OPTIONS_INSTANCE; - optSequenceSize.subject = 0; - optSequenceSize.key = CARLA_URI_MAP_ID_BUF_SEQUENCE_SIZE; - optSequenceSize.size = sizeof(int); - optSequenceSize.type = CARLA_URI_MAP_ID_ATOM_INT; - optSequenceSize.value = &sequenceSize; - - LV2_Options_Option& optSampleRate(opts[SampleRate]); - optSampleRate.context = LV2_OPTIONS_INSTANCE; - optSampleRate.subject = 0; - optSampleRate.key = CARLA_URI_MAP_ID_PARAM_SAMPLE_RATE; - optSampleRate.size = sizeof(double); - optSampleRate.type = CARLA_URI_MAP_ID_ATOM_DOUBLE; - optSampleRate.value = &sampleRate; - - LV2_Options_Option& optNull(opts[Null]); - optNull.context = LV2_OPTIONS_INSTANCE; - optNull.subject = 0; - optNull.key = CARLA_URI_MAP_ID_NULL; - optNull.size = 0; - optNull.type = CARLA_URI_MAP_ID_NULL; - optNull.value = nullptr; - } - - CARLA_DECLARE_NON_COPY_STRUCT(Lv2PluginOptions) -}; -#endif +const uint32_t kFeatureCount = 0; // ----------------------------------------------------- @@ -368,74 +67,12 @@ public: carla_fill(fFeatures, kFeatureCount+1, nullptr); pData->osc.thread.setMode(CarlaPluginThread::PLUGIN_THREAD_LV2_GUI); - -#if 0 - for (uint32_t i=0; i < CARLA_URI_MAP_ID_COUNT; ++i) - fCustomURIDs.append(nullptr); - - fAtomForge.Blank = CARLA_URI_MAP_ID_ATOM_BLANK; - fAtomForge.Bool = CARLA_URI_MAP_ID_ATOM_BOOL; - fAtomForge.Chunk = CARLA_URI_MAP_ID_ATOM_CHUNK; - fAtomForge.Double = CARLA_URI_MAP_ID_ATOM_DOUBLE; - fAtomForge.Float = CARLA_URI_MAP_ID_ATOM_FLOAT; - fAtomForge.Int = CARLA_URI_MAP_ID_ATOM_INT; - fAtomForge.Literal = CARLA_URI_MAP_ID_ATOM_LITERAL; - fAtomForge.Long = CARLA_URI_MAP_ID_ATOM_LONG; - fAtomForge.Path = CARLA_URI_MAP_ID_ATOM_PATH; - fAtomForge.Property = CARLA_URI_MAP_ID_ATOM_PROPERTY; - fAtomForge.Resource = CARLA_URI_MAP_ID_ATOM_RESOURCE; - fAtomForge.Sequence = CARLA_URI_MAP_ID_ATOM_SEQUENCE; - fAtomForge.String = CARLA_URI_MAP_ID_ATOM_STRING; - fAtomForge.Tuple = CARLA_URI_MAP_ID_ATOM_TUPLE; - fAtomForge.URI = CARLA_URI_MAP_ID_ATOM_URI; - fAtomForge.URID = CARLA_URI_MAP_ID_ATOM_URID; - fAtomForge.Vector = CARLA_URI_MAP_ID_ATOM_VECTOR; -#endif } ~Lv2Plugin() override { carla_debug("Lv2Plugin::~Lv2Plugin()"); -#if 0 - // close UI - if (fUi.type != PLUGIN_UI_NULL) - { - showCustomUI(false); - - if (fUi.type == PLUGIN_UI_OSC) - { - pData->osc.thread.stop(pData->engine->getOptions().uiBridgesTimeout); - } - else - { - if (fFeatures[kFeatureIdUiDataAccess] != nullptr && fFeatures[kFeatureIdUiDataAccess]->data != nullptr) - delete (LV2_Extension_Data_Feature*)fFeatures[kFeatureIdUiDataAccess]->data; - - if (fFeatures[kFeatureIdUiPortMap] != nullptr && fFeatures[kFeatureIdUiPortMap]->data != nullptr) - delete (LV2UI_Port_Map*)fFeatures[kFeatureIdUiPortMap]->data; - - if (fFeatures[kFeatureIdUiResize] != nullptr && fFeatures[kFeatureIdUiResize]->data != nullptr) - delete (LV2UI_Resize*)fFeatures[kFeatureIdUiResize]->data; - - if (fFeatures[kFeatureIdExternalUi] != nullptr && fFeatures[kFeatureIdExternalUi]->data != nullptr) - { - const LV2_External_UI_Host* const uiHost((const LV2_External_UI_Host*)fFeatures[kFeatureIdExternalUi]->data); - - if (uiHost->plugin_human_id != nullptr) - delete[] uiHost->plugin_human_id; - - delete uiHost; - } - - fUi.descriptor = nullptr; - pData->uiLibClose(); - } - - fUi.rdfDescriptor = nullptr; - } -#endif - pData->singleMutex.lock(); pData->masterMutex.lock(); @@ -469,62 +106,6 @@ public: fRdfDescriptor = nullptr; } -#if 0 - if (fFeatures[kFeatureIdEvent] != nullptr && fFeatures[kFeatureIdEvent]->data != nullptr) - delete (LV2_Event_Feature*)fFeatures[kFeatureIdEvent]->data; - - if (fFeatures[kFeatureIdLogs] != nullptr && fFeatures[kFeatureIdLogs]->data != nullptr) - delete (LV2_Log_Log*)fFeatures[kFeatureIdLogs]->data; - - if (fFeatures[kFeatureIdStateMakePath] != nullptr && fFeatures[kFeatureIdStateMakePath]->data != nullptr) - delete (LV2_State_Make_Path*)fFeatures[kFeatureIdStateMakePath]->data; - - if (fFeatures[kFeatureIdStateMapPath] != nullptr && fFeatures[kFeatureIdStateMapPath]->data != nullptr) - delete (LV2_State_Map_Path*)fFeatures[kFeatureIdStateMapPath]->data; - - if (fFeatures[kFeatureIdPrograms] != nullptr && fFeatures[kFeatureIdPrograms]->data != nullptr) - delete (LV2_Programs_Host*)fFeatures[kFeatureIdPrograms]->data; - - if (fFeatures[kFeatureIdRtMemPool] != nullptr && fFeatures[kFeatureIdRtMemPool]->data != nullptr) - delete (LV2_RtMemPool_Pool*)fFeatures[kFeatureIdRtMemPool]->data; - - if (fFeatures[kFeatureIdUriMap] != nullptr && fFeatures[kFeatureIdUriMap]->data != nullptr) - delete (LV2_URI_Map_Feature*)fFeatures[kFeatureIdUriMap]->data; - - if (fFeatures[kFeatureIdUridMap] != nullptr && fFeatures[kFeatureIdUridMap]->data != nullptr) - delete (LV2_URID_Map*)fFeatures[kFeatureIdUridMap]->data; - - if (fFeatures[kFeatureIdUridUnmap] != nullptr && fFeatures[kFeatureIdUridUnmap]->data != nullptr) - delete (LV2_URID_Unmap*)fFeatures[kFeatureIdUridUnmap]->data; - - if (fFeatures[kFeatureIdWorker] != nullptr && fFeatures[kFeatureIdWorker]->data != nullptr) - delete (LV2_Worker_Schedule*)fFeatures[kFeatureIdWorker]->data; -#endif - -#if 0 - for (uint32_t i=0; i < kFeatureCount; ++i) - { - if (fFeatures[i] != nullptr) - { - delete fFeatures[i]; - fFeatures[i] = nullptr; - } - } - - for (List::Itenerator it = fCustomURIDs.begin(); it.valid(); it.next()) - { - const char*& uri(*it); - - if (uri != nullptr) - { - delete[] uri; - uri = nullptr; - } - } - - fCustomURIDs.clear(); -#endif - clearBuffers(); } @@ -536,9 +117,9 @@ public: return PLUGIN_LV2; } - PluginCategory getCategory() const override + PluginCategory getCategory() const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr, CarlaPlugin::getCategory()); const LV2_Property cat1(fRdfDescriptor->Type[0]); const LV2_Property cat2(fRdfDescriptor->Type[1]); @@ -568,12 +149,12 @@ public: if (LV2_IS_UTILITY(cat1, cat2)) return PLUGIN_CATEGORY_UTILITY; - return getPluginCategoryFromName(pData->name); + return CarlaPlugin::getCategory(); } - long getUniqueId() const override + long getUniqueId() const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr, 0); return fRdfDescriptor->UniqueID; } @@ -583,7 +164,7 @@ public: uint32_t getMidiInCount() const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr, 0); uint32_t count = 0; @@ -600,7 +181,7 @@ public: uint32_t getMidiOutCount() const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr, 0); uint32_t count = 0; @@ -615,10 +196,10 @@ public: return count; } - uint32_t getParameterScalePointCount(const uint32_t parameterId) const override + uint32_t getParameterScalePointCount(const uint32_t parameterId) const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr, 0); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0); const int32_t rindex(pData->param.data[parameterId].rindex); @@ -639,7 +220,7 @@ public: // ------------------------------------------------------------------- // Information (per-plugin data) - unsigned int getOptionsAvailable() const override + unsigned int getOptionsAvailable() const noexcept override { const uint32_t hasMidiIn(getMidiInCount() > 0); @@ -670,10 +251,10 @@ public: return options; } - float getParameterValue(const uint32_t parameterId) const override + float getParameterValue(const uint32_t parameterId) const noexcept override { - CARLA_ASSERT(fParamBuffers != nullptr); - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(fParamBuffers != nullptr, 0.0f); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f); if (pData->param.data[parameterId].hints & PARAMETER_IS_STRICT_BOUNDS) pData->param.ranges[parameterId].fixValue(fParamBuffers[parameterId]); @@ -681,11 +262,11 @@ public: return fParamBuffers[parameterId]; } - float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const override + float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); - CARLA_ASSERT(parameterId < pData->param.count); - CARLA_ASSERT(scalePointId < getParameterScalePointCount(parameterId)); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr, 0.0f); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f); + CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f); const int32_t rindex(pData->param.data[parameterId].rindex); @@ -703,10 +284,10 @@ public: return 0.0f; } - void getLabel(char* const strBuf) const override + void getLabel(char* const strBuf) const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); - CARLA_ASSERT(fRdfDescriptor->URI != nullptr); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor->URI != nullptr,); if (fRdfDescriptor->URI != nullptr) std::strncpy(strBuf, fRdfDescriptor->URI, STR_MAX); @@ -714,9 +295,9 @@ public: CarlaPlugin::getLabel(strBuf); } - void getMaker(char* const strBuf) const override + void getMaker(char* const strBuf) const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); if (fRdfDescriptor->Author != nullptr) std::strncpy(strBuf, fRdfDescriptor->Author, STR_MAX); @@ -724,9 +305,9 @@ public: CarlaPlugin::getMaker(strBuf); } - void getCopyright(char* const strBuf) const override + void getCopyright(char* const strBuf) const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); if (fRdfDescriptor->License != nullptr) std::strncpy(strBuf, fRdfDescriptor->License, STR_MAX); @@ -734,9 +315,9 @@ public: CarlaPlugin::getCopyright(strBuf); } - void getRealName(char* const strBuf) const override + void getRealName(char* const strBuf) const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); if (fRdfDescriptor->Name != nullptr) std::strncpy(strBuf, fRdfDescriptor->Name, STR_MAX); @@ -744,10 +325,10 @@ public: CarlaPlugin::getRealName(strBuf); } - void getParameterName(const uint32_t parameterId, char* const strBuf) const override + void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); const int32_t rindex(pData->param.data[parameterId].rindex); @@ -757,10 +338,10 @@ public: CarlaPlugin::getParameterName(parameterId, strBuf); } - void getParameterSymbol(const uint32_t parameterId, char* const strBuf) const override + void getParameterSymbol(const uint32_t parameterId, char* const strBuf) const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); const int32_t rindex(pData->param.data[parameterId].rindex); @@ -770,10 +351,10 @@ public: CarlaPlugin::getParameterSymbol(parameterId, strBuf); } - void getParameterUnit(const uint32_t parameterId, char* const strBuf) const override + void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); const int32_t rindex(pData->param.data[parameterId].rindex); @@ -869,11 +450,11 @@ public: CarlaPlugin::getParameterUnit(parameterId, strBuf); } - void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const override + void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept override { - CARLA_ASSERT(fRdfDescriptor != nullptr); - CARLA_ASSERT(parameterId < pData->param.count); - CARLA_ASSERT(scalePointId < getParameterScalePointCount(parameterId)); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); + CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId),); const int32_t rindex(pData->param.data[parameterId].rindex); @@ -896,53 +477,12 @@ public: CarlaPlugin::getParameterScalePointLabel(parameterId, scalePointId, strBuf); } -#if 0 - // ------------------------------------------------------------------- - // Set data (state) - - void prepareForSave() override - { - CARLA_ASSERT(fHandle != nullptr); - - if (fExt.state != nullptr && fExt.state->save != nullptr) - { - fExt.state->save(fHandle, carla_lv2_state_store, this, LV2_STATE_IS_POD, fFeatures); - - if (fHandle2 != nullptr) - fExt.state->save(fHandle2, carla_lv2_state_store, this, LV2_STATE_IS_POD, fFeatures); - } - } - - // ------------------------------------------------------------------- - // Set data (internal stuff) - - void setName(const char* const newName) override - { - CarlaPlugin::setName(newName); - - //QString guiTitle(QString("%1 (GUI)").arg((const char*)pData->name)); - - //if (pData->gui != nullptr) - //pData->gui->setWindowTitle(guiTitle); - - if (fFeatures[kFeatureIdExternalUi] != nullptr && fFeatures[kFeatureIdExternalUi]->data != nullptr) - { - LV2_External_UI_Host* const uiHost((LV2_External_UI_Host*)fFeatures[kFeatureIdExternalUi]->data); - - if (uiHost->plugin_human_id != nullptr) - delete[] uiHost->plugin_human_id; - - //uiHost->plugin_human_id = carla_strdup(guiTitle.toUtf8().constData()); - } - } -#endif - // ------------------------------------------------------------------- // Set data (plugin-specific stuff) - void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); const float fixedValue(pData->param.getFixedValue(parameterId, value)); fParamBuffers[parameterId] = fixedValue; @@ -950,4511 +490,1080 @@ public: CarlaPlugin::setParameterValue(parameterId, fixedValue, sendGui, sendOsc, sendCallback); } - void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) override + // ------------------------------------------------------------------- + // Plugin state + + void reload() override { - CARLA_ASSERT(fDescriptor != nullptr); - CARLA_ASSERT(fHandle != nullptr); - CARLA_ASSERT(type != nullptr); - CARLA_ASSERT(key != nullptr); - CARLA_ASSERT(value != nullptr); - carla_debug("Lv2Plugin::setCustomData(%s, %s, %s, %s)", type, key, value, bool2str(sendGui)); + CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); + carla_debug("Lv2Plugin::reload() - start"); - if (type == nullptr) - return carla_stderr2("Lv2Plugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is invalid", type, key, value, bool2str(sendGui)); + const EngineProcessMode processMode(pData->engine->getProccessMode()); - if (key == nullptr) - return carla_stderr2("Lv2Plugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - key is null", type, key, value, bool2str(sendGui)); + // Safely disable plugin for reload + const ScopedDisabler sd(this); - if (value == nullptr) - return carla_stderr2("Lv2Plugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - value is null", type, key, value, bool2str(sendGui)); + if (pData->active) + deactivate(); - CarlaPlugin::setCustomData(type, key, value, sendGui); + clearBuffers(); -#if 0 - // FIXME - we should only call this once, after all data is stored + const float sampleRate(static_cast(pData->engine->getSampleRate())); + const uint32_t portCount(static_cast(fRdfDescriptor->PortCount)); - if (fExt.state != nullptr) - { - LV2_State_Status status; + uint32_t aIns, aOuts, params, j; + aIns = aOuts = params = 0; - { - const ScopedSingleProcessLocker spl(this, true); + bool forcedStereoIn, forcedStereoOut; + forcedStereoIn = forcedStereoOut = false; - status = fExt.state->restore(fHandle, carla_lv2_state_retrieve, this, 0, fFeatures); + bool needsCtrlIn, needsCtrlOut; + needsCtrlIn = needsCtrlOut = false; - if (fHandle2 != nullptr) - fExt.state->restore(fHandle, carla_lv2_state_retrieve, this, 0, fFeatures); - } + for (uint32_t i=0; i < portCount; ++i) + { + const LV2_Property portTypes(fRdfDescriptor->Ports[i].Types); - switch (status) + if (LV2_IS_PORT_AUDIO(portTypes)) { - case LV2_STATE_SUCCESS: - carla_debug("Lv2Plugin::setCustomData(\"%s\", \"%s\", , %s) - success", type, key, bool2str(sendGui)); - break; - case LV2_STATE_ERR_UNKNOWN: - carla_stderr("Lv2Plugin::setCustomData(\"%s\", \"%s\", , %s) - unknown error", type, key, bool2str(sendGui)); - break; - case LV2_STATE_ERR_BAD_TYPE: - carla_stderr("Lv2Plugin::setCustomData(\"%s\", \"%s\", , %s) - error, bad type", type, key, bool2str(sendGui)); - break; - case LV2_STATE_ERR_BAD_FLAGS: - carla_stderr("Lv2Plugin::setCustomData(\"%s\", \"%s\", , %s) - error, bad flags", type, key, bool2str(sendGui)); - break; - case LV2_STATE_ERR_NO_FEATURE: - carla_stderr("Lv2Plugin::setCustomData(\"%s\", \"%s\", , %s) - error, missing feature", type, key, bool2str(sendGui)); - break; - case LV2_STATE_ERR_NO_PROPERTY: - carla_stderr("Lv2Plugin::setCustomData(\"%s\", \"%s\", , %s) - error, missing property", type, key, bool2str(sendGui)); - break; + if (LV2_IS_PORT_INPUT(portTypes)) + aIns += 1; + else if (LV2_IS_PORT_OUTPUT(portTypes)) + aOuts += 1; } + else if (LV2_IS_PORT_CONTROL(portTypes)) + params += 1; } -#endif - - if (sendGui) - { - //CustomData cdata; - //cdata.type = type; - //cdata.key = key; - //cdata.value = value; - //uiTransferCustomData(&cdata); - } - } - -#if 0 - void setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override - { - CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); - CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast(fRdfDescriptor->PresetCount),); - CARLA_SAFE_ASSERT_RETURN(sendGui || sendOsc || sendCallback,); // never call this from RT - if (index >= 0 && index < static_cast(fRdfDescriptor->PresetCount)) + if ((pData->options & PLUGIN_OPTION_FORCE_STEREO) != 0 && (aIns == 1 || aOuts == 1) /*&& fExt.state == nullptr && fExt.worker == nullptr*/) { - Lv2WorldClass& lv2World(Lv2WorldClass::getInstance()); + if (fHandle2 == nullptr) + fHandle2 = fDescriptor->instantiate(fDescriptor, sampleRate, fRdfDescriptor->Bundle, fFeatures); - if (const LilvState* state = lv2World.getState(fRdfDescriptor->Presets[index].URI, (const LV2_URID_Map*)fFeatures[kFeatureIdUridMap]->data)) + if (fHandle2 != nullptr) { - const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback)); - - lilv_state_restore(state, fExt.state, fHandle, carla_lilv_set_port_value, this, 0, fFeatures); + if (aIns == 1) + { + aIns = 2; + forcedStereoIn = true; + } - if (fHandle2 != nullptr) - lilv_state_restore(state, fExt.state, fHandle2, carla_lilv_set_port_value, this, 0, fFeatures); + if (aOuts == 1) + { + aOuts = 2; + forcedStereoOut = true; + } } } - CarlaPlugin::setProgram(index, sendGui, sendOsc, sendCallback); - } + if (aIns > 0) + { + pData->audioIn.createNew(aIns); + fAudioInBuffers = new float*[aIns]; - void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override - { - CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); - CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); - CARLA_SAFE_ASSERT_RETURN(index >= -1 && index < static_cast(pData->midiprog.count),); + for (uint32_t i=0; i < aIns; ++i) + fAudioInBuffers[i] = nullptr; + } - if (index >= 0 && fExt.programs != nullptr && fExt.programs->select_program != nullptr) + if (aOuts > 0) { - const uint32_t bank(pData->midiprog.data[index].bank); - const uint32_t program(pData->midiprog.data[index].program); + pData->audioOut.createNew(aOuts); + fAudioOutBuffers = new float*[aOuts]; + needsCtrlIn = true; - const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback)); + for (uint32_t i=0; i < aOuts; ++i) + fAudioOutBuffers[i] = nullptr; + } - fExt.programs->select_program(fHandle, bank, program); + if (params > 0) + { + pData->param.createNew(params, true); - if (fHandle2 != nullptr) - fExt.programs->select_program(fHandle2, bank, program); + fParamBuffers = new float[params]; + FLOAT_CLEAR(fParamBuffers, params); } - CarlaPlugin::setMidiProgram(index, sendGui, sendOsc, sendCallback); - } -#endif + const uint portNameSize(pData->engine->getMaxPortNameSize()); + CarlaString portName; -#if 0 - // ------------------------------------------------------------------- - // Set ui stuff + for (uint32_t i=0, iAudioIn=0, iAudioOut=0, iCtrl=0; i < portCount; ++i) + { + const LV2_Property portTypes(fRdfDescriptor->Ports[i].Types); - void showCustomUI(const bool yesNo) override - { - if (fUi.type == PLUGIN_UI_NULL) - return; + portName.clear(); - if (fUi.type == PLUGIN_UI_OSC) - { - if (yesNo) + if (LV2_IS_PORT_AUDIO(portTypes) || LV2_IS_PORT_ATOM_SEQUENCE(portTypes) || LV2_IS_PORT_CV(portTypes) || LV2_IS_PORT_EVENT(portTypes) || LV2_IS_PORT_MIDI_LL(portTypes)) { - pData->osc.thread.start(); + if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT) + { + portName = pData->name; + portName += ":"; + } + + portName += fRdfDescriptor->Ports[i].Name; + portName.truncate(portNameSize); } - else + + if (LV2_IS_PORT_AUDIO(portTypes)) { - if (pData->osc.data.target != nullptr) + if (LV2_IS_PORT_INPUT(portTypes)) { - osc_send_hide(pData->osc.data); - osc_send_quit(pData->osc.data); - pData->osc.data.free(); + j = iAudioIn++; + pData->audioIn.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true); + pData->audioIn.ports[j].rindex = i; + + if (forcedStereoIn) + { + portName += "_2"; + pData->audioIn.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true); + pData->audioIn.ports[1].rindex = i; + } } + else if (LV2_IS_PORT_OUTPUT(portTypes)) + { + j = iAudioOut++; + pData->audioOut.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false); + pData->audioOut.ports[j].rindex = i; - pData->osc.thread.stop(pData->engine->getOptions().uiBridgesTimeout); + if (forcedStereoOut) + { + portName += "_2"; + pData->audioOut.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false); + pData->audioOut.ports[1].rindex = i; + } + } + else + carla_stderr("WARNING - Got a broken Port (Audio, but not input or output)"); } + else if (LV2_IS_PORT_CONTROL(portTypes)) + { + const LV2_Property portProps(fRdfDescriptor->Ports[i].Properties); + const LV2_Property portDesignation(fRdfDescriptor->Ports[i].Designation); + const LV2_RDF_PortPoints portPoints(fRdfDescriptor->Ports[i].Points); - return; - } - - // take some precautions - CARLA_ASSERT(fUi.descriptor != nullptr); - CARLA_ASSERT(fUi.rdfDescriptor != nullptr); + j = iCtrl++; + pData->param.data[j].type = PARAMETER_UNKNOWN; + pData->param.data[j].hints = 0x0; + pData->param.data[j].index = j; + pData->param.data[j].rindex = i; + pData->param.data[j].midiCC = -1; + pData->param.data[j].midiChannel = 0; - if (fUi.descriptor == nullptr) - return; - if (fUi.rdfDescriptor == nullptr) - return; + float min, max, def, step, stepSmall, stepLarge; - if (yesNo) - { - CARLA_ASSERT(fUi.descriptor->instantiate != nullptr); + // min value + if (LV2_HAVE_MINIMUM_PORT_POINT(portPoints.Hints)) + min = portPoints.Minimum; + else + min = 0.0f; - if (fUi.descriptor->instantiate == nullptr) - return; - } - else - { - CARLA_ASSERT(fUi.descriptor->cleanup != nullptr); + // max value + if (LV2_HAVE_MAXIMUM_PORT_POINT(portPoints.Hints)) + max = portPoints.Maximum; + else + max = 1.0f; - if (fUi.handle == nullptr) - return; - if (fUi.descriptor->cleanup == nullptr) - return; - } + if (min > max) + max = min; + else if (max < min) + min = max; - if (fUi.type == PLUGIN_UI_EXTERNAL) - { - if (yesNo) - { - if (fUi.handle == nullptr) + // stupid hack for ir.lv2 (broken plugin) + if (std::strcmp(fRdfDescriptor->URI, "http://factorial.hu/plugins/lv2/ir") == 0 && std::strncmp(fRdfDescriptor->Ports[i].Name, "FileHash", 8) == 0) { - fUi.widget = nullptr; - fUi.handle = fUi.descriptor->instantiate(fUi.descriptor, fRdfDescriptor->URI, fUi.rdfDescriptor->Bundle, - carla_lv2_ui_write_function, this, &fUi.widget, fFeatures); + min = 0.0f; + max = (float)0xffffff; } - CARLA_ASSERT(fUi.handle != nullptr); - CARLA_ASSERT(fUi.widget != nullptr); - - if (fUi.handle == nullptr || fUi.widget == nullptr) + if (max - min == 0.0f) { - fUi.handle = nullptr; - fUi.widget = nullptr; - pData->engine->callback(ENGINE_CALLBACK_ERROR, pData->id, 0, 0, 0.0f, "Plugin refused to open its own UI"); - pData->engine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, pData->id, 0, 0, 0.0f, nullptr); - return; + carla_stderr2("WARNING - Broken plugin parameter '%s': max - min == 0.0f", fRdfDescriptor->Ports[i].Name); + max = min + 0.1f; } - updateUi(); - - LV2_EXTERNAL_UI_SHOW((LV2_External_UI_Widget*)fUi.widget); - } - else - { - CARLA_ASSERT(fUi.widget != nullptr); + // default value + if (LV2_HAVE_DEFAULT_PORT_POINT(portPoints.Hints)) + { + def = portPoints.Default; + } + else + { + // no default value + if (min < 0.0f && max > 0.0f) + def = 0.0f; + else + def = min; + } - if (fUi.widget != nullptr) - LV2_EXTERNAL_UI_HIDE((LV2_External_UI_Widget*)fUi.widget); + if (def < min) + def = min; + else if (def > max) + def = max; - fUi.descriptor->cleanup(fUi.handle); - fUi.handle = nullptr; - fUi.widget = nullptr; - } - } - else // means PLUGIN_UI_PARENT || PLUGIN_UI_QT - { -#if 0 - if (yesNo) - { - if (pData->gui == nullptr) + if (LV2_IS_PORT_SAMPLE_RATE(portProps)) { - // TODO - CarlaPluginGui::Options guiOptions; - guiOptions.parented = (fUi.type == PLUGIN_UI_PARENT); - guiOptions.resizable = isUiResizable(); - - pData->gui = new CarlaPluginGui(pData->engine, this, guiOptions, pData->guiGeometry); + min *= sampleRate; + max *= sampleRate; + def *= sampleRate; + pData->param.data[j].hints |= PARAMETER_USES_SAMPLERATE; } - if (fUi.type == PLUGIN_UI_PARENT) + if (LV2_IS_PORT_TOGGLED(portProps)) { - fFeatures[kFeatureIdUiParent]->data = pData->gui->getContainerWinId(); - fFeatures[kFeatureIdUiParent]->URI = LV2_UI__parent; + step = max - min; + stepSmall = step; + stepLarge = step; + pData->param.data[j].hints |= PARAMETER_IS_BOOLEAN; } - - if (fUi.handle == nullptr) + else if (LV2_IS_PORT_INTEGER(portProps)) { - fUi.widget = nullptr; - fUi.handle = fUi.descriptor->instantiate(fUi.descriptor, fRdfDescriptor->URI, fUi.rdfDescriptor->Bundle, - carla_lv2_ui_write_function, this, &fUi.widget, fFeatures); + step = 1.0f; + stepSmall = 1.0f; + stepLarge = 10.0f; + pData->param.data[j].hints |= PARAMETER_IS_INTEGER; } - - CARLA_ASSERT(fUi.handle != nullptr); - CARLA_ASSERT(fUi.widget != nullptr); - - if (fUi.handle == nullptr || fUi.widget == nullptr) + else { - fUi.handle = nullptr; - fUi.widget = nullptr; - - pData->guiGeometry = pData->gui->saveGeometry(); - pData->gui->close(); - delete pData->gui; - pData->gui = nullptr; - - pData->engine->callback(CALLBACK_ERROR, pData->id, 0, 0, 0.0f, "Plugin refused to open its own UI"); - pData->engine->callback(CALLBACK_SHOW_GUI, pData->id, -1, 0, 0.0f, nullptr); - return; + float range = max - min; + step = range/100.0f; + stepSmall = range/1000.0f; + stepLarge = range/10.0f; } - if (fUi.type == PLUGIN_UI_QT) - pData->gui->setWidget((QWidget*)fUi.widget); - - updateUi(); - - pData->gui->setWindowTitle(QString("%1 (GUI)").arg((const char*)pData->name)); - pData->gui->show(); - } - else - { - fUi.descriptor->cleanup(fUi.handle); - fUi.handle = nullptr; - fUi.widget = nullptr; - - if (pData->gui != nullptr) + if (LV2_IS_PORT_INPUT(portTypes)) { - pData->guiGeometry = pData->gui->saveGeometry(); - pData->gui->close(); - delete pData->gui; - pData->gui = nullptr; - } - } -#endif - } - } + if (LV2_IS_PORT_DESIGNATION_LATENCY(portDesignation)) + { + carla_stderr("Plugin has latency input port, this should not happen!"); + } + else if (LV2_IS_PORT_DESIGNATION_SAMPLE_RATE(portDesignation)) + { + def = sampleRate; + step = 1.0f; + stepSmall = 1.0f; + stepLarge = 1.0f; - void idle() override - { - //if (fUi.type == PLUGIN_UI_NULL) - // return CarlaPlugin::idleGui(); + //pData->param.data[j].type = PARAMETER_SAMPLE_RATE; + pData->param.data[j].hints = 0x0; + } + else if (LV2_IS_PORT_DESIGNATION_FREEWHEELING(portDesignation)) + { + //pData->param.data[j].type = PARAMETER_LV2_FREEWHEEL; + } + else if (LV2_IS_PORT_DESIGNATION_TIME(portDesignation)) + { + //pData->param.data[j].type = PARAMETER_LV2_TIME; + } + else + { + pData->param.data[j].type = PARAMETER_INPUT; + pData->param.data[j].hints |= PARAMETER_IS_ENABLED; + pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE; + needsCtrlIn = true; + } - //if (! fAtomQueueOut.isEmpty()) - { - Lv2AtomQueue tmpQueue; - tmpQueue.copyDataFromQueue(fAtomQueueOut); + // MIDI CC value + const LV2_RDF_PortMidiMap& portMidiMap(fRdfDescriptor->Ports[i].MidiMap); - uint32_t portIndex; - const LV2_Atom* atom; - const bool hasPortEvent(fUi.handle != nullptr && fUi.descriptor != nullptr && fUi.descriptor->port_event != nullptr); + if (LV2_IS_PORT_MIDI_MAP_CC(portMidiMap.Type)) + { + if (portMidiMap.Number < 0x5F && ! MIDI_IS_CONTROL_BANK_SELECT(portMidiMap.Number)) + pData->param.data[j].midiCC = int16_t(portMidiMap.Number); + } + } + else if (LV2_IS_PORT_OUTPUT(portTypes)) + { + if (LV2_IS_PORT_DESIGNATION_LATENCY(portDesignation)) + { + min = 0.0f; + max = sampleRate; + def = 0.0f; + step = 1.0f; + stepSmall = 1.0f; + stepLarge = 1.0f; - while (tmpQueue.get(&atom, &portIndex)) - { - //carla_stdout("OUTPUT message IN GUI REMOVED FROM BUFFER"); + //pData->param.data[j].type = PARAMETER_LATENCY; + pData->param.data[j].hints = 0x0; + } + else if (LV2_IS_PORT_DESIGNATION_SAMPLE_RATE(portDesignation)) + { + def = sampleRate; + step = 1.0f; + stepSmall = 1.0f; + stepLarge = 1.0f; - if (fUi.type == PLUGIN_UI_OSC) - { - if (pData->osc.data.target != nullptr) + //pData->param.data[j].type = PARAMETER_SAMPLE_RATE; + pData->param.data[j].hints = 0x0; + } + else if (LV2_IS_PORT_DESIGNATION_FREEWHEELING(portDesignation)) + { + carla_stderr("Plugin has freewheeling output port, this should not happen!"); + } + else if (LV2_IS_PORT_DESIGNATION_TIME(portDesignation)) { - //QByteArray chunk((const char*)atom, lv2_atom_total_size(atom)); - //osc_send_lv2_atom_transfer(pData->osc.data, portIndex, chunk.toBase64().constData()); + //pData->param.data[j].type = PARAMETER_LV2_TIME; + } + else + { + pData->param.data[j].type = PARAMETER_OUTPUT; + pData->param.data[j].hints |= PARAMETER_IS_ENABLED; + pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE; + needsCtrlOut = true; } } - else if (fUi.type != PLUGIN_UI_NULL) + else { - if (hasPortEvent) - fUi.descriptor->port_event(fUi.handle, portIndex, lv2_atom_total_size(atom), CARLA_URI_MAP_ID_ATOM_TRANSFER_EVENT, atom); + pData->param.data[j].type = PARAMETER_UNKNOWN; + carla_stderr2("WARNING - Got a broken Port (Control, but not input or output)"); } - } - } - if (fUi.handle != nullptr && fUi.descriptor != nullptr) - { - if (fUi.type == PLUGIN_UI_EXTERNAL && fUi.widget != nullptr) - LV2_EXTERNAL_UI_RUN((LV2_External_UI_Widget*)fUi.widget); + // extra parameter hints + if (LV2_IS_PORT_ENUMERATION(portProps)) + pData->param.data[j].hints |= PARAMETER_USES_SCALEPOINTS; - if (fExt.uiidle != nullptr && fExt.uiidle->idle(fUi.handle) != 0) - { - showCustomUI(false); - pData->engine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, pData->id, 0, 0, 0.0f, nullptr); - } - } + if (LV2_IS_PORT_LOGARITHMIC(portProps)) + pData->param.data[j].hints |= PARAMETER_IS_LOGARITHMIC; - CarlaPlugin::idle(); - } -#endif - - // ------------------------------------------------------------------- - // Plugin state - - void reload() override - { - CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr,); - CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); - CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); - CARLA_SAFE_ASSERT_RETURN(fRdfDescriptor != nullptr,); - carla_debug("Lv2Plugin::reload() - start"); - - const EngineProcessMode processMode(pData->engine->getProccessMode()); - - // Safely disable plugin for reload - const ScopedDisabler sd(this); - - if (pData->active) - deactivate(); - - clearBuffers(); - - const float sampleRate(static_cast(pData->engine->getSampleRate())); - const uint32_t portCount(static_cast(fRdfDescriptor->PortCount)); - - uint32_t aIns, aOuts, cvIns, cvOuts, params, j; - aIns = aOuts = cvIns = cvOuts = params = 0; - LinkedList evIns, evOuts; - - bool forcedStereoIn, forcedStereoOut; - forcedStereoIn = forcedStereoOut = false; - - bool needsCtrlIn, needsCtrlOut; - needsCtrlIn = needsCtrlOut = false; - - for (uint32_t i=0; i < portCount; ++i) - { - const LV2_Property portTypes(fRdfDescriptor->Ports[i].Types); - - if (LV2_IS_PORT_AUDIO(portTypes)) - { - if (LV2_IS_PORT_INPUT(portTypes)) - aIns += 1; - else if (LV2_IS_PORT_OUTPUT(portTypes)) - aOuts += 1; - } - else if (LV2_IS_PORT_CV(portTypes)) - { - if (LV2_IS_PORT_INPUT(portTypes)) - cvIns += 1; - else if (LV2_IS_PORT_OUTPUT(portTypes)) - cvOuts += 1; - } -#if 0 - else if (LV2_IS_PORT_ATOM_SEQUENCE(portTypes)) - { - if (LV2_IS_PORT_INPUT(portTypes)) - evIns.append(CARLA_EVENT_DATA_ATOM); - else if (LV2_IS_PORT_OUTPUT(portTypes)) - evOuts.append(CARLA_EVENT_DATA_ATOM); - } - else if (LV2_IS_PORT_EVENT(portTypes)) - { - if (LV2_IS_PORT_INPUT(portTypes)) - evIns.append(CARLA_EVENT_DATA_EVENT); - else if (LV2_IS_PORT_OUTPUT(portTypes)) - evOuts.append(CARLA_EVENT_DATA_EVENT); - } - else if (LV2_IS_PORT_MIDI_LL(portTypes)) - { - if (LV2_IS_PORT_INPUT(portTypes)) - evIns.append(CARLA_EVENT_DATA_MIDI_LL); - else if (LV2_IS_PORT_OUTPUT(portTypes)) - evOuts.append(CARLA_EVENT_DATA_MIDI_LL); - } -#endif - else if (LV2_IS_PORT_CONTROL(portTypes)) - params += 1; - } - -#if 0 - // check extensions - fExt.options = nullptr; - fExt.programs = nullptr; - fExt.state = nullptr; - fExt.worker = nullptr; - - if (fDescriptor->extension_data != nullptr) - { - if (pData->extraHints & PLUGIN_HAS_EXTENSION_OPTIONS) - fExt.options = (const LV2_Options_Interface*)fDescriptor->extension_data(LV2_OPTIONS__interface); - - if (pData->extraHints & PLUGIN_HAS_EXTENSION_PROGRAMS) - fExt.programs = (const LV2_Programs_Interface*)fDescriptor->extension_data(LV2_PROGRAMS__Interface); - - if (pData->extraHints & PLUGIN_HAS_EXTENSION_STATE) - fExt.state = (const LV2_State_Interface*)fDescriptor->extension_data(LV2_STATE__interface); - - if (pData->extraHints & PLUGIN_HAS_EXTENSION_WORKER) - fExt.worker = (const LV2_Worker_Interface*)fDescriptor->extension_data(LV2_WORKER__interface); - } -#endif - - if ((pData->options & PLUGIN_OPTION_FORCE_STEREO) != 0 && (aIns == 1 || aOuts == 1) /*&& fExt.state == nullptr && fExt.worker == nullptr*/) - { - if (fHandle2 == nullptr) - fHandle2 = fDescriptor->instantiate(fDescriptor, sampleRate, fRdfDescriptor->Bundle, fFeatures); - - if (fHandle2 != nullptr) - { - if (aIns == 1) - { - aIns = 2; - forcedStereoIn = true; - } - - if (aOuts == 1) - { - aOuts = 2; - forcedStereoOut = true; - } - } - } - - if (aIns > 0) - { - pData->audioIn.createNew(aIns); - fAudioInBuffers = new float*[aIns]; - - for (uint32_t i=0; i < aIns; ++i) - fAudioInBuffers[i] = nullptr; - } - - if (aOuts > 0) - { - pData->audioOut.createNew(aOuts); - fAudioOutBuffers = new float*[aOuts]; - needsCtrlIn = true; - - for (uint32_t i=0; i < aOuts; ++i) - fAudioOutBuffers[i] = nullptr; - } - - if (cvIns > 0) - { - //fCvIn.createNew(cvIns); - needsCtrlIn = true; - } - - if (cvOuts > 0) - { - //fCvOut.createNew(cvOuts); - needsCtrlOut = true; - } - - if (params > 0) - { - pData->param.createNew(params+cvIns+cvOuts, true); - - fParamBuffers = new float[params+cvIns+cvOuts]; - FLOAT_CLEAR(fParamBuffers, params+cvIns+cvOuts); - } - -#if 0 - if (evIns.count() > 0) - { - const size_t count(evIns.count()); - - fEventsIn.createNew(count); - - for (j=0; j < count; ++j) - { - const uint32_t& type(evIns.getAt(j)); - - if (type == CARLA_EVENT_DATA_ATOM) - { - fEventsIn.data[j].type = CARLA_EVENT_DATA_ATOM; - fEventsIn.data[j].atom = lv2_atom_buffer_new(MAX_EVENT_BUFFER, CARLA_URI_MAP_ID_ATOM_SEQUENCE, true); - } - else if (type == CARLA_EVENT_DATA_EVENT) - { - fEventsIn.data[j].type = CARLA_EVENT_DATA_EVENT; - fEventsIn.data[j].event = lv2_event_buffer_new(MAX_EVENT_BUFFER, LV2_EVENT_AUDIO_STAMP); - } - else if (type == CARLA_EVENT_DATA_MIDI_LL) - { - fEventsIn.data[j].type = CARLA_EVENT_DATA_MIDI_LL; - fEventsIn.data[j].midi = new LV2_MIDI; - fEventsIn.data[j].midi->event_count = 0; - fEventsIn.data[j].midi->capacity = MAX_EVENT_BUFFER; - fEventsIn.data[j].midi->size = 0; - fEventsIn.data[j].midi->data = new unsigned char[MAX_EVENT_BUFFER]; - } - } - } - - if (evOuts.count() > 0) - { - const size_t count(evOuts.count()); - - fEventsOut.createNew(count); - - for (j=0; j < count; ++j) - { - const uint32_t& type(evOuts.getAt(j)); - - if (type == CARLA_EVENT_DATA_ATOM) - { - fEventsOut.data[j].type = CARLA_EVENT_DATA_ATOM; - fEventsOut.data[j].atom = lv2_atom_buffer_new(MAX_EVENT_BUFFER, CARLA_URI_MAP_ID_ATOM_SEQUENCE, false); - } - else if (type == CARLA_EVENT_DATA_EVENT) - { - fEventsOut.data[j].type = CARLA_EVENT_DATA_EVENT; - fEventsOut.data[j].event = lv2_event_buffer_new(MAX_EVENT_BUFFER, LV2_EVENT_AUDIO_STAMP); - } - else if (type == CARLA_EVENT_DATA_MIDI_LL) - { - fEventsOut.data[j].type = CARLA_EVENT_DATA_MIDI_LL; - fEventsOut.data[j].midi = new LV2_MIDI; - fEventsOut.data[j].midi->event_count = 0; - fEventsOut.data[j].midi->capacity = MAX_EVENT_BUFFER; - fEventsOut.data[j].midi->size = 0; - fEventsOut.data[j].midi->data = new unsigned char[MAX_EVENT_BUFFER]; - } - } - } -#endif - - const uint portNameSize(pData->engine->getMaxPortNameSize()); - CarlaString portName; - - for (uint32_t i=0, iAudioIn=0, iAudioOut=0, /*iCvIn=0, iCvOut=0, iEvIn=0, iEvOut=0,*/ iCtrl=0; i < portCount; ++i) - { - const LV2_Property portTypes(fRdfDescriptor->Ports[i].Types); - - portName.clear(); - - if (LV2_IS_PORT_AUDIO(portTypes) || LV2_IS_PORT_ATOM_SEQUENCE(portTypes) || LV2_IS_PORT_CV(portTypes) || LV2_IS_PORT_EVENT(portTypes) || LV2_IS_PORT_MIDI_LL(portTypes)) - { - if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT) - { - portName = pData->name; - portName += ":"; - } - - portName += fRdfDescriptor->Ports[i].Name; - portName.truncate(portNameSize); - } - - if (LV2_IS_PORT_AUDIO(portTypes)) - { - if (LV2_IS_PORT_INPUT(portTypes)) - { - j = iAudioIn++; - pData->audioIn.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true); - pData->audioIn.ports[j].rindex = i; - - if (forcedStereoIn) - { - portName += "_2"; - pData->audioIn.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, true); - pData->audioIn.ports[1].rindex = i; - } - } - else if (LV2_IS_PORT_OUTPUT(portTypes)) - { - j = iAudioOut++; - pData->audioOut.ports[j].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false); - pData->audioOut.ports[j].rindex = i; - - if (forcedStereoOut) - { - portName += "_2"; - pData->audioOut.ports[1].port = (CarlaEngineAudioPort*)pData->client->addPort(kEnginePortTypeAudio, portName, false); - pData->audioOut.ports[1].rindex = i; - } - } - else - carla_stderr("WARNING - Got a broken Port (Audio, but not input or output)"); - } -#if 0 - else if (LV2_IS_PORT_CV(portTypes)) - { - if (LV2_IS_PORT_INPUT(portTypes)) - { - j = iCvIn++; - fCvIn.ports[j].port = (CarlaEngineCVPort*)pData->client->addPort(kEnginePortTypeCV, portName, true); - fCvIn.ports[j].rindex = i; - fCvIn.ports[j].param = params + j; - - fDescriptor->connect_port(fHandle, i, fCvIn.ports[j].port->getBuffer()); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, i, fCvIn.ports[j].port->getBuffer()); - - j = fCvIn.ports[j].param; - pData->param.data[j].index = j; - pData->param.data[j].rindex = i; - pData->param.data[j].hints = PARAMETER_IS_INPUT|PARAMETER_IS_ENABLED|PARAMETER_IS_READ_ONLY; - pData->param.data[j].midiChannel = 0; - pData->param.data[j].midiCC = -1; - pData->param.ranges[j].min = -1.0f; - pData->param.ranges[j].max = 1.0f; - pData->param.ranges[j].def = 0.0f; - pData->param.ranges[j].step = 0.01f; - pData->param.ranges[j].stepSmall = 0.001f; - pData->param.ranges[j].stepLarge = 0.1f; - fParamBuffers[j] = 0.0f; - - } - else if (LV2_IS_PORT_OUTPUT(portTypes)) - { - j = iCvOut++; - fCvOut.ports[j].port = (CarlaEngineCVPort*)pData->client->addPort(kEnginePortTypeCV, portName, false); - fCvOut.ports[j].rindex = i; - fCvOut.ports[j].param = params + cvIns + j; - - fDescriptor->connect_port(fHandle, i, fCvOut.ports[j].port->getBuffer()); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, i, fCvOut.ports[j].port->getBuffer()); - - j = fCvOut.ports[j].param; - pData->param.data[j].index = j; - pData->param.data[j].rindex = i; - pData->param.data[j].hints = PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE; - pData->param.data[j].midiChannel = 0; - pData->param.data[j].midiCC = -1; - pData->param.ranges[j].min = -1.0f; - pData->param.ranges[j].max = 1.0f; - pData->param.ranges[j].def = 0.0f; - pData->param.ranges[j].step = 0.01f; - pData->param.ranges[j].stepSmall = 0.001f; - pData->param.ranges[j].stepLarge = 0.1f; - fParamBuffers[j] = 0.0f; - } - else - carla_stderr("WARNING - Got a broken Port (CV, but not input or output)"); - } - else if (LV2_IS_PORT_ATOM_SEQUENCE(portTypes)) - { - if (LV2_IS_PORT_INPUT(portTypes)) - { - j = iEvIn++; - - fDescriptor->connect_port(fHandle, i, &fEventsIn.data[j].atom->atoms); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, i, &fEventsIn.data[j].atom->atoms); - - fEventsIn.data[j].rindex = i; - - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - fEventsIn.data[j].type |= CARLA_EVENT_TYPE_MIDI; - if (portTypes & LV2_PORT_DATA_PATCH_MESSAGE) - fEventsIn.data[j].type |= CARLA_EVENT_TYPE_MESSAGE; - if (portTypes & LV2_PORT_DATA_TIME_POSITION) - fEventsIn.data[j].type |= CARLA_EVENT_TYPE_TIME; - - if (evIns.count() == 1) - { - fEventsIn.ctrl = &fEventsIn.data[j]; - fEventsIn.ctrlIndex = j; - - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - needsCtrlIn = true; - } - else - { - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - fEventsIn.data[j].port = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true); - - if (LV2_IS_PORT_DESIGNATION_CONTROL(fRdfDescriptor->Ports[i].Designation)) - { - fEventsIn.ctrl = &fEventsIn.data[j]; - fEventsIn.ctrlIndex = j; - } - } - } - else if (LV2_IS_PORT_OUTPUT(portTypes)) - { - j = iEvOut++; - - fDescriptor->connect_port(fHandle, i, &fEventsOut.data[j].atom->atoms); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, i, &fEventsOut.data[j].atom->atoms); - - fEventsOut.data[j].rindex = i; - - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - fEventsOut.data[j].type |= CARLA_EVENT_TYPE_MIDI; - if (portTypes & LV2_PORT_DATA_PATCH_MESSAGE) - fEventsOut.data[j].type |= CARLA_EVENT_TYPE_MESSAGE; - if (portTypes & LV2_PORT_DATA_TIME_POSITION) - fEventsOut.data[j].type |= CARLA_EVENT_TYPE_TIME; - - if (evOuts.count() == 1) - { - fEventsOut.ctrl = &fEventsOut.data[j]; - fEventsOut.ctrlIndex = j; - - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - needsCtrlOut = true; - } - else - { - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - fEventsOut.data[j].port = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false); - - if (LV2_IS_PORT_DESIGNATION_CONTROL(fRdfDescriptor->Ports[i].Designation)) - { - fEventsOut.ctrl = &fEventsOut.data[j]; - fEventsOut.ctrlIndex = j; - } - } - } - else - carla_stderr("WARNING - Got a broken Port (Atom-Sequence, but not input or output)"); - } - else if (LV2_IS_PORT_EVENT(portTypes)) - { - if (LV2_IS_PORT_INPUT(portTypes)) - { - j = iEvIn++; - - fDescriptor->connect_port(fHandle, i, fEventsIn.data[j].event); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, i, fEventsIn.data[j].event); - - fEventsIn.data[j].rindex = i; - - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - fEventsIn.data[j].type |= CARLA_EVENT_TYPE_MIDI; - if (portTypes & LV2_PORT_DATA_PATCH_MESSAGE) - fEventsIn.data[j].type |= CARLA_EVENT_TYPE_MESSAGE; - if (portTypes & LV2_PORT_DATA_TIME_POSITION) - fEventsIn.data[j].type |= CARLA_EVENT_TYPE_TIME; - - if (evIns.count() == 1) - { - fEventsIn.ctrl = &fEventsIn.data[j]; - fEventsIn.ctrlIndex = j; - - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - needsCtrlIn = true; - } - else - { - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - fEventsIn.data[j].port = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true); - - if (LV2_IS_PORT_DESIGNATION_CONTROL(fRdfDescriptor->Ports[i].Designation)) - { - fEventsIn.ctrl = &fEventsIn.data[j]; - fEventsIn.ctrlIndex = j; - } - } - } - else if (LV2_IS_PORT_OUTPUT(portTypes)) - { - j = iEvOut++; - - fDescriptor->connect_port(fHandle, i, fEventsOut.data[j].event); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, i, fEventsOut.data[j].event); - - fEventsOut.data[j].rindex = i; - - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - fEventsOut.data[j].type |= CARLA_EVENT_TYPE_MIDI; - if (portTypes & LV2_PORT_DATA_PATCH_MESSAGE) - fEventsOut.data[j].type |= CARLA_EVENT_TYPE_MESSAGE; - if (portTypes & LV2_PORT_DATA_TIME_POSITION) - fEventsOut.data[j].type |= CARLA_EVENT_TYPE_TIME; - - if (evOuts.count() == 1) - { - fEventsOut.ctrl = &fEventsOut.data[j]; - fEventsOut.ctrlIndex = j; - - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - needsCtrlOut = true; - } - else - { - if (portTypes & LV2_PORT_DATA_MIDI_EVENT) - fEventsOut.data[j].port = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false); - - if (LV2_IS_PORT_DESIGNATION_CONTROL(fRdfDescriptor->Ports[i].Designation)) - { - fEventsOut.ctrl = &fEventsOut.data[j]; - fEventsOut.ctrlIndex = j; - } - } - } - else - carla_stderr("WARNING - Got a broken Port (Event, but not input or output)"); - } - else if (LV2_IS_PORT_MIDI_LL(portTypes)) - { - if (LV2_IS_PORT_INPUT(portTypes)) - { - j = iEvIn++; - - fDescriptor->connect_port(fHandle, i, fEventsIn.data[j].midi); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, i, fEventsIn.data[j].midi); - - fEventsIn.data[j].type |= CARLA_EVENT_TYPE_MIDI; - fEventsIn.data[j].rindex = i; - - if (evIns.count() == 1) - { - needsCtrlIn = true; - fEventsIn.ctrl = &fEventsIn.data[j]; - fEventsIn.ctrlIndex = j; - } - else - { - fEventsIn.data[j].port = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true); - - if (LV2_IS_PORT_DESIGNATION_CONTROL(fRdfDescriptor->Ports[i].Designation)) - { - fEventsIn.ctrl = &fEventsIn.data[j]; - fEventsIn.ctrlIndex = j; - } - } - } - else if (LV2_IS_PORT_OUTPUT(portTypes)) - { - j = iEvOut++; - - fDescriptor->connect_port(fHandle, i, fEventsOut.data[j].midi); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, i, fEventsOut.data[j].midi); - - fEventsOut.data[j].type |= CARLA_EVENT_TYPE_MIDI; - fEventsOut.data[j].rindex = i; - - if (evOuts.count() == 1) - { - needsCtrlOut = true; - fEventsOut.ctrl = &fEventsOut.data[j]; - fEventsOut.ctrlIndex = j; - } - else - { - fEventsOut.data[j].port = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false); - - if (LV2_IS_PORT_DESIGNATION_CONTROL(fRdfDescriptor->Ports[i].Designation)) - { - fEventsOut.ctrl = &fEventsOut.data[j]; - fEventsOut.ctrlIndex = j; - } - } - } - else - carla_stderr("WARNING - Got a broken Port (MIDI, but not input or output)"); - } -#endif - else if (LV2_IS_PORT_CONTROL(portTypes)) - { - const LV2_Property portProps(fRdfDescriptor->Ports[i].Properties); - const LV2_Property portDesignation(fRdfDescriptor->Ports[i].Designation); - const LV2_RDF_PortPoints portPoints(fRdfDescriptor->Ports[i].Points); - - j = iCtrl++; - pData->param.data[j].type = PARAMETER_UNKNOWN; - pData->param.data[j].hints = 0x0; - pData->param.data[j].index = j; - pData->param.data[j].rindex = i; - pData->param.data[j].midiCC = -1; - pData->param.data[j].midiChannel = 0; - - float min, max, def, step, stepSmall, stepLarge; - - // min value - if (LV2_HAVE_MINIMUM_PORT_POINT(portPoints.Hints)) - min = portPoints.Minimum; - else - min = 0.0f; - - // max value - if (LV2_HAVE_MAXIMUM_PORT_POINT(portPoints.Hints)) - max = portPoints.Maximum; - else - max = 1.0f; - - if (min > max) - max = min; - else if (max < min) - min = max; - - // stupid hack for ir.lv2 (broken plugin) - if (std::strcmp(fRdfDescriptor->URI, "http://factorial.hu/plugins/lv2/ir") == 0 && std::strncmp(fRdfDescriptor->Ports[i].Name, "FileHash", 8) == 0) - { - min = 0.0f; - max = (float)0xffffff; - } - - if (max - min == 0.0f) - { - carla_stderr2("WARNING - Broken plugin parameter '%s': max - min == 0.0f", fRdfDescriptor->Ports[i].Name); - max = min + 0.1f; - } - - // default value - if (LV2_HAVE_DEFAULT_PORT_POINT(portPoints.Hints)) - { - def = portPoints.Default; - } - else - { - // no default value - if (min < 0.0f && max > 0.0f) - def = 0.0f; - else - def = min; - } - - if (def < min) - def = min; - else if (def > max) - def = max; - - if (LV2_IS_PORT_SAMPLE_RATE(portProps)) - { - min *= sampleRate; - max *= sampleRate; - def *= sampleRate; - pData->param.data[j].hints |= PARAMETER_USES_SAMPLERATE; - } - - if (LV2_IS_PORT_TOGGLED(portProps)) - { - step = max - min; - stepSmall = step; - stepLarge = step; - pData->param.data[j].hints |= PARAMETER_IS_BOOLEAN; - } - else if (LV2_IS_PORT_INTEGER(portProps)) - { - step = 1.0f; - stepSmall = 1.0f; - stepLarge = 10.0f; - pData->param.data[j].hints |= PARAMETER_IS_INTEGER; - } - else - { - float range = max - min; - step = range/100.0f; - stepSmall = range/1000.0f; - stepLarge = range/10.0f; - } - - if (LV2_IS_PORT_INPUT(portTypes)) - { - if (LV2_IS_PORT_DESIGNATION_LATENCY(portDesignation)) - { - carla_stderr("Plugin has latency input port, this should not happen!"); - } - else if (LV2_IS_PORT_DESIGNATION_SAMPLE_RATE(portDesignation)) - { - def = sampleRate; - step = 1.0f; - stepSmall = 1.0f; - stepLarge = 1.0f; - - //pData->param.data[j].type = PARAMETER_SAMPLE_RATE; - pData->param.data[j].hints = 0x0; - } - else if (LV2_IS_PORT_DESIGNATION_FREEWHEELING(portDesignation)) - { - //pData->param.data[j].type = PARAMETER_LV2_FREEWHEEL; - } - else if (LV2_IS_PORT_DESIGNATION_TIME(portDesignation)) - { - //pData->param.data[j].type = PARAMETER_LV2_TIME; - } - else - { - pData->param.data[j].type = PARAMETER_INPUT; - pData->param.data[j].hints |= PARAMETER_IS_ENABLED; - pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE; - needsCtrlIn = true; - } - - // MIDI CC value - const LV2_RDF_PortMidiMap& portMidiMap(fRdfDescriptor->Ports[i].MidiMap); - - if (LV2_IS_PORT_MIDI_MAP_CC(portMidiMap.Type)) - { - if (portMidiMap.Number < 0x5F && ! MIDI_IS_CONTROL_BANK_SELECT(portMidiMap.Number)) - pData->param.data[j].midiCC = int16_t(portMidiMap.Number); - } - } - else if (LV2_IS_PORT_OUTPUT(portTypes)) - { - if (LV2_IS_PORT_DESIGNATION_LATENCY(portDesignation)) - { - min = 0.0f; - max = sampleRate; - def = 0.0f; - step = 1.0f; - stepSmall = 1.0f; - stepLarge = 1.0f; - - //pData->param.data[j].type = PARAMETER_LATENCY; - pData->param.data[j].hints = 0x0; - } - else if (LV2_IS_PORT_DESIGNATION_SAMPLE_RATE(portDesignation)) - { - def = sampleRate; - step = 1.0f; - stepSmall = 1.0f; - stepLarge = 1.0f; - - //pData->param.data[j].type = PARAMETER_SAMPLE_RATE; - pData->param.data[j].hints = 0x0; - } - else if (LV2_IS_PORT_DESIGNATION_FREEWHEELING(portDesignation)) - { - carla_stderr("Plugin has freewheeling output port, this should not happen!"); - } - else if (LV2_IS_PORT_DESIGNATION_TIME(portDesignation)) - { - //pData->param.data[j].type = PARAMETER_LV2_TIME; - } - else - { - pData->param.data[j].type = PARAMETER_OUTPUT; - pData->param.data[j].hints |= PARAMETER_IS_ENABLED; - pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE; - needsCtrlOut = true; - } - } - else - { - pData->param.data[j].type = PARAMETER_UNKNOWN; - carla_stderr2("WARNING - Got a broken Port (Control, but not input or output)"); - } - - // extra parameter hints - if (LV2_IS_PORT_ENUMERATION(portProps)) - pData->param.data[j].hints |= PARAMETER_USES_SCALEPOINTS; - - if (LV2_IS_PORT_LOGARITHMIC(portProps)) - pData->param.data[j].hints |= PARAMETER_IS_LOGARITHMIC; - - if (LV2_IS_PORT_TRIGGER(portProps)) - pData->param.data[j].hints |= PARAMETER_IS_TRIGGER; - - if (LV2_IS_PORT_STRICT_BOUNDS(portProps)) - pData->param.data[j].hints |= PARAMETER_IS_STRICT_BOUNDS; - - // check if parameter is not enabled or automable - if (LV2_IS_PORT_NOT_ON_GUI(portProps)) - { - pData->param.data[j].hints &= ~(PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE); - } - else if (LV2_IS_PORT_CAUSES_ARTIFACTS(portProps) || LV2_IS_PORT_EXPENSIVE(portProps) || LV2_IS_PORT_NOT_AUTOMATIC(portProps)) - pData->param.data[j].hints &= ~PARAMETER_IS_AUTOMABLE; - - pData->param.ranges[j].min = min; - pData->param.ranges[j].max = max; - pData->param.ranges[j].def = def; - pData->param.ranges[j].step = step; - pData->param.ranges[j].stepSmall = stepSmall; - pData->param.ranges[j].stepLarge = stepLarge; - - // Start parameters in their default values - //if (pData->param.data[j].type != PARAMETER_LV2_FREEWHEEL) - fParamBuffers[j] = def; - //else - // fParamBuffers[j] = min; - - fDescriptor->connect_port(fHandle, i, &fParamBuffers[j]); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, i, &fParamBuffers[j]); - } - else - { - // Port Type not supported, but it's optional anyway - fDescriptor->connect_port(fHandle, i, nullptr); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, i, nullptr); - } - } - - if (needsCtrlIn) - { - portName.clear(); - - if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT) - { - portName = pData->name; - portName += ":"; - } - - portName += "events-in"; - portName.truncate(portNameSize); - - pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true); - } - - if (needsCtrlOut) - { - portName.clear(); - - if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT) - { - portName = pData->name; - portName += ":"; - } - - portName += "events-out"; - portName.truncate(portNameSize); - - pData->event.portOut = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false); - } - -#if 0 - if (fEventsIn.ctrl != nullptr && fEventsIn.ctrl->port == nullptr) - fEventsIn.ctrl->port = pData->event.portIn; - - if (fEventsOut.ctrl != nullptr && fEventsOut.ctrl->port == nullptr) - fEventsOut.ctrl->port = pData->event.portOut; -#endif - - if (forcedStereoIn || forcedStereoOut) - pData->options |= PLUGIN_OPTION_FORCE_STEREO; - else - pData->options &= ~PLUGIN_OPTION_FORCE_STEREO; - - // plugin hints - pData->hints = 0x0; - - if (isRealtimeSafe()) - pData->hints |= PLUGIN_IS_RTSAFE; - -#if 0 - if (fUi.type != PLUGIN_UI_NULL) - { - pData->hints |= PLUGIN_HAS_CUSTOM_UI; - - if (fUi.type == PLUGIN_UI_QT || fUi.type == PLUGIN_UI_PARENT) - pData->hints |= PLUGIN_NEEDS_SINGLE_THREAD; - } -#endif - - //if (LV2_IS_GENERATOR(fRdfDescriptor->Type[0], fRdfDescriptor->Type[1])) - // pData->hints |= PLUGIN_IS_SYNTH; - - if (aOuts > 0 && (aIns == aOuts || aIns == 1)) - pData->hints |= PLUGIN_CAN_DRYWET; - - if (aOuts > 0) - pData->hints |= PLUGIN_CAN_VOLUME; - - if (aOuts >= 2 && aOuts % 2 == 0) - pData->hints |= PLUGIN_CAN_BALANCE; - - // extra plugin hints - pData->extraHints &= ~PLUGIN_EXTRA_HINT_CAN_RUN_RACK; - -#if 0 - if (fExt.state != nullptr || fExt.worker != nullptr) - { - if ((aIns == 0 || aIns == 2) && (aOuts == 0 || aOuts == 2) && evIns.count() <= 1 && evOuts.count() <= 1) - pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; - } - else - { - if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0) && evIns.count() <= 1 && evOuts.count() <= 1) - pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; - } -#endif - - bufferSizeChanged(pData->engine->getBufferSize()); - reloadPrograms(true); - - if (pData->active) - activate(); - - evIns.clear(); - evOuts.clear(); - - carla_debug("Lv2Plugin::reload() - end"); - } - -#if 0 - void reloadPrograms(const bool init) override - { - carla_debug("Lv2Plugin::reloadPrograms(%s)", bool2str(init)); - uint32_t i, oldCount = pData->midiprog.count; - const int32_t current = pData->midiprog.current; - - // special LV2 programs handling - if (init) - { - pData->prog.clear(); - - const uint32_t count(fRdfDescriptor->PresetCount); - - if (count > 0) - { - pData->prog.createNew(count); - - for (i=0; i < count; ++i) - pData->prog.names[i] = carla_strdup(fRdfDescriptor->Presets[i].Label); - } - } - - // Delete old programs - pData->midiprog.clear(); - - // Query new programs - uint32_t count = 0; - if (fExt.programs != nullptr && fExt.programs->get_program != nullptr && fExt.programs->select_program != nullptr) - { - while (fExt.programs->get_program(fHandle, count)) - ++count; - } - - if (count > 0) - { - pData->midiprog.createNew(count); - - // Update data - for (i=0; i < count; ++i) - { - const LV2_Program_Descriptor* const pdesc(fExt.programs->get_program(fHandle, i)); - CARLA_ASSERT(pdesc != nullptr); - CARLA_ASSERT(pdesc->name != nullptr); - - pData->midiprog.data[i].bank = pdesc->bank; - pData->midiprog.data[i].program = pdesc->program; - pData->midiprog.data[i].name = carla_strdup(pdesc->name); - } - } - -#ifndef BUILD_BRIDGE - // Update OSC Names - if (pData->engine->isOscControlRegistered()) - { - pData->engine->oscSend_control_set_midi_program_count(pData->id, count); - - for (i=0; i < count; ++i) - pData->engine->oscSend_control_set_midi_program_data(pData->id, i, pData->midiprog.data[i].bank, pData->midiprog.data[i].program, pData->midiprog.data[i].name); - } -#endif - - if (init) - { - if (count > 0) - { - setMidiProgram(0, false, false, false); - } - else - { - // load default state - Lv2WorldClass& lv2World(Lv2WorldClass::getInstance()); - - if (const LilvState* state = lv2World.getState(fDescriptor->URI, (const LV2_URID_Map*)fFeatures[kFeatureIdUridMap]->data)) - { - lilv_state_restore(state, fExt.state, fHandle, carla_lilv_set_port_value, this, 0, fFeatures); - - if (fHandle2 != nullptr) - lilv_state_restore(state, fExt.state, fHandle2, carla_lilv_set_port_value, this, 0, fFeatures); - } - } - } - else - { - // Check if current program is invalid - bool programChanged = false; - - if (count == oldCount+1) - { - // one midi program added, probably created by user - pData->midiprog.current = oldCount; - programChanged = true; - } - else if (current < 0 && count > 0) - { - // programs exist now, but not before - pData->midiprog.current = 0; - programChanged = true; - } - else if (current >= 0 && count == 0) - { - // programs existed before, but not anymore - pData->midiprog.current = -1; - programChanged = true; - } - else if (current >= static_cast(count)) - { - // current midi program > count - pData->midiprog.current = 0; - programChanged = true; - } - else - { - // no change - pData->midiprog.current = current; - } - - if (programChanged) - setMidiProgram(pData->midiprog.current, true, true, true); - - pData->engine->callback(ENGINE_CALLBACK_RELOAD_PROGRAMS, pData->id, 0, 0, 0.0f, nullptr); - } - } -#endif - - // ------------------------------------------------------------------- - // Plugin processing - - void activate() override - { - CARLA_ASSERT(fDescriptor != nullptr); - CARLA_ASSERT(fHandle != nullptr); - - if (fDescriptor->activate != nullptr) - { - fDescriptor->activate(fHandle); - - if (fHandle2 != nullptr) - fDescriptor->activate(fHandle2); - } - - //fFirstActive = true; - } - - void deactivate() override - { - CARLA_ASSERT(fDescriptor != nullptr); - CARLA_ASSERT(fHandle != nullptr); - - if (fDescriptor->deactivate != nullptr) - { - fDescriptor->deactivate(fHandle); - - if (fHandle2 != nullptr) - fDescriptor->deactivate(fHandle2); - } - } - - void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) override - { - uint32_t i, k; - - // -------------------------------------------------------------------------------------------------------- - // Check if active - - if (! pData->active) - { - // disable any output sound - for (i=0; i < pData->audioOut.count; ++i) - FLOAT_CLEAR(outBuffer[i], frames); - return; - } - -#if 0 - // -------------------------------------------------------------------------------------------------------- - // Handle events from different APIs - - LV2_Atom_Buffer_Iterator evInAtomIters[fEventsIn.count]; - LV2_Event_Iterator evInEventIters[fEventsIn.count]; - LV2_MIDIState evInMidiStates[fEventsIn.count]; - - for (i=0; i < fEventsIn.count; ++i) - { - if (fEventsIn.data[i].type & CARLA_EVENT_DATA_ATOM) - { - lv2_atom_buffer_reset(fEventsIn.data[i].atom, true); - lv2_atom_buffer_begin(&evInAtomIters[i], fEventsIn.data[i].atom); - } - else if (fEventsIn.data[i].type & CARLA_EVENT_DATA_EVENT) - { - lv2_event_buffer_reset(fEventsIn.data[i].event, LV2_EVENT_AUDIO_STAMP, fEventsIn.data[i].event->data); - lv2_event_begin(&evInEventIters[i], fEventsIn.data[i].event); - } - else if (fEventsIn.data[i].type & CARLA_EVENT_DATA_MIDI_LL) - { - fEventsIn.data[i].midi->event_count = 0; - fEventsIn.data[i].midi->size = 0; - evInMidiStates[i].midi = fEventsIn.data[i].midi; - evInMidiStates[i].frame_count = frames; - evInMidiStates[i].position = 0; - } - } - - for (i=0; i < fEventsOut.count; ++i) - { - if (fEventsOut.data[i].type & CARLA_EVENT_DATA_ATOM) - { - lv2_atom_buffer_reset(fEventsOut.data[i].atom, false); - } - else if (fEventsOut.data[i].type & CARLA_EVENT_DATA_EVENT) - { - lv2_event_buffer_reset(fEventsOut.data[i].event, LV2_EVENT_AUDIO_STAMP, fEventsOut.data[i].event->data); - } - else if (fEventsOut.data[i].type & CARLA_EVENT_DATA_MIDI_LL) - { - // not needed - } - } - - CARLA_PROCESS_CONTINUE_CHECK; -#endif - - // -------------------------------------------------------------------------------------------------------- - // Check if needs reset - - if (pData->needsReset) - { -#if 0 - uint8_t midiData[3] = { 0 }; - - if (fEventsIn.ctrl != nullptr && (fEventsIn.ctrl->type & CARLA_EVENT_TYPE_MIDI) != 0) - { - k = fEventsIn.ctrlIndex; - - if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) - { - for (i=0; i < MAX_MIDI_CHANNELS; ++i) - { - midiData[0] = MIDI_STATUS_CONTROL_CHANGE + i; - midiData[1] = MIDI_CONTROL_ALL_NOTES_OFF; - - if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - lv2_atom_buffer_write(&evInAtomIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - lv2_event_write(&evInEventIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - lv2midi_put_event(&evInMidiStates[k], 0, 3, midiData); - - midiData[0] = MIDI_STATUS_CONTROL_CHANGE + i; - midiData[1] = MIDI_CONTROL_ALL_SOUND_OFF; - - if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - lv2_atom_buffer_write(&evInAtomIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - lv2_event_write(&evInEventIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - lv2midi_put_event(&evInMidiStates[k], 0, 3, midiData); - } - } - else if (pData->ctrlChannel >= 0 && pData->ctrlChannel < MAX_MIDI_CHANNELS) - { - for (k=0; k < MAX_MIDI_NOTE; ++k) - { - midiData[0] = MIDI_STATUS_NOTE_OFF + pData->ctrlChannel; - midiData[1] = k; - - if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - lv2_atom_buffer_write(&evInAtomIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - lv2_event_write(&evInEventIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - lv2midi_put_event(&evInMidiStates[k], 0, 3, midiData); - } - } - } -#endif - //if (pData->latency > 0) - { - //for (i=0; i < pData->audioIn.count; ++i) - // FloatVectorOperations::clear(pData->latencyBuffers[i], pData->latency); - } - - pData->needsReset = false; - - CARLA_PROCESS_CONTINUE_CHECK; - } - -#if 0 - // -------------------------------------------------------------------------------------------------------- - // TimeInfo - - const EngineTimeInfo& timeInfo(pData->engine->getTimeInfo()); - - if (fFirstActive || fLastTimeInfo != timeInfo) - { - bool doPostRt; - int32_t rindex; - - // update input ports - for (k=0; k < pData->param.count; ++k) - { - //if (pData->param.data[k].type != PARAMETER_LV2_TIME) - continue; - - doPostRt = false; - rindex = pData->param.data[k].rindex; - - CARLA_ASSERT(rindex >= 0 && rindex < static_cast(fRdfDescriptor->PortCount)); - - switch (fRdfDescriptor->Ports[rindex].Designation) - { - // Non-BBT - case LV2_PORT_DESIGNATION_TIME_SPEED: - if (fLastTimeInfo.playing != timeInfo.playing) - { - fParamBuffers[k] = timeInfo.playing ? 1.0f : 0.0f; - doPostRt = true; - } - break; - case LV2_PORT_DESIGNATION_TIME_FRAME: - if (fLastTimeInfo.frame != timeInfo.frame) - { - fParamBuffers[k] = timeInfo.frame; - doPostRt = true; - } - break; - case LV2_PORT_DESIGNATION_TIME_FRAMES_PER_SECOND: - break; - - // BBT - case LV2_PORT_DESIGNATION_TIME_BAR: - if ((timeInfo.valid & EngineTimeInfo::kValidBBT) != 0 && fLastTimeInfo.bbt.bar != timeInfo.bbt.bar) - { - fParamBuffers[k] = timeInfo.bbt.bar - 1; - doPostRt = true; - } - break; - case LV2_PORT_DESIGNATION_TIME_BAR_BEAT: - if ((timeInfo.valid & EngineTimeInfo::kValidBBT) != 0 && (fLastTimeInfo.bbt.tick != timeInfo.bbt.tick || - fLastTimeInfo.bbt.ticksPerBeat != timeInfo.bbt.ticksPerBeat)) - { - fParamBuffers[k] = timeInfo.bbt.beat - 1 + (double(timeInfo.bbt.tick) / timeInfo.bbt.ticksPerBeat); - doPostRt = true; - } - break; - case LV2_PORT_DESIGNATION_TIME_BEAT: - if ((timeInfo.valid & EngineTimeInfo::kValidBBT) != 0 && fLastTimeInfo.bbt.beat != timeInfo.bbt.beat) - { - fParamBuffers[k] = timeInfo.bbt.beat - 1; - doPostRt = true; - } - break; - case LV2_PORT_DESIGNATION_TIME_BEAT_UNIT: - if ((timeInfo.valid & EngineTimeInfo::kValidBBT) != 0 && fLastTimeInfo.bbt.beatType != timeInfo.bbt.beatType) - { - fParamBuffers[k] = timeInfo.bbt.beatType; - doPostRt = true; - } - break; - case LV2_PORT_DESIGNATION_TIME_BEATS_PER_BAR: - if ((timeInfo.valid & EngineTimeInfo::kValidBBT) != 0 && fLastTimeInfo.bbt.beatsPerBar != timeInfo.bbt.beatsPerBar) - { - fParamBuffers[k] = timeInfo.bbt.beatsPerBar; - doPostRt = true; - } - break; - case LV2_PORT_DESIGNATION_TIME_BEATS_PER_MINUTE: - if ((timeInfo.valid & EngineTimeInfo::kValidBBT) != 0 && fLastTimeInfo.bbt.beatsPerMinute != timeInfo.bbt.beatsPerMinute) - { - fParamBuffers[k] = timeInfo.bbt.beatsPerMinute; - doPostRt = true; - } - break; - } - - if (doPostRt) - pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(k), 1, fParamBuffers[k]); - } - - for (i = 0; i < fEventsIn.count; ++i) - { - if ((fEventsIn.data[i].type & CARLA_EVENT_DATA_ATOM) == 0 || (fEventsIn.data[i].type & CARLA_EVENT_TYPE_TIME) == 0) - continue; - - uint8_t timeInfoBuf[256] = { 0 }; - lv2_atom_forge_set_buffer(&fAtomForge, timeInfoBuf, sizeof(timeInfoBuf)); - - LV2_Atom_Forge_Frame forgeFrame; - lv2_atom_forge_blank(&fAtomForge, &forgeFrame, 1, CARLA_URI_MAP_ID_TIME_POSITION); - lv2_atom_forge_property_head(&fAtomForge, CARLA_URI_MAP_ID_TIME_SPEED, 0); - lv2_atom_forge_float(&fAtomForge, timeInfo.playing ? 1.0f : 0.0f); - lv2_atom_forge_property_head(&fAtomForge, CARLA_URI_MAP_ID_TIME_FRAME, 0); - lv2_atom_forge_long(&fAtomForge, timeInfo.frame); - - if (timeInfo.valid & EngineTimeInfo::kValidBBT) - { - lv2_atom_forge_property_head(&fAtomForge, CARLA_URI_MAP_ID_TIME_BAR, 0); - lv2_atom_forge_long(&fAtomForge, timeInfo.bbt.bar - 1); - lv2_atom_forge_property_head(&fAtomForge, CARLA_URI_MAP_ID_TIME_BAR_BEAT, 0); - lv2_atom_forge_float(&fAtomForge, timeInfo.bbt.beat - 1 + (double(timeInfo.bbt.tick) / timeInfo.bbt.ticksPerBeat)); - lv2_atom_forge_property_head(&fAtomForge, CARLA_URI_MAP_ID_TIME_BEAT, 0); - lv2_atom_forge_long(&fAtomForge, timeInfo.bbt.beat -1); - lv2_atom_forge_property_head(&fAtomForge, CARLA_URI_MAP_ID_TIME_BEAT_UNIT, 0); - lv2_atom_forge_float(&fAtomForge, timeInfo.bbt.beatType); - lv2_atom_forge_property_head(&fAtomForge, CARLA_URI_MAP_ID_TIME_BEATS_PER_BAR, 0); - lv2_atom_forge_float(&fAtomForge, timeInfo.bbt.beatsPerBar); - lv2_atom_forge_property_head(&fAtomForge, CARLA_URI_MAP_ID_TIME_BEATS_PER_MINUTE, 0); - lv2_atom_forge_float(&fAtomForge, timeInfo.bbt.beatsPerMinute); - } - - LV2_Atom* const atom((LV2_Atom*)timeInfoBuf); - lv2_atom_buffer_write(&evInAtomIters[i], 0, 0, atom->type, atom->size, LV2_ATOM_BODY_CONST(atom)); - - CARLA_ASSERT(atom->size < 256); - } - - pData->postRtEvents.trySplice(); - - std::memcpy(&fLastTimeInfo, &timeInfo, sizeof(EngineTimeInfo)); - - CARLA_PROCESS_CONTINUE_CHECK; - } -#endif - -#if 0 - // -------------------------------------------------------------------------------------------------------- - // Event Input and Processing - - if (fEventsIn.ctrl != nullptr) - { - // ---------------------------------------------------------------------------------------------------- - // Message Input - - if (fAtomQueueIn.tryLock()) - { - //if (! fAtomQueueIn.isEmpty()) - { - uint32_t portIndex; - const LV2_Atom* atom; - - k = fEventsIn.ctrlIndex; - - while (fAtomQueueIn.get(&atom, &portIndex)) - { - carla_debug("Event input message sent to plugin DSP, type %i:\"%s\", size:%i/%i", - atom->type, carla_lv2_urid_unmap(this, atom->type), - atom->size, lv2_atom_total_size(atom) - ); - - if (! lv2_atom_buffer_write(&evInAtomIters[k], 0, 0, atom->type, atom->size, LV2_ATOM_BODY_CONST(atom))) - { - carla_stdout("Event input buffer full, 1 message lost"); - break; - } - } - } - - fAtomQueueIn.unlock(); - } - - // ---------------------------------------------------------------------------------------------------- - // MIDI Input (External) - - if (pData->extNotes.mutex.tryLock()) - { - if ((fEventsIn.ctrl->type & CARLA_EVENT_TYPE_MIDI) == 0) - { - // does not handle MIDI - pData->extNotes.data.clear(); - } - else - { - k = fEventsIn.ctrlIndex; - - while (! pData->extNotes.data.isEmpty()) - { - const ExternalMidiNote& note(pData->extNotes.data.getFirst(true)); - - CARLA_ASSERT(note.channel >= 0 && note.channel < MAX_MIDI_CHANNELS); - - uint8_t midiEvent[3]; - midiEvent[0] = (note.velo > 0) ? MIDI_STATUS_NOTE_ON : MIDI_STATUS_NOTE_OFF; - midiEvent[0] += note.channel; - midiEvent[1] = note.note; - midiEvent[2] = note.velo; - - if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - lv2_atom_buffer_write(&evInAtomIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiEvent); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - lv2_event_write(&evInEventIters[k], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiEvent); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - lv2midi_put_event(&evInMidiStates[k], 0, 3, midiEvent); - } - } - - pData->extNotes.mutex.unlock(); - - } // End of MIDI Input (External) - - // ---------------------------------------------------------------------------------------------------- - // Event Input (System) - - bool allNotesOffSent = false; - bool sampleAccurate = (pData->options & PLUGIN_OPTION_FIXED_BUFFERS) == 0; - - uint32_t time, nEvents = (fEventsIn.ctrl->port != nullptr) ? fEventsIn.ctrl->port->getEventCount() : 0; - uint32_t startTime = 0; - uint32_t timeOffset = 0; - uint32_t nextBankId = 0; - - if (pData->midiprog.current >= 0 && pData->midiprog.count > 0) - nextBankId = pData->midiprog.data[pData->midiprog.current].bank; - - for (i=0; i < nEvents; ++i) - { - const EngineEvent& event(fEventsIn.ctrl->port->getEvent(i)); - - time = event.time; - - if (time >= frames) - continue; - - CARLA_ASSERT_INT2(time >= timeOffset, time, timeOffset); - - if (time > timeOffset && sampleAccurate) - { - if (processSingle(inBuffer, outBuffer, time - timeOffset, timeOffset)) - { - startTime = 0; - timeOffset = time; - - if (pData->midiprog.current >= 0 && pData->midiprog.count > 0) - nextBankId = pData->midiprog.data[pData->midiprog.current].bank; - else - nextBankId = 0; - - // reset iters - k = fEventsIn.ctrlIndex; - - if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - { - lv2_atom_buffer_reset(fEventsIn.data[k].atom, true); - lv2_atom_buffer_begin(&evInAtomIters[k], fEventsIn.data[k].atom); - } - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - { - lv2_event_buffer_reset(fEventsIn.data[k].event, LV2_EVENT_AUDIO_STAMP, fEventsIn.data[k].event->data); - lv2_event_begin(&evInEventIters[k], fEventsIn.data[k].event); - } - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - { - fEventsIn.data[k].midi->event_count = 0; - fEventsIn.data[k].midi->size = 0; - evInMidiStates[k].position = time; - } - } - else - startTime += timeOffset; - } - - // Control change - switch (event.type) - { - case kEngineEventTypeNull: - break; - - case kEngineEventTypeControl: - { - const EngineControlEvent& ctrlEvent(event.ctrl); - - switch (ctrlEvent.type) - { - case kEngineControlEventTypeNull: - break; - - case kEngineControlEventTypeParameter: - { -#ifndef BUILD_BRIDGE - // Control backend stuff - if (event.channel == pData->ctrlChannel) - { - float value; - - if (MIDI_IS_CONTROL_BREATH_CONTROLLER(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_DRYWET) > 0) - { - value = ctrlEvent.value; - setDryWet(value, false, false); - pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_DRYWET, 0, value); - } - - if (MIDI_IS_CONTROL_CHANNEL_VOLUME(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_VOLUME) > 0) - { - value = ctrlEvent.value*127.0f/100.0f; - setVolume(value, false, false); - pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_VOLUME, 0, value); - } - - if (MIDI_IS_CONTROL_BALANCE(ctrlEvent.param) && (pData->hints & PLUGIN_CAN_BALANCE) > 0) - { - float left, right; - value = ctrlEvent.value/0.5f - 1.0f; - - if (value < 0.0f) - { - left = -1.0f; - right = (value*2.0f)+1.0f; - } - else if (value > 0.0f) - { - left = (value*2.0f)-1.0f; - right = 1.0f; - } - else - { - left = -1.0f; - right = 1.0f; - } - - setBalanceLeft(left, false, false); - setBalanceRight(right, false, false); - pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_LEFT, 0, left); - pData->postponeRtEvent(kPluginPostRtEventParameterChange, PARAMETER_BALANCE_RIGHT, 0, right); - } - } -#endif - - // Control plugin parameters - for (k=0; k < pData->param.count; ++k) - { - if (pData->param.data[k].midiChannel != event.channel) - continue; - if (pData->param.data[k].midiCC != ctrlEvent.param) - continue; - if ((pData->param.data[k].hints & PARAMETER_IS_INPUT) == 0) - continue; - if ((pData->param.data[k].hints & PARAMETER_IS_AUTOMABLE) == 0) - continue; - - float value; - - if (pData->param.data[k].hints & PARAMETER_IS_BOOLEAN) - { - value = (ctrlEvent.value < 0.5f) ? pData->param.ranges[k].min : pData->param.ranges[k].max; - } - else - { - value = pData->param.ranges[k].getUnnormalizedValue(ctrlEvent.value); - - if (pData->param.data[k].hints & PARAMETER_IS_INTEGER) - value = std::rint(value); - } - - setParameterValue(k, value, false, false, false); - pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(k), 0, value); - } - - if ((pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) != 0 && ctrlEvent.param <= 0x5F) - { - uint8_t midiData[3]; - midiData[0] = MIDI_STATUS_CONTROL_CHANGE + i; - midiData[1] = ctrlEvent.param; - midiData[2] = ctrlEvent.value*127.0f; - - if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - lv2_atom_buffer_write(&evInAtomIters[fEventsIn.ctrlIndex], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - lv2_event_write(&evInEventIters[fEventsIn.ctrlIndex], 0, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - lv2midi_put_event(&evInMidiStates[fEventsIn.ctrlIndex], 0, 3, midiData); - } - - break; - } - - case kEngineControlEventTypeMidiBank: - if (event.channel == pData->ctrlChannel && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) - nextBankId = ctrlEvent.param; - break; - - case kEngineControlEventTypeMidiProgram: - if (event.channel == pData->ctrlChannel && (pData->options & PLUGIN_OPTION_MAP_PROGRAM_CHANGES) != 0) - { - const uint32_t nextProgramId = ctrlEvent.param; - - for (k=0; k < pData->midiprog.count; ++k) - { - if (pData->midiprog.data[k].bank == nextBankId && pData->midiprog.data[k].program == nextProgramId) - { - setMidiProgram(k, false, false, false); - pData->postponeRtEvent(kPluginPostRtEventMidiProgramChange, k, 0, 0.0f); - break; - } - } - } - break; - - case kEngineControlEventTypeAllSoundOff: - if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) - { - const uint32_t mtime(sampleAccurate ? startTime : time); - - uint8_t midiData[3]; - midiData[0] = MIDI_STATUS_CONTROL_CHANGE + i; - midiData[1] = MIDI_CONTROL_ALL_SOUND_OFF; - midiData[2] = 0; - - if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - lv2_atom_buffer_write(&evInAtomIters[fEventsIn.ctrlIndex], mtime, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - lv2_event_write(&evInEventIters[fEventsIn.ctrlIndex], mtime, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - lv2midi_put_event(&evInMidiStates[fEventsIn.ctrlIndex], mtime, 3, midiData); - } - break; - - case kEngineControlEventTypeAllNotesOff: - if (pData->options & PLUGIN_OPTION_SEND_ALL_SOUND_OFF) - { - if (event.channel == pData->ctrlChannel && ! allNotesOffSent) - { - allNotesOffSent = true; - sendMidiAllNotesOffToCallback(); - } - - const uint32_t mtime(sampleAccurate ? startTime : time); - - uint8_t midiData[3]; - midiData[0] = MIDI_STATUS_CONTROL_CHANGE + i; - midiData[1] = MIDI_CONTROL_ALL_NOTES_OFF; - midiData[2] = 0; - - if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - lv2_atom_buffer_write(&evInAtomIters[fEventsIn.ctrlIndex], mtime, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - lv2_event_write(&evInEventIters[fEventsIn.ctrlIndex], mtime, 0, CARLA_URI_MAP_ID_MIDI_EVENT, 3, midiData); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - lv2midi_put_event(&evInMidiStates[fEventsIn.ctrlIndex], mtime, 3, midiData); - } - break; - } - - break; - } - - case kEngineEventTypeMidi: - { - const EngineMidiEvent& midiEvent(event.midi); - - uint8_t status = MIDI_GET_STATUS_FROM_DATA(midiEvent.data); - uint8_t channel = event.channel; - uint32_t mtime = sampleAccurate ? startTime : time; - - if (MIDI_IS_STATUS_CHANNEL_PRESSURE(status) && (pData->options & PLUGIN_OPTION_SEND_CHANNEL_PRESSURE) == 0) - continue; - if (MIDI_IS_STATUS_CONTROL_CHANGE(status) && (pData->options & PLUGIN_OPTION_SEND_CONTROL_CHANGES) == 0) - continue; - if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status) && (pData->options & PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH) == 0) - continue; - if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status) && (pData->options & PLUGIN_OPTION_SEND_PITCHBEND) == 0) - continue; - - // Fix bad note-off - if (status == MIDI_STATUS_NOTE_ON && midiEvent.data[2] == 0) - status -= 0x10; - - k = fEventsIn.ctrlIndex; - - if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_ATOM) - lv2_atom_buffer_write(&evInAtomIters[k], mtime, 0, CARLA_URI_MAP_ID_MIDI_EVENT, midiEvent.size, midiEvent.data); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_EVENT) - lv2_event_write(&evInEventIters[k], mtime, 0, CARLA_URI_MAP_ID_MIDI_EVENT, midiEvent.size, midiEvent.data); - - else if (fEventsIn.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) - lv2midi_put_event(&evInMidiStates[k], mtime, midiEvent.size, midiEvent.data); - - if (status == MIDI_STATUS_NOTE_ON) - pData->postponeRtEvent(kPluginPostRtEventNoteOn, channel, midiEvent.data[1], midiEvent.data[2]); - else if (status == MIDI_STATUS_NOTE_OFF) - pData->postponeRtEvent(kPluginPostRtEventNoteOff, channel, midiEvent.data[1], 0.0f); - - break; - } - } - } - - pData->postRtEvents.trySplice(); - - if (frames > timeOffset) - processSingle(inBuffer, outBuffer, frames - timeOffset, timeOffset); - - } // End of Event Input and Processing - - // -------------------------------------------------------------------------------------------------------- - // Plugin processing (no events) - - else -#endif - { - processSingle(inBuffer, outBuffer, frames, 0); - - } // End of Plugin processing (no events) - -#if 0 - CARLA_PROCESS_CONTINUE_CHECK; - - // -------------------------------------------------------------------------------------------------------- - // MIDI Output - - if (fEventsOut.ctrl != nullptr) - { - if (fEventsOut.ctrl->type & CARLA_EVENT_DATA_ATOM) - { - const uint32_t rindex(fEventsOut.ctrl->rindex); - const LV2_Atom_Event* ev; - LV2_Atom_Buffer_Iterator iter; - - uint8_t* data; - lv2_atom_buffer_begin(&iter, fEventsOut.ctrl->atom); - - while (true) - { - data = nullptr; - ev = lv2_atom_buffer_get(&iter, &data); - - if (ev == nullptr || data == nullptr) - break; - - if (ev->body.type == CARLA_URI_MAP_ID_MIDI_EVENT && fEventsOut.ctrl->port != nullptr) - fEventsOut.ctrl->port->writeMidiEvent(ev->time.frames, ev->body.size, data); - - else if (ev->body.type == CARLA_URI_MAP_ID_ATOM_BLANK) - fAtomQueueOut.put(&ev->body, rindex); - - lv2_atom_buffer_increment(&iter); - } - } - else if ((fEventsOut.ctrl->type & CARLA_EVENT_DATA_EVENT) != 0 && fEventsOut.ctrl->port != nullptr) - { - const LV2_Event* ev; - LV2_Event_Iterator iter; - - uint8_t* data; - lv2_event_begin(&iter, fEventsOut.ctrl->event); - - while (true) - { - data = nullptr; - ev = lv2_event_get(&iter, &data); - - if (ev == nullptr || data == nullptr) - break; - - if (ev->type == CARLA_URI_MAP_ID_MIDI_EVENT) - fEventsOut.ctrl->port->writeMidiEvent(ev->frames, ev->size, data); - - lv2_event_increment(&iter); - } - } - else if ((fEventsOut.ctrl->type & CARLA_EVENT_DATA_MIDI_LL) != 0 && fEventsOut.ctrl->port != nullptr) - { - LV2_MIDIState state = { fEventsOut.ctrl->midi, frames, 0 }; - - uint32_t eventSize; - double eventTime; - unsigned char* eventData; - - while (lv2midi_get_event(&state, &eventTime, &eventSize, &eventData) < frames) - { - if (eventData == nullptr || eventSize == 0) - break; - - fEventsOut.ctrl->port->writeMidiEvent(eventTime, eventSize, eventData); - lv2midi_step(&state); - } - } - } -#endif - - // -------------------------------------------------------------------------------------------------------- - // Control Output - - if (pData->event.portOut != nullptr) - { - uint8_t channel; - uint16_t param; - float value; - - for (k=0; k < pData->param.count; ++k) - { - if (pData->param.data[k].type != PARAMETER_OUTPUT) - continue; - - if (pData->param.data[k].hints & PARAMETER_IS_STRICT_BOUNDS) - pData->param.ranges[k].fixValue(fParamBuffers[k]); - - if (pData->param.data[k].midiCC > 0) - { - channel = pData->param.data[k].midiChannel; - param = static_cast(pData->param.data[k].midiCC); - value = pData->param.ranges[k].getNormalizedValue(fParamBuffers[k]); - pData->event.portOut->writeControlEvent(0, channel, kEngineControlEventTypeParameter, param, value); - } - } - - } // End of Control Output - - CARLA_PROCESS_CONTINUE_CHECK; - -#if 0 - // -------------------------------------------------------------------------------------------------------- - // Final work - - if (fExt.worker != nullptr && fExt.worker->end_run != nullptr) - { - fExt.worker->end_run(fHandle); - - if (fHandle2 != nullptr) - fExt.worker->end_run(fHandle2); - } -#endif - - //fFirstActive = false; - - // -------------------------------------------------------------------------------------------------------- - } - - bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset) - { - CARLA_ASSERT(frames > 0); - - if (frames == 0) - return false; - - if (pData->audioIn.count > 0) - { - CARLA_ASSERT(inBuffer != nullptr); - if (inBuffer == nullptr) - return false; - } - if (pData->audioOut.count > 0) - { - CARLA_ASSERT(outBuffer != nullptr); - if (outBuffer == nullptr) - return false; - } - - uint32_t i, k; - - // -------------------------------------------------------------------------------------------------------- - // Try lock, silence otherwise - - if (pData->engine->isOffline()) - { - pData->singleMutex.lock(); - } - else if (! pData->singleMutex.tryLock()) - { - for (i=0; i < pData->audioOut.count; ++i) - { - for (k=0; k < frames; ++k) - outBuffer[i][k+timeOffset] = 0.0f; - } - - return false; - } - - // -------------------------------------------------------------------------------------------------------- - // Reset audio buffers - - for (i=0; i < pData->audioIn.count; ++i) - FLOAT_COPY(fAudioInBuffers[i], inBuffer[i]+timeOffset, frames); - - for (i=0; i < pData->audioOut.count; ++i) - FLOAT_CLEAR(fAudioOutBuffers[i], frames); - -#if 0 - // -------------------------------------------------------------------------------------------------------- - // Set CV input buffers - - for (i=0; i < fCvIn.count; ++i) - { - const uint32_t cvIndex(fCvIn.ports[i].param); - const float cvValue((fCvIn.ports[i].port->getBuffer()+timeOffset)[0]); - - if (fParamBuffers[cvIndex] != cvValue) - { - fParamBuffers[cvIndex] = cvValue; - pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(cvIndex), 0, cvValue); - } - } -#endif - - // -------------------------------------------------------------------------------------------------------- - // Run plugin - - fDescriptor->run(fHandle, frames); - - if (fHandle2 != nullptr) - fDescriptor->run(fHandle2, frames); - - // -------------------------------------------------------------------------------------------------------- - // Special Parameters - - for (k=0; k < pData->param.count; ++k) - { - if (pData->param.data[k].type != PARAMETER_INPUT) - continue; - - if (pData->param.data[k].hints & PARAMETER_IS_TRIGGER) - { - if (fParamBuffers[k] != pData->param.ranges[k].def) - { - fParamBuffers[k] = pData->param.ranges[k].def; - pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(k), 0, fParamBuffers[k]); - } - } - } - - pData->postRtEvents.trySplice(); - -#ifndef BUILD_BRIDGE - // -------------------------------------------------------------------------------------------------------- - // Post-processing (dry/wet, volume and balance) - - { - const bool doDryWet = (pData->hints & PLUGIN_CAN_DRYWET) != 0 && pData->postProc.dryWet != 1.0f; - const bool doBalance = (pData->hints & PLUGIN_CAN_BALANCE) != 0 && (pData->postProc.balanceLeft != -1.0f || pData->postProc.balanceRight != 1.0f); - - bool isPair; - float bufValue, oldBufLeft[doBalance ? frames : 1]; - - for (i=0; i < pData->audioOut.count; ++i) - { - // Dry/Wet - if (doDryWet) - { - for (k=0; k < frames; ++k) - { - // TODO - //if (k < pData->latency && pData->latency < frames) - // bufValue = (pData->audioIn.count == 1) ? pData->latencyBuffers[0][k] : pData->latencyBuffers[i][k]; - //else - // bufValue = (pData->audioIn.count == 1) ? inBuffer[0][k-m_latency] : inBuffer[i][k-m_latency]; - - bufValue = fAudioInBuffers[(pData->audioIn.count == 1) ? 0 : i][k]; - fAudioOutBuffers[i][k] = (fAudioOutBuffers[i][k] * pData->postProc.dryWet) + (bufValue * (1.0f - pData->postProc.dryWet)); - } - } - - // Balance - if (doBalance) - { - isPair = (i % 2 == 0); - - if (isPair) - { - CARLA_ASSERT(i+1 < pData->audioOut.count); - FLOAT_COPY(oldBufLeft, fAudioOutBuffers[i], frames); - } - - float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f; - float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f; - - for (k=0; k < frames; ++k) - { - if (isPair) - { - // left - fAudioOutBuffers[i][k] = oldBufLeft[k] * (1.0f - balRangeL); - fAudioOutBuffers[i][k] += fAudioOutBuffers[i+1][k] * (1.0f - balRangeR); - } - else - { - // right - fAudioOutBuffers[i][k] = fAudioOutBuffers[i][k] * balRangeR; - fAudioOutBuffers[i][k] += oldBufLeft[k] * balRangeL; - } - } - } - - // Volume (and buffer copy) - { - for (k=0; k < frames; ++k) - outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k] * pData->postProc.volume; - } - } - -# if 0 - // Latency, save values for next callback, TODO - if (pData->latency > 0 && pData->latency < frames) - { - for (i=0; i < pData->audioIn.count; ++i) - FloatVectorOperations::copy(pData->latencyBuffers[i], inBuffer[i] + (frames - pData->latency), pData->latency); - } -# endif - } // End of Post-processing -#else - for (i=0; i < pData->audioOut.count; ++i) - { - for (k=0; k < frames; ++k) - outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k]; - } -#endif - -#if 0 - // -------------------------------------------------------------------------------------------------------- - // Set CV output buffers - - for (i=0; i < fCvOut.count; ++i) - { - const uint32_t cvIndex(fCvOut.ports[i].param); - const float cvValue(fCvOut.ports[i].port->getBuffer()[0]); - -#if 0 - fCvOut.ports[i].port->writeBuffer(frames, timeOffset); -#endif - fParamBuffers[cvIndex] = cvValue; - } -#endif - - // -------------------------------------------------------------------------------------------------------- - - pData->singleMutex.unlock(); - return true; - } - - void bufferSizeChanged(const uint32_t newBufferSize) override - { - CARLA_ASSERT_INT(newBufferSize > 0, newBufferSize); - carla_debug("Lv2Plugin::bufferSizeChanged(%i) - start", newBufferSize); - - for (uint32_t i=0; i < pData->audioIn.count; ++i) - { - if (fAudioInBuffers[i] != nullptr) - delete[] fAudioInBuffers[i]; - fAudioInBuffers[i] = new float[newBufferSize]; - } - - for (uint32_t i=0; i < pData->audioOut.count; ++i) - { - if (fAudioOutBuffers[i] != nullptr) - delete[] fAudioOutBuffers[i]; - fAudioOutBuffers[i] = new float[newBufferSize]; - } - -#if 0 - for (uint32_t i=0; i < fCvIn.count; ++i) - { - if (CarlaEngineCVPort* const port = fCvIn.ports[i].port) - { - //port->setBufferSize(newBufferSize); - - fDescriptor->connect_port(fHandle, fCvIn.ports[i].rindex, port->getBuffer()); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, fCvIn.ports[i].rindex, port->getBuffer()); - } - } - - for (uint32_t i=0; i < fCvOut.count; ++i) - { - if (CarlaEngineCVPort* const port = fCvOut.ports[i].port) - { - //port->setBufferSize(newBufferSize); - - fDescriptor->connect_port(fHandle, fCvOut.ports[i].rindex, port->getBuffer()); - - if (fHandle2 != nullptr) - fDescriptor->connect_port(fHandle2, fCvOut.ports[i].rindex, port->getBuffer()); - } - } -#endif - - if (fHandle2 == nullptr) - { - for (uint32_t i=0; i < pData->audioIn.count; ++i) - { - CARLA_ASSERT(fAudioInBuffers[i] != nullptr); - fDescriptor->connect_port(fHandle, pData->audioIn.ports[i].rindex, fAudioInBuffers[i]); - } - - for (uint32_t i=0; i < pData->audioOut.count; ++i) - { - CARLA_ASSERT(fAudioOutBuffers[i] != nullptr); - fDescriptor->connect_port(fHandle, pData->audioOut.ports[i].rindex, fAudioOutBuffers[i]); - } - } - else - { - if (pData->audioIn.count > 0) - { - CARLA_ASSERT(pData->audioIn.count == 2); - CARLA_ASSERT(fAudioInBuffers[0] != nullptr); - CARLA_ASSERT(fAudioInBuffers[1] != nullptr); - - fDescriptor->connect_port(fHandle, pData->audioIn.ports[0].rindex, fAudioInBuffers[0]); - fDescriptor->connect_port(fHandle2, pData->audioIn.ports[1].rindex, fAudioInBuffers[1]); - } - - if (pData->audioOut.count > 0) - { - CARLA_ASSERT(pData->audioOut.count == 2); - CARLA_ASSERT(fAudioOutBuffers[0] != nullptr); - CARLA_ASSERT(fAudioOutBuffers[1] != nullptr); - - fDescriptor->connect_port(fHandle, pData->audioOut.ports[0].rindex, fAudioOutBuffers[0]); - fDescriptor->connect_port(fHandle2, pData->audioOut.ports[1].rindex, fAudioOutBuffers[1]); - } - } - -#if 0 - if (fLv2Options.maxBufferSize != static_cast(newBufferSize) || (fLv2Options.minBufferSize > 1 && fLv2Options.minBufferSize != static_cast(newBufferSize))) - { - fLv2Options.maxBufferSize = newBufferSize; - - if (fLv2Options.minBufferSize > 1) - fLv2Options.minBufferSize = newBufferSize; - - if (fExt.options != nullptr && fExt.options->set != nullptr) - { - fExt.options->set(fHandle, &fLv2Options.optMinBlockLenth); - fExt.options->set(fHandle, &fLv2Options.optMaxBlockLenth); - } - } -#endif - - carla_debug("Lv2Plugin::bufferSizeChanged(%i) - end", newBufferSize); - } - - void sampleRateChanged(const double newSampleRate) override - { - CARLA_ASSERT_INT(newSampleRate > 0.0, newSampleRate); - carla_debug("Lv2Plugin::sampleRateChanged(%g) - start", newSampleRate); - -#if 0 - if (fLv2Options.sampleRate != newSampleRate) - { - fLv2Options.sampleRate = newSampleRate; - - if (fExt.options != nullptr && fExt.options->set != nullptr) - fExt.options->set(fHandle, &fLv2Options.optSampleRate); - } -#endif - - for (uint32_t k=0; k < pData->param.count; ++k) - { - //if (pData->param.data[k].type == PARAMETER_SAMPLE_RATE) - { - fParamBuffers[k] = float(newSampleRate); - pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(k), 1, fParamBuffers[k]); - } - } - - carla_debug("Lv2Plugin::sampleRateChanged(%g) - end", newSampleRate); - } - - void offlineModeChanged(const bool isOffline) override - { - for (uint32_t k=0; k < pData->param.count; ++k) - { - //if (pData->param.data[k].type == PARAMETER_LV2_FREEWHEEL) - { - fParamBuffers[k] = isOffline ? pData->param.ranges[k].max : pData->param.ranges[k].min; - pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(k), 1, fParamBuffers[k]); - } - } - } - - // ------------------------------------------------------------------- - // Plugin buffers - - void initBuffers() override - { -#if 0 - fEventsIn.initBuffers(); - fEventsOut.initBuffers(); - fCvIn.initBuffers(); - fCvOut.initBuffers(); -#endif - - CarlaPlugin::initBuffers(); - } - - void clearBuffers() override - { - carla_debug("Lv2Plugin::clearBuffers() - start"); - - if (fAudioInBuffers != nullptr) - { - for (uint32_t i=0; i < pData->audioIn.count; ++i) - { - if (fAudioInBuffers[i] != nullptr) - { - delete[] fAudioInBuffers[i]; - fAudioInBuffers[i] = nullptr; - } - } - - delete[] fAudioInBuffers; - fAudioInBuffers = nullptr; - } - - if (fAudioOutBuffers != nullptr) - { - for (uint32_t i=0; i < pData->audioOut.count; ++i) - { - if (fAudioOutBuffers[i] != nullptr) - { - delete[] fAudioOutBuffers[i]; - fAudioOutBuffers[i] = nullptr; - } - } - - delete[] fAudioOutBuffers; - fAudioOutBuffers = nullptr; - } - - if (fParamBuffers != nullptr) - { - delete[] fParamBuffers; - fParamBuffers = nullptr; - } - -#if 0 - fEventsIn.clear(); - fEventsOut.clear(); - fCvIn.clear(); - fCvOut.clear(); -#endif - - CarlaPlugin::clearBuffers(); - - carla_debug("Lv2Plugin::clearBuffers() - end"); - } - -#if 0 - // ------------------------------------------------------------------- - // Post-poned UI Stuff - - void uiParameterChange(const uint32_t index, const float value) override - { - CARLA_ASSERT(fDescriptor != nullptr); - CARLA_ASSERT(fHandle != nullptr); - CARLA_ASSERT(index < pData->param.count); - - if (fDescriptor == nullptr || fHandle == nullptr) - return; - if (index >= pData->param.count) - return; - - if (fUi.type == PLUGIN_UI_OSC) - { - if (pData->osc.data.target != nullptr) - osc_send_control(pData->osc.data, pData->param.data[index].rindex, value); - } - else - { - if (fUi.handle != nullptr && fUi.descriptor != nullptr && fUi.descriptor->port_event != nullptr) - fUi.descriptor->port_event(fUi.handle, pData->param.data[index].rindex, sizeof(float), 0, &value); - } - } - - void uiMidiProgramChange(const uint32_t index) override - { - CARLA_ASSERT(index < pData->midiprog.count); - - if (index >= pData->midiprog.count) - return; - - if (fUi.type == PLUGIN_UI_OSC) - { - if (pData->osc.data.target != nullptr) - osc_send_midi_program(pData->osc.data, pData->midiprog.data[index].bank, pData->midiprog.data[index].program); - } - else - { - if (fExt.uiprograms != nullptr && fExt.uiprograms->select_program != nullptr) - fExt.uiprograms->select_program(fUi.handle, pData->midiprog.data[index].bank, pData->midiprog.data[index].program); - } - } - - void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) override - { - CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); - CARLA_ASSERT(note < MAX_MIDI_NOTE); - CARLA_ASSERT(velo > 0 && velo < MAX_MIDI_VALUE); - - if (channel >= MAX_MIDI_CHANNELS) - return; - if (note >= MAX_MIDI_NOTE) - return; - if (velo >= MAX_MIDI_VALUE) - return; - - if (fUi.type == PLUGIN_UI_OSC) - { - if (pData->osc.data.target != nullptr) - { - uint8_t midiData[4] = { 0 }; - midiData[1] = MIDI_STATUS_NOTE_ON + channel; - midiData[2] = note; - midiData[3] = velo; - osc_send_midi(pData->osc.data, midiData); - } - } - else - { - if (fUi.handle != nullptr && fUi.descriptor != nullptr && fUi.descriptor->port_event != nullptr && fEventsIn.ctrl != nullptr) - { - LV2_Atom_MidiEvent midiEv; - midiEv.event.time.frames = 0; - midiEv.event.body.type = CARLA_URI_MAP_ID_MIDI_EVENT; - midiEv.event.body.size = 3; - midiEv.data[0] = MIDI_STATUS_NOTE_OFF + channel; - midiEv.data[1] = note; - midiEv.data[2] = velo; - - fUi.descriptor->port_event(fUi.handle, fEventsIn.ctrl->rindex, 3, CARLA_URI_MAP_ID_ATOM_TRANSFER_ATOM, &midiEv); - } - } - } - - void uiNoteOff(const uint8_t channel, const uint8_t note) override - { - CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); - CARLA_ASSERT(note < MAX_MIDI_NOTE); - - if (channel >= MAX_MIDI_CHANNELS) - return; - if (note >= MAX_MIDI_NOTE) - return; - - if (fUi.type == PLUGIN_UI_OSC) - { - if (pData->osc.data.target != nullptr) - { - uint8_t midiData[4] = { 0 }; - midiData[1] = MIDI_STATUS_NOTE_OFF + channel; - midiData[2] = note; - osc_send_midi(pData->osc.data, midiData); - } - } - else - { - if (fUi.handle != nullptr && fUi.descriptor != nullptr && fUi.descriptor->port_event != nullptr && fEventsIn.ctrl != nullptr) - { - LV2_Atom_MidiEvent midiEv; - midiEv.event.time.frames = 0; - midiEv.event.body.type = CARLA_URI_MAP_ID_MIDI_EVENT; - midiEv.event.body.size = 3; - midiEv.data[0] = MIDI_STATUS_NOTE_OFF + channel; - midiEv.data[1] = note; - midiEv.data[2] = 0; - - fUi.descriptor->port_event(fUi.handle, fEventsIn.ctrl->rindex, 3, CARLA_URI_MAP_ID_ATOM_TRANSFER_ATOM, &midiEv); - } - } - } -#endif - - // ------------------------------------------------------------------- - -protected: -// void guiClosedCallback() override -// { -// showGui(false); -// pData->engine->callback(CALLBACK_SHOW_GUI, pData->id, 0, 0, 0.0f, nullptr); -// } - -#if 0 - // ------------------------------------------------------------------- - - LV2_URID getCustomURID(const char* const uri) - { - CARLA_ASSERT(uri != nullptr); - carla_debug("Lv2Plugin::getCustomURID(\"%s\")", uri); - - if (uri == nullptr) - return CARLA_URI_MAP_ID_NULL; - - for (size_t i=0; i < fCustomURIDs.count(); ++i) - { - const char*& thisUri(fCustomURIDs.getAt(i)); - if (thisUri != nullptr && std::strcmp(thisUri, uri) == 0) - return i; - } - - fCustomURIDs.append(carla_strdup(uri)); - - const LV2_URID urid(fCustomURIDs.count()-1); - - if (fUi.type == PLUGIN_UI_OSC && pData->osc.data.target != nullptr) - osc_send_lv2_urid_map(pData->osc.data, urid, uri); - - return urid; - } - - const char* getCustomURIString(const LV2_URID urid) - { - CARLA_ASSERT(urid != CARLA_URI_MAP_ID_NULL); - CARLA_ASSERT_INT2(urid < fCustomURIDs.count(), urid, fCustomURIDs.count()); - carla_debug("Lv2Plugin::getCustomURIString(%i)", urid); - - if (urid == CARLA_URI_MAP_ID_NULL) - return nullptr; - if (urid < fCustomURIDs.count()) - return fCustomURIDs.getAt(urid); - - return nullptr; - } - - // ------------------------------------------------------------------- - - void handleProgramChanged(const int32_t index) - { - CARLA_ASSERT_INT(index >= -1, index); - carla_debug("Lv2Plugin::handleProgramChanged(%i)", index); - - if (index == -1) - { - const ScopedSingleProcessLocker spl(this, true); - return reloadPrograms(false); - } - - if (index >= 0 && index < static_cast(pData->midiprog.count) && fExt.programs != nullptr && fExt.programs->get_program != nullptr) - { - if (const LV2_Program_Descriptor* progDesc = fExt.programs->get_program(fHandle, index)) - { - CARLA_ASSERT(progDesc->name != nullptr); - - if (pData->midiprog.data[index].name != nullptr) - delete[] pData->midiprog.data[index].name; - - pData->midiprog.data[index].name = carla_strdup(progDesc->name ? progDesc->name : ""); - - if (index == pData->midiprog.current) - pData->engine->callback(ENGINE_CALLBACK_UPDATE, pData->id, 0, 0, 0.0, nullptr); - else - pData->engine->callback(ENGINE_CALLBACK_RELOAD_PROGRAMS, pData->id, 0, 0, 0.0, nullptr); - } - } - } - - // ------------------------------------------------------------------- - - LV2_State_Status handleStateStore(const uint32_t key, const void* const value, const size_t size, const uint32_t type, const uint32_t flags) - { - CARLA_ASSERT(key != CARLA_URI_MAP_ID_NULL); - CARLA_ASSERT(value != nullptr); - CARLA_ASSERT(size > 0); - carla_debug("Lv2Plugin::handleStateStore(%i, %p, " P_SIZE ", %i, %i)", key, value, size, type, flags); - - // basic checks - if (key == CARLA_URI_MAP_ID_NULL) - { - carla_stderr2("Lv2Plugin::handleStateStore(%i, %p, " P_SIZE ", %i, %i) - invalid key", key, value, size, type, flags); - return LV2_STATE_ERR_NO_PROPERTY; - } - - if (value == nullptr || size == 0) - { - carla_stderr2("Lv2Plugin::handleStateStore(%i, %p, " P_SIZE ", %i, %i) - invalid value", key, value, size, type, flags); - return LV2_STATE_ERR_NO_PROPERTY; - } - - if ((flags & LV2_STATE_IS_POD) == 0) - { - carla_stderr2("Lv2Plugin::handleStateStore(%i, %p, " P_SIZE ", %i, %i) - invalid flags", key, value, size, type, flags); - return LV2_STATE_ERR_BAD_FLAGS; - } - - const char* const stype(carla_lv2_urid_unmap(this, type)); - - if (stype == nullptr) - { - carla_stderr2("Lv2Plugin::handleStateStore(%i, %p, " P_SIZE ", %i, %i) - invalid type", key, value, size, type, flags); - return LV2_STATE_ERR_BAD_TYPE; - } - - const char* const uriKey(carla_lv2_urid_unmap(this, key)); - - if (uriKey == nullptr) - { - carla_stderr2("Lv2Plugin::handleStateStore(%i, %p, " P_SIZE ", %i, %i) - invalid key URI", key, value, size, type, flags); - return LV2_STATE_ERR_NO_PROPERTY; - } - - // Check if we already have this key - for (List::Itenerator it = pData->custom.begin(); it.valid(); it.next()) - { - CustomData& data(*it); - - if (std::strcmp(data.key, uriKey) == 0) - { - if (data.value != nullptr) - delete[] data.value; - - if (std::strcmp(stype, LV2_ATOM__String) == 0 || std::strcmp(stype, LV2_ATOM__Path) == 0) - data.value = carla_strdup((const char*)value); - //else - //data.value = carla_strdup(QByteArray((const char*)value, size).toBase64().constData()); - - return LV2_STATE_SUCCESS; - } - } - - // Otherwise store it - CustomData newData; - newData.type = carla_strdup(stype); - newData.key = carla_strdup(uriKey); - - if (std::strcmp(stype, LV2_ATOM__String) == 0 || std::strcmp(stype, LV2_ATOM__Path) == 0) - newData.value = carla_strdup((const char*)value); - //else - //newData.value = carla_strdup(QByteArray((const char*)value, size).toBase64().constData()); - - pData->custom.append(newData); - - return LV2_STATE_SUCCESS; - } - - const void* handleStateRetrieve(const uint32_t key, size_t* const size, uint32_t* const type, uint32_t* const flags) - { - CARLA_ASSERT(key != CARLA_URI_MAP_ID_NULL); - carla_debug("Lv2Plugin::handleStateRetrieve(%i, %p, %p, %p)", key, size, type, flags); - - // basic checks - if (key == CARLA_URI_MAP_ID_NULL) - { - carla_stderr2("Lv2Plugin::handleStateRetrieve(%i, %p, %p, %p) - invalid key", key, size, type, flags); - return nullptr; - } - - if (size == nullptr || type == nullptr || flags == nullptr) - { - carla_stderr2("Lv2Plugin::handleStateRetrieve(%i, %p, %p, %p) - invalid data", key, size, type, flags); - return nullptr; - } - - const char* const uriKey(carla_lv2_urid_unmap(this, key)); - - if (uriKey == nullptr) - { - carla_stderr2("Lv2Plugin::handleStateRetrieve(%i, %p, %p, %p) - failed to find key", key, size, type, flags); - return nullptr; - } - - const char* stype = nullptr; - const char* stringData = nullptr; - - for (List::Itenerator it = pData->custom.begin(); it.valid(); it.next()) - { - CustomData& data(*it); - - if (std::strcmp(data.key, uriKey) == 0) - { - stype = data.type; - stringData = data.value; - break; - } - } - - if (stringData == nullptr) - { - carla_stderr2("Lv2Plugin::handleStateRetrieve(%i, %p, %p, %p) - invalid key '%s'", key, size, type, flags, uriKey); - return nullptr; - } - - *type = carla_lv2_urid_map(this, stype); - *flags = LV2_STATE_IS_POD; - - if (std::strcmp(stype, LV2_ATOM__String) == 0 || std::strcmp(stype, LV2_ATOM__Path) == 0) - { - *size = std::strlen(stringData); - return stringData; - } - else - { -// static QByteArray chunk; -// chunk = QByteArray::fromBase64(stringData); -// *size = chunk.size(); -// return chunk.constData(); - return nullptr; - } - } - - // ------------------------------------------------------------------- - - LV2_Worker_Status handleWorkerSchedule(const uint32_t size, const void* const data) - { - carla_stdout("Lv2Plugin::handleWorkerSchedule(%i, %p)", size, data); - - if (fExt.worker == nullptr || fExt.worker->work == nullptr) - { - carla_stderr("Lv2Plugin::handleWorkerSchedule(%i, %p) - plugin has no worker", size, data); - return LV2_WORKER_ERR_UNKNOWN; - } - - //if (pData->engine->isOffline()) - fExt.worker->work(fHandle, carla_lv2_worker_respond, this, size, data); - //else - // postponeEvent(PluginPostEventCustom, size, 0, 0.0, data); - - return LV2_WORKER_SUCCESS; - } - - LV2_Worker_Status handleWorkerRespond(const uint32_t size, const void* const data) - { - carla_stdout("Lv2Plugin::handleWorkerRespond(%i, %p)", size, data); - -#if 0 - LV2_Atom_Worker workerAtom; - workerAtom.atom.type = CARLA_URI_MAP_ID_ATOM_WORKER; - workerAtom.atom.size = sizeof(LV2_Atom_Worker_Body); - workerAtom.body.size = size; - workerAtom.body.data = data; - - atomQueueIn.put(0, (const LV2_Atom*)&workerAtom); -#endif - - return LV2_WORKER_SUCCESS; - } - - // ------------------------------------------------------------------- - - void handleExternalUiClosed() - { - CARLA_ASSERT(fUi.type == PLUGIN_UI_EXTERNAL); - - if (fUi.handle != nullptr && fUi.descriptor != nullptr && fUi.descriptor->cleanup != nullptr) - fUi.descriptor->cleanup(fUi.handle); - - fUi.handle = nullptr; - fUi.widget = nullptr; - pData->engine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, pData->id, 0, 0, 0.0f, nullptr); - } - - uint32_t handleUiPortMap(const char* const symbol) - { - CARLA_ASSERT(symbol != nullptr); - - if (symbol == nullptr) - return LV2UI_INVALID_PORT_INDEX; - - for (uint32_t i=0; i < fRdfDescriptor->PortCount; ++i) - { - if (std::strcmp(fRdfDescriptor->Ports[i].Symbol, symbol) == 0) - return i; - } - - return LV2UI_INVALID_PORT_INDEX; - } - - int handleUiResize(const int width, const int height) - { - CARLA_ASSERT(width > 0); - CARLA_ASSERT(height > 0); - - if (width <= 0 || height <= 0) - return 1; - - //if (pData->gui != nullptr) - // pData->gui->setSize(width, height); - - return 0; - } - - void handleUiWrite(const uint32_t rindex, const uint32_t bufferSize, const uint32_t format, const void* const buffer) - { - if (format == 0) - { - CARLA_ASSERT(buffer != nullptr); - CARLA_ASSERT(bufferSize == sizeof(float)); - - if (buffer == nullptr || bufferSize != sizeof(float)) - return; + if (LV2_IS_PORT_TRIGGER(portProps)) + pData->param.data[j].hints |= PARAMETER_IS_TRIGGER; - const float value(*(const float*)buffer); + if (LV2_IS_PORT_STRICT_BOUNDS(portProps)) + pData->param.data[j].hints |= PARAMETER_IS_STRICT_BOUNDS; - for (uint32_t i=0; i < pData->param.count; ++i) - { - if (pData->param.data[i].rindex == static_cast(rindex)) + // check if parameter is not enabled or automable + if (LV2_IS_PORT_NOT_ON_GUI(portProps)) { - if (fParamBuffers[i] != value) - setParameterValue(i, value, false, true, true); - break; + pData->param.data[j].hints &= ~(PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE); } - } - } - else if (format == CARLA_URI_MAP_ID_ATOM_TRANSFER_ATOM || format == CARLA_URI_MAP_ID_ATOM_TRANSFER_EVENT) - { - CARLA_ASSERT(bufferSize != 0); - CARLA_ASSERT(buffer != nullptr); - - if (bufferSize == 0 || buffer == nullptr) - return; - - fAtomQueueIn.put((const LV2_Atom*)buffer, rindex); - } - else - { - carla_stdout("Lv2Plugin::handleUiWrite(%i, %i, %i:\"%s\", %p) - unknown format", rindex, bufferSize, format, carla_lv2_urid_unmap(this, format), buffer); - } - } - - void handleLilvSetPortValue(const char* const portSymbol, const void* const value, uint32_t size, uint32_t type) - { - CARLA_ASSERT(portSymbol != nullptr); - CARLA_ASSERT(value != nullptr); - CARLA_ASSERT(size > 0); - CARLA_ASSERT(type != CARLA_URI_MAP_ID_NULL); - - if (portSymbol == nullptr) - return; - if (value == nullptr) - return; - if (size == 0) - return; - if (type == CARLA_URI_MAP_ID_NULL) - return; + else if (LV2_IS_PORT_CAUSES_ARTIFACTS(portProps) || LV2_IS_PORT_EXPENSIVE(portProps) || LV2_IS_PORT_NOT_AUTOMATIC(portProps)) + pData->param.data[j].hints &= ~PARAMETER_IS_AUTOMABLE; - const int32_t rindex(handleUiPortMap(portSymbol)); + pData->param.ranges[j].min = min; + pData->param.ranges[j].max = max; + pData->param.ranges[j].def = def; + pData->param.ranges[j].step = step; + pData->param.ranges[j].stepSmall = stepSmall; + pData->param.ranges[j].stepLarge = stepLarge; - if (rindex < 0) - return; + // Start parameters in their default values + //if (pData->param.data[j].type != PARAMETER_LV2_FREEWHEEL) + fParamBuffers[j] = def; + //else + // fParamBuffers[j] = min; - if (size == sizeof(float) && type == CARLA_URI_MAP_ID_ATOM_FLOAT) - { - const float valuef(*(const float*)value); + fDescriptor->connect_port(fHandle, i, &fParamBuffers[j]); - for (uint32_t i=0; i < pData->param.count; ++i) - { - if (pData->param.data[i].rindex == rindex) - { - setParameterValue(i, valuef, true, true, true); - break; - } + if (fHandle2 != nullptr) + fDescriptor->connect_port(fHandle2, i, &fParamBuffers[j]); } - } - } -#endif - - // ------------------------------------------------------------------- - - bool isRealtimeSafe() const - { - CARLA_ASSERT(fRdfDescriptor != nullptr); - - for (uint32_t i=0; i < fRdfDescriptor->FeatureCount; ++i) - { - if (std::strcmp(fRdfDescriptor->Features[i].URI, LV2_CORE__hardRTCapable) == 0) - return true; - } - - return false; - } - - bool needsFixedBuffer() const - { - CARLA_ASSERT(fRdfDescriptor != nullptr); - - for (uint32_t i=0; i < fRdfDescriptor->FeatureCount; ++i) - { - if (std::strcmp(fRdfDescriptor->Features[i].URI, LV2_BUF_SIZE__fixedBlockLength) == 0) - return true; - } - - return false; - } - - // ------------------------------------------------------------------- - - const char* getUiBridgePath(const LV2_Property type) const - { - //const EngineOptions& options(pData->engine->getOptions()); - - switch (type) - { -// case LV2_UI_GTK2: -// return options.bridge_lv2Gtk2; -// case LV2_UI_GTK3: -// return options.bridge_lv2Gtk3; -// case LV2_UI_QT4: -// return options.bridge_lv2Qt4; -// case LV2_UI_QT5: -// return options.bridge_lv2Qt5; -// case LV2_UI_COCOA: -// return options.bridge_lv2Cocoa; -// case LV2_UI_WINDOWS: -// return options.bridge_lv2Win; -// case LV2_UI_X11: -// return options.bridge_lv2X11; - default: - return nullptr; - } - } - - bool isUiBridgeable(const uint32_t uiId) const - { - const LV2_RDF_UI& rdfUi(fRdfDescriptor->UIs[uiId]); - - for (uint32_t i=0; i < rdfUi.FeatureCount; ++i) - { - if (std::strcmp(rdfUi.Features[i].URI, LV2_INSTANCE_ACCESS_URI) == 0) - return false; - if (std::strcmp(rdfUi.Features[i].URI, LV2_DATA_ACCESS_URI) == 0) - return false; - } - - return true; - } - -#if 0 - bool isUiResizable() const - { - for (uint32_t i=0; i < fUi.rdfDescriptor->FeatureCount; ++i) - { - if (std::strcmp(fUi.rdfDescriptor->Features[i].URI, LV2_UI__fixedSize) == 0) - return false; - if (std::strcmp(fUi.rdfDescriptor->Features[i].URI, LV2_UI__noUserResize) == 0) - return false; - } - - return true; - } - - void updateUi() - { - CARLA_ASSERT(fUi.handle != nullptr); - CARLA_ASSERT(fUi.descriptor != nullptr); - - fExt.uiidle = nullptr; - fExt.uiprograms = nullptr; - - if (fUi.descriptor->extension_data != nullptr) - { - fExt.uiidle = (const LV2UI_Idle_Interface*)fUi.descriptor->extension_data(LV2_UI__idleInterface); - fExt.uiprograms = (const LV2_Programs_UI_Interface*)fUi.descriptor->extension_data(LV2_PROGRAMS__UIInterface); - - // check if invalid - if (fExt.uiidle != nullptr && fExt.uiidle->idle == nullptr) - fExt.uiidle = nullptr; - - if (fExt.uiprograms != nullptr && fExt.uiprograms->select_program == nullptr) - fExt.uiprograms = nullptr; - - // update midi program - if (fExt.uiprograms && pData->midiprog.count > 0 && pData->midiprog.current >= 0) - fExt.uiprograms->select_program(fUi.handle, pData->midiprog.data[pData->midiprog.current].bank, - pData->midiprog.data[pData->midiprog.current].program); - } - - if (fUi.descriptor->port_event != nullptr) - { - // update control ports - float value; - for (uint32_t i=0; i < pData->param.count; ++i) + else { - value = getParameterValue(i); - fUi.descriptor->port_event(fUi.handle, pData->param.data[i].rindex, sizeof(float), CARLA_URI_MAP_ID_NULL, &value); - } - } - } -#endif - - // ------------------------------------------------------------------- - -public: - bool init(const char* const bundle, const char* const name, const char* const uri) - { - CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false); - - // --------------------------------------------------------------- - // first checks - - if (pData->client != nullptr) - { - pData->engine->setLastError("Plugin client is already registered"); - return false; - } - - if (bundle == nullptr || bundle[0] == '\0') - { - pData->engine->setLastError("null bundle"); - return false; - } - - if (uri == nullptr || uri[0] == '\0') - { - pData->engine->setLastError("null uri"); - return false; - } - - // --------------------------------------------------------------- - // get plugin from lv2_rdf (lilv) - - Lv2WorldClass& lv2World(Lv2WorldClass::getInstance()); - - // Convert bundle filename to URI - QString qBundle(QUrl::fromLocalFile(bundle).toString()); - if (! qBundle.endsWith(OS_SEP_STR)) - qBundle += OS_SEP_STR; - - // Load bundle - Lilv::Node lilvBundle(lv2World.new_uri(qBundle.toUtf8().constData())); - lv2World.load_bundle(lilvBundle); - - fRdfDescriptor = lv2_rdf_new(uri, true); - - if (fRdfDescriptor == nullptr) - { - pData->engine->setLastError("Failed to find the requested plugin in the LV2 Bundle"); - return false; - } - - // --------------------------------------------------------------- - // open DLL - - if (! pData->libOpen(fRdfDescriptor->Binary)) - { - pData->engine->setLastError(lib_error(fRdfDescriptor->Binary)); - return false; - } - -#if 0 - // --------------------------------------------------------------- - // initialize options - - fLv2Options.minBufferSize = 1; - fLv2Options.maxBufferSize = pData->engine->getBufferSize(); - fLv2Options.sampleRate = pData->engine->getSampleRate(); - - // --------------------------------------------------------------- - // initialize features (part 1) - - LV2_Event_Feature* const eventFt = new LV2_Event_Feature; - eventFt->callback_data = this; - eventFt->lv2_event_ref = carla_lv2_event_ref; - eventFt->lv2_event_unref = carla_lv2_event_unref; - - LV2_Log_Log* const logFt = new LV2_Log_Log; - logFt->handle = this; - logFt->printf = carla_lv2_log_printf; - logFt->vprintf = carla_lv2_log_vprintf; - - LV2_State_Make_Path* const stateMakePathFt = new LV2_State_Make_Path; - stateMakePathFt->handle = this; - stateMakePathFt->path = carla_lv2_state_make_path; - - LV2_State_Map_Path* const stateMapPathFt = new LV2_State_Map_Path; - stateMapPathFt->handle = this; - stateMapPathFt->abstract_path = carla_lv2_state_map_abstract_path; - stateMapPathFt->absolute_path = carla_lv2_state_map_absolute_path; - - LV2_Programs_Host* const programsFt = new LV2_Programs_Host; - programsFt->handle = this; - programsFt->program_changed = carla_lv2_program_changed; - - LV2_RtMemPool_Pool* const rtMemPoolFt = new LV2_RtMemPool_Pool; - lv2_rtmempool_init(rtMemPoolFt); - - LV2_URI_Map_Feature* const uriMapFt = new LV2_URI_Map_Feature; - uriMapFt->callback_data = this; - uriMapFt->uri_to_id = carla_lv2_uri_to_id; - - LV2_URID_Map* const uridMapFt = new LV2_URID_Map; - uridMapFt->handle = this; - uridMapFt->map = carla_lv2_urid_map; - - LV2_URID_Unmap* const uridUnmapFt = new LV2_URID_Unmap; - uridUnmapFt->handle = this; - uridUnmapFt->unmap = carla_lv2_urid_unmap; - - LV2_Worker_Schedule* const workerFt = new LV2_Worker_Schedule; - workerFt->handle = this; - workerFt->schedule_work = carla_lv2_worker_schedule; - - // --------------------------------------------------------------- - // initialize features (part 2) + // Port Type not supported, but it's optional anyway + fDescriptor->connect_port(fHandle, i, nullptr); - for (uint32_t i=0; i < kFeatureIdWorker+1; ++i) - fFeatures[i] = new LV2_Feature; + if (fHandle2 != nullptr) + fDescriptor->connect_port(fHandle2, i, nullptr); + } + } - fFeatures[kFeatureIdBufSizeBounded]->URI = LV2_BUF_SIZE__boundedBlockLength; - fFeatures[kFeatureIdBufSizeBounded]->data = nullptr; + if (needsCtrlIn) + { + portName.clear(); - fFeatures[kFeatureIdBufSizeFixed]->URI = LV2_BUF_SIZE__fixedBlockLength; - fFeatures[kFeatureIdBufSizeFixed]->data = nullptr; + if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT) + { + portName = pData->name; + portName += ":"; + } - fFeatures[kFeatureIdBufSizePowerOf2]->URI = LV2_BUF_SIZE__powerOf2BlockLength; - fFeatures[kFeatureIdBufSizePowerOf2]->data = nullptr; + portName += "events-in"; + portName.truncate(portNameSize); - fFeatures[kFeatureIdEvent]->URI = LV2_EVENT_URI; - fFeatures[kFeatureIdEvent]->data = eventFt; + pData->event.portIn = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true); + } - fFeatures[kFeatureIdHardRtCapable]->URI = LV2_CORE__hardRTCapable; - fFeatures[kFeatureIdHardRtCapable]->data = nullptr; + if (needsCtrlOut) + { + portName.clear(); - fFeatures[kFeatureIdInPlaceBroken]->URI = LV2_CORE__inPlaceBroken; - fFeatures[kFeatureIdInPlaceBroken]->data = nullptr; + if (processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT) + { + portName = pData->name; + portName += ":"; + } - fFeatures[kFeatureIdIsLive]->URI = LV2_CORE__isLive; - fFeatures[kFeatureIdIsLive]->data = nullptr; + portName += "events-out"; + portName.truncate(portNameSize); - fFeatures[kFeatureIdLogs]->URI = LV2_LOG__log; - fFeatures[kFeatureIdLogs]->data = logFt; + pData->event.portOut = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false); + } - fFeatures[kFeatureIdOptions]->URI = LV2_OPTIONS__options; - fFeatures[kFeatureIdOptions]->data = fLv2Options.opts; + if (forcedStereoIn || forcedStereoOut) + pData->options |= PLUGIN_OPTION_FORCE_STEREO; + else + pData->options &= ~PLUGIN_OPTION_FORCE_STEREO; - fFeatures[kFeatureIdPrograms]->URI = LV2_PROGRAMS__Host; - fFeatures[kFeatureIdPrograms]->data = programsFt; + // plugin hints + pData->hints = 0x0; - fFeatures[kFeatureIdRtMemPool]->URI = LV2_RTSAFE_MEMORY_POOL__Pool; - fFeatures[kFeatureIdRtMemPool]->data = rtMemPoolFt; + if (isRealtimeSafe()) + pData->hints |= PLUGIN_IS_RTSAFE; - fFeatures[kFeatureIdStateMakePath]->URI = LV2_STATE__makePath; - fFeatures[kFeatureIdStateMakePath]->data = stateMakePathFt; + if (LV2_IS_GENERATOR(fRdfDescriptor->Type[0], fRdfDescriptor->Type[1])) + pData->hints |= PLUGIN_IS_SYNTH; - fFeatures[kFeatureIdStateMapPath]->URI = LV2_STATE__mapPath; - fFeatures[kFeatureIdStateMapPath]->data = stateMapPathFt; + if (aOuts > 0 && (aIns == aOuts || aIns == 1)) + pData->hints |= PLUGIN_CAN_DRYWET; - fFeatures[kFeatureIdStrictBounds]->URI = LV2_PORT_PROPS__supportsStrictBounds; - fFeatures[kFeatureIdStrictBounds]->data = nullptr; + if (aOuts > 0) + pData->hints |= PLUGIN_CAN_VOLUME; - fFeatures[kFeatureIdUriMap]->URI = LV2_URI_MAP_URI; - fFeatures[kFeatureIdUriMap]->data = uriMapFt; + if (aOuts >= 2 && aOuts % 2 == 0) + pData->hints |= PLUGIN_CAN_BALANCE; - fFeatures[kFeatureIdUridMap]->URI = LV2_URID__map; - fFeatures[kFeatureIdUridMap]->data = uridMapFt; + // extra plugin hints + pData->extraHints &= ~PLUGIN_EXTRA_HINT_CAN_RUN_RACK; - fFeatures[kFeatureIdUridUnmap]->URI = LV2_URID__unmap; - fFeatures[kFeatureIdUridUnmap]->data = uridUnmapFt; + bufferSizeChanged(pData->engine->getBufferSize()); + reloadPrograms(true); - fFeatures[kFeatureIdWorker]->URI = LV2_WORKER__schedule; - fFeatures[kFeatureIdWorker]->data = workerFt; + if (pData->active) + activate(); - // check if it's possible to use non-fixed buffer size - if (! needsFixedBuffer()) - fFeatures[kFeatureIdBufSizeFixed]->URI = LV2_BUF_SIZE__boundedBlockLength; -#endif + carla_debug("Lv2Plugin::reload() - end"); + } - // --------------------------------------------------------------- - // get DLL main entry + // ------------------------------------------------------------------- + // Plugin processing -#if 0 - const LV2_Lib_Descriptor_Function libDescFn = (LV2_Lib_Descriptor_Function)pData->libSymbol("lv2_lib_descriptor"); + void activate() noexcept override + { + CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); - if (libDescFn != nullptr) + if (fDescriptor->activate != nullptr) { - // ----------------------------------------------------------- - // get lib descriptor - - const LV2_Lib_Descriptor* libFn = nullptr; //descLibFn(fRdfDescriptor->Bundle, features); + try { + fDescriptor->activate(fHandle); + } catch(...) {} - if (libFn == nullptr || libFn->get_plugin == nullptr) + if (fHandle2 != nullptr) { - pData->engine->setLastError("Plugin failed to return library descriptor"); - return false; + try { + fDescriptor->activate(fHandle2); + } catch(...) {} } + } + } - // ----------------------------------------------------------- - // get descriptor that matches URI - - uint32_t i = 0; - while ((fDescriptor = libFn->get_plugin(libFn->handle, i++))) - { - if (std::strcmp(fDescriptor->URI, uri) == 0) - break; - } + void deactivate() noexcept override + { + CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); - if (fDescriptor == nullptr) - libFn->cleanup(libFn->handle); - else -#endif + if (fDescriptor->deactivate != nullptr) { - const LV2_Descriptor_Function descFn = (LV2_Descriptor_Function)pData->libSymbol("lv2_descriptor"); + try { + fDescriptor->deactivate(fHandle); + } catch(...) {} - if (descFn == nullptr) + if (fHandle2 != nullptr) { - pData->engine->setLastError("Could not find the LV2 Descriptor in the plugin library"); - return false; + try { + fDescriptor->deactivate(fHandle2); + } catch(...) {} } + } + } - // ----------------------------------------------------------- - // get descriptor that matches URI + void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) override + { + uint32_t i, k; - uint32_t i = 0; - while ((fDescriptor = descFn(i++))) - { - carla_debug("LV2 Init @%i => '%s' vs '%s'", i, fDescriptor->URI, uri); - if (std::strcmp(fDescriptor->URI, uri) == 0) - break; - } - } + // -------------------------------------------------------------------------------------------------------- + // Check if active - if (fDescriptor == nullptr) + if (! pData->active) { - pData->engine->setLastError("Could not find the requested plugin URI in the plugin library"); - return false; + // disable any output sound + for (i=0; i < pData->audioOut.count; ++i) + FLOAT_CLEAR(outBuffer[i], frames); + return; } - // --------------------------------------------------------------- - // check supported port-types and features + // -------------------------------------------------------------------------------------------------------- + // Plugin processing (no events) - bool canContinue = true; + { + processSingle(inBuffer, outBuffer, frames, 0); - // Check supported ports - for (uint32_t i=0; i < fRdfDescriptor->PortCount; ++i) + } // End of Plugin processing (no events) + + // -------------------------------------------------------------------------------------------------------- + // Control Output + + if (pData->event.portOut != nullptr) { - const LV2_Property portTypes(fRdfDescriptor->Ports[i].Types); + uint8_t channel; + uint16_t param; + float value; - if (! is_lv2_port_supported(portTypes)) + for (k=0; k < pData->param.count; ++k) { - if (! LV2_IS_PORT_OPTIONAL(fRdfDescriptor->Ports[i].Properties)) + if (pData->param.data[k].type != PARAMETER_OUTPUT) + continue; + + if (pData->param.data[k].hints & PARAMETER_IS_STRICT_BOUNDS) + pData->param.ranges[k].fixValue(fParamBuffers[k]); + + if (pData->param.data[k].midiCC > 0) { - pData->engine->setLastError("Plugin requires a port type that is not currently supported"); - canContinue = false; - break; + channel = pData->param.data[k].midiChannel; + param = static_cast(pData->param.data[k].midiCC); + value = pData->param.ranges[k].getNormalizedValue(fParamBuffers[k]); + pData->event.portOut->writeControlEvent(0, channel, kEngineControlEventTypeParameter, param, value); } } - } - // Check supported features - for (uint32_t i=0; i < fRdfDescriptor->FeatureCount && canContinue; ++i) - { - if (LV2_IS_FEATURE_REQUIRED(fRdfDescriptor->Features[i].Type) && ! is_lv2_feature_supported(fRdfDescriptor->Features[i].URI)) - { -// QString msg(QString("Plugin requires a feature that is not supported:\n%1").arg(fRdfDescriptor->Features[i].URI)); -// pData->engine->setLastError(msg.toUtf8().constData()); - canContinue = false; - break; - } - } + } // End of Control Output -#if 0 - // Check extensions - for (uint32_t i=0; i < fRdfDescriptor->ExtensionCount; ++i) + CARLA_PROCESS_CONTINUE_CHECK; + + // -------------------------------------------------------------------------------------------------------- + } + + bool processSingle(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t timeOffset) + { + CARLA_SAFE_ASSERT_RETURN(frames > 0, false); + + if (pData->audioIn.count > 0) { - if (std::strcmp(fRdfDescriptor->Extensions[i], LV2_OPTIONS__interface) == 0) - pData->extraHints |= PLUGIN_HAS_EXTENSION_OPTIONS; - else if (std::strcmp(fRdfDescriptor->Extensions[i], LV2_PROGRAMS__Interface) == 0) - pData->extraHints |= PLUGIN_HAS_EXTENSION_PROGRAMS; - else if (std::strcmp(fRdfDescriptor->Extensions[i], LV2_STATE__interface) == 0) - pData->extraHints |= PLUGIN_HAS_EXTENSION_STATE; - else if (std::strcmp(fRdfDescriptor->Extensions[i], LV2_WORKER__interface) == 0) - pData->extraHints |= PLUGIN_HAS_EXTENSION_WORKER; - else - carla_stdout("Plugin has non-supported extension: '%s'", fRdfDescriptor->Extensions[i]); + CARLA_SAFE_ASSERT_RETURN(inBuffer != nullptr, false); } -#endif - - if (! canContinue) + if (pData->audioOut.count > 0) { - // error already set - return false; + CARLA_SAFE_ASSERT_RETURN(outBuffer != nullptr, false); } - // --------------------------------------------------------------- - // get info - - if (name != nullptr && name[0] != '\0') - pData->name = pData->engine->getUniquePluginName(name); - else - pData->name = pData->engine->getUniquePluginName(fRdfDescriptor->Name); - - // --------------------------------------------------------------- - // register client + uint32_t i, k; - pData->client = pData->engine->addClient(this); + // -------------------------------------------------------------------------------------------------------- + // Try lock, silence otherwise - if (pData->client == nullptr || ! pData->client->isOk()) + if (pData->engine->isOffline()) { - pData->engine->setLastError("Failed to register plugin client"); - return false; + pData->singleMutex.lock(); } - - // --------------------------------------------------------------- - // initialize plugin - - fHandle = fDescriptor->instantiate(fDescriptor, pData->engine->getSampleRate(), fRdfDescriptor->Bundle, fFeatures); - - if (fHandle == nullptr) + else if (! pData->singleMutex.tryLock()) { - pData->engine->setLastError("Plugin failed to initialize"); + for (i=0; i < pData->audioOut.count; ++i) + { + for (k=0; k < frames; ++k) + outBuffer[i][k+timeOffset] = 0.0f; + } + return false; } - // --------------------------------------------------------------- - // load plugin settings + // -------------------------------------------------------------------------------------------------------- + // Reset audio buffers - { - // set default options - pData->options = 0x0; + for (i=0; i < pData->audioIn.count; ++i) + FLOAT_COPY(fAudioInBuffers[i], inBuffer[i]+timeOffset, frames); - pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; + for (i=0; i < pData->audioOut.count; ++i) + FLOAT_CLEAR(fAudioOutBuffers[i], frames); - if (getMidiInCount() > 0 || needsFixedBuffer()) - pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; + // -------------------------------------------------------------------------------------------------------- + // Run plugin - if (pData->engine->getOptions().forceStereo) - pData->options |= PLUGIN_OPTION_FORCE_STEREO; + fDescriptor->run(fHandle, frames); - if (getMidiInCount() > 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 (fHandle2 != nullptr) + fDescriptor->run(fHandle2, frames); - // set identifier string - CarlaString identifier("V2/"); - identifier += uri; + // -------------------------------------------------------------------------------------------------------- + // Special Parameters - // load settings - pData->options = pData->loadSettings(pData->options, getOptionsAvailable()); + for (k=0; k < pData->param.count; ++k) + { + if (pData->param.data[k].type != PARAMETER_INPUT) + continue; - // ignore settings, we need this anyway - if (getMidiInCount() > 0 || needsFixedBuffer()) - pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; + if (pData->param.data[k].hints & PARAMETER_IS_TRIGGER) + { + if (fParamBuffers[k] != pData->param.ranges[k].def) + { + fParamBuffers[k] = pData->param.ranges[k].def; + pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(k), 0, fParamBuffers[k]); + } + } } - // --------------------------------------------------------------- - // gui stuff - - if (fRdfDescriptor->UICount == 0) - return true; - -#if 0 - // ----------------------------------------------------------- - // find more appropriate ui - - int eQt4, eQt5, eCocoa, eWindows, eX11, eGtk2, eGtk3, iCocoa, iWindows, iX11, iQt4, iQt5, iExt, iFinal; - eQt4 = eQt5 = eCocoa = eWindows = eX11 = eGtk2 = eGtk3 = iQt4 = iQt5 = iCocoa = iWindows = iX11 = iExt = iFinal = -1; + pData->postRtEvents.trySplice(); - const bool preferUiBridges(true); -//#ifdef BUILD_BRIDGE -// const bool preferUiBridges(pData->engine->getOptions().preferUiBridges); -//#else -// const bool preferUiBridges(pData->engine->getOptions().preferUiBridges && (pData->hints & PLUGIN_IS_BRIDGE) == 0); -//#endif +#ifndef BUILD_BRIDGE + // -------------------------------------------------------------------------------------------------------- + // Post-processing (dry/wet, volume and balance) - for (uint32_t i=0; i < fRdfDescriptor->UICount; ++i) { - CARLA_ASSERT(fRdfDescriptor->UIs[i].URI != nullptr); + const bool doDryWet = (pData->hints & PLUGIN_CAN_DRYWET) != 0 && pData->postProc.dryWet != 1.0f; + const bool doBalance = (pData->hints & PLUGIN_CAN_BALANCE) != 0 && (pData->postProc.balanceLeft != -1.0f || pData->postProc.balanceRight != 1.0f); - if (fRdfDescriptor->UIs[i].URI == nullptr) - { - carla_stderr("Plugin has an UI without a valid URI"); - continue; - } + bool isPair; + float bufValue, oldBufLeft[doBalance ? frames : 1]; - switch (fRdfDescriptor->UIs[i].Type) + for (i=0; i < pData->audioOut.count; ++i) { -#if 0//(QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) - case LV2_UI_QT4: - if (isUiBridgeable(i)) - eQt4 = i; - break; -#else - case LV2_UI_QT4: - if (isUiBridgeable(i) && preferUiBridges) - eQt4 = i; - iQt4 = i; - break; -#endif - -#if 0//(QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) - case LV2_UI_QT5: - if (isUiBridgeable(i) && preferUiBridges) - eQt5 = i; - iQt5 = i; - break; -#else - case LV2_UI_QT5: - if (isUiBridgeable(i) && preferUiBridges) - eQt5 = i; - break; -#endif - -#ifdef CARLA_OS_MAC - case LV2_UI_COCOA: - if (isUiBridgeable(i) && preferUiBridges) - eCocoa = i; - iCocoa = i; - break; -#endif + // Dry/Wet + if (doDryWet) + { + for (k=0; k < frames; ++k) + { + // TODO + //if (k < pData->latency && pData->latency < frames) + // bufValue = (pData->audioIn.count == 1) ? pData->latencyBuffers[0][k] : pData->latencyBuffers[i][k]; + //else + // bufValue = (pData->audioIn.count == 1) ? inBuffer[0][k-m_latency] : inBuffer[i][k-m_latency]; -#ifdef CARLA_OS_WIN - case LV2_UI_WINDOWS: - if (isUiBridgeable(i) && preferUiBridges) - eWindows = i; - iWindows = i; - break; -#endif + bufValue = fAudioInBuffers[(pData->audioIn.count == 1) ? 0 : i][k]; + fAudioOutBuffers[i][k] = (fAudioOutBuffers[i][k] * pData->postProc.dryWet) + (bufValue * (1.0f - pData->postProc.dryWet)); + } + } - case LV2_UI_X11: - if (isUiBridgeable(i) && preferUiBridges) - eX11 = i; -#ifdef Q_WS_X11 - iX11 = i; -#endif - break; + // Balance + if (doBalance) + { + isPair = (i % 2 == 0); - case LV2_UI_GTK2: - if (isUiBridgeable(i)) - eGtk2 = i; - break; + if (isPair) + { + CARLA_ASSERT(i+1 < pData->audioOut.count); + FLOAT_COPY(oldBufLeft, fAudioOutBuffers[i], frames); + } - case LV2_UI_GTK3: - if (isUiBridgeable(i)) - eGtk3 = i; - break; + float balRangeL = (pData->postProc.balanceLeft + 1.0f)/2.0f; + float balRangeR = (pData->postProc.balanceRight + 1.0f)/2.0f; - case LV2_UI_EXTERNAL: - case LV2_UI_OLD_EXTERNAL: - iExt = i; - break; + for (k=0; k < frames; ++k) + { + if (isPair) + { + // left + fAudioOutBuffers[i][k] = oldBufLeft[k] * (1.0f - balRangeL); + fAudioOutBuffers[i][k] += fAudioOutBuffers[i+1][k] * (1.0f - balRangeR); + } + else + { + // right + fAudioOutBuffers[i][k] = fAudioOutBuffers[i][k] * balRangeR; + fAudioOutBuffers[i][k] += oldBufLeft[k] * balRangeL; + } + } + } - default: - break; + // Volume (and buffer copy) + { + for (k=0; k < frames; ++k) + outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k] * pData->postProc.volume; + } } - } - - if (eQt4 >= 0) - iFinal = eQt4; - else if (eQt5 >= 0) - iFinal = eQt5; - else if (eCocoa >= 0) - iFinal = eCocoa; - else if (eWindows >= 0) - iFinal = eWindows; - else if (eX11 >= 0) - iFinal = eX11; - else if (iQt4 >= 0) - iFinal = iQt4; - else if (iQt5 >= 0) - iFinal = iQt5; - else if (iCocoa >= 0) - iFinal = iCocoa; - else if (iWindows >= 0) - iFinal = iWindows; - else if (iX11 >= 0) - iFinal = iX11; - else if (iExt >= 0) - iFinal = iExt; - else if (eGtk2 >= 0) - iFinal = eGtk2; - else if (eGtk3 >= 0) - iFinal = eGtk3; - - if (iFinal < 0) + } // End of Post-processing +#else + for (i=0; i < pData->audioOut.count; ++i) { - carla_stderr("Failed to find an appropriate LV2 UI for this plugin"); - return true; + for (k=0; k < frames; ++k) + outBuffer[i][k+timeOffset] = fAudioOutBuffers[i][k]; } +#endif - fUi.rdfDescriptor = &fRdfDescriptor->UIs[iFinal]; + // -------------------------------------------------------------------------------------------------------- - // ----------------------------------------------------------- - // check supported ui features + pData->singleMutex.unlock(); + return true; + } - canContinue = true; + void bufferSizeChanged(const uint32_t newBufferSize) override + { + CARLA_ASSERT_INT(newBufferSize > 0, newBufferSize); + carla_debug("Lv2Plugin::bufferSizeChanged(%i) - start", newBufferSize); - for (uint32_t i=0; i < fUi.rdfDescriptor->FeatureCount; ++i) + for (uint32_t i=0; i < pData->audioIn.count; ++i) { - if (LV2_IS_FEATURE_REQUIRED(fUi.rdfDescriptor->Features[i].Type) && ! is_lv2_ui_feature_supported(fUi.rdfDescriptor->Features[i].URI)) - { - carla_stderr2("Plugin UI requires a feature that is not supported:\n%s", fUi.rdfDescriptor->Features[i].URI); - canContinue = false; - break; - } + if (fAudioInBuffers[i] != nullptr) + delete[] fAudioInBuffers[i]; + fAudioInBuffers[i] = new float[newBufferSize]; } - if (! canContinue) + for (uint32_t i=0; i < pData->audioOut.count; ++i) { - fUi.rdfDescriptor = nullptr; - return true; + if (fAudioOutBuffers[i] != nullptr) + delete[] fAudioOutBuffers[i]; + fAudioOutBuffers[i] = new float[newBufferSize]; } - // ----------------------------------------------------------- - // initialize ui according to type - - const LV2_Property uiType(fUi.rdfDescriptor->Type); - - if (iFinal == eQt4 || iFinal == eQt5 || iFinal == eCocoa || iFinal == eWindows || iFinal == eX11 || iFinal == eGtk2 || iFinal == eGtk3) + if (fHandle2 == nullptr) { - // ------------------------------------------------------- - // initialize ui bridge + for (uint32_t i=0; i < pData->audioIn.count; ++i) + { + CARLA_ASSERT(fAudioInBuffers[i] != nullptr); + fDescriptor->connect_port(fHandle, pData->audioIn.ports[i].rindex, fAudioInBuffers[i]); + } - if (const char* const oscBinary = getUiBridgePath(uiType)) + for (uint32_t i=0; i < pData->audioOut.count; ++i) { - fUi.type = PLUGIN_UI_OSC; - pData->osc.thread.setOscData(oscBinary, fDescriptor->URI, fUi.rdfDescriptor->URI); + CARLA_ASSERT(fAudioOutBuffers[i] != nullptr); + fDescriptor->connect_port(fHandle, pData->audioOut.ports[i].rindex, fAudioOutBuffers[i]); } } else { - // ------------------------------------------------------- - // open UI DLL - - if (! pData->uiLibOpen(fUi.rdfDescriptor->Binary)) + if (pData->audioIn.count > 0) { - carla_stderr2("Could not load UI library, error was:\n%s", lib_error(fUi.rdfDescriptor->Binary)); - fUi.rdfDescriptor = nullptr; - return true; - } - - // ------------------------------------------------------- - // get UI DLL main entry - - LV2UI_DescriptorFunction uiDescFn = (LV2UI_DescriptorFunction)pData->uiLibSymbol("lv2ui_descriptor"); + CARLA_ASSERT(pData->audioIn.count == 2); + CARLA_ASSERT(fAudioInBuffers[0] != nullptr); + CARLA_ASSERT(fAudioInBuffers[1] != nullptr); - if (uiDescFn == nullptr) - { - carla_stderr2("Could not find the LV2UI Descriptor in the UI library"); - pData->uiLibClose(); - fUi.rdfDescriptor = nullptr; - return true; + fDescriptor->connect_port(fHandle, pData->audioIn.ports[0].rindex, fAudioInBuffers[0]); + fDescriptor->connect_port(fHandle2, pData->audioIn.ports[1].rindex, fAudioInBuffers[1]); } - // ------------------------------------------------------- - // get UI descriptor that matches UI URI - - uint32_t i = 0; - while ((fUi.descriptor = uiDescFn(i++))) + if (pData->audioOut.count > 0) { - if (std::strcmp(fUi.descriptor->URI, fUi.rdfDescriptor->URI) == 0) - break; - } + CARLA_ASSERT(pData->audioOut.count == 2); + CARLA_ASSERT(fAudioOutBuffers[0] != nullptr); + CARLA_ASSERT(fAudioOutBuffers[1] != nullptr); - if (fUi.descriptor == nullptr) - { - carla_stderr2("Could not find the requested GUI in the plugin UI library"); - pData->uiLibClose(); - fUi.rdfDescriptor = nullptr; - return true; + fDescriptor->connect_port(fHandle, pData->audioOut.ports[0].rindex, fAudioOutBuffers[0]); + fDescriptor->connect_port(fHandle2, pData->audioOut.ports[1].rindex, fAudioOutBuffers[1]); } + } - // ------------------------------------------------------- - // check if ui is usable - - switch (uiType) - { -#if 0//(QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) - case LV2_UI_QT5: - carla_debug("Will use LV2 Qt5 UI"); - fUi.type = PLUGIN_UI_QT; - break; -#else - case LV2_UI_QT4: - carla_debug("Will use LV2 Qt4 UI"); - fUi.type = PLUGIN_UI_QT; - break; -#endif - -#ifdef CARLA_OS_MAC - case LV2_UI_COCOA: - carla_debug("Will use LV2 Cocoa UI"); - fUi.type = PLUGIN_UI_PARENT; - break; -#endif - -#ifdef CARLA_OS_WIN - case LV2_UI_WINDOWS: - carla_debug("Will use LV2 Windows UI"); - fUi.type = PLUGIN_UI_PARENT; - break; -#endif - -#ifdef Q_WS_X11 - case LV2_UI_X11: - carla_debug("Will use LV2 X11 UI"); - fUi.type = PLUGIN_UI_PARENT; - break; -#endif - - case LV2_UI_GTK2: - carla_debug("Will use LV2 Gtk2 UI, NOT!"); - break; + carla_debug("Lv2Plugin::bufferSizeChanged(%i) - end", newBufferSize); + } - case LV2_UI_GTK3: - carla_debug("Will use LV2 Gtk3 UI, NOT!"); - break; + void sampleRateChanged(const double newSampleRate) override + { + CARLA_ASSERT_INT(newSampleRate > 0.0, int(newSampleRate)); + carla_debug("Lv2Plugin::sampleRateChanged(%g) - start", newSampleRate); - case LV2_UI_EXTERNAL: - case LV2_UI_OLD_EXTERNAL: - carla_debug("Will use LV2 External UI"); - fUi.type = PLUGIN_UI_EXTERNAL; + for (uint32_t k=0; k < pData->param.count; ++k) + { + if (pData->param.data[k].type == PARAMETER_INPUT && pData->param.special[k] == PARAMETER_SPECIAL_SAMPLE_RATE) + { + fParamBuffers[k] = float(newSampleRate); + pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(k), 1, fParamBuffers[k]); break; } + } + + carla_debug("Lv2Plugin::sampleRateChanged(%g) - end", newSampleRate); + } - if (fUi.type == PLUGIN_UI_NULL) + void offlineModeChanged(const bool isOffline) override + { + for (uint32_t k=0; k < pData->param.count; ++k) + { + if (pData->param.data[k].type == PARAMETER_INPUT && pData->param.special[k] == PARAMETER_SPECIAL_LV2_FREEWHEEL) { - pData->uiLibClose(); - fUi.descriptor = nullptr; - fUi.rdfDescriptor = nullptr; - return true; + fParamBuffers[k] = isOffline ? pData->param.ranges[k].max : pData->param.ranges[k].min; + pData->postponeRtEvent(kPluginPostRtEventParameterChange, static_cast(k), 1, fParamBuffers[k]); + break; } - - // ------------------------------------------------------- - // initialize ui features (part 1) - - //QString guiTitle(QString("%1 (GUI)").arg((const char*)pData->name)); - - LV2_Extension_Data_Feature* const uiDataFt = new LV2_Extension_Data_Feature; - uiDataFt->data_access = fDescriptor->extension_data; - - LV2UI_Port_Map* const uiPortMapFt = new LV2UI_Port_Map; - uiPortMapFt->handle = this; - uiPortMapFt->port_index = carla_lv2_ui_port_map; - - LV2UI_Resize* const uiResizeFt = new LV2UI_Resize; - uiResizeFt->handle = this; - uiResizeFt->ui_resize = carla_lv2_ui_resize; - - LV2_External_UI_Host* const uiExternalHostFt = new LV2_External_UI_Host; - uiExternalHostFt->ui_closed = carla_lv2_external_ui_closed; - uiExternalHostFt->plugin_human_id = nullptr; //carla_strdup(guiTitle.toUtf8().constData()); - - // ------------------------------------------------------- - // initialize ui features (part 2) - - for (uint32_t i=kFeatureIdUiDataAccess; i < kFeatureCount; ++i) - fFeatures[i] = new LV2_Feature; - - fFeatures[kFeatureIdUiDataAccess]->URI = LV2_DATA_ACCESS_URI; - fFeatures[kFeatureIdUiDataAccess]->data = uiDataFt; - - fFeatures[kFeatureIdUiInstanceAccess]->URI = LV2_INSTANCE_ACCESS_URI; - fFeatures[kFeatureIdUiInstanceAccess]->data = fHandle; - - fFeatures[kFeatureIdUiIdle]->URI = LV2_UI__idle; - fFeatures[kFeatureIdUiIdle]->data = nullptr; - - fFeatures[kFeatureIdUiFixedSize]->URI = LV2_UI__fixedSize; - fFeatures[kFeatureIdUiFixedSize]->data = nullptr; - - fFeatures[kFeatureIdUiMakeResident]->URI = LV2_UI__makeResident; - fFeatures[kFeatureIdUiMakeResident]->data = nullptr; - - fFeatures[kFeatureIdUiNoUserResize]->URI = LV2_UI__noUserResize; - fFeatures[kFeatureIdUiNoUserResize]->data = nullptr; - - fFeatures[kFeatureIdUiParent]->URI = LV2_UI__parent; - fFeatures[kFeatureIdUiParent]->data = nullptr; - - fFeatures[kFeatureIdUiPortMap]->URI = LV2_UI__portMap; - fFeatures[kFeatureIdUiPortMap]->data = uiPortMapFt; - - fFeatures[kFeatureIdUiPortSubscribe]->URI = LV2_UI__portSubscribe; - fFeatures[kFeatureIdUiPortSubscribe]->data = nullptr; - - fFeatures[kFeatureIdUiResize]->URI = LV2_UI__resize; - fFeatures[kFeatureIdUiResize]->data = uiResizeFt; - - fFeatures[kFeatureIdUiTouch]->URI = LV2_UI__touch; - fFeatures[kFeatureIdUiTouch]->data = nullptr; - - fFeatures[kFeatureIdExternalUi]->URI = LV2_EXTERNAL_UI__Host; - fFeatures[kFeatureIdExternalUi]->data = uiExternalHostFt; - - fFeatures[kFeatureIdExternalUiOld]->URI = LV2_EXTERNAL_UI_DEPRECATED_URI; - fFeatures[kFeatureIdExternalUiOld]->data = uiExternalHostFt; } -#endif - - return true; } -#if 0 // ------------------------------------------------------------------- + // Plugin buffers - void handleTransferAtom(const uint32_t portIndex, const LV2_Atom* const atom) - { - CARLA_ASSERT(atom != nullptr); - carla_debug("Lv2Plugin::handleTransferAtom(%i, %p)", portIndex, atom); - - fAtomQueueIn.put(atom, portIndex); - } - - void handleUridMap(const LV2_URID urid, const char* const uri) + void clearBuffers() override { - CARLA_ASSERT(urid != CARLA_URI_MAP_ID_NULL); - CARLA_ASSERT(uri != nullptr); - carla_debug("Lv2Plugin::handleUridMap(%i, \"%s\")", urid, uri); - - CARLA_SAFE_ASSERT_INT2(urid == fCustomURIDs.count(), urid, fCustomURIDs.count()); - - if (urid != fCustomURIDs.count()) - return; + carla_debug("Lv2Plugin::clearBuffers() - start"); - fCustomURIDs.append(carla_strdup(uri)); - } -#endif + if (fAudioInBuffers != nullptr) + { + for (uint32_t i=0; i < pData->audioIn.count; ++i) + { + if (fAudioInBuffers[i] != nullptr) + { + delete[] fAudioInBuffers[i]; + fAudioInBuffers[i] = nullptr; + } + } - // ------------------------------------------------------------------- + delete[] fAudioInBuffers; + fAudioInBuffers = nullptr; + } -private: - LV2_Handle fHandle; - LV2_Handle fHandle2; - LV2_Feature* fFeatures[kFeatureCount+1]; - const LV2_Descriptor* fDescriptor; - const LV2_RDF_Descriptor* fRdfDescriptor; + if (fAudioOutBuffers != nullptr) + { + for (uint32_t i=0; i < pData->audioOut.count; ++i) + { + if (fAudioOutBuffers[i] != nullptr) + { + delete[] fAudioOutBuffers[i]; + fAudioOutBuffers[i] = nullptr; + } + } - float** fAudioInBuffers; - float** fAudioOutBuffers; - float* fParamBuffers; + delete[] fAudioOutBuffers; + fAudioOutBuffers = nullptr; + } -#if 0 - Lv2AtomQueue fAtomQueueIn; - Lv2AtomQueue fAtomQueueOut; - LV2_Atom_Forge fAtomForge; - - PluginCVData fCvIn; - PluginCVData fCvOut; - Lv2PluginEventData fEventsIn; - Lv2PluginEventData fEventsOut; - Lv2PluginOptions fLv2Options; - - LinkedList fCustomURIDs; - - bool fFirstActive; // first process() call after activate() - EngineTimeInfo fLastTimeInfo; - - struct Extensions { - const LV2_Options_Interface* options; - const LV2_State_Interface* state; - const LV2_Worker_Interface* worker; - const LV2_Programs_Interface* programs; - const LV2UI_Idle_Interface* uiidle; - const LV2_Programs_UI_Interface* uiprograms; - - Extensions() - : options(nullptr), - state(nullptr), - worker(nullptr), - programs(nullptr), - uiidle(nullptr), - uiprograms(nullptr) {} - } fExt; - - struct UI { - Lv2PluginGuiType type; - LV2UI_Handle handle; - LV2UI_Widget widget; - const LV2UI_Descriptor* descriptor; - const LV2_RDF_UI* rdfDescriptor; - - UI() - : type(PLUGIN_UI_NULL), - handle(nullptr), - widget(nullptr), - descriptor(nullptr), - rdfDescriptor(nullptr) {} - - ~UI() + if (fParamBuffers != nullptr) { - CARLA_ASSERT(handle == nullptr); - CARLA_ASSERT(widget == nullptr); - CARLA_ASSERT(descriptor == nullptr); - CARLA_ASSERT(rdfDescriptor == nullptr); + delete[] fParamBuffers; + fParamBuffers = nullptr; } - } fUi; -#endif - -#if 0 - // ------------------------------------------------------------------- - // Event Feature - - static uint32_t carla_lv2_event_ref(LV2_Event_Callback_Data callback_data, LV2_Event* event) - { - carla_debug("carla_lv2_event_ref(%p, %p)", callback_data, event); - CARLA_ASSERT(callback_data != nullptr); - CARLA_ASSERT(event != nullptr); - - return 0; - } - - static uint32_t carla_lv2_event_unref(LV2_Event_Callback_Data callback_data, LV2_Event* event) - { - carla_debug("carla_lv2_event_unref(%p, %p)", callback_data, event); - CARLA_ASSERT(callback_data != nullptr); - CARLA_ASSERT(event != nullptr); + CarlaPlugin::clearBuffers(); - return 0; + carla_debug("Lv2Plugin::clearBuffers() - end"); } // ------------------------------------------------------------------- - // Logs Feature - static int carla_lv2_log_printf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, ...) + bool isRealtimeSafe() const { - CARLA_ASSERT(handle != nullptr); - CARLA_ASSERT(type > CARLA_URI_MAP_ID_NULL); - -#ifndef DEBUG - if (type == CARLA_URI_MAP_ID_LOG_TRACE) - return 0; -#endif + CARLA_ASSERT(fRdfDescriptor != nullptr); - va_list args; - va_start(args, fmt); - const int ret = carla_lv2_log_vprintf(handle, type, fmt, args); - va_end(args); + for (uint32_t i=0; i < fRdfDescriptor->FeatureCount; ++i) + { + if (std::strcmp(fRdfDescriptor->Features[i].URI, LV2_CORE__hardRTCapable) == 0) + return true; + } - return ret; + return false; } - static int carla_lv2_log_vprintf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, va_list ap) + bool needsFixedBuffer() const { - CARLA_ASSERT(handle != nullptr); - CARLA_ASSERT(type > CARLA_URI_MAP_ID_NULL); - -#ifndef DEBUG - if (type == CARLA_URI_MAP_ID_LOG_TRACE) - return 0; -#endif - - int ret = 0; + CARLA_ASSERT(fRdfDescriptor != nullptr); - switch (type) + for (uint32_t i=0; i < fRdfDescriptor->FeatureCount; ++i) { - case CARLA_URI_MAP_ID_LOG_ERROR: -#ifndef CARLA_OS_WIN - std::fprintf(stderr, "\x1b[31m"); -#endif - ret = std::vfprintf(stderr, fmt, ap); -#ifndef CARLA_OS_WIN - std::fprintf(stderr, "\x1b[0m"); -#endif - break; - - case CARLA_URI_MAP_ID_LOG_NOTE: - ret = std::vfprintf(stdout, fmt, ap); - break; - - case CARLA_URI_MAP_ID_LOG_TRACE: -#ifdef DEBUG -# ifndef CARLA_OS_WIN - std::fprintf(stdout, "\x1b[30;1m"); -# endif - ret = std::vfprintf(stdout, fmt, ap); -# ifndef CARLA_OS_WIN - std::fprintf(stdout, "\x1b[0m"); -# endif -#endif - break; - - case CARLA_URI_MAP_ID_LOG_WARNING: - ret = std::vfprintf(stderr, fmt, ap); - break; - - default: - break; + if (std::strcmp(fRdfDescriptor->Features[i].URI, LV2_BUF_SIZE__fixedBlockLength) == 0) + return true; } - return ret; + return false; } // ------------------------------------------------------------------- - // Programs Feature - static void carla_lv2_program_changed(LV2_Programs_Handle handle, int32_t index) +public: + bool init(const char* const bundle, const char* const name, const char* const uri) { - carla_debug("carla_lv2_program_changed(%p, %i)", handle, index); - CARLA_ASSERT(handle != nullptr); - - if (handle == nullptr) - return; - - ((Lv2Plugin*)handle)->handleProgramChanged(index); - } - - // ------------------------------------------------------------------- - // State Feature + CARLA_SAFE_ASSERT_RETURN(pData->engine != nullptr, false); - static char* carla_lv2_state_make_path(LV2_State_Make_Path_Handle handle, const char* path) - { - carla_debug("carla_lv2_state_make_path(%p, \"%s\")", handle, path); - CARLA_ASSERT(handle != nullptr); - CARLA_ASSERT(path != nullptr); + // --------------------------------------------------------------- + // first checks - if (path == nullptr) - return nullptr; + if (pData->client != nullptr) + { + pData->engine->setLastError("Plugin client is already registered"); + return false; + } - //QDir dir; - //dir.mkpath(path); - //return strdup(path); - return nullptr; - } + if (bundle == nullptr || bundle[0] == '\0') + { + pData->engine->setLastError("null bundle"); + return false; + } - static char* carla_lv2_state_map_abstract_path(LV2_State_Map_Path_Handle handle, const char* absolute_path) - { - carla_debug("carla_lv2_state_map_abstract_path(%p, \"%s\")", handle, absolute_path); - CARLA_ASSERT(handle != nullptr); - CARLA_ASSERT(absolute_path != nullptr); + if (uri == nullptr || uri[0] == '\0') + { + pData->engine->setLastError("null uri"); + return false; + } - if (absolute_path == nullptr) - return nullptr; + // --------------------------------------------------------------- + // get plugin from lv2_rdf (lilv) - //QDir dir(absolute_path); - //return strdup(dir.canonicalPath().toUtf8().constData()); - return nullptr; - } + Lv2WorldClass& lv2World(Lv2WorldClass::getInstance()); - static char* carla_lv2_state_map_absolute_path(LV2_State_Map_Path_Handle handle, const char* abstract_path) - { - carla_debug("carla_lv2_state_map_absolute_path(%p, \"%s\")", handle, abstract_path); - CARLA_ASSERT(handle != nullptr); - CARLA_ASSERT(abstract_path != nullptr); + // Convert bundle filename to URI + QString qBundle(QUrl::fromLocalFile(bundle).toString()); + if (! qBundle.endsWith(OS_SEP_STR)) + qBundle += OS_SEP_STR; - if (abstract_path == nullptr) - return nullptr; + // Load bundle + Lilv::Node lilvBundle(lv2World.new_uri(qBundle.toUtf8().constData())); + lv2World.load_bundle(lilvBundle); - //QDir dir(abstract_path); - //return strdup(dir.absolutePath().toUtf8().constData()); - return nullptr; - } + fRdfDescriptor = lv2_rdf_new(uri, true); - static LV2_State_Status carla_lv2_state_store(LV2_State_Handle handle, uint32_t key, const void* value, size_t size, uint32_t type, uint32_t flags) - { - carla_debug("carla_lv2_state_store(%p, %i, %p, " P_SIZE ", %i, %i)", handle, key, value, size, type, flags); - CARLA_ASSERT(handle != nullptr); + if (fRdfDescriptor == nullptr) + { + pData->engine->setLastError("Failed to find the requested plugin in the LV2 Bundle"); + return false; + } - if (handle == nullptr) - return LV2_STATE_ERR_UNKNOWN; + // --------------------------------------------------------------- + // open DLL - return ((Lv2Plugin*)handle)->handleStateStore(key, value, size, type, flags); - } + if (! pData->libOpen(fRdfDescriptor->Binary)) + { + pData->engine->setLastError(lib_error(fRdfDescriptor->Binary)); + return false; + } - static const void* carla_lv2_state_retrieve(LV2_State_Handle handle, uint32_t key, size_t* size, uint32_t* type, uint32_t* flags) - { - carla_debug("carla_lv2_state_retrieve(%p, %i, %p, %p, %p)", handle, key, size, type, flags); - CARLA_ASSERT(handle != nullptr); + // --------------------------------------------------------------- + // get DLL main entry - if (handle == nullptr) - return nullptr; + const LV2_Descriptor_Function descFn = (LV2_Descriptor_Function)pData->libSymbol("lv2_descriptor"); - return ((Lv2Plugin*)handle)->handleStateRetrieve(key, size, type, flags); - } + if (descFn == nullptr) + { + pData->engine->setLastError("Could not find the LV2 Descriptor in the plugin library"); + return false; + } - // ------------------------------------------------------------------- - // URI-Map Feature + // ----------------------------------------------------------- + // get descriptor that matches URI - static uint32_t carla_lv2_uri_to_id(LV2_URI_Map_Callback_Data data, const char* map, const char* uri) - { - carla_debug("carla_lv2_uri_to_id(%p, \"%s\", \"%s\")", data, map, uri); - return carla_lv2_urid_map((LV2_URID_Map_Handle*)data, uri); + uint32_t i = 0; + while ((fDescriptor = descFn(i++))) + { + carla_debug("LV2 Init @%i => '%s' vs '%s'", i, fDescriptor->URI, uri); + if (std::strcmp(fDescriptor->URI, uri) == 0) + break; + } - // unused - (void)map; - } + if (fDescriptor == nullptr) + { + pData->engine->setLastError("Could not find the requested plugin URI in the plugin library"); + return false; + } - // ------------------------------------------------------------------- - // URID Feature + // --------------------------------------------------------------- + // check supported port-types and features - static LV2_URID carla_lv2_urid_map(LV2_URID_Map_Handle handle, const char* uri) - { - CARLA_ASSERT(handle != nullptr); - CARLA_ASSERT(uri != nullptr); - carla_debug("carla_lv2_urid_map(%p, \"%s\")", handle, uri); - - if (uri == nullptr) - return CARLA_URI_MAP_ID_NULL; - - // Atom types - if (std::strcmp(uri, LV2_ATOM__Blank) == 0) - return CARLA_URI_MAP_ID_ATOM_BLANK; - if (std::strcmp(uri, LV2_ATOM__Bool) == 0) - return CARLA_URI_MAP_ID_ATOM_BOOL; - if (std::strcmp(uri, LV2_ATOM__Chunk) == 0) - return CARLA_URI_MAP_ID_ATOM_CHUNK; - if (std::strcmp(uri, LV2_ATOM__Double) == 0) - return CARLA_URI_MAP_ID_ATOM_DOUBLE; - if (std::strcmp(uri, LV2_ATOM__Float) == 0) - return CARLA_URI_MAP_ID_ATOM_FLOAT; - if (std::strcmp(uri, LV2_ATOM__Int) == 0) - return CARLA_URI_MAP_ID_ATOM_INT; - if (std::strcmp(uri, LV2_ATOM__Literal) == 0) - return CARLA_URI_MAP_ID_ATOM_LITERAL; - if (std::strcmp(uri, LV2_ATOM__Long) == 0) - return CARLA_URI_MAP_ID_ATOM_LONG; - if (std::strcmp(uri, LV2_ATOM__Path) == 0) - return CARLA_URI_MAP_ID_ATOM_PATH; - if (std::strcmp(uri, LV2_ATOM__Property) == 0) - return CARLA_URI_MAP_ID_ATOM_PROPERTY; - if (std::strcmp(uri, LV2_ATOM__Resource) == 0) - return CARLA_URI_MAP_ID_ATOM_RESOURCE; - if (std::strcmp(uri, LV2_ATOM__Sequence) == 0) - return CARLA_URI_MAP_ID_ATOM_SEQUENCE; - if (std::strcmp(uri, LV2_ATOM__String) == 0) - return CARLA_URI_MAP_ID_ATOM_STRING; - if (std::strcmp(uri, LV2_ATOM__Tuple) == 0) - return CARLA_URI_MAP_ID_ATOM_TUPLE; - if (std::strcmp(uri, LV2_ATOM__URI) == 0) - return CARLA_URI_MAP_ID_ATOM_URI; - if (std::strcmp(uri, LV2_ATOM__URID) == 0) - return CARLA_URI_MAP_ID_ATOM_URID; - if (std::strcmp(uri, LV2_ATOM__Vector) == 0) - return CARLA_URI_MAP_ID_ATOM_VECTOR; - if (std::strcmp(uri, LV2_ATOM__atomTransfer) == 0) - return CARLA_URI_MAP_ID_ATOM_TRANSFER_ATOM; - if (std::strcmp(uri, LV2_ATOM__eventTransfer) == 0) - return CARLA_URI_MAP_ID_ATOM_TRANSFER_EVENT; - - // BufSize types - if (std::strcmp(uri, LV2_BUF_SIZE__maxBlockLength) == 0) - return CARLA_URI_MAP_ID_BUF_MAX_LENGTH; - if (std::strcmp(uri, LV2_BUF_SIZE__minBlockLength) == 0) - return CARLA_URI_MAP_ID_BUF_MIN_LENGTH; - if (std::strcmp(uri, LV2_BUF_SIZE__sequenceSize) == 0) - return CARLA_URI_MAP_ID_BUF_SEQUENCE_SIZE; - - // Log types - if (std::strcmp(uri, LV2_LOG__Error) == 0) - return CARLA_URI_MAP_ID_LOG_ERROR; - if (std::strcmp(uri, LV2_LOG__Note) == 0) - return CARLA_URI_MAP_ID_LOG_NOTE; - if (std::strcmp(uri, LV2_LOG__Trace) == 0) - return CARLA_URI_MAP_ID_LOG_TRACE; - if (std::strcmp(uri, LV2_LOG__Warning) == 0) - return CARLA_URI_MAP_ID_LOG_WARNING; - - // Time types - if (std::strcmp(uri, LV2_TIME__Position) == 0) - return CARLA_URI_MAP_ID_TIME_POSITION; - if (std::strcmp(uri, LV2_TIME__bar) == 0) - return CARLA_URI_MAP_ID_TIME_BAR; - if (std::strcmp(uri, LV2_TIME__barBeat) == 0) - return CARLA_URI_MAP_ID_TIME_BAR_BEAT; - if (std::strcmp(uri, LV2_TIME__beat) == 0) - return CARLA_URI_MAP_ID_TIME_BEAT; - if (std::strcmp(uri, LV2_TIME__beatUnit) == 0) - return CARLA_URI_MAP_ID_TIME_BEAT_UNIT; - if (std::strcmp(uri, LV2_TIME__beatsPerBar) == 0) - return CARLA_URI_MAP_ID_TIME_BEATS_PER_BAR; - if (std::strcmp(uri, LV2_TIME__beatsPerMinute) == 0) - return CARLA_URI_MAP_ID_TIME_BEATS_PER_MINUTE; - if (std::strcmp(uri, LV2_TIME__frame) == 0) - return CARLA_URI_MAP_ID_TIME_FRAME; - if (std::strcmp(uri, LV2_TIME__framesPerSecond) == 0) - return CARLA_URI_MAP_ID_TIME_FRAMES_PER_SECOND; - if (std::strcmp(uri, LV2_TIME__speed) == 0) - return CARLA_URI_MAP_ID_TIME_SPEED; - - // Others - if (std::strcmp(uri, LV2_MIDI__MidiEvent) == 0) - return CARLA_URI_MAP_ID_MIDI_EVENT; - if (std::strcmp(uri, LV2_PARAMETERS__sampleRate) == 0) - return CARLA_URI_MAP_ID_PARAM_SAMPLE_RATE; - - if (handle == nullptr) - return CARLA_URI_MAP_ID_NULL; - - // Custom types - return ((Lv2Plugin*)handle)->getCustomURID(uri); - } + bool canContinue = true; - static const char* carla_lv2_urid_unmap(LV2_URID_Map_Handle handle, LV2_URID urid) - { - carla_debug("carla_lv2_urid_unmap(%p, %i)", handle, urid); - CARLA_ASSERT(handle != nullptr); - CARLA_ASSERT(urid > CARLA_URI_MAP_ID_NULL); - - if (urid == CARLA_URI_MAP_ID_NULL) - return nullptr; - - // Atom types - if (urid == CARLA_URI_MAP_ID_ATOM_BLANK) - return LV2_ATOM__Blank; - if (urid == CARLA_URI_MAP_ID_ATOM_BOOL) - return LV2_ATOM__Bool; - if (urid == CARLA_URI_MAP_ID_ATOM_CHUNK) - return LV2_ATOM__Chunk; - if (urid == CARLA_URI_MAP_ID_ATOM_DOUBLE) - return LV2_ATOM__Double; - if (urid == CARLA_URI_MAP_ID_ATOM_FLOAT) - return LV2_ATOM__Float; - if (urid == CARLA_URI_MAP_ID_ATOM_INT) - return LV2_ATOM__Int; - if (urid == CARLA_URI_MAP_ID_ATOM_LITERAL) - return LV2_ATOM__Literal; - if (urid == CARLA_URI_MAP_ID_ATOM_LONG) - return LV2_ATOM__Long; - if (urid == CARLA_URI_MAP_ID_ATOM_PATH) - return LV2_ATOM__Path; - if (urid == CARLA_URI_MAP_ID_ATOM_PROPERTY) - return LV2_ATOM__Property; - if (urid == CARLA_URI_MAP_ID_ATOM_RESOURCE) - return LV2_ATOM__Resource; - if (urid == CARLA_URI_MAP_ID_ATOM_SEQUENCE) - return LV2_ATOM__Sequence; - if (urid == CARLA_URI_MAP_ID_ATOM_STRING) - return LV2_ATOM__String; - if (urid == CARLA_URI_MAP_ID_ATOM_TUPLE) - return LV2_ATOM__Tuple; - if (urid == CARLA_URI_MAP_ID_ATOM_URI) - return LV2_ATOM__URI; - if (urid == CARLA_URI_MAP_ID_ATOM_URID) - return LV2_ATOM__URID; - if (urid == CARLA_URI_MAP_ID_ATOM_VECTOR) - return LV2_ATOM__Vector; - if (urid == CARLA_URI_MAP_ID_ATOM_TRANSFER_ATOM) - return LV2_ATOM__atomTransfer; - if (urid == CARLA_URI_MAP_ID_ATOM_TRANSFER_EVENT) - return LV2_ATOM__eventTransfer; - - // BufSize types - if (urid == CARLA_URI_MAP_ID_BUF_MAX_LENGTH) - return LV2_BUF_SIZE__maxBlockLength; - if (urid == CARLA_URI_MAP_ID_BUF_MIN_LENGTH) - return LV2_BUF_SIZE__minBlockLength; - if (urid == CARLA_URI_MAP_ID_BUF_SEQUENCE_SIZE) - return LV2_BUF_SIZE__sequenceSize; - - // Log types - if (urid == CARLA_URI_MAP_ID_LOG_ERROR) - return LV2_LOG__Error; - if (urid == CARLA_URI_MAP_ID_LOG_NOTE) - return LV2_LOG__Note; - if (urid == CARLA_URI_MAP_ID_LOG_TRACE) - return LV2_LOG__Trace; - if (urid == CARLA_URI_MAP_ID_LOG_WARNING) - return LV2_LOG__Warning; - - // Time types - if (urid == CARLA_URI_MAP_ID_TIME_POSITION) - return LV2_TIME__Position; - if (urid == CARLA_URI_MAP_ID_TIME_BAR) - return LV2_TIME__bar; - if (urid == CARLA_URI_MAP_ID_TIME_BAR_BEAT) - return LV2_TIME__barBeat; - if (urid == CARLA_URI_MAP_ID_TIME_BEAT) - return LV2_TIME__beat; - if (urid == CARLA_URI_MAP_ID_TIME_BEAT_UNIT) - return LV2_TIME__beatUnit; - if (urid == CARLA_URI_MAP_ID_TIME_BEATS_PER_BAR) - return LV2_TIME__beatsPerBar; - if (urid == CARLA_URI_MAP_ID_TIME_BEATS_PER_MINUTE) - return LV2_TIME__beatsPerMinute; - if (urid == CARLA_URI_MAP_ID_TIME_FRAME) - return LV2_TIME__frame; - if (urid == CARLA_URI_MAP_ID_TIME_FRAMES_PER_SECOND) - return LV2_TIME__framesPerSecond; - if (urid == CARLA_URI_MAP_ID_TIME_SPEED) - return LV2_TIME__speed; - - // Others - if (urid == CARLA_URI_MAP_ID_MIDI_EVENT) - return LV2_MIDI__MidiEvent; - if (urid == CARLA_URI_MAP_ID_PARAM_SAMPLE_RATE) - return LV2_PARAMETERS__sampleRate; - - if (handle == nullptr) - return nullptr; - - // Custom types - return ((Lv2Plugin*)handle)->getCustomURIString(urid); - } + // Check supported ports + for (uint32_t i=0; i < fRdfDescriptor->PortCount; ++i) + { + const LV2_Property portTypes(fRdfDescriptor->Ports[i].Types); - // ------------------------------------------------------------------- - // Worker Feature + if (! is_lv2_port_supported(portTypes)) + { + if (! LV2_IS_PORT_OPTIONAL(fRdfDescriptor->Ports[i].Properties)) + { + pData->engine->setLastError("Plugin requires a port type that is not currently supported"); + canContinue = false; + break; + } + } + } - static LV2_Worker_Status carla_lv2_worker_schedule(LV2_Worker_Schedule_Handle handle, uint32_t size, const void* data) - { - CARLA_ASSERT(handle != nullptr); - carla_debug("carla_lv2_worker_schedule(%p, %i, %p)", handle, size, data); + // Check supported features + for (uint32_t i=0; i < fRdfDescriptor->FeatureCount && canContinue; ++i) + { + if (LV2_IS_FEATURE_REQUIRED(fRdfDescriptor->Features[i].Type) && ! is_lv2_feature_supported(fRdfDescriptor->Features[i].URI)) + { +// QString msg(QString("Plugin requires a feature that is not supported:\n%1").arg(fRdfDescriptor->Features[i].URI)); +// pData->engine->setLastError(msg.toUtf8().constData()); + canContinue = false; + break; + } + } - if (handle == nullptr) - return LV2_WORKER_ERR_UNKNOWN; + if (! canContinue) + { + // error already set + return false; + } - return ((Lv2Plugin*)handle)->handleWorkerSchedule(size, data); - } + // --------------------------------------------------------------- + // get info - static LV2_Worker_Status carla_lv2_worker_respond(LV2_Worker_Respond_Handle handle, uint32_t size, const void* data) - { - CARLA_ASSERT(handle != nullptr); - carla_debug("carla_lv2_worker_respond(%p, %i, %p)", handle, size, data); + if (name != nullptr && name[0] != '\0') + pData->name = pData->engine->getUniquePluginName(name); + else + pData->name = pData->engine->getUniquePluginName(fRdfDescriptor->Name); - if (handle == nullptr) - return LV2_WORKER_ERR_UNKNOWN; + // --------------------------------------------------------------- + // register client - return ((Lv2Plugin*)handle)->handleWorkerRespond(size, data); - } + pData->client = pData->engine->addClient(this); - // ------------------------------------------------------------------- - // UI Port-Map Feature + if (pData->client == nullptr || ! pData->client->isOk()) + { + pData->engine->setLastError("Failed to register plugin client"); + return false; + } - static uint32_t carla_lv2_ui_port_map(LV2UI_Feature_Handle handle, const char* symbol) - { - carla_debug("carla_lv2_ui_port_map(%p, \"%s\")", handle, symbol); - CARLA_ASSERT(handle); + // --------------------------------------------------------------- + // initialize plugin - if (handle == nullptr) - return LV2UI_INVALID_PORT_INDEX; + fHandle = fDescriptor->instantiate(fDescriptor, pData->engine->getSampleRate(), fRdfDescriptor->Bundle, fFeatures); - return ((Lv2Plugin*)handle)->handleUiPortMap(symbol); - } + if (fHandle == nullptr) + { + pData->engine->setLastError("Plugin failed to initialize"); + return false; + } - // ------------------------------------------------------------------- - // UI Resize Feature + // --------------------------------------------------------------- + // load plugin settings - static int carla_lv2_ui_resize(LV2UI_Feature_Handle handle, int width, int height) - { - carla_debug("carla_lv2_ui_resize(%p, %i, %i)", handle, width, height); - CARLA_ASSERT(handle != nullptr); + { + // set default options + pData->options = 0x0; - if (handle == nullptr) - return 1; + pData->options |= PLUGIN_OPTION_MAP_PROGRAM_CHANGES; - return ((Lv2Plugin*)handle)->handleUiResize(width, height); - } + if (getMidiInCount() > 0 || needsFixedBuffer()) + pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; - // ------------------------------------------------------------------- - // External UI Feature + if (pData->engine->getOptions().forceStereo) + pData->options |= PLUGIN_OPTION_FORCE_STEREO; - static void carla_lv2_external_ui_closed(LV2UI_Controller controller) - { - carla_debug("carla_lv2_external_ui_closed(%p)", controller); - CARLA_ASSERT(controller != nullptr); + if (getMidiInCount() > 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 (controller == nullptr) - return; + // set identifier string + CarlaString identifier("V2/"); + identifier += uri; - ((Lv2Plugin*)controller)->handleExternalUiClosed(); - } + // load settings + pData->options = pData->loadSettings(pData->options, getOptionsAvailable()); - // ------------------------------------------------------------------- - // UI Extension + // ignore settings, we need this anyway + if (getMidiInCount() > 0 || needsFixedBuffer()) + pData->options |= PLUGIN_OPTION_FIXED_BUFFERS; + } - static void carla_lv2_ui_write_function(LV2UI_Controller controller, uint32_t port_index, uint32_t buffer_size, uint32_t format, const void* buffer) - { - CARLA_ASSERT(controller != nullptr); - carla_debug("carla_lv2_ui_write_function(%p, %i, %i, %i, %p)", controller, port_index, buffer_size, format, buffer); + // --------------------------------------------------------------- + // gui stuff - if (controller == nullptr) - return; + if (fRdfDescriptor->UICount == 0) + return true; - ((Lv2Plugin*)controller)->handleUiWrite(port_index, buffer_size, format, buffer); + return true; } // ------------------------------------------------------------------- - // Lilv State - static void carla_lilv_set_port_value(const char* port_symbol, void* user_data, const void* value, uint32_t size, uint32_t type) - { - CARLA_ASSERT(user_data != nullptr); - carla_debug("carla_lilv_set_port_value(\"%s\", %p, %p, %i, %i)", port_symbol, user_data, value, size, type); - - if (user_data == nullptr) - return; +private: + LV2_Handle fHandle; + LV2_Handle fHandle2; + LV2_Feature* fFeatures[kFeatureCount+1]; + const LV2_Descriptor* fDescriptor; + const LV2_RDF_Descriptor* fRdfDescriptor; - ((Lv2Plugin*)user_data)->handleLilvSetPortValue(port_symbol, value, size, type); - } -#endif + float** fAudioInBuffers; + float** fAudioOutBuffers; + float* fParamBuffers; // ------------------------------------------------------------------- @@ -5470,20 +1579,10 @@ int CarlaEngineOsc::handleMsgLv2AtomTransfer(CARLA_ENGINE_OSC_HANDLE_ARGS2) CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "is"); carla_debug("CarlaOsc::handleMsgLv2AtomTransfer()"); - const int32_t portIndex = argv[0]->i; - //const char* const atomBuf = (const char*)&argv[1]->s; - - if (portIndex < 0) - return 0; - -// QByteArray chunk; -// chunk = QByteArray::fromBase64(atomBuf); -// -// LV2_Atom* const atom = (LV2_Atom*)chunk.data(); -// lv2PluginPtr->handleTransferAtom(portIndex, atom); return 0; // unused for now + (void)argv; (void)plugin; } @@ -5492,16 +1591,10 @@ int CarlaEngineOsc::handleMsgLv2UridMap(CARLA_ENGINE_OSC_HANDLE_ARGS2) CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "is"); carla_debug("CarlaOsc::handleMsgLv2EventTransfer()"); - const int32_t urid = argv[0]->i; - //const char* const uri = (const char*)&argv[1]->s; - - if (urid <= 0) - return 0; - - //lv2PluginPtr->handleUridMap(urid, uri); return 0; // unused for now + (void)argv; (void)plugin; } @@ -5511,6 +1604,8 @@ CARLA_BACKEND_END_NAMESPACE #endif // WANT_LV2 +// ------------------------------------------------------------------------------------------------------------------- + CARLA_BACKEND_START_NAMESPACE CarlaPlugin* CarlaPlugin::newLV2(const Initializer& init) @@ -5543,3 +1638,5 @@ CarlaPlugin* CarlaPlugin::newLV2(const Initializer& init) } CARLA_BACKEND_END_NAMESPACE + +// ------------------------------------------------------------------------------------------------------------------- diff --git a/source/backend/plugin/NativePlugin.cpp b/source/backend/plugin/NativePlugin.cpp index d30955600..18eb7a409 100644 --- a/source/backend/plugin/NativePlugin.cpp +++ b/source/backend/plugin/NativePlugin.cpp @@ -205,7 +205,7 @@ public: return PLUGIN_INTERNAL; } - PluginCategory getCategory() const override + PluginCategory getCategory() const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, PLUGIN_CATEGORY_NONE); @@ -225,13 +225,14 @@ public: return fMidiOut.count; } - uint32_t getParameterScalePointCount(const uint32_t parameterId) const override + uint32_t getParameterScalePointCount(const uint32_t parameterId) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, 0); CARLA_SAFE_ASSERT_RETURN(fDescriptor->get_parameter_info != nullptr, 0); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, 0); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0); + // FIXME - try if (const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, parameterId)) return param->scalePointCount; @@ -247,11 +248,12 @@ public: // ------------------------------------------------------------------- // Information (per-plugin data) - unsigned int getOptionsAvailable() const override + unsigned int getOptionsAvailable() const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, 0x0); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, 0); + // FIXME - try const bool hasMidiProgs(fDescriptor->get_midi_program_count != nullptr && fDescriptor->get_midi_program_count(fHandle) > 0); unsigned int options = 0x0; @@ -284,17 +286,18 @@ public: return options; } - float getParameterValue(const uint32_t parameterId) const override + float getParameterValue(const uint32_t parameterId) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, 0.0f); CARLA_SAFE_ASSERT_RETURN(fDescriptor->get_parameter_value != nullptr, 0.0f); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, 0.0f); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f); + // FIXME - try return fDescriptor->get_parameter_value(fHandle, parameterId); } - float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const override + float getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr, 0.0f); CARLA_SAFE_ASSERT_RETURN(fDescriptor->get_parameter_info != nullptr, 0.0f); @@ -302,6 +305,7 @@ public: CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0.0f); CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f); + // FIXME - try if (const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, parameterId)) { const NativeParameterScalePoint* scalePoint(¶m->scalePoints[scalePointId]); @@ -312,7 +316,7 @@ public: return 0.0f; } - void getLabel(char* const strBuf) const override + void getLabel(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -322,7 +326,7 @@ public: CarlaPlugin::getLabel(strBuf); } - void getMaker(char* const strBuf) const override + void getMaker(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -332,7 +336,7 @@ public: CarlaPlugin::getMaker(strBuf); } - void getCopyright(char* const strBuf) const override + void getCopyright(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -342,7 +346,7 @@ public: CarlaPlugin::getCopyright(strBuf); } - void getRealName(char* const strBuf) const override + void getRealName(char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); @@ -352,13 +356,14 @@ public: CarlaPlugin::getRealName(strBuf); } - void getParameterName(const uint32_t parameterId, char* const strBuf) const override + void getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fDescriptor->get_parameter_info != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); + // FIXME - try if (const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, parameterId)) { if (param->name != nullptr) @@ -374,7 +379,7 @@ public: CarlaPlugin::getParameterName(parameterId, strBuf); } - void getParameterText(const uint32_t parameterId, const float value, char* const strBuf) const override + void getParameterText(const uint32_t parameterId, const float value, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fDescriptor->get_parameter_text != nullptr,); @@ -382,6 +387,7 @@ public: CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); + // FIXME - try if (const char* const text = fDescriptor->get_parameter_text(fHandle, parameterId, value)) { std::strncpy(strBuf, text, STR_MAX); @@ -392,13 +398,14 @@ public: CarlaPlugin::getParameterText(parameterId, value, strBuf); } - void getParameterUnit(const uint32_t parameterId, char* const strBuf) const override + void getParameterUnit(const uint32_t parameterId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fDescriptor->get_parameter_info != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); + // FIXME - try if (const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, parameterId)) { if (param->unit != nullptr) @@ -413,7 +420,7 @@ public: CarlaPlugin::getParameterUnit(parameterId, strBuf); } - void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const override + void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fDescriptor->get_parameter_info != nullptr,); @@ -421,6 +428,7 @@ public: CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId),); + // FIXME - try if (const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, parameterId)) { const NativeParameterScalePoint* scalePoint(¶m->scalePoints[scalePointId]); @@ -492,7 +500,7 @@ public: CarlaPlugin::setName(newName); } - void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) override + void setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept override { if (channel < MAX_MIDI_CHANNELS && pData->midiprog.count > 0) pData->midiprog.current = fCurMidiProgs[channel]; @@ -503,7 +511,7 @@ public: // ------------------------------------------------------------------- // Set data (plugin-specific stuff) - void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fDescriptor->set_parameter_value != nullptr,); @@ -512,6 +520,7 @@ public: const float fixedValue(pData->param.getFixedValue(parameterId, value)); + // FIXME - try fDescriptor->set_parameter_value(fHandle, parameterId, fixedValue); if (fHandle2 != nullptr) @@ -596,7 +605,7 @@ public: CarlaPlugin::setCustomData(type, key, value, sendGui); } - void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) override + void setMidiProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); @@ -614,10 +623,16 @@ public: const ScopedSingleProcessLocker spl(this, (sendGui || sendOsc || sendCallback)); - fDescriptor->set_midi_program(fHandle, channel, bank, program); + try { + fDescriptor->set_midi_program(fHandle, channel, bank, program); + } catch(...) {} if (fHandle2 != nullptr) - fDescriptor->set_midi_program(fHandle2, channel, bank, program); + { + try { + fDescriptor->set_midi_program(fHandle2, channel, bank, program); + } catch(...) {} + } fCurMidiProgs[channel] = index; } @@ -1160,31 +1175,43 @@ public: // ------------------------------------------------------------------- // Plugin processing - void activate() override + void activate() noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); if (fDescriptor->activate != nullptr) { - fDescriptor->activate(fHandle); + try { + fDescriptor->activate(fHandle); + } catch(...) {} if (fHandle2 != nullptr) - fDescriptor->activate(fHandle2); + { + try { + fDescriptor->activate(fHandle2); + } catch(...) {} + } } } - void deactivate() override + void deactivate() noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); if (fDescriptor->deactivate != nullptr) { - fDescriptor->deactivate(fHandle); + try { + fDescriptor->deactivate(fHandle); + } catch(...) {} if (fHandle2 != nullptr) - fDescriptor->deactivate(fHandle2); + { + try { + fDescriptor->deactivate(fHandle2); + } catch(...) {} + } } } @@ -1913,7 +1940,7 @@ public: // ------------------------------------------------------------------- // Post-poned UI Stuff - void uiParameterChange(const uint32_t index, const float value) override + void uiParameterChange(const uint32_t index, const float /*value*/) noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); @@ -1926,11 +1953,11 @@ public: if (index >= pData->param.count) return; - if (fDescriptor->ui_set_parameter_value != nullptr) - fDescriptor->ui_set_parameter_value(fHandle, index, value); + //if (fDescriptor->ui_set_parameter_value != nullptr) + // fDescriptor->ui_set_parameter_value(fHandle, index, value); } - void uiMidiProgramChange(const uint32_t index) override + void uiMidiProgramChange(const uint32_t index) noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); @@ -1943,11 +1970,11 @@ public: if (index >= pData->midiprog.count) return; - if (fDescriptor->ui_set_midi_program != nullptr) // TODO - fDescriptor->ui_set_midi_program(fHandle, 0, pData->midiprog.data[index].bank, pData->midiprog.data[index].program); + //if (fDescriptor->ui_set_midi_program != nullptr) // TODO + // fDescriptor->ui_set_midi_program(fHandle, 0, pData->midiprog.data[index].bank, pData->midiprog.data[index].program); } - void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) override + void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); @@ -1969,7 +1996,7 @@ public: // TODO } - void uiNoteOff(const uint8_t channel, const uint8_t note) override + void uiNoteOff(const uint8_t channel, const uint8_t note) noexcept override { CARLA_SAFE_ASSERT_RETURN(fDescriptor != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr,); @@ -2151,19 +2178,16 @@ protected: // ------------------------------------------------------------------- public: - static size_t getPluginCount() + static size_t getPluginCount() noexcept { return sPluginDescriptors.count(); } - static const NativePluginDescriptor* getPluginDescriptor(const size_t index) + static const NativePluginDescriptor* getPluginDescriptor(const size_t index) noexcept { - CARLA_ASSERT(index < sPluginDescriptors.count()); + CARLA_SAFE_ASSERT_RETURN(index < sPluginDescriptors.count(), nullptr); - if (index < sPluginDescriptors.count()) - return sPluginDescriptors.getAt(index); - - return nullptr; + return sPluginDescriptors.getAt(index); } static void registerPlugin(const NativePluginDescriptor* desc) @@ -2441,12 +2465,12 @@ void carla_register_native_plugin(const NativePluginDescriptor* desc) CARLA_BACKEND_START_NAMESPACE #ifdef WANT_NATIVE -size_t CarlaPlugin::getNativePluginCount() +size_t CarlaPlugin::getNativePluginCount() noexcept { return NativePlugin::getPluginCount(); } -const NativePluginDescriptor* CarlaPlugin::getNativePluginDescriptor(const size_t index) +const NativePluginDescriptor* CarlaPlugin::getNativePluginDescriptor(const size_t index) noexcept { return NativePlugin::getPluginDescriptor(index); } diff --git a/source/modules/jackbridge/JackBridge.hpp b/source/modules/jackbridge/JackBridge.hpp index 5f490ed75..4ccca6804 100644 --- a/source/modules/jackbridge/JackBridge.hpp +++ b/source/modules/jackbridge/JackBridge.hpp @@ -361,9 +361,9 @@ CARLA_EXPORT bool jackbridge_custom_set_data_appearance_callback(jack_client_t* CARLA_EXPORT const char** jackbridge_custom_get_keys(jack_client_t* client, const char* client_name); #endif -CARLA_EXPORT bool jackbridge_sem_init(void* sem); -CARLA_EXPORT bool jackbridge_sem_destroy(void* sem); -CARLA_EXPORT bool jackbridge_sem_post(void* sem); +CARLA_EXPORT bool jackbridge_sem_init(void* sem) noexcept; +CARLA_EXPORT bool jackbridge_sem_destroy(void* sem) noexcept; +CARLA_EXPORT bool jackbridge_sem_post(void* sem) noexcept; CARLA_EXPORT bool jackbridge_sem_timedwait(void* sem, int secs); #endif // JACKBRIDGE_HPP_INCLUDED diff --git a/source/modules/jackbridge/JackBridge2.cpp b/source/modules/jackbridge/JackBridge2.cpp index 29b42c3fd..c435af994 100644 --- a/source/modules/jackbridge/JackBridge2.cpp +++ b/source/modules/jackbridge/JackBridge2.cpp @@ -24,26 +24,26 @@ #ifndef JACKBRIDGE_HPP_INCLUDED // don't include the whole JACK API in this file -CARLA_EXPORT bool jackbridge_sem_init(void* sem); -CARLA_EXPORT bool jackbridge_sem_destroy(void* sem); -CARLA_EXPORT bool jackbridge_sem_post(void* sem); +CARLA_EXPORT bool jackbridge_sem_init(void* sem) noexcept; +CARLA_EXPORT bool jackbridge_sem_destroy(void* sem) noexcept; +CARLA_EXPORT bool jackbridge_sem_post(void* sem) noexcept; CARLA_EXPORT bool jackbridge_sem_timedwait(void* sem, int secs); #endif // ----------------------------------------------------------------------------- #if JACKBRIDGE_DUMMY -bool jackbridge_sem_init(void*) +bool jackbridge_sem_init(void*) noexcept { return false; } -bool jackbridge_sem_destroy(void*) +bool jackbridge_sem_destroy(void*) noexcept { return false; } -bool jackbridge_sem_post(void*) +bool jackbridge_sem_post(void*) noexcept { return false; } @@ -58,17 +58,17 @@ bool jackbridge_sem_timedwait(void*, int) #include #include -bool jackbridge_sem_init(void* sem) +bool jackbridge_sem_init(void* sem) noexcept { return (sem_init((sem_t*)sem, 1, 0) == 0); } -bool jackbridge_sem_destroy(void* sem) +bool jackbridge_sem_destroy(void* sem) noexcept { return (sem_destroy((sem_t*)sem) == 0); } -bool jackbridge_sem_post(void* sem) +bool jackbridge_sem_post(void* sem) noexcept { return (sem_post((sem_t*)sem) == 0); } diff --git a/source/tests/CarlaBackendDummy.cpp b/source/tests/CarlaBackendDummy.cpp index 6c2edaf08..e69de29bb 100644 --- a/source/tests/CarlaBackendDummy.cpp +++ b/source/tests/CarlaBackendDummy.cpp @@ -1,207 +0,0 @@ -/* - * Carla Tests - * Copyright (C) 2013 Filipe Coelho - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * For a full copy of the GNU General Public License see the doc/GPL.txt file. - */ - -#include "CarlaPlugin.hpp" -#include "CarlaEngine.hpp" - -CARLA_BACKEND_START_NAMESPACE - -// 1 - utils -// 2 - engine -// 3 - plugin -// 4 - standalone -#define ANSI_TEST_N 2 - -#if ANSI_TEST_N != 3 -struct SaveState {}; - -// ----------------------------------------------------------------------- -// Fallback data - -static const ParameterData kParameterDataNull; -static const ParameterRanges kParameterRangesNull; -static const MidiProgramData kMidiProgramDataNull; -static const CustomData kCustomDataNull; - -// ----------------------------------------------------------------------- -// CarlaPlugin - -CarlaPlugin::CarlaPlugin(CarlaEngine* const, const unsigned int id) - : fId(id), pData(nullptr) {} -CarlaPlugin::~CarlaPlugin() {} - -uint32_t CarlaPlugin::getLatencyInFrames() const noexcept { return 0; } -uint32_t CarlaPlugin::getAudioInCount() const noexcept { return 0; } -uint32_t CarlaPlugin::getAudioOutCount() const noexcept { return 0; } -uint32_t CarlaPlugin::getMidiInCount() const noexcept { return 0; } -uint32_t CarlaPlugin::getMidiOutCount() const noexcept { return 0; } -uint32_t CarlaPlugin::getParameterCount() const noexcept { return 0; } -uint32_t CarlaPlugin::getParameterScalePointCount(const uint32_t) const { return 0; } -uint32_t CarlaPlugin::getProgramCount() const noexcept { return 0; } -uint32_t CarlaPlugin::getMidiProgramCount() const noexcept { return 0; } -uint32_t CarlaPlugin::getCustomDataCount() const noexcept { return 0; } -int32_t CarlaPlugin::getCurrentProgram() const noexcept { return 0; } -int32_t CarlaPlugin::getCurrentMidiProgram() const noexcept { return 0; } - -const ParameterData& CarlaPlugin::getParameterData(const uint32_t) const { return kParameterDataNull; } -const ParameterRanges& CarlaPlugin::getParameterRanges(const uint32_t) const { return kParameterRangesNull; } -bool CarlaPlugin::isParameterOutput(const uint32_t) const { return false; } -const MidiProgramData& CarlaPlugin::getMidiProgramData(const uint32_t) const { return kMidiProgramDataNull; } -const CustomData& CarlaPlugin::getCustomData(const uint32_t) const { return kCustomDataNull; } -int32_t CarlaPlugin::getChunkData(void** const) const { return 0; } -unsigned int CarlaPlugin::getAvailableOptions() const { return 0x0; } - -float CarlaPlugin::getParameterValue(const uint32_t) const { return 0.0f; } -float CarlaPlugin::getParameterScalePointValue(const uint32_t, const uint32_t) const { return 0.0f; } - -void CarlaPlugin::getLabel(char* const) const noexcept {} -void CarlaPlugin::getMaker(char* const) const noexcept {} -void CarlaPlugin::getCopyright(char* const) const noexcept {} -void CarlaPlugin::getRealName(char* const) const noexcept {} -void CarlaPlugin::getParameterName(const uint32_t, char* const) const {} -void CarlaPlugin::getParameterSymbol(const uint32_t, char* const) const {} -void CarlaPlugin::getParameterText(const uint32_t, const float, char* const) const {} -void CarlaPlugin::getParameterUnit(const uint32_t, char* const) const {} -void CarlaPlugin::getParameterScalePointLabel(const uint32_t, const uint32_t, char* const) const {} -void CarlaPlugin::getProgramName(const uint32_t, char* const) const {} -void CarlaPlugin::getMidiProgramName(const uint32_t, char* const) const {} -void CarlaPlugin::getParameterCountInfo(uint32_t* const, uint32_t* const, uint32_t* const) const {} - -void CarlaPlugin::prepareForSave() {} -const SaveState& CarlaPlugin::getSaveState() { static SaveState saveState; return saveState; } - -void CarlaPlugin::loadSaveState(const SaveState&) {} -bool CarlaPlugin::saveStateToFile(const char* const) { return false; } -bool CarlaPlugin::loadStateFromFile(const char* const) { return false; } - -void CarlaPlugin::setId(const unsigned int newId) noexcept { fId = newId; } -void CarlaPlugin::setName(const char* const newName) { fName = newName; } -void CarlaPlugin::setEnabled(const bool yesNo) { fEnabled = yesNo; } - -void CarlaPlugin::setOption(const unsigned int, const bool) {} -void CarlaPlugin::setActive(const bool, const bool, const bool) {} -void CarlaPlugin::setDryWet(const float, const bool, const bool) {} -void CarlaPlugin::setVolume(const float, const bool, const bool) {} -void CarlaPlugin::setBalanceLeft(const float, const bool, const bool) {} -void CarlaPlugin::setBalanceRight(const float, const bool, const bool) {} -void CarlaPlugin::setPanning(const float, const bool, const bool) {} -void CarlaPlugin::setCtrlChannel(const int8_t, const bool, const bool) {} -void CarlaPlugin::setParameterValue(const uint32_t, const float, const bool, const bool, const bool) {} -void CarlaPlugin::setParameterValueByRealIndex(const int32_t, const float, const bool, const bool, const bool) {} -void CarlaPlugin::setParameterMidiChannel(const uint32_t, uint8_t, const bool, const bool) {} -void CarlaPlugin::setParameterMidiCC(const uint32_t, int16_t, const bool, const bool) {} -void CarlaPlugin::setCustomData(const char* const, const char* const, const char* const, const bool) {} -void CarlaPlugin::setChunkData(const char* const) {} -void CarlaPlugin::setProgram(int32_t, const bool, const bool, const bool) {} -void CarlaPlugin::setMidiProgram(int32_t, const bool, const bool, const bool) {} -void CarlaPlugin::setMidiProgramById(const uint32_t, const uint32_t, const bool, const bool, const bool) {} -void CarlaPlugin::showGui(const bool) {} -void CarlaPlugin::idleGui() {} -void CarlaPlugin::reloadPrograms(const bool) {} -void CarlaPlugin::activate() {} -void CarlaPlugin::deactivate() {} -void CarlaPlugin::bufferSizeChanged(const uint32_t) {} -void CarlaPlugin::sampleRateChanged(const double) {} -void CarlaPlugin::offlineModeChanged(const bool) {} -bool CarlaPlugin::tryLock() { return false; } -void CarlaPlugin::unlock() {} -void CarlaPlugin::initBuffers() {} -void CarlaPlugin::clearBuffers() {} -void CarlaPlugin::registerToOscClient() {} -void CarlaPlugin::updateOscData(const lo_address&, const char* const) {} -//void CarlaPlugin::freeOscData() {} -bool CarlaPlugin::waitForOscGuiShow() { return false; } -void CarlaPlugin::sendMidiSingleNote(const uint8_t, const uint8_t, const uint8_t, const bool, const bool, const bool) {} -void CarlaPlugin::sendMidiAllNotesOffToCallback() {} -void CarlaPlugin::postRtEventsRun() {} -void CarlaPlugin::uiParameterChange(const uint32_t, const float) {} -void CarlaPlugin::uiProgramChange(const uint32_t) {} -void CarlaPlugin::uiMidiProgramChange(const uint32_t) {} -void CarlaPlugin::uiNoteOn(const uint8_t, const uint8_t, const uint8_t) {} -void CarlaPlugin::uiNoteOff(const uint8_t, const uint8_t) {} - -size_t CarlaPlugin::getNativePluginCount() { return 0; } -const PluginDescriptor* CarlaPlugin::getNativePluginDescriptor(const size_t) { return nullptr; } -#endif - -#if ANSI_TEST_N != 2 -// ----------------------------------------------------------------------- -// CarlaEngine - -CarlaEngine::CarlaEngine() - : fBufferSize(0), - fSampleRate(0.0), - pData(nullptr) {} -CarlaEngine::~CarlaEngine() {} - -unsigned int CarlaEngine::getDriverCount() { return 0; } -const char* CarlaEngine::getDriverName(const unsigned int) { return nullptr; } -const char** CarlaEngine::getDriverDeviceNames(const unsigned int) { return nullptr; } -CarlaEngine* CarlaEngine::newDriverByName(const char* const) { return nullptr; } - -unsigned int CarlaEngine::getMaxClientNameSize() const noexcept { return 0; } -unsigned int CarlaEngine::getMaxPortNameSize() const noexcept { return 0; } -unsigned int CarlaEngine::getCurrentPluginCount() const noexcept { return 0; } -unsigned int CarlaEngine::getMaxPluginNumber() const noexcept { return 0; } - -bool CarlaEngine::init(const char* const) { return false; } -bool CarlaEngine::close() { return false; } -void CarlaEngine::idle() {} -CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const) { return nullptr; } - -void CarlaEngine::removeAllPlugins() {} -bool CarlaEngine::addPlugin(const BinaryType, const PluginType, const char* const, const char* const, const char* const, - const void* const) { return false; } -bool CarlaEngine::removePlugin(const unsigned int) { return false; } -bool CarlaEngine::clonePlugin(const unsigned int) { return false; } -bool CarlaEngine::replacePlugin(const unsigned int) { return false; } -bool CarlaEngine::switchPlugins(const unsigned int, const unsigned int) { return false; } - -const char* CarlaEngine::renamePlugin(const unsigned int, const char* const) { return nullptr; } -CarlaPlugin* CarlaEngine::getPlugin(const unsigned int) const { return nullptr; } -CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned int) const noexcept { return nullptr; } -const char* CarlaEngine::getUniquePluginName(const char* const) { return nullptr; } - -bool CarlaEngine::loadFilename(const char* const) { return false; } -bool CarlaEngine::loadProject(const char* const) { return false; } -bool CarlaEngine::saveProject(const char* const) { return false; } - -float CarlaEngine::getInputPeak(const unsigned int, const unsigned short) const { return 0.0f; } -float CarlaEngine::getOutputPeak(const unsigned int, const unsigned short) const { return 0.0f; } - -void CarlaEngine::callback(const CallbackType, const unsigned int, const int, const int, const float, const char* const) {} -void CarlaEngine::setCallback(const CallbackFunc, void* const) {} -bool CarlaEngine::patchbayConnect(int, int) { return false; } -bool CarlaEngine::patchbayDisconnect(int) { return false; } -void CarlaEngine::patchbayRefresh() {} -void CarlaEngine::transportPlay() {} -void CarlaEngine::transportPause() {} -void CarlaEngine::transportRelocate(const uint32_t) {} - -const char* CarlaEngine::getLastError() const noexcept { return nullptr; } -void CarlaEngine::setLastError(const char* const) {} -void CarlaEngine::setAboutToClose() {} -void CarlaEngine::setOption(const OptionsType, const int, const char* const) {} -bool CarlaEngine::isOscControlRegistered() const noexcept { return false; } -void CarlaEngine::idleOsc() {} -const char* CarlaEngine::getOscServerPathTCP() const noexcept { return nullptr; } -const char* CarlaEngine::getOscServerPathUDP() const noexcept { return nullptr; } -#endif - -// ----------------------------------------------------------------------- - -CARLA_BACKEND_END_NAMESPACE diff --git a/source/utils/CarlaRingBuffer.hpp b/source/utils/CarlaRingBuffer.hpp index adb70ab49..fe63d0163 100644 --- a/source/utils/CarlaRingBuffer.hpp +++ b/source/utils/CarlaRingBuffer.hpp @@ -21,9 +21,9 @@ #include "CarlaUtils.hpp" -#ifndef RING_BUFFER_SIZE -# define RING_BUFFER_SIZE 2048 -#endif +//#ifndef RING_BUFFER_SIZE +#define RING_BUFFER_SIZE 2048 +//#endif // ----------------------------------------------------------------------- // RingBuffer struct @@ -97,28 +97,28 @@ public: // ------------------------------------------------------------------- - char readChar() + char readChar() noexcept { char c = '\0'; tryRead(&c, sizeof(char)); return c; } - int32_t readInt() + int32_t readInt() noexcept { int32_t i = 0; tryRead(&i, sizeof(int32_t)); return i; } - int64_t readLong() + int64_t readLong() noexcept { int64_t l = 0; tryRead(&l, sizeof(int64_t)); return l; } - float readFloat() + float readFloat() noexcept { float f = 0.0f; tryRead(&f, sizeof(float)); @@ -127,22 +127,22 @@ public: // ------------------------------------------------------------------- - void writeChar(const char value) + void writeChar(const char value) noexcept { tryWrite(&value, sizeof(char)); } - void writeInt(const int32_t value) + void writeInt(const int32_t value) noexcept { tryWrite(&value, sizeof(int32_t)); } - void writeLong(const int64_t value) + void writeLong(const int64_t value) noexcept { tryWrite(&value, sizeof(int64_t)); } - void writeFloat(const float value) + void writeFloat(const float value) noexcept { tryWrite(&value, sizeof(float)); } @@ -150,7 +150,7 @@ public: // ------------------------------------------------------------------- protected: - void tryRead(void* const buf, const size_t size) + void tryRead(void* const buf, const size_t size) noexcept { CARLA_SAFE_ASSERT_RETURN(fRingBuf != nullptr,); CARLA_SAFE_ASSERT_RETURN(buf != nullptr,); @@ -194,7 +194,7 @@ protected: fRingBuf->tail = static_cast(readto); } - void tryWrite(const void* const buf, const size_t size) + void tryWrite(const void* const buf, const size_t size) noexcept { CARLA_SAFE_ASSERT_RETURN(fRingBuf != nullptr,); CARLA_SAFE_ASSERT_RETURN(buf != nullptr,); diff --git a/source/utils/LinkedList.hpp b/source/utils/LinkedList.hpp index ee0b6f5f8..ff2c10a93 100644 --- a/source/utils/LinkedList.hpp +++ b/source/utils/LinkedList.hpp @@ -70,7 +70,7 @@ public: class Itenerator { public: - Itenerator(const k_list_head* queue) + Itenerator(const k_list_head* queue) noexcept : fData(nullptr), fEntry(queue->next), fEntry2(fEntry->next), @@ -92,7 +92,7 @@ public: fEntry2 = fEntry->next; } - T& getValue() + T& getValue() noexcept { fData = list_entry(fEntry, Data, siblings); CARLA_ASSERT(fData != nullptr); @@ -108,7 +108,7 @@ public: friend class AbstractLinkedList; }; - Itenerator begin() const + Itenerator begin() const noexcept { return Itenerator(&fQueue); } @@ -199,7 +199,33 @@ public: return false; } - T& getAt(const size_t index, const bool remove = false) + T& getAt(const size_t index) noexcept + { + if (fCount == 0 || index >= fCount) + return fRetValue; + + size_t i = 0; + Data* data = nullptr; + k_list_head* entry; + k_list_head* entry2; + + list_for_each_safe(entry, entry2, &fQueue) + { + if (index != i++) + continue; + + data = list_entry(entry, Data, siblings); + + if (data != nullptr) + fRetValue = data->value; + + break; + } + + return fRetValue; + } + + T& getAt(const size_t index, const bool remove) { if (fCount == 0 || index >= fCount) return fRetValue; @@ -309,7 +335,7 @@ public: } } - void spliceAppend(AbstractLinkedList& list, const bool init = true) + void spliceAppend(AbstractLinkedList& list, const bool init = true) noexcept { if (init) { @@ -324,7 +350,7 @@ public: } } - void spliceInsert(AbstractLinkedList& list, const bool init = true) + void spliceInsert(AbstractLinkedList& list, const bool init = true) noexcept { if (init) {