diff --git a/src/carla-backend/carla_plugin.h b/src/carla-backend/carla_plugin.h index 4f4335a..dca0fd7 100644 --- a/src/carla-backend/carla_plugin.h +++ b/src/carla-backend/carla_plugin.h @@ -153,7 +153,7 @@ struct ExternalMidiNote { * * \brief Carla Backend base plugin class * - * This is the base class for all available plugin types in Carla Backend.\n + * This is the base class for all available plugin types available in Carla Backend.\n * All virtual calls are implemented in this class as fallback, so it's safe to only override needed calls. * * \see PluginType @@ -408,7 +408,8 @@ public: } /*! - * Get the number of parameters. + * Get the number of parameters.\n + * To know the number of parameter inputs and outputs, use getParameterCountInfo() instead. */ uint32_t parameterCount() const { @@ -416,7 +417,7 @@ public: } /*! - * Get the number of scalepoints for parameter \a paramId. + * Get the number of scalepoints for parameter \a parameterId. */ virtual uint32_t parameterScalePointCount(uint32_t parameterId) { @@ -511,7 +512,7 @@ public: * * \see setChunkData() */ - virtual int32_t chunkData(void** dataPtr) + virtual int32_t chunkData(void** const dataPtr) { assert(dataPtr); return 0; @@ -519,7 +520,7 @@ public: #ifndef BUILD_BRIDGE /*! - * Get the plugin's OSC data. + * Get the plugin's internal OSC data. */ const OscData* oscData() const { @@ -540,7 +541,7 @@ public: } /*! - * Get the scalepoint \a scalePointId value of parameter \a parameterId. + * Get the scalepoint \a scalePointId value of the parameter \a parameterId. */ virtual double getParameterScalePointValue(uint32_t parameterId, uint32_t scalePointId) { @@ -552,7 +553,7 @@ public: /*! * Get the plugin's label (URI for PLUGIN_LV2). */ - virtual void getLabel(char* strBuf) + virtual void getLabel(char* const strBuf) { *strBuf = 0; } @@ -560,7 +561,7 @@ public: /*! * Get the plugin's maker. */ - virtual void getMaker(char* strBuf) + virtual void getMaker(char* const strBuf) { *strBuf = 0; } @@ -568,7 +569,7 @@ public: /*! * Get the plugin's copyright/license. */ - virtual void getCopyright(char* strBuf) + virtual void getCopyright(char* const strBuf) { *strBuf = 0; } @@ -578,51 +579,51 @@ public: * * \see name() */ - virtual void getRealName(char* strBuf) + virtual void getRealName(char* const strBuf) { *strBuf = 0;; } /*! - * Get the parameter name of \a parameterId. + * Get the name of the parameter \a parameterId. */ - virtual void getParameterName(uint32_t parameterId, char* strBuf) + virtual void getParameterName(uint32_t parameterId, char* const strBuf) { assert(parameterId < param.count); *strBuf = 0; } /*! - * Get the parameter symbol of \a parameterId. + * Get the symbol of the parameter \a parameterId. */ - virtual void getParameterSymbol(uint32_t parameterId, char* strBuf) + virtual void getParameterSymbol(uint32_t parameterId, char* const strBuf) { assert(parameterId < param.count); *strBuf = 0; } /*! - * Get the custom parameter text of \a parameterId. + * Get the custom text of the parameter \a parameterId. */ - virtual void getParameterText(uint32_t parameterId, char* strBuf) + virtual void getParameterText(uint32_t parameterId, char* const strBuf) { assert(parameterId < param.count); *strBuf = 0; } /*! - * Get the parameter unit of \a parameterId. + * Get the unit of the parameter \a parameterId. */ - virtual void getParameterUnit(uint32_t parameterId, char* strBuf) + virtual void getParameterUnit(uint32_t parameterId, char* const strBuf) { assert(parameterId < param.count); *strBuf = 0; } /*! - * Get the scalepoint \a scalePointId label of parameter \a parameterId. + * Get the scalepoint \a scalePointId label of the parameter \a parameterId. */ - virtual void getParameterScalePointLabel(uint32_t parameterId, uint32_t scalePointId, char* strBuf) + virtual void getParameterScalePointLabel(uint32_t parameterId, uint32_t scalePointId, char* const strBuf) { assert(parameterId < param.count); assert(scalePointId < parameterScalePointCount(parameterId)); @@ -630,28 +631,32 @@ public: } /*! - * Get the program name at \a index. + * Get the name of the program at \a index. */ - void getProgramName(uint32_t index, char* strBuf) + void getProgramName(uint32_t index, char* const strBuf) { assert(index < prog.count); strncpy(strBuf, prog.names[index], STR_MAX); } /*! - * Get the MIDI program name at \a index. + * Get the name of the MIDI program at \a index. + * + * \see getMidiProgramInfo() */ - void getMidiProgramName(uint32_t index, char* strBuf) + void getMidiProgramName(uint32_t index, char* const strBuf) { assert(index < midiprog.count); strncpy(strBuf, midiprog.data[index].name, STR_MAX); } /*! - * Get information about the parameter count.\n + * Get information about the plugin's parameter count.\n * This is used to check how many input, output and total parameters are available.\n * * \note Some parameters might not be input or output (ie, invalid). + * + * \see parameterCount() */ void getParameterCountInfo(PortCountInfo* const info) { @@ -670,6 +675,8 @@ public: /*! * Get information about the MIDI program at \a index. + * + * \see getMidiProgramName() */ void getMidiProgramInfo(MidiProgramInfo* const info, uint32_t index) { @@ -681,8 +688,6 @@ public: /*! * Get information about the plugin's custom GUI, if provided. - * - * \note Make sure to verify the plugin has a custom GUI before calling this function! */ virtual void getGuiInfo(GuiInfo* const info) { @@ -694,7 +699,7 @@ public: // Set data (internal stuff) /*! - * Enable or disable the plugin, according to \a enable. + * Enable or disable the plugin according to \a yesNo. * * When a plugin is disabled, it will never be processed or managed in any way.\n * If you want to "bypass" a plugin, use setActive() instead. @@ -709,13 +714,12 @@ public: /*! * Set plugin as active according to \a active. * - * \param sendOsc send message change over OSC - * \param sendCallback send message change to registered callback + * \param sendOsc Send message change over OSC + * \param sendCallback Send message change to registered callback */ void setActive(bool active, bool sendOsc, bool sendCallback) { m_active = active; - double value = active ? 1.0 : 0.0; if (sendCallback) @@ -735,11 +739,11 @@ public: } /*! - * Set the dry/wet signal value according to \a value.\n + * Set the plugin's dry/wet signal value to \a value.\n * \a value must be between 0.0 and 1.0. * - * \param sendOsc send message change over OSC - * \param sendCallback send message change to registered callback + * \param sendOsc Send message change over OSC + * \param sendCallback Send message change to registered callback */ void setDryWet(double value, bool sendOsc, bool sendCallback) { @@ -767,11 +771,11 @@ public: } /*! - * Set the output volume according to \a value.\n + * Set the plugin's output volume to \a value.\n * \a value must be between 0.0 and 1.27. * - * \param sendOsc send message change over OSC - * \param sendCallback send message change to registered callback + * \param sendOsc Send message change over OSC + * \param sendCallback Send message change to registered callback */ void setVolume(double value, bool sendOsc, bool sendCallback) { @@ -799,11 +803,11 @@ public: } /*! - * Set the output balance-left value according to \a value.\n + * Set the plugin's output balance-left value to \a value.\n * \a value must be between -1.0 and 1.0. * - * \param sendOsc send message change over OSC - * \param sendCallback send message change to registered callback + * \param sendOsc Send message change over OSC + * \param sendCallback Send message change to registered callback */ void setBalanceLeft(double value, bool sendOsc, bool sendCallback) { @@ -831,11 +835,11 @@ public: } /*! - * Set the output balance-right value according to \a value.\n + * Set the plugin's output balance-right value to \a value.\n * \a value must be between -1.0 and 1.0. * - * \param sendOsc send message change over OSC - * \param sendCallback send message change to registered callback + * \param sendOsc Send message change over OSC + * \param sendCallback Send message change to registered callback */ void setBalanceRight(double value, bool sendOsc, bool sendCallback) { @@ -863,8 +867,10 @@ public: } #ifndef BUILD_BRIDGE - // TODO - virtual int setOscBridgeInfo(PluginBridgeInfoType type, lo_arg** argv) + /*! + * TODO + */ + virtual int setOscBridgeInfo(PluginBridgeInfoType type, lo_arg** const argv) { return 1; Q_UNUSED(type); @@ -876,21 +882,20 @@ public: // Set data (plugin-specific stuff) /*! - * Set a plugin's parameter value. + * Set a plugin's parameter value.\n * \a value must be within the parameter's range. * - * \param parameterId parameter to change - * \param value new parameter value - * \param sendGui send message change to plugin's custom GUI, if any - * \param sendOsc send message change over OSC - * \param sendCallback send message change to registered callback + * \param parameterId The parameter to change + * \param value The new parameter value + * \param sendGui Send message change to plugin's custom GUI, if any + * \param sendOsc Send message change over OSC + * \param sendCallback Send message change to registered callback * * \see getParameterValue() */ virtual void setParameterValue(uint32_t parameterId, double value, bool sendGui, bool sendOsc, bool sendCallback) { assert(parameterId < param.count); - fixParameterValue(value, param.ranges[parameterId]); if (sendCallback) callback_action(CALLBACK_PARAMETER_CHANGED, m_id, parameterId, 0, value); @@ -909,7 +914,17 @@ public: Q_UNUSED(sendGui); } - // FIXME? (better name?) + /*! + * Set a plugin's parameter value, including internal parameters.\n + * \a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex). + * + * \see setActive() + * \see setDryWet() + * \see setVolume() + * \see setBalanceLeft() + * \see setBalanceRight() + * \see setParameterValue() + */ void setParameterValueByRIndex(int32_t rindex, double value, bool gui_send, bool osc_send, bool callback_send) { if (rindex == PARAMETER_ACTIVE) @@ -931,40 +946,40 @@ public: } /*! - * Set parameter's \a parameterId MIDI channel to \a channel. + * Set parameter's \a parameterId MIDI channel to \a channel.\n * \a channel must be between 0 and 15. */ - void setParameterMidiChannel(uint32_t index, uint8_t channel) + void setParameterMidiChannel(uint32_t parameterId, uint8_t channel) { - assert(index < param.count && channel < 16); - param.data[index].midiChannel = channel; + assert(parameterId < param.count && channel < 16); + param.data[parameterId].midiChannel = channel; #ifndef BUILD_BRIDGE // FIXME //if (m_hints & PLUGIN_IS_BRIDGE) - // osc_send_set_parameter_midi_channel(&osc.data, m_id, index, channel); + // osc_send_set_parameter_midi_channel(&osc.data, m_id, parameterId, channel); #endif } /*! - * Set parameter's \a parameterId MIDI CC to \a cc. + * Set parameter's \a parameterId MIDI CC to \a cc.\n * \a cc must be between 0 and 15. */ - void setParameterMidiCC(uint32_t index, int16_t cc) + void setParameterMidiCC(uint32_t parameterId, int16_t cc) { - assert(index < param.count); - param.data[index].midiCC = cc; + assert(parameterId < param.count); + param.data[parameterId].midiCC = cc; #ifndef BUILD_BRIDGE // FIXME //if (m_hints & PLUGIN_IS_BRIDGE) - // osc_send_set_parameter_midi_cc(&osc.data, m_id, index, midi_cc); + // osc_send_set_parameter_midi_cc(&osc.data, m_id, parameterId, midi_cc); #endif } /*! * Add a custom data set.\n - * If \a key already exists, it's value will be replaced with \a value. + * If \a key already exists, its value will be swapped with \a value. * * \param type Type of data used in \a value. * \param key A key identifing this data set. @@ -972,27 +987,27 @@ public: * * \see customData() */ - virtual void setCustomData(CustomDataType type, const char* key, const char* value, bool sendGui) + virtual void setCustomData(CustomDataType type, const char* const key, const char* const value, bool sendGui) { qDebug("setCustomData(%i, %s, %s, %s)", type, key, value, bool2str(sendGui)); - bool save_data = true; + bool saveData = true; switch (type) { case CUSTOM_DATA_INVALID: - save_data = false; + saveData = false; break; case CUSTOM_DATA_STRING: // Ignore some keys if (strncmp(key, "OSC:", 4) == 0 || strcmp(key, "guiVisible") || strcmp(key, "CarlaBridgeSaveNow") == 0) - save_data = false; + saveData = false; break; default: break; } - if (save_data) + if (saveData) { assert(key); assert(value); @@ -1009,11 +1024,11 @@ public: } // False if we get here, so store it - CustomData new_data; - new_data.type = type; - new_data.key = strdup(key); - new_data.value = strdup(value); - custom.push_back(new_data); + CustomData newData; + newData.type = type; + newData.key = strdup(key); + newData.value = strdup(value); + custom.push_back(newData); } } @@ -1025,7 +1040,7 @@ public: * * \note Make sure to verify the plugin supports chunks before calling this function! */ - virtual void setChunkData(const char* stringData) + virtual void setChunkData(const char* const stringData) { assert(stringData); } @@ -1033,7 +1048,7 @@ public: /*! * Change the current plugin program to \a index. * - * When \a index is negative the plugin's program is considered unset. + * If \a index is negative the plugin's program will be considered unset. * The plugin's default parameter values will be updated when this function is called. * * \param index New program index to use @@ -1045,6 +1060,10 @@ public: virtual void setProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool block) { assert(index < (int32_t)prog.count); + + if (index < -1) + index = -1; + prog.current = index; if (sendCallback) @@ -1058,29 +1077,47 @@ public: if (m_hints & PLUGIN_IS_BRIDGE) osc_send_program(&osc.data, prog.current); } +#else + Q_UNUSED(sendOsc); #endif // Change default parameter values - for (uint32_t i=0; i < param.count; i++) + if (index >= 0) { - param.ranges[i].def = getParameterValue(i); + for (uint32_t i=0; i < param.count; i++) + { + param.ranges[i].def = getParameterValue(i); #ifndef BUILD_BRIDGE - if (sendOsc) - osc_global_send_set_default_value(m_id, i, param.ranges[i].def); + if (sendOsc) + osc_global_send_set_default_value(m_id, i, param.ranges[i].def); #endif + } } -#ifdef BUILD_BRIDGE - Q_UNUSED(sendOsc); -#endif Q_UNUSED(sendGui); Q_UNUSED(block); } + /*! + * Change the current MIDI plugin program to \a index. + * + * If \a index is negative the plugin's program will be considered unset. + * The plugin's default parameter values will be updated when this function is called. + * + * \param index New program index to use + * \param sendGui Send message change to plugin's custom GUI, if any + * \param sendOsc Send message change over OSC + * \param sendCallback Send message change to registered callback + * \param block Block the audio callback + */ virtual void setMidiProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool block) { assert(index < (int32_t)midiprog.count); + + if (index < -1) + index = -1; + midiprog.current = index; if (sendCallback) @@ -1094,30 +1131,36 @@ public: if (m_hints & PLUGIN_IS_BRIDGE) osc_send_program(&osc.data, midiprog.current); } +#else + Q_UNUSED(sendOsc); #endif - // Sound banks never change defaults - if (m_type == PLUGIN_GIG || m_type == PLUGIN_SF2 || m_type == PLUGIN_SFZ) - return; - // Change default parameter values - for (uint32_t i=0; i < param.count; i++) + if (index >= 0) { - param.ranges[i].def = getParameterValue(i); + // Sound banks never change defaults + if (m_type == PLUGIN_GIG || m_type == PLUGIN_SF2 || m_type == PLUGIN_SFZ) + return; + + for (uint32_t i=0; i < param.count; i++) + { + param.ranges[i].def = getParameterValue(i); #ifndef BUILD_BRIDGE - if (sendOsc) - osc_global_send_set_default_value(m_id, i, param.ranges[i].def); + if (sendOsc) + osc_global_send_set_default_value(m_id, i, param.ranges[i].def); #endif + } } -#ifdef BUILD_BRIDGE - Q_UNUSED(sendOsc); -#endif Q_UNUSED(sendGui); Q_UNUSED(block); } + /*! + * 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(uint32_t bank, uint32_t program, bool sendGui, bool sendOsc, bool sendCallback, bool block) { for (uint32_t i=0; i < midiprog.count; i++) @@ -1130,17 +1173,33 @@ public: // ------------------------------------------------------------------- // Set gui stuff + /*! + * Set plugin's custom GUI stuff.\n + * Parameters change between plugin types. + * + * \note This function must be always called from the main thread. + */ virtual void setGuiData(int data, GuiDataHandle handle) { Q_UNUSED(data); Q_UNUSED(handle); } + /*! + * Show (or hide) a plugin's custom GUI according to \a yesNo. + * + * \note This function must be always called from the main thread. + */ virtual void showGui(bool yesNo) { Q_UNUSED(yesNo); } + /*! + * Idle plugin's custom GUI. + * + * \note This function must be always called from the main thread. + */ virtual void idleGui() { } @@ -1148,15 +1207,25 @@ public: // ------------------------------------------------------------------- // Plugin state + /*! + * Reload the plugin's entire state (including programs).\n + * The plugin will be disabled during this call. + */ virtual void reload() { } + /*! + * Reload the plugin's programs state. + */ virtual void reloadPrograms(bool init) { Q_UNUSED(init); } + /*! + * Tell the plugin to prepare for save. + */ virtual void prepareForSave() { } @@ -1164,12 +1233,15 @@ public: // ------------------------------------------------------------------- // Plugin processing - virtual void process(float** ains_buffer, float** aouts_buffer, uint32_t nframes, uint32_t nframesOffset = 0) + /*! + * Plugin process callback. + */ + virtual void process(float** inBuffer, float** outBuffer, uint32_t frames, uint32_t framesOffset = 0) { - Q_UNUSED(ains_buffer); - Q_UNUSED(aouts_buffer); - Q_UNUSED(nframes); - Q_UNUSED(nframesOffset); + Q_UNUSED(inBuffer); + Q_UNUSED(outBuffer); + Q_UNUSED(frames); + Q_UNUSED(framesOffset); } #ifdef CARLA_ENGINE_JACK @@ -1207,6 +1279,9 @@ public: } #endif + /*! + * Tell the plugin the current buffer size has changed. + */ virtual void bufferSizeChanged(uint32_t newBufferSize) { Q_UNUSED(newBufferSize); @@ -1215,6 +1290,9 @@ public: // ------------------------------------------------------------------- // OSC stuff + /*! + * Register this plugin to the global OSC client. + */ void registerToOsc() { #ifdef BUILD_BRIDGE @@ -1287,7 +1365,7 @@ public: osc_global_send_set_plugin_ports(m_id, audioInCount(), audioOutCount(), midiInCount(), midiOutCount(), param_info.ins, param_info.outs, param_info.total); // Parameters - osc_global_send_set_parameter_value(m_id, PARAMETER_ACTIVE, m_active ? 1.0f : 0.0f); + osc_global_send_set_parameter_value(m_id, PARAMETER_ACTIVE, m_active ? 1.0 : 0.0); osc_global_send_set_parameter_value(m_id, PARAMETER_DRYWET, x_drywet); osc_global_send_set_parameter_value(m_id, PARAMETER_VOLUME, x_vol); osc_global_send_set_parameter_value(m_id, PARAMETER_BALANCE_LEFT, x_bal_left); @@ -1326,6 +1404,10 @@ public: } #ifndef BUILD_BRIDGE + /*! + * Update the plugin's internal OSC data according to \a source and \a url.\n + * This is used for OSC-GUI bridges. + */ void updateOscData(lo_address source, const char* url) { const char* host; @@ -1375,11 +1457,18 @@ public: } } + /*! + * Clear the plugin's internal OSC data. + */ void clearOscData() { osc_clear_data(&osc.data); } + /*! + * Show the plugin's OSC based GUI.\n + * This is a handy function that waits for the GUI to respond and automatically asks it to show itself. + */ bool showOscGui() { // wait for UI 'update' call @@ -1400,6 +1489,10 @@ public: // ------------------------------------------------------------------- // MIDI events + /*! + * Send a single midi note to be processed in the next audio callback.\n + * A note with 0 velocity means note-off. + */ virtual void sendMidiSingleNote(uint8_t note, uint8_t velo, bool sendGui, bool sendOsc, bool sendCallback) { carla_midi_lock(); @@ -1442,37 +1535,41 @@ public: Q_UNUSED(sendGui); } + /*! + * Send all midi notes off for the next audio callback.\n + * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead. + */ void sendMidiAllNotesOff() { carla_midi_lock(); postEvents.mutex.lock(); - unsigned short pe_pad = 0; + unsigned short postPad = 0; for (unsigned short i=0; i < MAX_POST_EVENTS; i++) { if (postEvents.data[i].type == PluginPostEventNull) { - pe_pad = i; - break; - } - else if (i + MAX_POST_EVENTS == MAX_MIDI_EVENTS) - { - qWarning("post-events buffer full, making room for all notes off now"); - pe_pad = i - 1; + postPad = i; break; } } + if (postPad == MAX_POST_EVENTS - 1) + { + qWarning("post-events buffer full, making room for all notes off now"); + postPad -= 128; + } + for (unsigned short i=0; i < 128; i++) { extMidiNotes[i].valid = true; extMidiNotes[i].note = i; extMidiNotes[i].velo = 0; - postEvents.data[i+pe_pad].type = PluginPostEventNoteOff; - postEvents.data[i+pe_pad].index = i; - postEvents.data[i+pe_pad].value = 0.0; + postEvents.data[i + postPad].type = PluginPostEventNoteOff; + postEvents.data[i + postPad].index = i; + postEvents.data[i + postPad].value = 0.0; } postEvents.mutex.unlock(); @@ -1482,10 +1579,13 @@ public: // ------------------------------------------------------------------- // Post-poned events + /*! + * Post pone an event of type \a type.\n + * The event will be processed later in a high-priority thread (but not the main one). + */ void postponeEvent(PluginPostEventType type, int32_t index, double value) { postEvents.mutex.lock(); - for (unsigned short i=0; iPortCount) return rdf_descriptor->Ports[rindex].ScalePointCount; + return 0; } // ------------------------------------------------------------------- // Information (per-plugin data) - double getParameterValue(uint32_t paramId) + double getParameterValue(uint32_t parameterId) { - assert(paramId < param.count); - return param_buffers[paramId]; + assert(parameterId < param.count); + return param_buffers[parameterId]; } - double getParameterScalePointValue(uint32_t paramId, uint32_t scalepointId) + double getParameterScalePointValue(uint32_t parameterId, uint32_t scalePointId) { - assert(paramId < param.count); - assert(scalepointId < paramScalePointCount(paramId)); - int32_t param_rindex = param.data[paramId].rindex; - if (rdf_descriptor && param_rindex < (int32_t)rdf_descriptor->PortCount) - return rdf_descriptor->Ports[param_rindex].ScalePoints[scalepointId].Value; + assert(parameterId < param.count); + assert(scalePointId < parameterScalePointCount(parameterId)); + int32_t rindex = param.data[parameterId].rindex; + + if (rdf_descriptor && rindex < (int32_t)rdf_descriptor->PortCount) + { + const LADSPA_RDF_ScalePoint* const scalePoint = &rdf_descriptor->Ports[rindex].ScalePoints[scalePointId]; + + if (scalePoint) + return rdf_descriptor->Ports[rindex].ScalePoints[scalePointId].Value; + } + return 0.0; } - void getLabel(char* strBuf) + void getLabel(char* const strBuf) { - strncpy(strBuf, descriptor->Label, STR_MAX); + if (descriptor->Label) + strncpy(strBuf, descriptor->Label, STR_MAX); + else + CarlaPlugin::getLabel(strBuf); } - void getMaker(char* strBuf) + void getMaker(char* const strBuf) { if (rdf_descriptor && rdf_descriptor->Creator) strncpy(strBuf, rdf_descriptor->Creator, STR_MAX); - else + else if (descriptor->Maker) strncpy(strBuf, descriptor->Maker, STR_MAX); + else + CarlaPlugin::getMaker(strBuf); } - void getCopyright(char* strBuf) + void getCopyright(char* const strBuf) { - strncpy(strBuf, descriptor->Copyright, STR_MAX); + if (descriptor->Copyright) + strncpy(strBuf, descriptor->Copyright, STR_MAX); + else + CarlaPlugin::getCopyright(strBuf); } - void getRealName(char* strBuf) + void getRealName(char* const strBuf) { if (rdf_descriptor && rdf_descriptor->Title) strncpy(strBuf, rdf_descriptor->Title, STR_MAX); - else + else if (descriptor->Name) strncpy(strBuf, descriptor->Name, STR_MAX); + else + CarlaPlugin::getRealName(strBuf); } - void getParameterName(uint32_t paramId, char* strBuf) + void getParameterName(uint32_t parameterId, char* const strBuf) { - assert(paramId < param.count); - int32_t rindex = param.data[paramId].rindex; + assert(parameterId < param.count); + int32_t rindex = param.data[parameterId].rindex; + strncpy(strBuf, descriptor->PortNames[rindex], STR_MAX); } - void getParameterSymbol(uint32_t paramId, char* strBuf) + void getParameterSymbol(uint32_t parameterId, char* const strBuf) { - assert(paramId < param.count); - int32_t rindex = param.data[paramId].rindex; + assert(parameterId < param.count); + int32_t rindex = param.data[parameterId].rindex; + if (rdf_descriptor && rindex < (int32_t)rdf_descriptor->PortCount) { const LADSPA_RDF_Port* const Port = &rdf_descriptor->Ports[rindex]; - if (LADSPA_PORT_HAS_LABEL(Port->Hints)) + + if (LADSPA_PORT_HAS_LABEL(Port->Hints) && Port->Label) { strncpy(strBuf, Port->Label, STR_MAX); return; } } + *strBuf = 0; } - void getParameterUnit(uint32_t paramId, char* strBuf) + void getParameterUnit(uint32_t parameterId, char* const strBuf) { - assert(paramId < param.count); - int32_t rindex = param.data[paramId].rindex; + assert(parameterId < param.count); + int32_t rindex = param.data[parameterId].rindex; + if (rdf_descriptor && rindex < (int32_t)rdf_descriptor->PortCount) { const LADSPA_RDF_Port* const Port = &rdf_descriptor->Ports[rindex]; + if (LADSPA_PORT_HAS_UNIT(Port->Hints)) { switch (Port->Unit) @@ -249,30 +275,38 @@ public: } } } + *strBuf = 0; } - void getParameterScalePointLabel(uint32_t paramId, uint32_t scalePointId, char* strBuf) + void getParameterScalePointLabel(uint32_t parameterId, uint32_t scalePointId, char* const strBuf) { - assert(paramId < param.count); - assert(scalePointId < paramScalePointCount(paramId)); - int32_t param_rindex = param.data[paramId].rindex; - if (rdf_descriptor && param_rindex < (int32_t)rdf_descriptor->PortCount) + assert(parameterId < param.count); + assert(scalePointId < parameterScalePointCount(parameterId)); + int32_t rindex = param.data[parameterId].rindex; + + if (rdf_descriptor && rindex < (int32_t)rdf_descriptor->PortCount) { - strncpy(strBuf, rdf_descriptor->Ports[param_rindex].ScalePoints[scalePointId].Label, STR_MAX); - return; + const LADSPA_RDF_ScalePoint* const scalePoint = &rdf_descriptor->Ports[rindex].ScalePoints[scalePointId]; + + if (scalePoint && scalePoint->Label) + { + strncpy(strBuf, rdf_descriptor->Ports[rindex].ScalePoints[scalePointId].Label, STR_MAX); + return; + } } + *strBuf = 0; } // ------------------------------------------------------------------- // Set data (plugin-specific stuff) - void setParameterValue(uint32_t paramId, double value, bool sendGui, bool sendOsc, bool sendCallback) + void setParameterValue(uint32_t parameterId, double value, bool sendGui, bool sendOsc, bool sendCallback) { - assert(paramId < param.count); - param_buffers[paramId] = fixParameterValue(value, param.ranges[paramId]); - CarlaPlugin::setParameterValue(paramId, value, sendGui, sendOsc, sendCallback); + assert(parameterId < param.count); + param_buffers[parameterId] = fixParameterValue(value, param.ranges[parameterId]); + CarlaPlugin::setParameterValue(parameterId, value, sendGui, sendOsc, sendCallback); } // ------------------------------------------------------------------- @@ -332,10 +366,10 @@ public: param_buffers = new float[params]; } - const int port_name_size = CarlaEngine::maxPortNameSize() - 1; - char port_name[port_name_size]; - bool needs_cin = false; - bool needs_cout = false; + const int portNameSize = CarlaEngine::maxPortNameSize() - 1; + char portName[portNameSize]; + bool needsCin = false; + bool needsCout = false; for (unsigned long i=0; iPortNames[i], port_name_size/2); + strcpy(portName, m_name); + strcat(portName, ":"); + strncat(portName, descriptor->PortNames[i], portNameSize/2); } else #endif - strncpy(port_name, descriptor->PortNames[i], port_name_size); + strncpy(portName, descriptor->PortNames[i], portNameSize); if (LADSPA_IS_PORT_INPUT(PortType)) { j = ain.count++; - ain.ports[j] = (CarlaEngineAudioPort*)x_client->addPort(port_name, CarlaEnginePortTypeAudio, true); + ain.ports[j] = (CarlaEngineAudioPort*)x_client->addPort(portName, CarlaEnginePortTypeAudio, true); ain.rindexes[j] = i; } else if (LADSPA_IS_PORT_OUTPUT(PortType)) { j = aout.count++; - aout.ports[j] = (CarlaEngineAudioPort*)x_client->addPort(port_name, CarlaEnginePortTypeAudio, false); + aout.ports[j] = (CarlaEngineAudioPort*)x_client->addPort(portName, CarlaEnginePortTypeAudio, false); aout.rindexes[j] = i; - needs_cin = true; + needsCin = true; } else qWarning("WARNING - Got a broken Port (Audio, but not input or output)"); @@ -508,7 +542,7 @@ public: param.data[j].type = PARAMETER_INPUT; param.data[j].hints |= PARAMETER_IS_ENABLED; param.data[j].hints |= PARAMETER_IS_AUTOMABLE; - needs_cin = true; + needsCin = true; } else if (LADSPA_IS_PORT_OUTPUT(PortType)) { @@ -529,7 +563,7 @@ public: param.data[j].type = PARAMETER_OUTPUT; param.data[j].hints |= PARAMETER_IS_ENABLED; param.data[j].hints |= PARAMETER_IS_AUTOMABLE; - needs_cout = true; + needsCout = true; } } else @@ -566,34 +600,34 @@ public: } } - if (needs_cin) + if (needsCin) { #ifndef BUILD_BRIDGE if (carla_options.process_mode != PROCESS_MODE_MULTIPLE_CLIENTS) { - strcpy(port_name, m_name); - strcat(port_name, ":control-in"); + strcpy(portName, m_name); + strcat(portName, ":control-in"); } else #endif - strcpy(port_name, "control-in"); + strcpy(portName, "control-in"); - param.portCin = (CarlaEngineControlPort*)x_client->addPort(port_name, CarlaEnginePortTypeControl, true); + param.portCin = (CarlaEngineControlPort*)x_client->addPort(portName, CarlaEnginePortTypeControl, true); } - if (needs_cout) + if (needsCout) { #ifndef BUILD_BRIDGE if (carla_options.process_mode != PROCESS_MODE_MULTIPLE_CLIENTS) { - strcpy(port_name, m_name); - strcat(port_name, ":control-out"); + strcpy(portName, m_name); + strcat(portName, ":control-out"); } else #endif - strcpy(port_name, "control-out"); + strcpy(portName, "control-out"); - param.portCout = (CarlaEngineControlPort*)x_client->addPort(port_name, CarlaEnginePortTypeControl, false); + param.portCout = (CarlaEngineControlPort*)x_client->addPort(portName, CarlaEnginePortTypeControl, false); } ain.count = ains; @@ -620,7 +654,7 @@ public: // ------------------------------------------------------------------- // Plugin processing - void process(float** ains_buffer, float** aouts_buffer, uint32_t nframes, uint32_t nframesOffset) + void process(float** inBuffer, float** outBuffer, uint32_t frames, uint32_t framesOffset) { uint32_t i, k; @@ -636,21 +670,21 @@ public: { if (ain.count == 1) { - for (k=0; k < nframes; k++) + for (k=0; k < frames; k++) { - if (abs(ains_buffer[0][k]) > ains_peak_tmp[0]) - ains_peak_tmp[0] = abs(ains_buffer[0][k]); + if (abs(inBuffer[0][k]) > ains_peak_tmp[0]) + ains_peak_tmp[0] = abs(inBuffer[0][k]); } } else if (ain.count >= 1) { - for (k=0; k < nframes; k++) + for (k=0; k < frames; k++) { - if (abs(ains_buffer[0][k]) > ains_peak_tmp[0]) - ains_peak_tmp[0] = abs(ains_buffer[0][k]); + if (abs(inBuffer[0][k]) > ains_peak_tmp[0]) + ains_peak_tmp[0] = abs(inBuffer[0][k]); - if (abs(ains_buffer[1][k]) > ains_peak_tmp[1]) - ains_peak_tmp[1] = abs(ains_buffer[1][k]); + if (abs(inBuffer[1][k]) > ains_peak_tmp[1]) + ains_peak_tmp[1] = abs(inBuffer[1][k]); } } } @@ -662,51 +696,51 @@ public: if (param.portCin && m_active && m_activeBefore) { - void* cin_buffer = param.portCin->getBuffer(); + void* cinBuffer = param.portCin->getBuffer(); - const CarlaEngineControlEvent* cin_event; - uint32_t time, n_cin_events = param.portCin->getEventCount(cin_buffer); + const CarlaEngineControlEvent* cinEvent; + uint32_t time, nEvents = param.portCin->getEventCount(cinBuffer); - for (i=0; i < n_cin_events; i++) + for (i=0; i < nEvents; i++) { - cin_event = param.portCin->getEvent(cin_buffer, i); + cinEvent = param.portCin->getEvent(cinBuffer, i); - if (! cin_event) + if (! cinEvent) continue; - time = cin_event->time - nframesOffset; + time = cinEvent->time - framesOffset; - if (time >= nframes) + if (time >= frames) continue; // Control change - switch (cin_event->type) + switch (cinEvent->type) { case CarlaEngineEventControlChange: { double value; // Control backend stuff - if (cin_event->channel == cin_channel) + if (cinEvent->channel == cin_channel) { - if (MIDI_IS_CONTROL_BREATH_CONTROLLER(cin_event->controller) && (m_hints & PLUGIN_CAN_DRYWET) > 0) + if (MIDI_IS_CONTROL_BREATH_CONTROLLER(cinEvent->controller) && (m_hints & PLUGIN_CAN_DRYWET) > 0) { - value = cin_event->value; + value = cinEvent->value; setDryWet(value, false, false); postponeEvent(PluginPostEventParameterChange, PARAMETER_DRYWET, value); continue; } - else if (MIDI_IS_CONTROL_CHANNEL_VOLUME(cin_event->controller) && (m_hints & PLUGIN_CAN_VOLUME) > 0) + else if (MIDI_IS_CONTROL_CHANNEL_VOLUME(cinEvent->controller) && (m_hints & PLUGIN_CAN_VOLUME) > 0) { - value = cin_event->value*127/100; + value = cinEvent->value*127/100; setVolume(value, false, false); postponeEvent(PluginPostEventParameterChange, PARAMETER_VOLUME, value); continue; } - else if (MIDI_IS_CONTROL_BALANCE(cin_event->controller) && (m_hints & PLUGIN_CAN_BALANCE) > 0) + else if (MIDI_IS_CONTROL_BALANCE(cinEvent->controller) && (m_hints & PLUGIN_CAN_BALANCE) > 0) { double left, right; - value = cin_event->value/0.5 - 1.0; + value = cinEvent->value/0.5 - 1.0; if (value < 0) { @@ -735,9 +769,9 @@ public: // Control plugin parameters for (k=0; k < param.count; k++) { - if (param.data[k].midiChannel != cin_event->channel) + if (param.data[k].midiChannel != cinEvent->channel) continue; - if (param.data[k].midiCC != cin_event->controller) + if (param.data[k].midiCC != cinEvent->controller) continue; if (param.data[k].type != PARAMETER_INPUT) continue; @@ -746,11 +780,11 @@ public: { if (param.data[k].hints & PARAMETER_IS_BOOLEAN) { - value = cin_event->value < 0.5 ? param.ranges[k].min : param.ranges[k].max; + value = cinEvent->value < 0.5 ? param.ranges[k].min : param.ranges[k].max; } else { - value = cin_event->value * (param.ranges[k].max - param.ranges[k].min) + param.ranges[k].min; + value = cinEvent->value * (param.ranges[k].max - param.ranges[k].min) + param.ranges[k].min; if (param.data[k].hints & PARAMETER_IS_INTEGER) value = rint(value); @@ -765,7 +799,7 @@ public: } case CarlaEngineEventAllSoundOff: - if (cin_event->channel == cin_channel) + if (cinEvent->channel == cin_channel) { if (descriptor->deactivate) descriptor->deactivate(handle); @@ -810,13 +844,13 @@ public: } for (i=0; i < ain.count; i++) - descriptor->connect_port(handle, ain.rindexes[i], ains_buffer[i]); + descriptor->connect_port(handle, ain.rindexes[i], inBuffer[i]); for (i=0; i < aout.count; i++) - descriptor->connect_port(handle, aout.rindexes[i], aouts_buffer[i]); + descriptor->connect_port(handle, aout.rindexes[i], outBuffer[i]); if (descriptor->run) - descriptor->run(handle, nframes); + descriptor->run(handle, frames); } else { @@ -839,25 +873,25 @@ public: bool do_balance = (m_hints & PLUGIN_CAN_BALANCE) > 0 && (x_bal_left != -1.0 || x_bal_right != 1.0); double bal_rangeL, bal_rangeR; - float old_bal_left[do_balance ? nframes : 0]; + float oldBufLeft[do_balance ? frames : 0]; for (i=0; i < aout.count; i++) { // Dry/Wet and Volume if (do_drywet || do_volume) { - for (k=0; k aouts_peak_tmp[i]) - aouts_peak_tmp[i] = abs(aouts_buffer[i][k]); + if (abs(outBuffer[i][k]) > aouts_peak_tmp[i]) + aouts_peak_tmp[i] = abs(outBuffer[i][k]); } } } @@ -899,7 +933,7 @@ public: { // disable any output sound if not active for (i=0; i < aout.count; i++) - memset(aouts_buffer[i], 0.0f, sizeof(float)*nframes); + memset(outBuffer[i], 0.0f, sizeof(float)*frames); aouts_peak_tmp[0] = 0.0; aouts_peak_tmp[1] = 0.0; @@ -913,10 +947,10 @@ public: if (param.portCout && m_active) { - void* cout_buffer = param.portCout->getBuffer(); + void* coutBuffer = param.portCout->getBuffer(); - if (nframesOffset == 0 || ! m_activeBefore) - param.portCout->initBuffer(cout_buffer); + if (framesOffset == 0 || ! m_activeBefore) + param.portCout->initBuffer(coutBuffer); double value; @@ -929,7 +963,7 @@ public: if (param.data[k].midiCC > 0) { value = (param_buffers[k] - param.ranges[k].min) / (param.ranges[k].max - param.ranges[k].min); - param.portCout->writeEvent(cout_buffer, CarlaEngineEventControlChange, nframesOffset, param.data[k].midiChannel, param.data[k].midiCC, value); + param.portCout->writeEvent(coutBuffer, CarlaEngineEventControlChange, framesOffset, param.data[k].midiChannel, param.data[k].midiCC, value); } } } diff --git a/src/carla.py b/src/carla.py index f4acccc..55e63da 100755 --- a/src/carla.py +++ b/src/carla.py @@ -69,8 +69,8 @@ save_state_parameter = { 'name': "", 'symbol': "", 'value': 0.0, - 'midi_channel': 1, - 'midi_cc': -1 + 'midiChannel': 1, + 'midiCC': -1 } save_state_custom_data = { @@ -194,12 +194,12 @@ def getStateDictFromXML(xml_node): elif ptag == "value": if isNumber(ptext): x_save_state_parameter['value'] = float(ptext) - elif ptag == "midi_channel": + elif ptag == "midiChannel": if ptext.isdigit(): - x_save_state_parameter['midi_channel'] = int(ptext) - elif ptag == "midi_cc": + x_save_state_parameter['midiChannel'] = int(ptext) + elif ptag == "midiCC": if ptext.isdigit(): - x_save_state_parameter['midi_cc'] = int(ptext) + x_save_state_parameter['midiCC'] = int(ptext) xml_subdata = xml_subdata.nextSibling() @@ -1254,8 +1254,8 @@ class PluginParameter(QWidget, ui_carla_parameter.Ui_PluginParameter): self.widget.set_value(pinfo['current'], False) self.widget.set_label(pinfo['unit']) self.widget.set_step(pinfo['step']) - self.widget.set_step_small(pinfo['step_small']) - self.widget.set_step_large(pinfo['step_large']) + self.widget.set_step_small(pinfo['stepSmall']) + self.widget.set_step_large(pinfo['stepLarge']) self.widget.set_scalepoints(pinfo['scalepoints'], (pinfo['hints'] & PARAMETER_USES_SCALEPOINTS)) if (not self.hints & PARAMETER_IS_ENABLED): @@ -1283,8 +1283,8 @@ class PluginParameter(QWidget, ui_carla_parameter.Ui_PluginParameter): self.combo.setVisible(False) self.sb_channel.setVisible(False) - self.set_parameter_midi_channel(pinfo['midi_channel']) - self.set_parameter_midi_cc(pinfo['midi_cc']) + self.set_parameter_midi_channel(pinfo['midiChannel']) + self.set_parameter_midi_cc(pinfo['midiCC']) self.connect(self.widget, SIGNAL("valueChanged(double)"), SLOT("slot_valueChanged(double)")) self.connect(self.sb_channel, SIGNAL("valueChanged(int)"), SLOT("slot_midiChannelChanged(int)")) @@ -1611,10 +1611,10 @@ class PluginEdit(QDialog, ui_carla_edit.Ui_PluginEdit): 'minimum': param_ranges['min'], 'maximum': param_ranges['max'], 'step': param_ranges['step'], - 'step_small': param_ranges['step_small'], - 'step_large': param_ranges['step_large'], - 'midi_channel': param_data['midi_channel'], - 'midi_cc': param_data['midi_cc'], + 'stepSmall': param_ranges['stepSmall'], + 'stepLarge': param_ranges['stepLarge'], + 'midiChannel': param_data['midiChannel'], + 'midiCC': param_data['midiCC'], 'current': CarlaHost.get_current_parameter_value(self.plugin_id, i) } @@ -1695,10 +1695,10 @@ class PluginEdit(QDialog, ui_carla_edit.Ui_PluginEdit): 'minimum': 0, 'maximum': 0, 'step': 0, - 'step_small': 0, - 'step_large': 0, - 'midi_channel': 0, - 'midi_cc': -1, + 'stepSmall': 0, + 'stepLarge': 0, + 'midiChannel': 0, + 'midiCC': -1, 'current': 0.0 } @@ -2354,8 +2354,8 @@ class PluginWidget(QFrame, ui_carla_plugin.Ui_PluginWidget): x_save_state_parameter['name'] = cString(parameter_info['name']) x_save_state_parameter['symbol'] = cString(parameter_info['symbol']) x_save_state_parameter['value'] = CarlaHost.get_current_parameter_value(self.plugin_id, parameter_data['index']) - x_save_state_parameter['midi_channel'] = parameter_data['midi_channel'] + 1 - x_save_state_parameter['midi_cc'] = parameter_data['midi_cc'] + x_save_state_parameter['midiChannel'] = parameter_data['midiChannel'] + 1 + x_save_state_parameter['midiCC'] = parameter_data['midiCC'] if (parameter_data['hints'] & PARAMETER_USES_SAMPLERATE): x_save_state_parameter['value'] /= CarlaHost.get_sample_rate() @@ -2421,9 +2421,9 @@ class PluginWidget(QFrame, ui_carla_plugin.Ui_PluginWidget): if (parameter['symbol']): content += " %s\n" % parameter['symbol'] content += " %f\n" % parameter['value'] - if (parameter['midi_cc'] > 0): - content += " %i\n" % parameter['midi_channel'] - content += " %i\n" % parameter['midi_cc'] + if (parameter['midiCC'] > 0): + content += " %i\n" % parameter['midiChannel'] + content += " %i\n" % parameter['midiCC'] content += " \n" if (x_save_state_dict['CurrentProgramIndex'] >= 0): @@ -2560,8 +2560,8 @@ class PluginWidget(QFrame, ui_carla_plugin.Ui_PluginWidget): parameter['value'] *= CarlaHost.get_sample_rate() CarlaHost.set_parameter_value(self.plugin_id, index, parameter['value']) - CarlaHost.set_parameter_midi_channel(self.plugin_id, index, parameter['midi_channel'] - 1) - CarlaHost.set_parameter_midi_cc(self.plugin_id, index, parameter['midi_cc']) + CarlaHost.set_parameter_midi_channel(self.plugin_id, index, parameter['midiChannel'] - 1) + CarlaHost.set_parameter_midi_cc(self.plugin_id, index, parameter['midiCC']) else: print("Could not set parameter data for %i -> %s" % (parameter['index'], parameter['name'])) diff --git a/src/carla_backend.py b/src/carla_backend.py index b150a92..ddc5bcb 100644 --- a/src/carla_backend.py +++ b/src/carla_backend.py @@ -680,8 +680,8 @@ class ParameterData(Structure): ("index", c_int32), ("rindex", c_int32), ("hints", c_int32), - ("midi_channel", c_uint8), - ("midi_cc", c_int16) + ("midiChannel", c_uint8), + ("midiCC", c_int16) ] class ParameterRanges(Structure): @@ -690,8 +690,8 @@ class ParameterRanges(Structure): ("min", c_double), ("max", c_double), ("step", c_double), - ("step_small", c_double), - ("step_large", c_double) + ("stepSmall", c_double), + ("stepLarge", c_double) ] class CustomData(Structure):