| @@ -919,7 +919,13 @@ CARLA_EXPORT void carla_set_chunk_data(uint pluginId, const char* chunkData); | |||
| CARLA_EXPORT void carla_prepare_for_save(uint pluginId); | |||
| /*! | |||
| * Randomize a plugin's parameters. | |||
| * Reset all plugin's parameters. | |||
| * @param pluginId Plugin | |||
| */ | |||
| CARLA_EXPORT void carla_reset_parameters(uint pluginId); | |||
| /*! | |||
| * Randomize all plugin's parameters. | |||
| * @param pluginId Plugin | |||
| */ | |||
| CARLA_EXPORT void carla_randomize_parameters(uint pluginId); | |||
| @@ -374,6 +374,11 @@ public: | |||
| */ | |||
| virtual void prepareForSave(); | |||
| /*! | |||
| * Reset all possible parameters. | |||
| */ | |||
| virtual void resetParameters() noexcept; | |||
| /*! | |||
| * Randomize all possible parameters. | |||
| */ | |||
| @@ -454,24 +454,60 @@ void CarlaPlugin::prepareForSave() | |||
| { | |||
| } | |||
| void CarlaPlugin::resetParameters() noexcept | |||
| { | |||
| for (uint i=0; i < pData->param.count; ++i) | |||
| { | |||
| const ParameterData& paramData(pData->param.data[i]); | |||
| const ParameterRanges& paramRanges(pData->param.ranges[i]); | |||
| if (paramData.type != PARAMETER_INPUT) | |||
| continue; | |||
| if ((paramData.hints & PARAMETER_IS_ENABLED) == 0) | |||
| continue; | |||
| setParameterValue(i, paramRanges.def, true, true, true); | |||
| } | |||
| } | |||
| void CarlaPlugin::randomizeParameters() noexcept | |||
| { | |||
| float value, random; | |||
| char strBuf[STR_MAX+1]; | |||
| strBuf[STR_MAX] = '\0'; | |||
| std::srand(static_cast<uint>(std::time(nullptr))); | |||
| for (uint i=0; i < pData->param.count; ++i) | |||
| { | |||
| const ParameterData& paramData(pData->param.data[i]); | |||
| const ParameterRanges& paramRanges(pData->param.ranges[i]); | |||
| const ParameterData& paramData(pData->param.data[i]); | |||
| if (paramData.type != PARAMETER_INPUT) | |||
| continue; | |||
| if ((paramData.hints & PARAMETER_IS_ENABLED) == 0) | |||
| continue; | |||
| random = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX); | |||
| value = random * (paramRanges.max - paramRanges.min) + paramRanges.min; | |||
| getParameterName(i, strBuf); | |||
| if (std::strstr(strBuf, "olume") != nullptr) | |||
| continue; | |||
| const ParameterRanges& paramRanges(pData->param.ranges[i]); | |||
| if (paramData.hints & PARAMETER_IS_BOOLEAN) | |||
| { | |||
| random = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX); | |||
| value = random > 0.5 ? paramRanges.max : paramRanges.min; | |||
| } | |||
| else | |||
| { | |||
| random = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX); | |||
| value = random * (paramRanges.max - paramRanges.min) + paramRanges.min; | |||
| if (paramData.hints & PARAMETER_IS_INTEGER) | |||
| value = std::rint(value); | |||
| } | |||
| setParameterValue(i, value, true, true, true); | |||
| } | |||
| @@ -2027,6 +2027,17 @@ void carla_prepare_for_save(uint pluginId) | |||
| carla_stderr2("carla_prepare_for_save(%i) - could not find plugin", pluginId); | |||
| } | |||
| void carla_reset_parameters(uint pluginId) | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,); | |||
| carla_debug("carla_reset_parameters(%i)", pluginId); | |||
| if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId)) | |||
| return plugin->resetParameters(); | |||
| carla_stderr2("carla_reset_parameters(%i) - could not find plugin", pluginId); | |||
| } | |||
| void carla_randomize_parameters(uint pluginId) | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(gStandalone.engine != nullptr,); | |||
| @@ -1706,7 +1706,12 @@ class Host(object): | |||
| def prepare_for_save(self, pluginId): | |||
| self.lib.carla_prepare_for_save(pluginId) | |||
| # Randomize a plugin's parameters. | |||
| # Reset all plugin's parameters. | |||
| # @param pluginId Plugin | |||
| def reset_parameters(self, pluginId): | |||
| self.lib.carla_reset_parameters(pluginId) | |||
| # Randomize all plugin's parameters. | |||
| # @param pluginId Plugin | |||
| def randomize_parameters(self, pluginId): | |||
| self.lib.carla_randomize_parameters(pluginId) | |||
| @@ -1984,6 +1989,12 @@ class Host(object): | |||
| self.lib.carla_prepare_for_save.argtypes = [c_uint] | |||
| self.lib.carla_prepare_for_save.restype = None | |||
| self.lib.carla_reset_parameters.argtypes = [c_uint] | |||
| self.lib.carla_reset_parameters.restype = None | |||
| self.lib.carla_randomize_parameters.argtypes = [c_uint] | |||
| self.lib.carla_randomize_parameters.restype = None | |||
| self.lib.carla_send_midi_note.argtypes = [c_uint, c_uint8, c_uint8, c_uint8] | |||
| self.lib.carla_send_midi_note.restype = None | |||
| @@ -461,6 +461,10 @@ class AbstractPluginSlot(QFrame): | |||
| actActive = menu.addAction(self.tr("Disable") if isEnabled else self.tr("Enable")) | |||
| menu.addSeparator() | |||
| actReset = menu.addAction(self.tr("Reset parameters")) | |||
| actRandom = menu.addAction(self.tr("Randomize parameters")) | |||
| menu.addSeparator() | |||
| if bEdit is not None: | |||
| actEdit = menu.addAction(self.tr("Edit")) | |||
| actEdit.setCheckable(True) | |||
| @@ -488,10 +492,21 @@ class AbstractPluginSlot(QFrame): | |||
| if actSel == actActive: | |||
| self.setActive(not isEnabled, True, True) | |||
| elif actSel == actReset: | |||
| if gCarla.host is None: return | |||
| gCarla.host.reset_parameters(self.fPluginId) | |||
| elif actSel == actRandom: | |||
| if gCarla.host is None: return | |||
| gCarla.host.randomize_parameters(self.fPluginId) | |||
| elif actSel == actGui: | |||
| bGui.click() | |||
| elif actSel == actEdit: | |||
| bEdit.click() | |||
| elif actSel == actClone: | |||
| if gCarla.host is not None and not gCarla.host.clone_plugin(self.fPluginId): | |||
| CustomMessageBox(self, QMessageBox.Warning, self.tr("Error"), self.tr("Operation failed"), | |||