diff --git a/Source/SpikeSorter.cpp b/Source/SpikeSorter.cpp index 88b46cb..20c7482 100644 --- a/Source/SpikeSorter.cpp +++ b/Source/SpikeSorter.cpp @@ -115,8 +115,6 @@ void Electrode::updateSettings (SpikeChannel* channel) SpikeSorter::SpikeSorter() : GenericProcessor ("Spike Sorter") { cache = std::make_unique(); - - addIntParameter (Parameter::STREAM_SCOPE, "electrode_index", "Electrode Index", "The current electrode index being viewed", 0, 0, 1000); } AudioProcessorEditor* SpikeSorter::createEditor() @@ -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(); @@ -151,6 +162,8 @@ void SpikeSorter::updateSettings() electrode->reset(); } + Array electrodeNames; + for (auto spikeChannel : spikeChannels) { if (spikeChannel->isValid()) @@ -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 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 SpikeSorter::getElectrodesForStream (uint16 streamId) diff --git a/Source/SpikeSorter.h b/Source/SpikeSorter.h index 2f19849..f172f0e 100644 --- a/Source/SpikeSorter.h +++ b/Source/SpikeSorter.h @@ -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& buffer) override; diff --git a/Source/SpikeSorterEditor.cpp b/Source/SpikeSorterEditor.cpp index a301c7e..bd01671 100644 --- a/Source/SpikeSorterEditor.cpp +++ b/Source/SpikeSorterEditor.cpp @@ -33,15 +33,11 @@ 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() @@ -49,15 +45,14 @@ 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; @@ -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); } \ No newline at end of file diff --git a/Source/SpikeSorterEditor.h b/Source/SpikeSorterEditor.h index 94e043f..63964de 100644 --- a/Source/SpikeSorterEditor.h +++ b/Source/SpikeSorterEditor.h @@ -39,8 +39,7 @@ class SpikeSorterCanvas; */ -class SpikeSorterEditor : public VisualizerEditor, - public ComboBox::Listener +class SpikeSorterEditor : public VisualizerEditor { public: /** Constructor*/ @@ -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();