Skip to content
Snippets Groups Projects
Commit 6b63900e authored by jsiegle's avatar jsiegle
Browse files

Update FilterNode from SpikeSorting branch

parent 8d51bf5c
No related branches found
No related tags found
No related merge requests found
......@@ -36,35 +36,52 @@ FilterEditor::FilterEditor(GenericProcessor* parentNode, bool useDefaultParamete
lastHighCutString = " ";
highCutLabel = new Label("high cut label", "High cut:");
highCutLabel->setBounds(35,80,80,20);
highCutLabel->setBounds(10,65,80,20);
highCutLabel->setFont(Font("Small Text", 12, Font::plain));
highCutLabel->setColour(Label::textColourId, Colours::darkgrey);
addAndMakeVisible(highCutLabel);
lowCutLabel = new Label("low cut label", "Low cut:");
lowCutLabel->setBounds(35,30,80,20);
lowCutLabel->setBounds(10,25,80,20);
lowCutLabel->setFont(Font("Small Text", 12, Font::plain));
lowCutLabel->setColour(Label::textColourId, Colours::darkgrey);
addAndMakeVisible(lowCutLabel);
lowCutValue = new Label("low cut value", lastLowCutString);
lowCutValue->setBounds(40,50,60,20);
lowCutValue->setBounds(15,42,60,18);
lowCutValue->setFont(Font("Default", 15, Font::plain));
lowCutValue->setColour(Label::textColourId, Colours::white);
lowCutValue->setColour(Label::backgroundColourId, Colours::grey);
lowCutValue->setEditable(true);
lowCutValue->addListener(this);
lowCutValue->setTooltip("Set the low cut for the selected channels");
addAndMakeVisible(lowCutValue);
highCutValue = new Label("high cut label", lastHighCutString);
highCutValue->setBounds(40,100,60,20);
highCutValue->setBounds(15,82,60,18);
highCutValue->setFont(Font("Default", 15, Font::plain));
highCutValue->setColour(Label::textColourId, Colours::white);
highCutValue->setColour(Label::backgroundColourId, Colours::grey);
highCutValue->setEditable(true);
highCutValue->addListener(this);
highCutValue->setTooltip("Set the high cut for the selected channels");
addAndMakeVisible(highCutValue);
applyFilterOnADC = new UtilityButton("+ADCs",Font("Default", 10, Font::plain));
applyFilterOnADC->addListener(this);
applyFilterOnADC->setBounds(90,70,40,18);
applyFilterOnADC->setClickingTogglesState(true);
applyFilterOnADC->setTooltip("When this button is off, ADC channels will not be filtered");
addAndMakeVisible(applyFilterOnADC);
applyFilterOnChan = new UtilityButton("+CH",Font("Default", 10, Font::plain));
applyFilterOnChan->addListener(this);
applyFilterOnChan->setBounds(95,95,30,18);
applyFilterOnChan->setClickingTogglesState(true);
applyFilterOnChan->setToggleState(true, false);
applyFilterOnChan->setTooltip("When this button is off, selected channels will not be filtered");
addAndMakeVisible(applyFilterOnChan);
}
FilterEditor::~FilterEditor()
......@@ -117,11 +134,11 @@ void FilterEditor::labelTextChanged(Label* label)
if (label == highCutValue)
{
double minVal = fn->getLowCutValueForChannel(n);
double minVal = fn->getLowCutValueForChannel(chans[n]);
if (requestedValue > minVal)
{
fn->setCurrentChannel(n);
fn->setCurrentChannel(chans[n]);
fn->setParameter(1, requestedValue);
}
......@@ -130,11 +147,11 @@ void FilterEditor::labelTextChanged(Label* label)
}
else
{
double maxVal = fn->getHighCutValueForChannel(n);
double maxVal = fn->getHighCutValueForChannel(chans[n]);
if (requestedValue < maxVal)
{
fn->setCurrentChannel(n);
fn->setCurrentChannel(chans[n]);
fn->setParameter(0, requestedValue);
}
......@@ -145,39 +162,42 @@ void FilterEditor::labelTextChanged(Label* label)
}
void FilterEditor::buttonEvent(Button* button)
void FilterEditor::channelChanged(int chan)
{
//std::cout << button->getRadioGroupId() << " " << button->getName() << std::endl;
//if (!checkDrawerButton(button) && !checkChannelSelectors(button)) {
// String value = button->getName();
// float val;
FilterNode* fn = (FilterNode*) getProcessor();
// val = value.getFloatValue();
highCutValue->setText(String(fn->getHighCutValueForChannel(chan)), dontSendNotification);
lowCutValue->setText(String(fn->getLowCutValueForChannel(chan)), dontSendNotification);
applyFilterOnChan->setToggleState(fn->getBypassStatusForChannel(chan), false);
// Array<int> chans = getActiveChannels();
}
// GenericProcessor* p = (GenericProcessor*) getAudioProcessor();
void FilterEditor::buttonEvent(Button* button)
{
// for (int n = 0; n < chans.size(); n++)
// {
if (button == applyFilterOnADC)
{
FilterNode* fn = (FilterNode*) getProcessor();
fn->setApplyOnADC(applyFilterOnADC->getToggleState());
// p->setCurrentChannel(chans[n]);
} else if (button == applyFilterOnChan)
{
FilterNode* fn = (FilterNode*) getProcessor();
// if (button->getRadioGroupId() == 1)
// getAudioProcessor()->setParameter(0,val);
// else
// getAudioProcessor()->setParameter(1,val*1000.0f);
Array<int> chans = getActiveChannels();
// }
//std::cout << button->getRadioGroupId() << " " << val << std::endl;
// }
for (int n = 0; n < chans.size(); n++)
{
float newValue = button->getToggleState() ? 1.0 : 0.0;
fn->setCurrentChannel(chans[n]);
fn->setParameter(2, newValue);
}
}
}
void FilterEditor::saveEditorParameters(XmlElement* xml)
void FilterEditor::saveCustomParameters(XmlElement* xml)
{
xml->setAttribute("Type", "FilterEditor");
......@@ -185,9 +205,10 @@ void FilterEditor::saveEditorParameters(XmlElement* xml)
XmlElement* textLabelValues = xml->createNewChildElement("VALUES");
textLabelValues->setAttribute("HighCut",lastHighCutString);
textLabelValues->setAttribute("LowCut",lastLowCutString);
textLabelValues->setAttribute("ApplyToADC", applyFilterOnADC->getToggleState());
}
void FilterEditor::loadEditorParameters(XmlElement* xml)
void FilterEditor::loadCustomParameters(XmlElement* xml)
{
forEachXmlChildElement(*xml, xmlNode)
......@@ -196,6 +217,7 @@ void FilterEditor::loadEditorParameters(XmlElement* xml)
{
highCutValue->setText(xmlNode->getStringAttribute("HighCut"),dontSendNotification);
lowCutValue->setText(xmlNode->getStringAttribute("LowCut"),dontSendNotification);
applyFilterOnADC->setToggleState(xmlNode->getBoolAttribute("ApplyToADC",false),true);
}
}
}
......@@ -39,20 +39,22 @@ class FilterViewport;
*/
class FilterEditor : public GenericEditor,
public Label::Listener
public Label::Listener
{
public:
FilterEditor(GenericProcessor* parentNode, bool useDefaultParameterEditors);
virtual ~FilterEditor();
void buttonEvent(Button* button);
void buttonEvent(Button* button);
void labelTextChanged(Label* label);
void saveEditorParameters(XmlElement* xml);
void loadEditorParameters(XmlElement* xml);
void saveCustomParameters(XmlElement* xml);
void loadCustomParameters(XmlElement* xml);
void setDefaults(double lowCut, double highCut);
void channelChanged(int chan);
private:
String lastHighCutString;
......@@ -63,6 +65,8 @@ private:
ScopedPointer<Label> highCutValue;
ScopedPointer<Label> lowCutValue;
ScopedPointer<UtilityButton> applyFilterOnADC;
ScopedPointer<UtilityButton> applyFilterOnChan;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FilterEditor);
......
......@@ -46,7 +46,7 @@ FilterNode::FilterNode()
// highCutValues.add(9000.0f);
// parameters.add(Parameter("high cut",highCutValues, 2, 1));
applyOnADC = false;
}
FilterNode::~FilterNode()
......@@ -126,13 +126,20 @@ AudioProcessorEditor* FilterNode::createEditor()
void FilterNode::updateSettings()
{
if (getNumInputs() < 1024 && getNumInputs() != filters.size())
int id = nodeId;
int numInputs = getNumInputs();
int numfilt = filters.size();
if (numInputs < 1024 && numInputs != numfilt)
{
// SO fixed this. I think values were never restored correctly because you cleared lowCuts.
Array<double> oldlowCuts, oldhighCuts;
oldlowCuts = lowCuts;
oldhighCuts = highCuts;
filters.clear();
lowCuts.clear();
highCuts.clear();
shouldFilterChannel.clear();
for (int n = 0; n < getNumInputs(); n++)
{
......@@ -154,12 +161,14 @@ void FilterNode::updateSettings()
// restore defaults
shouldFilterChannel.add(true);
float lc, hc;
if (lowCuts.size() > n)
if (oldlowCuts.size() > n)
{
lc = lowCuts[n];
hc = highCuts[n];
lc = oldlowCuts[n];
hc = oldhighCuts[n];
} else {
lc = defaultLowCut;
hc = defaultHighCut;
......@@ -173,6 +182,8 @@ void FilterNode::updateSettings()
}
setApplyOnADC(applyOnADC);
}
double FilterNode::getLowCutValueForChannel(int chan)
......@@ -185,6 +196,11 @@ double FilterNode::getHighCutValueForChannel(int chan)
return highCuts[chan];
}
bool FilterNode::getBypassStatusForChannel(int chan)
{
return shouldFilterChannel[chan];
}
void FilterNode::setFilterParameters(double lowCut, double highCut, int chan)
{
......@@ -202,52 +218,41 @@ void FilterNode::setFilterParameters(double lowCut, double highCut, int chan)
void FilterNode::setParameter(int parameterIndex, float newValue)
{
if (newValue <= 0.01 || newValue >= 10000.0f)
return;
if (parameterIndex < 2) // change filter settings
{
//std::cout << "Setting channel " << currentChannel;// << std::endl;
if (newValue <= 0.01 || newValue >= 10000.0f)
return;
if (parameterIndex == 0)
{
// std::cout << " low cut to " << newValue << std::endl;
lowCuts.set(currentChannel,newValue);
}
else
{
//std::cout << " high cut to " << newValue << std::endl;
highCuts.set(currentChannel,newValue);
}
//std::cout << "Setting channel " << currentChannel;// << std::endl;
//std::cout << newValue << std::endl;
if (parameterIndex == 0)
{
// std::cout << " low cut to " << newValue << std::endl;
lowCuts.set(currentChannel,newValue);
}
else if (parameterIndex == 1)
{
//std::cout << " high cut to " << newValue << std::endl;
highCuts.set(currentChannel,newValue);
}
setFilterParameters(lowCuts[currentChannel],
setFilterParameters(lowCuts[currentChannel],
highCuts[currentChannel],
currentChannel);
editor->updateParameterButtons(parameterIndex);
// Deprecated code:
//if (parameterIndex)
//
// Parameter& p = parameters.getReference(parameterIndex);
// p.setValue(newValue, currentChannel);
// Parameter& p1 = parameters.getReference(0);
// Parameter& p2 = parameters.getReference(1);
// std::cout << float(p1[currentChannel]) << " ";
// std::cout << float(p2[currentChannel]) << std::endl;
// if (parameterIndex == 0) {
// parameters[0].setValue(newValue, currentChannel);
// setFilterParameters(newValue, parameters[0][currentChannel], currentChannel);
// } else {
// parameters[1].setValue(newValue, currentChannel);
// setFilterParameters(lowCuts[currentChannel], newValue, currentChannel);
// }
editor->updateParameterButtons(parameterIndex);
} else // change channel bypass state
{
if (newValue == 0)
{
shouldFilterChannel.set(currentChannel, false);
} else {
shouldFilterChannel.set(currentChannel, true);
}
}
}
void FilterNode::process(AudioSampleBuffer& buffer,
......@@ -257,12 +262,32 @@ void FilterNode::process(AudioSampleBuffer& buffer,
for (int n = 0; n < getNumOutputs(); n++)
{
float* ptr = buffer.getSampleData(n);
filters[n]->process(nSamples, &ptr);
if (shouldFilterChannel[n])
{
float* ptr = buffer.getSampleData(n);
filters[n]->process(nSamples, &ptr);
}
}
}
void FilterNode::setApplyOnADC(bool state)
{
for (int n = 0; n < channels.size(); n++)
{
if (channels[n]->isADCchannel)
{
setCurrentChannel(n);
if (state)
setParameter(2,1.0);
else
setParameter(2,0.0);
}
}
}
void FilterNode::saveCustomChannelParametersToXml(XmlElement* channelInfo, int channelNumber, bool isEventChannel)
{
......@@ -275,6 +300,7 @@ void FilterNode::saveCustomChannelParametersToXml(XmlElement* channelInfo, int c
XmlElement* channelParams = channelInfo->createNewChildElement("PARAMETERS");
channelParams->setAttribute("highcut",highCuts[channelNumber]);
channelParams->setAttribute("lowcut",lowCuts[channelNumber]);
channelParams->setAttribute("shouldFilter",shouldFilterChannel[channelNumber]);
}
}
......@@ -292,6 +318,7 @@ void FilterNode::loadCustomChannelParametersFromXml(XmlElement* channelInfo, boo
{
highCuts.set(channelNum, subNode->getDoubleAttribute("highcut",defaultHighCut));
lowCuts.set(channelNum, subNode->getDoubleAttribute("lowcut",defaultLowCut));
shouldFilterChannel.set(channelNum, subNode->getBoolAttribute("shouldFilter",true));
setFilterParameters(lowCuts[channelNum],
highCuts[channelNum],
......
......@@ -58,18 +58,22 @@ public:
double getLowCutValueForChannel(int chan);
double getHighCutValueForChannel(int chan);
bool getBypassStatusForChannel(int chan);
void updateSettings();
void saveCustomChannelParametersToXml(XmlElement* channelInfo, int channelNumber, bool isEventChannel);
void loadCustomChannelParametersFromXml(XmlElement* channelInfo, bool isEventChannel);
void setApplyOnADC(bool state);
private:
Array<double> lowCuts, highCuts;
OwnedArray<Dsp::Filter> filters;
Array<bool> shouldFilterChannel;
bool applyOnADC;
double defaultLowCut;
double defaultHighCut;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment