Skip to content
Snippets Groups Projects
Commit 794dbd16 authored by Aaron Cuevas Lopez's avatar Aaron Cuevas Lopez Committed by wonkoderverstaendige
Browse files

Make ChannelMap able to disable channels

parent ec2a70f4
Branches
Tags
No related merge requests found
/*
------------------------------------------------------------------
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2013 Open Ephys
This file is part of the Open Ephys GUI
Copyright (C) 2013 Open Ephys
------------------------------------------------------------------
------------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -28,16 +28,17 @@
ChannelMappingNode::ChannelMappingNode()
: GenericProcessor("Channel Map"), channelBuffer(1,10000)
: GenericProcessor("Channel Map"), channelBuffer(1,10000), previousChannelCount(0)
{
referenceArray.resize(1024); // make room for 1024 channels
channelArray.resize(1024);
referenceArray.resize(1024); // make room for 1024 channels
channelArray.resize(1024);
for (int i = 0; i < referenceArray.size(); i++)
{
channelArray.set(i, i);
for (int i = 0; i < referenceArray.size(); i++)
{
channelArray.set(i, i);
referenceArray.set(i,-1);
}
enabledChannelArray.set(i,true);
}
for (int i = 0; i < NUM_REFERENCES; i++)
{
referenceChannels.set(i, -1);
......@@ -52,19 +53,40 @@ ChannelMappingNode::~ChannelMappingNode()
AudioProcessorEditor* ChannelMappingNode::createEditor()
{
editor = new ChannelMappingEditor(this, true);
editor = new ChannelMappingEditor(this, true);
std::cout << "Creating editor." << std::endl;
std::cout << "Creating editor." << std::endl;
return editor;
return editor;
}
void ChannelMappingNode::updateSettings()
{
if (getNumInputs() > 0)
channelBuffer.setSize(getNumInputs(), 10000);
if (getNumInputs() > 0)
channelBuffer.setSize(getNumInputs(), 10000);
if (getNumInputs() != previousChannelCount)
{
previousChannelCount = getNumInputs();
}
else
{
int j=0;
for (int i=0; i < getNumInputs(); i++)
{
if (enabledChannelArray[i])
{
j++;
}
else
{
channels.remove(j);
}
}
settings.numOutputs=j;
}
}
......@@ -72,63 +94,76 @@ void ChannelMappingNode::updateSettings()
void ChannelMappingNode::setParameter(int parameterIndex, float newValue)
{
if (parameterIndex == 1)
{
if (parameterIndex == 1)
{
referenceArray.set(currentChannel, (int) newValue);
}
}
else if (parameterIndex == 2)
{
referenceChannels.set((int) newValue, currentChannel);
}
else
{
channelArray.set(currentChannel, (int) newValue);
}
else if (parameterIndex == 3)
{
enabledChannelArray.set(currentChannel, (newValue != 0) ? true : false);
}
else
{
channelArray.set(currentChannel, (int) newValue);
}
}
void ChannelMappingNode::process(AudioSampleBuffer& buffer,
MidiBuffer& midiMessages,
int& nSamples)
MidiBuffer& midiMessages,
int& nSamples)
{
int j=0;
// use copy constructor to set the data to refer to
channelBuffer = buffer;
// use copy constructor to set the data to refer to
channelBuffer = buffer;
// copy it back into the buffer according to the channel mapping
buffer.clear();
// copy it back into the buffer according to the channel mapping
buffer.clear();
for (int i = 0; i < buffer.getNumChannels(); i++)
{
buffer.addFrom(i, // destChannel
0, // destStartSample
channelBuffer, // source
channelArray[i], // sourceChannel
0, // sourceStartSample
nSamples, // numSamples
1.0f // gain to apply to source (positive for original signal)
);
for (int i = 0; i < buffer.getNumChannels(); i++)
{
if (enabledChannelArray[channelArray[i]])
{
buffer.addFrom(j, // destChannel
0, // destStartSample
channelBuffer, // source
channelArray[i], // sourceChannel
0, // sourceStartSample
nSamples, // numSamples
1.0f // gain to apply to source (positive for original signal)
);
j++;
}
}
}
// now do the referencing
for (int i = 0; i < buffer.getNumChannels(); i++)
{
j=0;
// now do the referencing
for (int i = 0; i < buffer.getNumChannels(); i++)
{
int realChan = channelArray[i];
if ((referenceArray[realChan] > -1) && referenceChannels[referenceArray[realChan]] > -1)
{
buffer.addFrom(i, // destChannel
0, // destStartSample
channelBuffer, // source
referenceChannels[referenceArray[realChan]], // sourceChannel
0, // sourceStartSample
nSamples, // numSamples
-1.0f // gain to apply to source (negative for reference)
);
}
}
if (enabledChannelArray[realChan])
{
if ((referenceArray[realChan] > -1) && referenceChannels[referenceArray[realChan]] > -1)
{
buffer.addFrom(j, // destChannel
0, // destStartSample
channelBuffer, // source
referenceChannels[referenceArray[realChan]], // sourceChannel
0, // sourceStartSample
nSamples, // numSamples
-1.0f // gain to apply to source (negative for reference)
);
}
j++;
}
}
}
......@@ -67,6 +67,9 @@ private:
Array<int> referenceArray;
Array<int> referenceChannels;
Array<int> channelArray;
Array<bool> enabledChannelArray;
int previousChannelCount;
AudioSampleBuffer channelBuffer;
......
......@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ChannelMappingEditor.h"
#include "../ChannelMappingNode.h"
#include "../../UI/EditorViewport.h"
#include "ChannelSelector.h"
#include <stdio.h>
......@@ -96,6 +97,7 @@ void ChannelMappingEditor::createElectrodeButtons(int numNeeded)
referenceArray.clear();
channelArray.clear();
referenceChannels.clear();
enabledChannelArray.clear();
int width = 20;
int height = 15;
......@@ -120,8 +122,10 @@ void ChannelMappingEditor::createElectrodeButtons(int numNeeded)
getProcessor()->setCurrentChannel(i);
getProcessor()->setParameter(0,i); // set channel mapping to standard channel
getProcessor()->setParameter(1,-1); // set reference to none
getProcessor()->setParameter(3,1); //enable channel
channelArray.add(i+1);
enabledChannelArray.add(true);
if (column % 16 == 0)
{
......@@ -167,6 +171,7 @@ void ChannelMappingEditor::buttonEvent(Button* button)
{
if (reorderActive)
{
channelSelector->activateButtons();
reorderActive = false;
selectedReference = 0;
for (int i=0; i < referenceButtons.size(); i++)
......@@ -174,6 +179,13 @@ void ChannelMappingEditor::buttonEvent(Button* button)
referenceButtons[i]->setEnabled(true);
}
referenceButtons[0]->setToggleState(true,false);
Array<int> a;
if (referenceChannels[selectedReference] >= 0 )
{
a.add(referenceChannels[selectedReference]);
}
channelSelector->setActiveChannels(a);
for (int i = 0; i < electrodeButtons.size(); i++)
{
......@@ -187,12 +199,21 @@ void ChannelMappingEditor::buttonEvent(Button* button)
{
electrodeButtons[i]->setToggleState(false,false);
}
if (enabledChannelArray[electrodeButtons[i]->getChannelNum()-1])
{
electrodeButtons[i]->setEnabled(true);
}
else
{
electrodeButtons[i]->setEnabled(false);
}
}
selectAllButton->setEnabled(true);
}
else
{
reorderActive = true;
channelSelector->inactivateButtons();
for (int i=0; i < referenceButtons.size(); i++)
{
......@@ -203,8 +224,17 @@ void ChannelMappingEditor::buttonEvent(Button* button)
for (int i = 0; i < electrodeButtons.size(); i++)
{
electrodeButtons[i]->setClickingTogglesState(false);
electrodeButtons[i]->setToggleState(true,false);
electrodeButtons[i]->setEnabled(true);
if (enabledChannelArray[electrodeButtons[i]->getChannelNum()-1])
{
electrodeButtons[i]->setToggleState(true,false);
}
else
{
electrodeButtons[i]->setToggleState(false,false);
}
electrodeButtons[i]->addMouseListener(this,false);
}
selectAllButton->setEnabled(false);
}
......@@ -404,7 +434,8 @@ void ChannelMappingEditor::saveEditorParameters(XmlElement* xml)
XmlElement* channelXml = xml->createNewChildElement("CHANNEL");
channelXml->setAttribute("Number", i);
channelXml->setAttribute("Mapping", channelArray[i]);
channelXml->setAttribute("Reference", referenceArray[i]);
channelXml->setAttribute("Reference", referenceArray[channelArray[i]-1]);
channelXml->setAttribute("Enabled",enabledChannelArray[channelArray[i]-1]);
}
for (int i = 0; i< referenceChannels.size(); i++)
{
......@@ -427,18 +458,26 @@ void ChannelMappingEditor::loadEditorParameters(XmlElement* xml)
int mapping = channelXml->getIntAttribute("Mapping");
int reference = channelXml->getIntAttribute("Reference");
bool enabled = channelXml->getBoolAttribute("Enabled");
channelArray.set(i, mapping);
referenceArray.set(i, reference);
referenceArray.set(mapping-1, reference);
enabledChannelArray.set(mapping-1,enabled);
electrodeButtons[i]->setChannelNum(mapping);
electrodeButtons[i]->setEnabled(enabled);
electrodeButtons[i]->repaint();
getProcessor()->setCurrentChannel(i);
getProcessor()->setParameter(1, reference); // set reference
getProcessor()->setParameter(0, mapping-1); // set mapping
getProcessor()->setCurrentChannel(mapping-1);
getProcessor()->setParameter(1, reference); // set reference
getProcessor()->setParameter(3,enabled ? 1 : 0); //set enabled
}
}
......@@ -490,7 +529,14 @@ void ChannelMappingEditor::mouseDrag(const MouseEvent &e)
Image dragImage(Image::ARGB,20,15,true);
Graphics g(dragImage);
g.setColour(Colours::orange);
if (button->getToggleState())
{
g.setColour(Colours::orange);
}
else
{
g.setColour(Colours::darkgrey);
}
g.fillAll();
g.setColour(Colours::black);
g.drawText(String(button->getChannelNum()),0,0,20,15,Justification::centred,true);
......@@ -532,6 +578,14 @@ void ChannelMappingEditor::mouseDrag(const MouseEvent &e)
for (int i = lastHoverButton; i > hoverButton; i--)
{
electrodeButtons[i]->setChannelNum(electrodeButtons[i-1]->getChannelNum());
if (enabledChannelArray[electrodeButtons[i]->getChannelNum()-1]) //Could be more compact, but definitely less legible
{
electrodeButtons[i]->setToggleState(true,false);
}
else
{
electrodeButtons[i]->setToggleState(false,false);
}
}
}
else
......@@ -539,9 +593,18 @@ void ChannelMappingEditor::mouseDrag(const MouseEvent &e)
for (int i = lastHoverButton; i < hoverButton; i++)
{
electrodeButtons[i]->setChannelNum(electrodeButtons[i+1]->getChannelNum());
if (enabledChannelArray[electrodeButtons[i]->getChannelNum()-1])
{
electrodeButtons[i]->setToggleState(true,false);
}
else
{
electrodeButtons[i]->setToggleState(false,false);
}
}
}
electrodeButtons[hoverButton]->setChannelNum(draggingChannel);
electrodeButtons[hoverButton]->setToggleState(enabledChannelArray[draggingChannel-1],false);
lastHoverButton = hoverButton;
repaint();
......@@ -582,4 +645,28 @@ void ChannelMappingEditor::setChannelPosition(int position, int channel)
getProcessor()->setCurrentChannel(position);
getProcessor()->setParameter(0,channel-1);
channelArray.set(position,channel);
}
void ChannelMappingEditor::mouseDoubleClick(const MouseEvent &e)
{
if ((reorderActive) && electrodeButtons.contains((ElectrodeButton*)e.originalComponent))
{
ElectrodeButton *button = (ElectrodeButton*)e.originalComponent;
if (button->getToggleState())
{
button->setToggleState(false,false);
enabledChannelArray.set(button->getChannelNum()-1,false);
getProcessor()->setCurrentChannel(button->getChannelNum()-1);
getProcessor()->setParameter(3,0);
}
else
{
button->setToggleState(true,false);
enabledChannelArray.set(button->getChannelNum()-1,true);
getProcessor()->setCurrentChannel(button->getChannelNum()-1);
getProcessor()->setParameter(3,1);
}
getEditorViewport()->makeEditorVisible(this, false, true);
}
}
\ No newline at end of file
......@@ -63,6 +63,8 @@ public:
void mouseUp(const MouseEvent &e);
void mouseDoubleClick(const MouseEvent &e);
private:
......@@ -77,6 +79,7 @@ private:
Array<int> channelArray;
Array<int> referenceArray;
Array<int> referenceChannels;
Array<bool> enabledChannelArray;
int previousChannelCount;
int selectedReference;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment