Skip to content

Commit

Permalink
Update selected electrode to param
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed Jan 22, 2025
1 parent f6ad170 commit c37d35a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 49 deletions.
31 changes: 29 additions & 2 deletions Source/SpikeSorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ void Electrode::updateSettings (SpikeChannel* channel)
SpikeSorter::SpikeSorter() : GenericProcessor ("Spike Sorter")
{
cache = std::make_unique<SpikeDisplayCache>();

addIntParameter (Parameter::STREAM_SCOPE, "electrode_index", "Electrode Index", "The current electrode index being viewed", 0, 0, 1000);
}

AudioProcessorEditor* SpikeSorter::createEditor()
Expand All @@ -126,6 +124,19 @@ AudioProcessorEditor* SpikeSorter::createEditor()
return editor.get();
}

void SpikeSorter::registerParameters()
{
addCategoricalParameter (Parameter::STREAM_SCOPE, "electrode_index", "Active Electrode", "The current electrode index being viewed", {}, 0);
}

void SpikeSorter::parameterValueChanged (Parameter* parameter)
{
if (parameter->getName() == "electrode_index")
{
((SpikeSorterEditor*) getEditor())->updateView();
}
}

bool SpikeSorter::startAcquisition()
{
SpikeSorterEditor* editor = (SpikeSorterEditor*) getEditor();
Expand All @@ -151,6 +162,8 @@ void SpikeSorter::updateSettings()
electrode->reset();
}

Array<String> electrodeNames;

for (auto spikeChannel : spikeChannels)
{
if (spikeChannel->isValid())
Expand All @@ -175,9 +188,23 @@ void SpikeSorter::updateSettings()
Electrode* e = new Electrode (this, spikeChannel, &computingThread);
electrodes.add (e);
electrodeMap[spikeChannel] = e;
electrodeNames.add (e->name);
}
}
}

for (auto stream : getDataStreams())
{
// update the spike channel parameter with the available spike channels
Array<String> spikeChannelNames;
//spikeChannelNames.add ("No spike channel");
for (auto spikeChan : stream->getSpikeChannels())
spikeChannelNames.add (spikeChan->getName());

CategoricalParameter* spikeChanParam = (CategoricalParameter*) stream->getParameter ("electrode_index");
spikeChanParam->setCategories (spikeChannelNames);
parameterValueChanged (stream->getParameter ("electrode_index"));
}
}

Array<Electrode*> SpikeSorter::getElectrodesForStream (uint16 streamId)
Expand Down
6 changes: 6 additions & 0 deletions Source/SpikeSorter.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ class SpikeSorter : public GenericProcessor
/** Destructor */
~SpikeSorter() {}

/** Registers parameters */
void registerParameters() override;

/** Handle parameter value change */
void parameterValueChanged (Parameter* parameter) override;

/** Calls checkForEvents(true) */
void process (AudioBuffer<float>& buffer) override;

Expand Down
72 changes: 30 additions & 42 deletions Source/SpikeSorterEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,26 @@ SpikeSorterEditor::SpikeSorterEditor (GenericProcessor* parentNode)

{
tabText = "Spike Sorter";
addComboBoxParameterEditor (Parameter::STREAM_SCOPE, "electrode_index", 20, 30);

electrodeList = new ComboBox ("Electrode List");
electrodeList->addListener (this);
electrodeList->setBounds (20, 70, 140, 20);
addAndMakeVisible (electrodeList);

electrodeSelectionLabel = new Label ("Label", "Active Electrode:");
electrodeSelectionLabel->setBounds (17, 40, 180, 20);
addAndMakeVisible (electrodeSelectionLabel);
ParameterEditor* electrodeIndexEditor = getParameterEditor ("electrode_index");
electrodeIndexEditor->setLayout (ParameterEditor::Layout::nameOnTop);
electrodeIndexEditor->setSize (160, 40);
}

Visualizer* SpikeSorterEditor::createNewCanvas()
{
SpikeSorter* processor = (SpikeSorter*) getProcessor();
spikeSorterCanvas = new SpikeSorterCanvas (processor);

selectedStreamHasChanged();
updateView();

return spikeSorterCanvas;
}

