Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set inital persistant value of COs #559

Merged
merged 6 commits into from
Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/control/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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<ConfigValue>* 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inital -> initial

}
}
m_defaultValue.setValue(0);
m_value.setValue(value);
m_value.setValue(initalValue);

//qDebug() << "Creating:" << m_trackKey << "at" << &m_value << sizeof(m_value);

Expand Down Expand Up @@ -101,7 +101,7 @@ void ControlDoublePrivate::insertAlias(const ConfigKey& alias, const ConfigKey&
// static
QSharedPointer<ControlDoublePrivate> ControlDoublePrivate::getControl(
const ConfigKey& key, bool warn, ControlObject* pCreatorCO,
bool bIgnoreNops, bool bTrack, bool bPersist) {
bool bIgnoreNops, bool bTrack, double defaulValue, bool bPersist) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultValue

if (key.isNull()) {
if (warn) {
qWarning() << "ControlDoublePrivate::getControl returning NULL"
Expand Down Expand Up @@ -130,7 +130,7 @@ QSharedPointer<ControlDoublePrivate> ControlDoublePrivate::getControl(
if (pCreatorCO) {
pControl = QSharedPointer<ControlDoublePrivate>(
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);
Expand Down
9 changes: 6 additions & 3 deletions src/control/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ControlDoublePrivate : public QObject {
static QSharedPointer<ControlDoublePrivate> 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<QSharedPointer<ControlDoublePrivate> >* pControlsList);
Expand Down Expand Up @@ -125,9 +125,12 @@ class ControlDoublePrivate : public QObject {
void valueChangeRequest(double value);

private:
// The defaultValue is adopted as initial value as well
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// If bPersist is true and the configuration object is not null,
// the initial value for this control is the value stored in the configuration.
// Otherwise, defaultValue is used.

// 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;
Expand Down
8 changes: 4 additions & 4 deletions src/controlobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions src/controlobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

// 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
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/controlpotmeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/controlpotmeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/controlpushbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/controlpushbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class ControlPushButton : public ControlObject {
}
}

ControlPushButton(ConfigKey key, bool bPersist=false);
ControlPushButton(ConfigKey key, double defaulValue = 0.0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultValue

bool bPersist = false);
virtual ~ControlPushButton();

inline ButtonMode getButtonMode() const {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/enginedelay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/engine/enginemaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,16 @@ EngineMaster::EngineMaster(ConfigObject<ConfigValue>* _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"));


Expand Down
18 changes: 6 additions & 12 deletions src/skin/legacyskinparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultValue

bool* created) {
ControlObject* pControl = ControlObject::getControl(key);

Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again

controlButton->setButtonMode(ControlPushButton::TOGGLE);
if (created) {
*created = true;
Expand All @@ -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<ConfigValue>* pConfig,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.
Expand Down