summaryrefslogtreecommitdiffstats
path: root/src/control
diff options
context:
space:
mode:
authorDaniel Schürmann <daschuer@mixxx.org>2014-09-01 00:26:39 +0200
committerDaniel Schürmann <daschuer@mixxx.org>2014-09-01 00:26:39 +0200
commit0526bfa95c355dcbe38f09f6d5225595ae7e1d6a (patch)
tree52220bb52c77e051e3a0415b81b6fddf2726af3c /src/control
parent1c3b03952c5e9c429188d8fefd555d4590613a07 (diff)
parent3e4b3ec6acc4b687476f16e72b628e9207210c00 (diff)
Merge remote-tracking branch 'upstream/master' into audiotaper
Conflicts: src/control/controlbehavior.cpp src/controleffectknob.cpp src/engine/engineaux.h src/engine/enginemicrophone.h
Diffstat (limited to 'src/control')
-rw-r--r--src/control/control.cpp25
-rw-r--r--src/control/control.h8
-rw-r--r--src/control/controlbehavior.cpp56
-rw-r--r--src/control/controlbehavior.h8
4 files changed, 59 insertions, 38 deletions
diff --git a/src/control/control.cpp b/src/control/control.cpp
index c5fabc8a57..8ebdd4c408 100644
--- a/src/control/control.cpp
+++ b/src/control/control.cpp
@@ -9,7 +9,9 @@
// Static member variable definition
ConfigObject<ConfigValue>* ControlDoublePrivate::s_pUserConfig = NULL;
QHash<ConfigKey, QWeakPointer<ControlDoublePrivate> > ControlDoublePrivate::s_qCOHash;
+QHash<ConfigKey, QWeakPointer<ControlDoublePrivate> > ControlDoublePrivate::s_qCOAliasHash;
QMutex ControlDoublePrivate::s_qCOHashMutex;
+QMutex ControlDoublePrivate::s_qCOAliasHashMutex;
/*
ControlDoublePrivate::ControlDoublePrivate()
@@ -77,12 +79,20 @@ ControlDoublePrivate::~ControlDoublePrivate() {
}
// static
+void ControlDoublePrivate::insertAlias(const ConfigKey& alias, const ConfigKey& key) {
+ QSharedPointer<ControlDoublePrivate> pControl = getControl(key);
+ QMutexLocker locker(&s_qCOAliasHashMutex);
+ s_qCOAliasHash.insert(alias, pControl);
+}
+
+// static
QSharedPointer<ControlDoublePrivate> ControlDoublePrivate::getControl(
const ConfigKey& key, bool warn, ControlObject* pCreatorCO,
bool bIgnoreNops, bool bTrack, bool bPersist) {
QMutexLocker locker(&s_qCOHashMutex);
QSharedPointer<ControlDoublePrivate> pControl;
QHash<ConfigKey, QWeakPointer<ControlDoublePrivate> >::const_iterator it = s_qCOHash.find(key);
+
if (it != s_qCOHash.end()) {
if (pCreatorCO) {
if (warn) {
@@ -91,7 +101,14 @@ QSharedPointer<ControlDoublePrivate> ControlDoublePrivate::getControl(
} else {
pControl = it.value();
}
+ } else {
+ QMutexLocker locker(&s_qCOAliasHashMutex);
+ QHash<ConfigKey, QWeakPointer<ControlDoublePrivate> >::const_iterator it = s_qCOAliasHash.find(key);
+ if (it != s_qCOAliasHash.end()) {
+ pControl = it.value();
+ }
}
+
locker.unlock();
if (pControl == NULL) {
@@ -191,6 +208,14 @@ double ControlDoublePrivate::getParameterForValue(double value) const {
return value;
}
+double ControlDoublePrivate::getParameterForMidiValue(double midiValue) const {
+ QSharedPointer<ControlNumericBehavior> pBehavior = m_pBehavior;
+ if (!pBehavior.isNull()) {
+ return pBehavior->midiValueToParameter(midiValue);
+ }
+ return midiValue;
+}
+
void ControlDoublePrivate::setMidiParameter(MidiOpCode opcode, double dParam) {
QSharedPointer<ControlNumericBehavior> pBehavior = m_pBehavior;
if (!pBehavior.isNull()) {
diff --git a/src/control/control.h b/src/control/control.h
index 54e383835d..5ff1c2532b 100644
--- a/src/control/control.h
+++ b/src/control/control.h
@@ -25,6 +25,8 @@ class ControlDoublePrivate : public QObject {
s_pUserConfig = pConfig;
}
+ static void insertAlias(const ConfigKey& alias, const ConfigKey& key);
+
// Gets the ControlDoublePrivate matching the given ConfigKey. If bCreate
// is true, allocates a new ControlDoublePrivate for the ConfigKey if one
// does not exist.
@@ -66,13 +68,14 @@ class ControlDoublePrivate : public QObject {
// Set the behavior to be used when setting values and translating between
// parameter and value space. Returns the previously set behavior (if any).
- // The caller must nut delete the behavior at any time. The memory is managed
+ // The caller must not delete the behavior at any time. The memory is managed
// by this function.
void setBehavior(ControlNumericBehavior* pBehavior);
void setParameter(double dParam, QObject* pSender);
double getParameter() const;
double getParameterForValue(double value) const;
+ double getParameterForMidiValue(double midiValue) const;
void setMidiParameter(MidiOpCode opcode, double dParam);
double getMidiParameter() const;
@@ -164,9 +167,12 @@ class ControlDoublePrivate : public QObject {
// Hash of ControlDoublePrivate instantiations.
static QHash<ConfigKey, QWeakPointer<ControlDoublePrivate> > s_qCOHash;
+ static QHash<ConfigKey, QWeakPointer<ControlDoublePrivate> > s_qCOAliasHash;
// Mutex guarding access to the ControlDoublePrivate hash.
static QMutex s_qCOHashMutex;
+ // Mutex guarding access to the ControlDoublePrivate aliases hash.
+ static QMutex s_qCOAliasHashMutex;
};
diff --git a/src/control/controlbehavior.cpp b/src/control/controlbehavior.cpp
index 6bf9b7cee4..e66fff7791 100644
--- a/src/control/controlbehavior.cpp
+++ b/src/control/controlbehavior.cpp
@@ -11,6 +11,10 @@ double ControlNumericBehavior::valueToParameter(double dValue) {
return dValue;
}
+double ControlNumericBehavior::midiValueToParameter(double midiValue) {
+ return midiValue;
+}
+
double ControlNumericBehavior::parameterToValue(double dParam) {
return dParam;
}
@@ -22,7 +26,8 @@ double ControlNumericBehavior::valueToMidiParameter(double dValue) {
void ControlNumericBehavior::setValueFromMidiParameter(MidiOpCode o, double dParam,
ControlDoublePrivate* pControl) {
Q_UNUSED(o);
- pControl->set(dParam, NULL);
+ double dNorm = midiValueToParameter(dParam);
+ pControl->set(parameterToValue(dNorm), NULL);
}
ControlPotmeterBehavior::ControlPotmeterBehavior(double dMinValue, double dMaxValue,
@@ -59,6 +64,17 @@ double ControlPotmeterBehavior::valueToParameter(double dValue) {
return (dValue - m_dMinValue) / m_dValueRange;
}
+double ControlPotmeterBehavior::midiValueToParameter(double midiValue) {
+ double parameter;
+ if (midiValue > 64) {
+ parameter = (midiValue - 1) / 126.0;
+ } else {
+ // Hack for 0.5 at 64
+ parameter = midiValue / 128.0;
+ }
+ return parameter;
+}
+
double ControlPotmeterBehavior::parameterToValue(double dParam) {
return m_dMinValue + (dParam * m_dValueRange);
}
@@ -66,17 +82,15 @@ double ControlPotmeterBehavior::parameterToValue(double dParam) {
double ControlPotmeterBehavior::valueToMidiParameter(double dValue) {
// 7-bit MIDI has 128 values [0, 127]. This means there is no such thing as
// center. The industry convention is that 64 is center. We fake things a
- // little bit here to make that the case. This piece-wise function is linear
- // from 0 to 64 with slope 128 and from 64 to 127 with slope 126.
+ // little bit here to make that the case. This function is linear from [0,
+ // 127.0/128.0] with slope 128 and then cuts off at 127 from 127.0/128.0 to
+ // 1.0. from 0 to 64 with slope 128 and from 64 to 127 with slope 126.
double dNorm = valueToParameter(dValue);
- return dNorm < 0.5 ? dNorm * 128.0 : dNorm * 126.0 + 1.0;
-}
-
-void ControlPotmeterBehavior::setValueFromMidiParameter(MidiOpCode o, double dParam,
- ControlDoublePrivate* pControl) {
- Q_UNUSED(o);
- double dNorm = dParam < 64 ? dParam / 128.0 : (dParam - 1.0) / 126.0;
- pControl->set(parameterToValue(dNorm), NULL);
+ if (dNorm > 0.5) {
+ return (dNorm * 126) + 1;
+ } else {
+ return dNorm * 128.0;
+ }
}
#define maxPosition 1.0
@@ -138,25 +152,6 @@ ControlLinPotmeterBehavior::ControlLinPotmeterBehavior(double dMinValue, double
ControlLinPotmeterBehavior::~ControlLinPotmeterBehavior() {
}
-double ControlLinPotmeterBehavior::valueToMidiParameter(double dValue) {
- // 7-bit MIDI has 128 values [0, 127]. This means there is no such thing as
- // center. The industry convention is that 64 is center. We fake things a
- // little bit here to make that the case. This function is linear from [0,
- // 127.0/128.0] with slope 128 and then cuts off at 127 from 127.0/128.0 to
- // 1.0. from 0 to 64 with slope 128 and from 64 to 127 with slope 126.
- double dNorm = valueToParameter(dValue);
- return math_max(127.0, dNorm * 128.0);
-}
-
-void ControlLinPotmeterBehavior::setValueFromMidiParameter(MidiOpCode o, double dParam,
- ControlDoublePrivate* pControl) {
- Q_UNUSED(o);
- double dNorm = dParam / 128.0;
- pControl->set(parameterToValue(dNorm), NULL);
-}
-
-
-
ControlAudioTaperPotBehavior::ControlAudioTaperPotBehavior(
double minDB, double maxDB,
double neutralParameter)
@@ -264,7 +259,6 @@ void ControlAudioTaperPotBehavior::setValueFromMidiParameter(MidiOpCode o, doubl
}
-
double ControlTTRotaryBehavior::valueToParameter(double dValue) {
return (dValue * 200.0 + 64) / 127.0;
}
diff --git a/src/control/controlbehavior.h b/src/control/controlbehavior.h
index 9e86cb05c0..fda203cad1 100644
--- a/src/control/controlbehavior.h
+++ b/src/control/controlbehavior.h
@@ -16,6 +16,7 @@ class ControlNumericBehavior {
virtual bool setFilter(double* dValue);
virtual double valueToParameter(double dValue);
+ virtual double midiValueToParameter(double midiValue);
virtual double parameterToValue(double dParam);
virtual double valueToMidiParameter(double dValue);
virtual void setValueFromMidiParameter(MidiOpCode o, double dParam,
@@ -30,10 +31,9 @@ class ControlPotmeterBehavior : public ControlNumericBehavior {
virtual bool setFilter(double* dValue);
virtual double valueToParameter(double dValue);
+ virtual double midiValueToParameter(double midiValue);
virtual double parameterToValue(double dParam);
virtual double valueToMidiParameter(double dValue);
- virtual void setValueFromMidiParameter(MidiOpCode o, double dParam,
- ControlDoublePrivate* pControl);
protected:
double m_dMinValue;
@@ -60,10 +60,6 @@ class ControlLinPotmeterBehavior : public ControlPotmeterBehavior {
ControlLinPotmeterBehavior(double dMinValue, double dMaxValue,
bool allowOutOfBounds);
virtual ~ControlLinPotmeterBehavior();
-
- virtual double valueToMidiParameter(double dValue);
- virtual void setValueFromMidiParameter(MidiOpCode o, double dParam,
- ControlDoublePrivate* pControl);
};
class ControlAudioTaperPotBehavior : public ControlPotmeterBehavior {