diff --git a/src/control/control.cpp b/src/control/control.cpp index 7ba8ac815cf..3de7c295b09 100644 --- a/src/control/control.cpp +++ b/src/control/control.cpp @@ -27,7 +27,7 @@ ControlDoublePrivate::ControlDoublePrivate() ControlDoublePrivate::ControlDoublePrivate(ConfigKey key, ControlObject* pCreatorCO, bool bIgnoreNops, bool bTrack, - bool bPersist) + double defaultValue, bool bPersist) : m_key(key), m_bPersistInConfiguration(bPersist), m_bIgnoreNops(bIgnoreNops), @@ -38,20 +38,20 @@ ControlDoublePrivate::ControlDoublePrivate(ConfigKey key, Stat::SAMPLE_VARIANCE | Stat::MIN | Stat::MAX), m_confirmRequired(false), m_pCreatorCO(pCreatorCO) { - initialize(); + initialize(defaultValue); } -void ControlDoublePrivate::initialize() { - double value = 0; +void ControlDoublePrivate::initialize(double defaultValue) { + m_defaultValue.setValue(defaultValue); + double initalValue = defaultValue; if (m_bPersistInConfiguration) { ConfigObject* pConfig = ControlDoublePrivate::s_pUserConfig; if (pConfig != NULL) { // Assume toDouble() returns 0 if conversion fails. - value = pConfig->getValueString(m_key).toDouble(); + initalValue = pConfig->getValueString(m_key).toDouble(); } } - m_defaultValue.setValue(0); - m_value.setValue(value); + m_value.setValue(initalValue); //qDebug() << "Creating:" << m_trackKey << "at" << &m_value << sizeof(m_value); @@ -101,7 +101,7 @@ void ControlDoublePrivate::insertAlias(const ConfigKey& alias, const ConfigKey& // static QSharedPointer ControlDoublePrivate::getControl( const ConfigKey& key, bool warn, ControlObject* pCreatorCO, - bool bIgnoreNops, bool bTrack, bool bPersist) { + bool bIgnoreNops, bool bTrack, double defaulValue, bool bPersist) { if (key.isNull()) { if (warn) { qWarning() << "ControlDoublePrivate::getControl returning NULL" @@ -130,7 +130,7 @@ QSharedPointer ControlDoublePrivate::getControl( if (pCreatorCO) { pControl = QSharedPointer( new ControlDoublePrivate(key, pCreatorCO, bIgnoreNops, - bTrack, bPersist)); + bTrack, defaulValue, bPersist)); locker.relock(); //qDebug() << "ControlDoublePrivate::s_qCOHash.insert(" << key.group << "," << key.item << ")"; s_qCOHash.insert(key, pControl); diff --git a/src/control/control.h b/src/control/control.h index c7e849373dc..659f72a9f4f 100644 --- a/src/control/control.h +++ b/src/control/control.h @@ -36,7 +36,7 @@ class ControlDoublePrivate : public QObject { static QSharedPointer getControl( const ConfigKey& key, bool warn = true, ControlObject* pCreatorCO = NULL, bool bIgnoreNops = true, bool bTrack = false, - bool bPersist = false); + double defaultValue = 0.0, bool bPersist = false); // Adds all ControlDoublePrivate that currently exist to pControlList static void getControls(QList >* pControlsList); @@ -125,9 +125,12 @@ class ControlDoublePrivate : public QObject { void valueChangeRequest(double value); private: + // The defaultValue is adopted as initial value as well + // except it is a persistent CO with a saved value in place ControlDoublePrivate(ConfigKey key, ControlObject* pCreatorCO, - bool bIgnoreNops, bool bTrack, bool bPersist); - void initialize(); + bool bIgnoreNops, bool bTrack, double defaultValue, + bool bPersist); + void initialize(double defaultValue); void setInner(double value, QObject* pSender); ConfigKey m_key; diff --git a/src/controlobject.cpp b/src/controlobject.cpp index 36f48529cd5..23edbec5c0b 100644 --- a/src/controlobject.cpp +++ b/src/controlobject.cpp @@ -29,8 +29,8 @@ ControlObject::ControlObject() { } ControlObject::ControlObject(ConfigKey key, bool bIgnoreNops, bool bTrack, - bool bPersist) { - initialize(key, bIgnoreNops, bTrack, bPersist); + double defaultValue, bool bPersist) { + initialize(key, bIgnoreNops, bTrack, defaultValue, bPersist); } ControlObject::~ControlObject() { @@ -40,14 +40,14 @@ ControlObject::~ControlObject() { } void ControlObject::initialize(ConfigKey key, bool bIgnoreNops, bool bTrack, - bool bPersist) { + double defaultValue, bool bPersist) { m_key = key; // Don't bother looking up the control if key is NULL. Prevents log spew. if (!m_key.isNull()) { m_pControl = ControlDoublePrivate::getControl(m_key, true, this, bIgnoreNops, bTrack, - bPersist); + defaultValue, bPersist); } // getControl can fail and return a NULL control even with the create flag. diff --git a/src/controlobject.h b/src/controlobject.h index 4cb536653ac..b605c59cc79 100644 --- a/src/controlobject.h +++ b/src/controlobject.h @@ -33,10 +33,12 @@ class ControlObject : public QObject { // bIgnoreNops: Don't emit a signal if the CO is set to its current value. // bTrack: Record statistics about this control. + // defaultValue: is adopted as initial value as well + // except it is a persistent CO with a saved value in place // bPersist: Store value on exit, load on startup. ControlObject(ConfigKey key, bool bIgnoreNops=true, bool bTrack=false, - bool bPersist=false); + double defaultValue = 0.0, bool bPersist=false); virtual ~ControlObject(); // Returns a pointer to the ControlObject matching the given ConfigKey @@ -164,7 +166,7 @@ class ControlObject : public QObject { private: void initialize(ConfigKey key, bool bIgnoreNops, bool bTrack, - bool bPersist); + double defaultValue, bool bPersist); inline bool ignoreNops() const { return m_pControl ? m_pControl->ignoreNops() : true; } diff --git a/src/controlpotmeter.cpp b/src/controlpotmeter.cpp index f64278ce12f..0bb0f0498cb 100644 --- a/src/controlpotmeter.cpp +++ b/src/controlpotmeter.cpp @@ -23,8 +23,9 @@ ControlPotmeter::ControlPotmeter(ConfigKey key, double dMinValue, double dMaxVal bool allowOutOfBounds, bool bIgnoreNops, bool bTrack, + double defaultValue, bool bPersist) - : ControlObject(key, bIgnoreNops, bTrack, bPersist), + : ControlObject(key, bIgnoreNops, bTrack, defaultValue, bPersist), m_controls(key) { setRange(dMinValue, dMaxValue, allowOutOfBounds); double default_value = dMinValue + 0.5 * (dMaxValue - dMinValue); diff --git a/src/controlpotmeter.h b/src/controlpotmeter.h index 9ea3577f788..80f2fcc9d54 100644 --- a/src/controlpotmeter.h +++ b/src/controlpotmeter.h @@ -77,6 +77,7 @@ class ControlPotmeter : public ControlObject { bool allowOutOfBounds = false, bool bIgnoreNops = true, bool bTrack = false, + double defaultValue = 0.0, bool bPersist = false); virtual ~ControlPotmeter(); diff --git a/src/controlpushbutton.cpp b/src/controlpushbutton.cpp index e0a9102bcc4..f88813c869a 100644 --- a/src/controlpushbutton.cpp +++ b/src/controlpushbutton.cpp @@ -21,8 +21,8 @@ Purpose: Creates a new simulated latching push-button. Input: key - Key for the configuration file -------- ------------------------------------------------------ */ -ControlPushButton::ControlPushButton(ConfigKey key, bool bPersist) - : ControlObject(key, false, false, bPersist), +ControlPushButton::ControlPushButton(ConfigKey key, double defaultValue, bool bPersist) + : ControlObject(key, false, false, defaultValue, bPersist), m_buttonMode(PUSH), m_iNoStates(2) { if (m_pControl) { diff --git a/src/controlpushbutton.h b/src/controlpushbutton.h index ecfe841221b..8a13b97e8fb 100644 --- a/src/controlpushbutton.h +++ b/src/controlpushbutton.h @@ -53,7 +53,8 @@ class ControlPushButton : public ControlObject { } } - ControlPushButton(ConfigKey key, bool bPersist=false); + ControlPushButton(ConfigKey key, double defaulValue = 0.0, + bool bPersist = false); virtual ~ControlPushButton(); inline ButtonMode getButtonMode() const { diff --git a/src/engine/enginedelay.cpp b/src/engine/enginedelay.cpp index 772a2b79ba4..d3e8f271ebb 100644 --- a/src/engine/enginedelay.cpp +++ b/src/engine/enginedelay.cpp @@ -28,7 +28,7 @@ EngineDelay::EngineDelay(const char* group, ConfigKey delayControl) m_iDelay(0) { m_pDelayBuffer = SampleUtil::alloc(kiMaxDelay); SampleUtil::clear(m_pDelayBuffer, kiMaxDelay); - m_pDelayPot = new ControlPotmeter(delayControl, 0, kdMaxDelayPot, false, true, false, true); + m_pDelayPot = new ControlPotmeter(delayControl, 0, kdMaxDelayPot, false, true, false, 0.0, true); m_pDelayPot->setDefaultValue(0); connect(m_pDelayPot, SIGNAL(valueChanged(double)), this, SLOT(slotDelayChanged()), Qt::DirectConnection); diff --git a/src/engine/enginemaster.cpp b/src/engine/enginemaster.cpp index daaf8b714da..c513299d9cc 100644 --- a/src/engine/enginemaster.cpp +++ b/src/engine/enginemaster.cpp @@ -168,16 +168,16 @@ EngineMaster::EngineMaster(ConfigObject* _config, m_pXFaderReverse->setButtonMode(ControlPushButton::TOGGLE); m_pKeylockEngine = new ControlObject(ConfigKey(group, "keylock_engine"), - true, false, true); + true, false, 0.0, true); m_pKeylockEngine->set(_config->getValueString( ConfigKey(group, "keylock_engine")).toDouble()); m_pMasterEnabled = new ControlObject(ConfigKey(group, "enabled"), - true, false, true); // persist = true + true, false, 0.0, true); // persist = true m_pMasterMonoMixdown = new ControlObject(ConfigKey(group, "mono_mixdown"), - true, false, true); // persist = true + true, false, 0.0, true); // persist = true m_pMasterTalkoverMix = new ControlObject(ConfigKey(group, "talkover_mix"), - true, false, true); // persist = true + true, false, 0.0, true); // persist = true m_pHeadphoneEnabled = new ControlObject(ConfigKey(group, "headEnabled")); diff --git a/src/skin/legacyskinparser.cpp b/src/skin/legacyskinparser.cpp index 9b1d11658b4..7c91b2e2371 100644 --- a/src/skin/legacyskinparser.cpp +++ b/src/skin/legacyskinparser.cpp @@ -83,7 +83,7 @@ QMutex LegacySkinParser::s_safeStringMutex; static bool sDebug = false; -ControlObject* controlFromConfigKey(ConfigKey key, bool bPersist, +ControlObject* controlFromConfigKey(ConfigKey key, double defaulValue, bool bPersist, bool* created) { ControlObject* pControl = ControlObject::getControl(key); @@ -100,7 +100,7 @@ ControlObject* controlFromConfigKey(ConfigKey key, bool bPersist, << "Creating it."; // Since the usual behavior here is to create a skin-defined push // button, actually make it a push button and set it to toggle. - ControlPushButton* controlButton = new ControlPushButton(key, bPersist); + ControlPushButton* controlButton = new ControlPushButton(key, defaulValue, bPersist); controlButton->setButtonMode(ControlPushButton::TOGGLE); if (created) { *created = true; @@ -121,7 +121,7 @@ ControlObject* LegacySkinParser::controlFromConfigNode(QDomElement element, bool bPersist = m_pContext->selectAttributeBool(keyElement, "persist", false); - return controlFromConfigKey(key, bPersist, created); + return controlFromConfigKey(key, 0.0, bPersist, created); } LegacySkinParser::LegacySkinParser(ConfigObject* pConfig, @@ -326,14 +326,8 @@ QWidget* LegacySkinParser::parseSkin(QString skinPath, QWidget* pParent) { // If there is no existing value for this CO in the skin, // update the config with the specified value. If the attribute // is set to persist, the value will be read when the control is created. - // TODO: This is a hack, but right now it's the cleanest way to - // get a CO with a specified initial value. We should have a better - // mechanism to provide initial default values for COs. - if (attribute.persist() && - m_pConfig->getValueString(configKey).isEmpty()) { - m_pConfig->set(configKey, ConfigValue(QString::number(value))); - } ControlObject* pControl = controlFromConfigKey(configKey, + value, attribute.persist(), &created); if (created) { @@ -622,7 +616,7 @@ QWidget* LegacySkinParser::parseWidgetStack(QDomElement node) { ConfigKey configKey = ConfigKey::parseCommaSeparated(currentpage_co); QString persist_co = node.attribute("persist"); bool persist = m_pContext->selectAttributeBool(node, "persist", false); - pCurrentPageControl = controlFromConfigKey(configKey, persist, + pCurrentPageControl = controlFromConfigKey(configKey, 0.0, persist, &createdCurrentPage); } @@ -684,7 +678,7 @@ QWidget* LegacySkinParser::parseWidgetStack(QDomElement node) { if (trigger_configkey.length() > 0) { ConfigKey configKey = ConfigKey::parseCommaSeparated(trigger_configkey); bool created; - pControl = controlFromConfigKey(configKey, false, &created); + pControl = controlFromConfigKey(configKey, 0.0, false, &created); if (created) { // If we created the control, parent it to the child widget so // it doesn't leak.