Skip to content

Commit e3c12aa

Browse files
authored
Merge pull request #221 from tne-lab/car-save-parameters
Save gain, reference and affected channel state in CAR plugin
2 parents 83e8d6d + f1a9662 commit e3c12aa

4 files changed

Lines changed: 69 additions & 0 deletions

File tree

Source/Plugins/CAR/CAR.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,43 @@ void CAR::setAffectedChannelState (int channel, bool newState)
138138
m_affectedChannels.add (channel);
139139
}
140140

141+
void CAR::saveCustomChannelParametersToXml(XmlElement* channelElement,
142+
int channelNumber, InfoObjectCommon::InfoObjectType channelType)
143+
{
144+
if (channelType == InfoObjectCommon::DATA_CHANNEL)
145+
{
146+
XmlElement* groupState = channelElement->createNewChildElement("GROUPSTATE");
147+
148+
const Array<int>& referenceChannels = getReferenceChannels();
149+
bool isReferenceChannel = referenceChannels.contains(channelNumber);
150+
groupState->setAttribute("reference", isReferenceChannel);
151+
152+
const Array<int>& affectedChannels = getAffectedChannels();
153+
bool isAffectedChannel = affectedChannels.contains(channelNumber);
154+
groupState->setAttribute("affected", isAffectedChannel);
155+
}
156+
}
157+
158+
void CAR::loadCustomChannelParametersFromXml(XmlElement* channelElement,
159+
InfoObjectCommon::InfoObjectType channelType)
160+
{
161+
if (channelType == InfoObjectCommon::DATA_CHANNEL)
162+
{
163+
int channelNumber = channelElement->getIntAttribute("number");
164+
165+
forEachXmlChildElementWithTagName(*channelElement, groupState, "GROUPSTATE")
166+
{
167+
if (groupState->hasAttribute("reference"))
168+
{
169+
bool isReferenceChannel = groupState->getBoolAttribute("reference");
170+
setReferenceChannelState(channelNumber, isReferenceChannel);
171+
}
172+
173+
if (groupState->hasAttribute("affected"))
174+
{
175+
bool isAffectedChannel = groupState->getBoolAttribute("affected");
176+
setAffectedChannelState(channelNumber, isAffectedChannel);
177+
}
178+
}
179+
}
180+
}

Source/Plugins/CAR/CAR.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ class CAR : public GenericProcessor
8080
void setReferenceChannelState (int channel, bool newState);
8181
void setAffectedChannelState (int channel, bool newState);
8282

83+
/** Saving/loading channel parameters */
84+
void saveCustomChannelParametersToXml(XmlElement* channelElement,
85+
int channelNumber, InfoObjectCommon::InfoObjectType channelType);
86+
void loadCustomChannelParametersFromXml(XmlElement* channelElement,
87+
InfoObjectCommon::InfoObjectType channelType);
8388

8489
private:
8590
LinearSmoothedValueAtomic<float> m_gainLevel;

Source/Plugins/CAR/CAREditor.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,24 @@ void CAREditor::sliderEvent (Slider* sliderWhichValueHasChanged)
144144

145145
processor->setGainLevel ( (float)sliderWhichValueHasChanged->getValue());
146146
}
147+
148+
void CAREditor::saveCustomParameters(XmlElement* xml)
149+
{
150+
auto processor = static_cast<CAR*> (getProcessor());
151+
152+
xml->setAttribute("Type", "CAREditor");
153+
154+
XmlElement* paramValues = xml->createNewChildElement("VALUES");
155+
paramValues->setAttribute("gainLevel", processor->getGainLevel());
156+
}
157+
158+
void CAREditor::loadCustomParameters(XmlElement* xml)
159+
{
160+
auto processor = static_cast<CAR*> (getProcessor());
161+
162+
forEachXmlChildElementWithTagName(*xml, xmlNode, "VALUES")
163+
{
164+
double gain = xmlNode->getDoubleAttribute("gainLevel", m_gainSlider->getValue());
165+
m_gainSlider->setValue(gain, sendNotificationSync);
166+
}
167+
}

Source/Plugins/CAR/CAREditor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class CAREditor : public GenericEditor
5858
void sliderEvent (Slider* sliderWhichValueHasChanged) override;
5959
void channelChanged (int channel, bool newState) override;
6060

61+
/** Saving/loading parameters */
62+
void saveCustomParameters(XmlElement* xml) override;
63+
void loadCustomParameters(XmlElement* xml) override;
6164

6265
private:
6366
enum ChannelsType

0 commit comments

Comments
 (0)