-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from badescunicu/switch_type_parameters
Effect Button Parameters
- Loading branch information
Showing
26 changed files
with
692 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#include <QtDebug> | ||
|
||
#include "controleffectknob.h" | ||
#include "effects/effectbuttonparameterslot.h" | ||
#include "controlobject.h" | ||
#include "controlpushbutton.h" | ||
|
||
EffectButtonParameterSlot::EffectButtonParameterSlot(const unsigned int iRackNumber, | ||
const unsigned int iChainNumber, | ||
const unsigned int iSlotNumber, | ||
const unsigned int iParameterNumber) | ||
: EffectParameterSlotBase(iRackNumber, iChainNumber, iSlotNumber, | ||
iParameterNumber) { | ||
QString itemPrefix = formatItemPrefix(iParameterNumber); | ||
m_pControlLoaded = new ControlObject( | ||
ConfigKey(m_group, itemPrefix + QString("_loaded"))); | ||
m_pControlLinkType = new ControlPushButton( | ||
ConfigKey(m_group, itemPrefix + QString("_link_type"))); | ||
m_pControlLinkType->setButtonMode(ControlPushButton::TOGGLE); | ||
m_pControlLinkType->setStates(EffectManifestParameter::NUM_LINK_TYPES); | ||
m_pControlValue = new ControlPushButton( | ||
ConfigKey(m_group, itemPrefix)); | ||
m_pControlValue->setButtonMode(ControlPushButton::POWERWINDOW); | ||
m_pControlType = new ControlObject( | ||
ConfigKey(m_group, itemPrefix + QString("_type"))); | ||
|
||
connect(m_pControlLinkType, SIGNAL(valueChanged(double)), | ||
this, SLOT(slotLinkType(double))); | ||
connect(m_pControlValue, SIGNAL(valueChanged(double)), | ||
this, SLOT(slotValueChanged(double))); | ||
|
||
// Read-only controls. | ||
m_pControlType->connectValueChangeRequest( | ||
this, SLOT(slotValueType(double)), Qt::AutoConnection); | ||
m_pControlLoaded->connectValueChangeRequest( | ||
this, SLOT(slotLoaded(double)), Qt::AutoConnection); | ||
|
||
clear(); | ||
} | ||
|
||
EffectButtonParameterSlot::~EffectButtonParameterSlot() { | ||
//qDebug() << debugString() << "destroyed"; | ||
delete m_pControlValue; | ||
} | ||
|
||
void EffectButtonParameterSlot::loadEffect(EffectPointer pEffect) { | ||
//qDebug() << debugString() << "loadEffect" << (pEffect ? pEffect->getManifest().name() : "(null)"); | ||
clear(); | ||
if (pEffect) { | ||
m_pEffect = pEffect; | ||
// Returns null if it doesn't have a parameter for that number | ||
m_pEffectParameter = pEffect->getButtonParameter(m_iParameterNumber); | ||
|
||
if (m_pEffectParameter) { | ||
//qDebug() << debugString() << "Loading effect parameter" << m_pEffectParameter->name(); | ||
double dValue = m_pEffectParameter->getValue().toDouble(); | ||
double dMinimum = m_pEffectParameter->getMinimum().toDouble(); | ||
double dMinimumLimit = dMinimum; // TODO(rryan) expose limit from EffectParameter | ||
double dMaximum = m_pEffectParameter->getMaximum().toDouble(); | ||
double dMaximumLimit = dMaximum; // TODO(rryan) expose limit from EffectParameter | ||
double dDefault = m_pEffectParameter->getDefault().toDouble(); | ||
|
||
if (dValue > dMaximum || dValue < dMinimum || | ||
dMinimum < dMinimumLimit || dMaximum > dMaximumLimit || | ||
dDefault > dMaximum || dDefault < dMinimum) { | ||
qWarning() << debugString() << "WARNING: EffectParameter does not satisfy basic sanity checks."; | ||
} | ||
|
||
// qDebug() << debugString() | ||
// << QString("Val: %1 Min: %2 MinLimit: %3 Max: %4 MaxLimit: %5 Default: %6") | ||
// .arg(dValue).arg(dMinimum).arg(dMinimumLimit).arg(dMaximum).arg(dMaximumLimit).arg(dDefault); | ||
|
||
m_pControlValue->set(dValue); | ||
m_pControlValue->setDefaultValue(dDefault); | ||
EffectManifestParameter::ControlHint type = m_pEffectParameter->getControlHint(); | ||
// TODO(rryan) expose this from EffectParameter | ||
m_pControlType->setAndConfirm(static_cast<double>(type)); | ||
// Default loaded parameters to loaded and unlinked | ||
m_pControlLoaded->setAndConfirm(1.0); | ||
m_pControlLinkType->set(m_pEffectParameter->getLinkType()); | ||
|
||
connect(m_pEffectParameter, SIGNAL(valueChanged(QVariant)), | ||
this, SLOT(slotParameterValueChanged(QVariant))); | ||
} | ||
|
||
// Update the newly loaded parameter to match the current chain | ||
// superknob if it is linked. | ||
onChainParameterChanged(m_dChainParameter); | ||
} | ||
emit(updated()); | ||
} | ||
|
||
void EffectButtonParameterSlot::clear() { | ||
//qDebug() << debugString() << "clear"; | ||
if (m_pEffectParameter) { | ||
m_pEffectParameter->disconnect(this); | ||
m_pEffectParameter = NULL; | ||
} | ||
|
||
m_pEffect.clear(); | ||
m_pControlLoaded->setAndConfirm(0.0); | ||
m_pControlValue->set(0.0); | ||
m_pControlValue->setDefaultValue(0.0); | ||
m_pControlType->setAndConfirm(0.0); | ||
m_pControlLinkType->set(EffectManifestParameter::LINK_NONE); | ||
emit(updated()); | ||
} | ||
|
||
void EffectButtonParameterSlot::slotParameterValueChanged(QVariant value) { | ||
//qDebug() << debugString() << "slotParameterValueChanged" << value.toDouble(); | ||
m_pControlValue->set(value.toDouble()); | ||
} | ||
|
||
void EffectButtonParameterSlot::onChainParameterChanged(double parameter) { | ||
m_dChainParameter = parameter; | ||
if (m_pEffectParameter != NULL) { | ||
switch (m_pEffectParameter->getLinkType()) { | ||
case EffectManifestParameter::LINK_INVERSE: | ||
parameter = 1.0 - parameter; | ||
// Intentional fall-through. | ||
case EffectManifestParameter::LINK_LINKED: | ||
if (parameter < 0.0 || parameter > 1.0) { | ||
return; | ||
} | ||
m_pControlValue->setParameterFrom(parameter, NULL); | ||
break; | ||
case EffectManifestParameter::LINK_NONE: | ||
default: | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef EFFECTBUTTONPARAMETERSLOT_H | ||
#define EFFECTBUTTONPARAMETERSLOT_H | ||
|
||
#include <QObject> | ||
#include <QVariant> | ||
#include <QString> | ||
|
||
#include "util.h" | ||
#include "controlobject.h" | ||
#include "effects/effect.h" | ||
#include "effects/effectparameterslotbase.h" | ||
|
||
class ControlObject; | ||
class ControlPushButton; | ||
|
||
class EffectButtonParameterSlot; | ||
typedef QSharedPointer<EffectButtonParameterSlot> EffectButtonParameterSlotPointer; | ||
|
||
class EffectButtonParameterSlot : public EffectParameterSlotBase { | ||
Q_OBJECT | ||
public: | ||
EffectButtonParameterSlot(const unsigned int iRackNumber, | ||
const unsigned int iChainNumber, | ||
const unsigned int iSlotNumber, | ||
const unsigned int iParameterNumber); | ||
virtual ~EffectButtonParameterSlot(); | ||
|
||
static QString formatItemPrefix(const unsigned int iParameterNumber) { | ||
return QString("button_parameter%1").arg(iParameterNumber + 1); | ||
} | ||
|
||
// Load the parameter of the given effect into this EffectButtonParameterSlot | ||
void loadEffect(EffectPointer pEffect); | ||
|
||
void onChainParameterChanged(double parameter); | ||
|
||
private slots: | ||
// Solely for handling control changes | ||
void slotParameterValueChanged(QVariant value); | ||
|
||
private: | ||
QString debugString() const { | ||
return QString("EffectButtonParameterSlot(%1,%2)").arg(m_group).arg(m_iParameterNumber); | ||
} | ||
|
||
// Clear the currently loaded effect | ||
void clear(); | ||
|
||
// Control exposed to the rest of Mixxx | ||
ControlPushButton* m_pControlValue; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(EffectButtonParameterSlot); | ||
}; | ||
|
||
#endif // EFFECTBUTTONPARAMETERSLOT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.