commit 8b271423a581cfa71a66cf6b1dec86f4640f0c7b
parent 3aac28653db9fdfc741030a49511c5c7bc30da22
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Sat, 17 Jul 2021 15:11:38 +0200
Host: add a slider to control the modulation amount
Diffstat:
6 files changed, 61 insertions(+), 9 deletions(-)
diff --git a/examples/host/plugin-host.cc b/examples/host/plugin-host.cc
@@ -722,6 +722,15 @@ void PluginHost::setParamValueByHost(PluginParam ¶m, double value) {
appToEngineValueQueue_.producerDone();
}
+void PluginHost::setParamModulationByHost(PluginParam ¶m, double value) {
+ checkForMainThread();
+
+ param.setModulation(value);
+
+ appToEngineModQueue_.set(param.info().id, param.info().cookie, value);
+ appToEngineModQueue_.producerDone();
+}
+
void PluginHost::scanParams() { clapParamsRescan(&host_, CLAP_PARAM_RESCAN_ALL); }
void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) {
@@ -819,7 +828,7 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) {
// update param value
h->checkValidParamValue(*it->second, value);
it->second->setValue(value);
- it->second->setModulatedValue(value);
+ it->second->setModulation(value);
}
}
}
diff --git a/examples/host/plugin-host.hh b/examples/host/plugin-host.hh
@@ -53,6 +53,7 @@ public:
void threadPoolEntry();
void setParamValueByHost(PluginParam ¶m, double value);
+ void setParamModulationByHost(PluginParam ¶m, double value);
auto ¶ms() const { return params_; }
auto &quickControlsPages() const { return quickControlsPages_; }
diff --git a/examples/host/plugin-param.cc b/examples/host/plugin-param.cc
@@ -2,7 +2,7 @@
#include "plugin-host.hh"
PluginParam::PluginParam(PluginHost &pluginHost, const clap_param_info &info, double value)
- : QObject(&pluginHost), info_(info), value_(value), modulated_value_(value) {}
+ : QObject(&pluginHost), info_(info), value_(value) {}
void PluginParam::setValue(double v) {
if (value_ == v)
@@ -12,11 +12,11 @@ void PluginParam::setValue(double v) {
valueChanged();
}
-void PluginParam::setModulatedValue(double v) {
- if (modulated_value_ == v)
+void PluginParam::setModulation(double v) {
+ if (modulation_ == v)
return;
- modulated_value_ = v;
+ modulation_ = v;
modulatedValueChanged();
}
diff --git a/examples/host/plugin-param.hh b/examples/host/plugin-param.hh
@@ -17,8 +17,12 @@ public:
double value() const { return value_; }
void setValue(double v);
- double modulatedValue() const { return modulated_value_; }
- void setModulatedValue(double v);
+ double modulation() const { return modulation_; }
+ void setModulation(double v);
+
+ double modulatedValue() const {
+ return std::min(info_.max_value, std::max(info_.min_value, value_ + modulation_));
+ }
bool isValueValid(const double v) const;
@@ -52,7 +56,7 @@ signals:
private:
bool is_being_adjusted_ = false;
clap_param_info info_;
- double value_;
- double modulated_value_;
+ double value_ = 0;
+ double modulation_ = 0;
std::unordered_map<int64_t, std::string> enum_entries_;
};
\ No newline at end of file
diff --git a/examples/host/plugin-parameters-widget.cc b/examples/host/plugin-parameters-widget.cc
@@ -112,12 +112,19 @@ PluginParametersWidget::PluginParametersWidget(QWidget *parent, PluginHost &plug
maxValueLabel_ = new QLabel;
defaultValueLabel_ = new QLabel;
isBeingAdjusted_ = new QLabel;
+
valueSlider_ = new QSlider;
valueSlider_->setMinimum(0);
valueSlider_->setMaximum(SLIDER_RANGE);
valueSlider_->setOrientation(Qt::Horizontal);
connect(valueSlider_, &QSlider::valueChanged, this, &PluginParametersWidget::sliderValueChanged);
+ modulationSlider_ = new QSlider;
+ modulationSlider_->setMinimum(SLIDER_RANGE);
+ modulationSlider_->setMaximum(SLIDER_RANGE);
+ modulationSlider_->setOrientation(Qt::Horizontal);
+ connect(modulationSlider_, &QSlider::valueChanged, this, &PluginParametersWidget::sliderModulationChanged);
+
auto formLayout = new QFormLayout(infoWidget);
formLayout->addRow(tr("id"), idLabel_);
formLayout->addRow(tr("name"), nameLabel_);
@@ -134,6 +141,7 @@ PluginParametersWidget::PluginParametersWidget(QWidget *parent, PluginHost &plug
formLayout->addRow(tr("default_value"), defaultValueLabel_);
formLayout->addRow(tr("is_being_adjusted"), isBeingAdjusted_);
formLayout->addRow(tr("value"), valueSlider_);
+ formLayout->addRow(tr("modulation"), modulationSlider_);
infoWidget->setLayout(formLayout);
@@ -222,6 +230,7 @@ void PluginParametersWidget::disconnectFromParam() {
void PluginParametersWidget::updateAll() {
updateParamInfo();
updateParamValue();
+ updateParamModulation();
updateParamIsBeingAjustedChanged();
}
@@ -283,6 +292,18 @@ void PluginParametersWidget::updateParamValue() {
valueSlider_->setValue(SLIDER_RANGE * (v - info.min_value) / (info.max_value - info.min_value));
}
+void PluginParametersWidget::updateParamModulation() {
+ if (valueSlider_->isSliderDown())
+ return;
+
+ if (!currentParam_)
+ return;
+
+ auto info = currentParam_->info();
+ auto v = currentParam_->value();
+ valueSlider_->setValue(SLIDER_RANGE * (v - info.min_value) / (info.max_value - info.min_value));
+}
+
void PluginParametersWidget::paramInfoChanged() { updateParamInfo(); }
void PluginParametersWidget::paramValueChanged() { updateParamValue(); }
@@ -298,4 +319,18 @@ void PluginParametersWidget::sliderValueChanged(int newValue) {
double value = newValue * (info.max_value - info.min_value) / SLIDER_RANGE + info.min_value;
pluginHost_.setParamValueByHost(*currentParam_, value);
+}
+
+void PluginParametersWidget::sliderModulationChanged(int newValue) {
+ if (!currentParam_)
+ return;
+
+ if (!modulationSlider_->isSliderDown())
+ return;
+
+ auto &info = currentParam_->info();
+
+ double dist = info.max_value - info.min_value;
+ double value = newValue * dist / SLIDER_RANGE;
+ pluginHost_.setParamModulationByHost(*currentParam_, value);
}
\ No newline at end of file
diff --git a/examples/host/plugin-parameters-widget.hh b/examples/host/plugin-parameters-widget.hh
@@ -64,10 +64,12 @@ private:
void paramInfoChanged();
void paramValueChanged();
void sliderValueChanged(int newValue);
+ void sliderModulationChanged(int newValue);
void updateAll();
void updateParamInfo();
void updateParamValue();
+ void updateParamModulation();
void updateParamIsBeingAjustedChanged();
static const constexpr int SLIDER_RANGE = 10000;
@@ -93,4 +95,5 @@ private:
QLabel * defaultValueLabel_ = nullptr;
QLabel * isBeingAdjusted_ = nullptr;
QSlider *valueSlider_ = nullptr;
+ QSlider *modulationSlider_ = nullptr;
};