Signed-off-by: falkTX <falktx@falktx.com>tags/v2.1-rc1
@@ -29,6 +29,8 @@ X_DATADIR_X = None | |||
import os | |||
import sys | |||
from math import fmod | |||
from PyQt5.Qt import PYQT_VERSION_STR | |||
from PyQt5.QtCore import qFatal, QT_VERSION, QT_VERSION_STR, qWarning, QDir, QSettings | |||
from PyQt5.QtGui import QIcon | |||
@@ -568,6 +570,23 @@ elif MACOS: | |||
else: | |||
DLL_EXTENSION = "so" | |||
# ------------------------------------------------------------------------------------------------------------ | |||
# Find decimal points for a parameter, using step and stepSmall | |||
def countDecimalPoints(step, stepSmall): | |||
if stepSmall >= 1.0: | |||
return 0 | |||
if step >= 1.0: | |||
return 2 | |||
count = 0 | |||
value = fmod(abs(stepSmall), 1) | |||
while value > 0.001 and value < 0.99 and count < 6: | |||
value = fmod(value*10, 1) | |||
count += 1 | |||
return count | |||
# ------------------------------------------------------------------------------------------------------------ | |||
# Check if a value is a number (float support) | |||
@@ -216,6 +216,7 @@ class JuceAboutW(QDialog): | |||
class PluginParameter(QWidget): | |||
mappedControlChanged = pyqtSignal(int, int) | |||
mappedRangeChanged = pyqtSignal(int, float, float) | |||
midiChannelChanged = pyqtSignal(int, int) | |||
valueChanged = pyqtSignal(int, float) | |||
@@ -233,9 +234,12 @@ class PluginParameter(QWidget): | |||
# ------------------------------------------------------------- | |||
# Internal stuff | |||
self.fDecimalPoints = max(2, countDecimalPoints(pInfo['step'], pInfo['stepSmall'])) | |||
self.fMappedCtrl = pInfo['mappedControlIndex'] | |||
self.fMappedMinimum = pInfo['mappedMinimum'] | |||
self.fMappedMaximum = pInfo['mappedMaximum'] | |||
self.fMinimum = pInfo['minimum'] | |||
self.fMaximum = pInfo['maximum'] | |||
self.fMidiChannel = pInfo['midiChannel'] | |||
self.fParameterId = pInfo['index'] | |||
self.fPluginId = pluginId | |||
@@ -422,6 +426,11 @@ class PluginParameter(QWidget): | |||
action.setCheckable(True) | |||
action.setChecked(True) | |||
menu.addSection("Range") | |||
actRangeMinimum = menu.addAction(self.tr("Set minimum... (%g)" % self.fMappedMinimum)) | |||
actRangeMaximum = menu.addAction(self.tr("Set maximum... (%g)" % self.fMappedMaximum)) | |||
actSel = menu.exec_(QCursor.pos()) | |||
if not actSel: | |||
@@ -433,6 +442,32 @@ class PluginParameter(QWidget): | |||
self.midiChannelChanged.emit(self.fParameterId, channel) | |||
return | |||
if actSel == actRangeMinimum: | |||
value, ok = QInputDialog.getDouble(self, | |||
self.tr("Custom Minimum"), | |||
"Custom minimum value to use:", | |||
self.fMappedMinimum, | |||
self.fMinimum, self.fMaximum, self.fDecimalPoints) | |||
if not ok: | |||
return | |||
self.fMappedMinimum = value | |||
self.mappedRangeChanged.emit(self.fParameterId, self.fMappedMinimum, self.fMappedMaximum) | |||
return | |||
if actSel == actRangeMaximum: | |||
value, ok = QInputDialog.getDouble(self, | |||
self.tr("Custom Maximum"), | |||
"Custom maximum value to use:", | |||
self.fMappedMaximum, | |||
self.fMinimum, self.fMaximum, self.fDecimalPoints) | |||
if not ok: | |||
return | |||
self.fMappedMaximum = value | |||
self.mappedRangeChanged.emit(self.fParameterId, self.fMappedMinimum, self.fMappedMaximum) | |||
return | |||
if actSel == actUnmap: | |||
ctrl = CONTROL_VALUE_NONE | |||
elif actSel == actCV: | |||
@@ -1387,6 +1422,10 @@ class PluginEdit(QDialog): | |||
def slot_parameterMappedControlChanged(self, parameterId, control): | |||
self.host.set_parameter_mapped_control_index(self.fPluginId, parameterId, control) | |||
@pyqtSlot(int, float, float) | |||
def slot_parameterMappedRangeChanged(self, parameterId, minimum, maximum): | |||
self.host.set_parameter_mapped_range(self.fPluginId, parameterId, minimum, maximum) | |||
@pyqtSlot(int, int) | |||
def slot_parameterMidiChannelChanged(self, parameterId, channel): | |||
self.host.set_parameter_midi_channel(self.fPluginId, parameterId, channel-1) | |||
@@ -1589,6 +1628,7 @@ class PluginEdit(QDialog): | |||
paramWidget.valueChanged.connect(self.slot_parameterValueChanged) | |||
paramWidget.mappedControlChanged.connect(self.slot_parameterMappedControlChanged) | |||
paramWidget.mappedRangeChanged.connect(self.slot_parameterMappedRangeChanged) | |||
paramWidget.midiChannelChanged.connect(self.slot_parameterMidiChannelChanged) | |||
scrollAreaLayout.addStretch() | |||
@@ -31,6 +31,8 @@ from PyQt5.QtWidgets import QAbstractSpinBox, QApplication, QComboBox, QDialog, | |||
import ui_inputdialog_value | |||
from carla_shared import countDecimalPoints | |||
# ------------------------------------------------------------------------------------------------------------ | |||
# Get a fixed value within min/max bounds | |||
@@ -50,31 +52,18 @@ def geFixedValue(name, value, minimum, maximum): | |||
# Custom InputDialog with Scale Points support | |||
class CustomInputDialog(QDialog): | |||
def __init__(self, parent, label, current, minimum, maximum, step, stepSmall, scalePoints): | |||
def __init__(self, parent, label, current, minimum, maximum, step, stepSmall, scalePoints, prefix, suffix): | |||
QDialog.__init__(self, parent) | |||
self.ui = ui_inputdialog_value.Ui_Dialog() | |||
self.ui.setupUi(self) | |||
# calculate num decimals from stepSmall | |||
if stepSmall >= 1.0: | |||
decimals = 0 | |||
elif step >= 1.0: | |||
decimals = 2 | |||
else: | |||
decfrac, decwhole = modf(stepSmall) | |||
if "000" in str(decfrac): | |||
decfrac = round(decfrac, str(decfrac).find("000")) | |||
else: | |||
decfrac = round(decfrac, 12) | |||
decimals = abs(len(str(decfrac))-len(str(decwhole))-1) | |||
self.ui.label.setText(label) | |||
self.ui.doubleSpinBox.setDecimals(decimals) | |||
self.ui.doubleSpinBox.setDecimals(countDecimalPoints(step, stepSmall)) | |||
self.ui.doubleSpinBox.setRange(minimum, maximum) | |||
self.ui.doubleSpinBox.setSingleStep(step) | |||
self.ui.doubleSpinBox.setValue(current) | |||
self.ui.doubleSpinBox.setPrefix(prefix) | |||
self.ui.doubleSpinBox.setSuffix(suffix) | |||
if not scalePoints: | |||
self.ui.groupBox.setVisible(False) | |||
@@ -125,9 +114,9 @@ class ParamProgressBar(QProgressBar): | |||
self.fLastPaintedValue = None | |||
self.fCurrentPaintedText = "" | |||
self.fLabel = "" | |||
self.fName = "" | |||
self.fPreLabel = " " | |||
self.fLabelPrefix = "" | |||
self.fLabelSuffix = "" | |||
self.fTextCall = None | |||
self.fValueCall = None | |||
@@ -169,12 +158,9 @@ class ParamProgressBar(QProgressBar): | |||
QProgressBar.setValue(self, int(vper * 10000)) | |||
return True | |||
def setLabel(self, label): | |||
self.fLabel = label.strip() | |||
if self.fLabel == "(coef)": | |||
self.fLabel = "" | |||
self.fPreLabel = "*" | |||
def setSuffixes(self, prefix, suffix): | |||
self.fLabelPrefix = prefix | |||
self.fLabelSuffix = suffix | |||
# force refresh of text value | |||
self.fLastPaintedValue = None | |||
@@ -246,13 +232,13 @@ class ParamProgressBar(QProgressBar): | |||
if self.fLastPaintedValue != self.fRealValue: | |||
self.fLastPaintedValue = self.fRealValue | |||
self.fCurrentPaintedText = self.fTextCall() | |||
self.setFormat("%s %s %s" % (self.fPreLabel, self.fCurrentPaintedText, self.fLabel)) | |||
self.setFormat("%s%s%s" % (self.fLabelPrefix, self.fCurrentPaintedText, self.fLabelSuffix)) | |||
elif self.fIsInteger: | |||
self.setFormat("%s %i %s" % (self.fPreLabel, int(self.fRealValue), self.fLabel)) | |||
self.setFormat("%s%i%s" % (self.fLabelPrefix, int(self.fRealValue), self.fLabelSuffix)) | |||
else: | |||
self.setFormat("%s %f %s" % (self.fPreLabel, self.fRealValue, self.fLabel)) | |||
self.setFormat("%s%f%s" % (self.fLabelPrefix, self.fRealValue, self.fLabelSuffix)) | |||
QProgressBar.paintEvent(self, event) | |||
@@ -267,6 +253,8 @@ class ParamSpinBox(QAbstractSpinBox): | |||
QAbstractSpinBox.__init__(self, parent) | |||
self.fName = "" | |||
self.fLabelPrefix = "" | |||
self.fLabelSuffix = "" | |||
self.fMinimum = 0.0 | |||
self.fMaximum = 1.0 | |||
@@ -365,7 +353,18 @@ class ParamSpinBox(QAbstractSpinBox): | |||
self.fStepLarge = value | |||
def setLabel(self, label): | |||
self.fBar.setLabel(label) | |||
prefix = "" | |||
suffix = label.strip() | |||
if suffix == "(coef)": | |||
prefix = "* " | |||
suffix = "" | |||
else: | |||
suffix = " " + suffix | |||
self.fLabelPrefix = prefix | |||
self.fLabelSuffix = suffix | |||
self.fBar.setSuffixes(prefix, suffix) | |||
def setName(self, name): | |||
self.fName = name | |||
@@ -561,7 +560,8 @@ class ParamSpinBox(QAbstractSpinBox): | |||
elif actSel == actSet: | |||
dialog = CustomInputDialog(self, self.fName, self.fValue, self.fMinimum, self.fMaximum, | |||
self.fStep, self.fStepSmall, self.fScalePoints) | |||
self.fStep, self.fStepSmall, self.fScalePoints, | |||
self.fLabelPrefix, self.fLabelSuffix) | |||
if dialog.exec_(): | |||
value = dialog.returnValue() | |||
self.setValue(value) | |||