void SpikeSorterEditor::selectedStreamHasChanged()
{
electrodeList->clear();

updateView();
if (selectedStream == 0)
{
return;
Expand All @@ -72,70 +67,63 @@ void SpikeSorterEditor::selectedStreamHasChanged()

for (auto electrode : currentElectrodes)
{
electrodeList->addItem (electrode->name, ++id);

if (electrode->plot->isVisible())
viewedPlot = id;
}

int electrodeIndex = processor->getDataStream (selectedStream)->getParameter ("electrode_index")->getValue();

electrodeList->setSelectedId (electrodeIndex + 1, true);
}

void SpikeSorterEditor::comboBoxChanged (ComboBox* comboBox)
void SpikeSorterEditor::updateView()
{
if (comboBox == electrodeList)
if (selectedStream == 0)
return;

SpikeSorter* processor = (SpikeSorter*) getProcessor();
currentElectrodes = processor->getElectrodesForStream (selectedStream);
if (currentElectrodes.size() == 0)
{
spikeSorterCanvas->setActiveElectrode (nullptr);
return;
}

if (spikeSorterCanvas != nullptr)
{
int index = electrodeList->getSelectedId() - 1;

if (spikeSorterCanvas != nullptr)
{
if (currentElectrodes.size() == 0)
{
spikeSorterCanvas->setActiveElectrode (nullptr);
return;
}

spikeSorterCanvas->setActiveElectrode (currentElectrodes[index]);

for (auto& stream : getProcessor()->getDataStreams())
if (stream->getName() == currentElectrodes[index]->streamName
&& stream->getSourceNodeId() == currentElectrodes[index]->streamSourceId)
stream->getParameter ("electrode_index")->setNextValue (index);
}
int electrodeIndex = processor->getDataStream (selectedStream)->getParameter ("electrode_index")->getValue();
spikeSorterCanvas->setActiveElectrode (currentElectrodes[electrodeIndex]);
}
}

void SpikeSorterEditor::updateSettings()
{
selectedStreamHasChanged();
updateView();
}

void SpikeSorterEditor::nextElectrode()
{
int numAvailable = electrodeList->getNumItems();

int currentID = electrodeList->getSelectedId();
SpikeSorter* processor = (SpikeSorter*) getProcessor();
int numAvailable = currentElectrodes.size();
int currentID = processor->getDataStream (selectedStream)->getParameter ("electrode_index")->getValue();

int nextID = currentID + 1;

if (nextID > numAvailable)
nextID = 1;

electrodeList->setSelectedId (nextID, sendNotification);
processor->getDataStream (selectedStream)->getParameter ("electrode_index")->setNextValue (nextID);
}

void SpikeSorterEditor::previousElectrode()
{
int numAvailable = electrodeList->getNumItems();
SpikeSorter* processor = (SpikeSorter*) getProcessor();
int numAvailable = currentElectrodes.size();

int currentID = electrodeList->getSelectedId();
int currentID = processor->getDataStream (selectedStream)->getParameter ("electrode_index")->getValue();

int previousID = currentID - 1;

if (previousID == 0)
previousID = numAvailable;

electrodeList->setSelectedId (previousID, sendNotification);
processor->getDataStream (selectedStream)->getParameter ("electrode_index")->setNextValue (previousID);
}
9 changes: 4 additions & 5 deletions Source/SpikeSorterEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class SpikeSorterCanvas;
*/

class SpikeSorterEditor : public VisualizerEditor,
public ComboBox::Listener
class SpikeSorterEditor : public VisualizerEditor
{
public:
/** Constructor*/
Expand All @@ -52,12 +51,12 @@ class SpikeSorterEditor : public VisualizerEditor,
/** Creates the SpikeSorterCanvas */
Visualizer* createNewCanvas();

/** ComboBox::Listener callback*/
void comboBoxChanged (ComboBox* comboBox) override;

/** Called when settings are updated */
void updateSettings() override;

/** Updates the view */
void updateView();

/** Selects the next available electrode */
void nextElectrode();

Expand Down

0 comments on commit c37d35a

Please sign in to comment.