Skip to content

Commit 546745a

Browse files
committed
Cache SpikeViewer settings
1 parent b90551b commit 546745a

7 files changed

Lines changed: 89 additions & 6 deletions

File tree

Plugins/BasicSpikeDisplay/SpikeDetector/PopupConfigurationWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ChannelSelectorCustomComponent :
105105
for (int i = 0; i < newChannels.size(); i++)
106106
{
107107
newArray.add(newChannels[i]);
108-
std::cout << "Channel " << newChannels[i] << " selected" << std::endl;
108+
LOGD("Channel ", newChannels[i], " selected");
109109
}
110110

111111
String s = "[";

Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplay.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void SpikeDisplay::clear()
5959
SpikePlot* SpikeDisplay::addSpikePlot(int numChannels, int electrodeNum, String name_)
6060
{
6161

62+
LOGD("Adding spike plot for electrode: ", electrodeNum, " named: ", name_, " with ", numChannels, " channels");
63+
6264
SpikePlot* spikePlot = new SpikePlot(canvas, electrodeNum, 1000 + numChannels, name_);
6365
spikePlots.add(spikePlot);
6466
addAndMakeVisible(spikePlot);
@@ -266,3 +268,15 @@ void SpikeDisplay::setRangeForWaveAxis(int plotNum, int axisNum, float range)
266268
if (spikePlots.size() > plotNum)
267269
return spikePlots[plotNum]->setRangeForChannel(axisNum, range);
268270
}
271+
272+
bool SpikeDisplay::getMonitorStateForPlot(int plotNum)
273+
{
274+
if (spikePlots.size() > plotNum)
275+
return spikePlots[plotNum]->getMonitorState();
276+
}
277+
278+
void SpikeDisplay::setMonitorStateForPlot(int plotNum, bool state)
279+
{
280+
if (spikePlots.size() > plotNum)
281+
return spikePlots[plotNum]->setMonitorState(state);
282+
}

Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplay.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ class SpikeDisplay : public Component
9595
/** Sets the range for a given plot*/
9696
void setRangeForWaveAxis(int plotNum, int axisNum, float range);
9797

98+
/** Returns the monitor state for a given plot*/
99+
bool getMonitorStateForPlot(int plotNum);
100+
101+
/** Sets the monitor state for a given plot*/
102+
void setMonitorStateForPlot(int plotNum, bool monitorState);
103+
98104
/** Allows the threshold coordinator to change thresholds synchronously*/
99105
void registerThresholdCoordinator(SpikeThresholdCoordinator* stc);
100106

Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,25 @@ SpikeDisplayCanvas::SpikeDisplayCanvas(SpikeDisplayNode* processor_) :
110110
update();
111111
}
112112

113+
void SpikeDisplayCanvas::cacheDisplaySettings(int electrode, int channel, double threshold, double range, bool isMonitored)
114+
{
115+
thresholds[electrode][channel] = threshold;
116+
ranges[electrode][channel] = range;
117+
monitors[electrode] = isMonitored;
118+
}
119+
120+
bool SpikeDisplayCanvas::hasCachedDisplaySettings(int electrode, int channel)
121+
{
122+
return thresholds[electrode].count(channel) > 0;
123+
}
124+
125+
void SpikeDisplayCanvas::invalidateDisplaySettings(int electrodeIndex)
126+
{
127+
thresholds.erase(electrodeIndex);
128+
ranges.erase(electrodeIndex);
129+
monitors.erase(electrodeIndex);
130+
}
131+
113132

114133
void SpikeDisplayCanvas::update()
115134
{
@@ -128,22 +147,27 @@ void SpikeDisplayCanvas::update()
128147
processor->getNameForElectrode(i));
129148
processor->addSpikePlotForElectrode(sp, i);
130149

131-
if (shouldApplySavedParams)
150+
if (monitors.size())
132151
{
152+
153+
spikeDisplay->setMonitorStateForPlot(i, monitors[i]);
154+
133155
for (int j = 0; j < processor->getNumberOfChannelsForElectrode(i); j++)
134156
{
157+
158+
LOGD("Updating spike plot: ", i, " channel: ", j, " threshold: ", thresholds[i][j], " range: ", ranges[i][j])
135159
spikeDisplay->setThresholdForWaveAxis(i,j,thresholds[i][j]);
136160
spikeDisplay->setRangeForWaveAxis(i,j,ranges[i][j]);
161+
spikeDisplay->setMonitorStateForPlot(i,monitors[i]);
137162
}
163+
138164
}
139165
}
140166

141167
spikeDisplay->resized();
142168

143169
}
144170

145-
146-
147171
void SpikeDisplayCanvas::refreshState()
148172
{
149173
// called when the component's tab becomes visible again
@@ -215,11 +239,14 @@ void SpikeDisplayCanvas::saveCustomParametersToXml(XmlElement* xml)
215239
{
216240
XmlElement* plotNode = xmlNode->createNewChildElement("PLOT");
217241

242+
plotNode->setAttribute("isMonitored", spikeDisplay->getMonitorStateForPlot(i));
243+
218244
for (int j = 0; j < spikeDisplay->getNumChannelsForPlot(i); j++)
219245
{
220246
XmlElement* axisNode = plotNode->createNewChildElement("AXIS");
221247
axisNode->setAttribute("thresh",spikeDisplay->getThresholdForWaveAxis(i,j));
222248
axisNode->setAttribute("range",spikeDisplay->getRangeForWaveAxis(i,j));
249+
223250
}
224251
}
225252

@@ -248,6 +275,8 @@ void SpikeDisplayCanvas::loadCustomParametersFromXml(XmlElement* xml)
248275

249276
plotIndex++;
250277

278+
monitors[plotIndex] = plotNode->getBoolAttribute("isMonitored");
279+
251280
//std::cout << "PLOT NUMBER " << plotIndex << std::endl;
252281

253282
int channelIndex = -1;
@@ -266,5 +295,4 @@ void SpikeDisplayCanvas::loadCustomParametersFromXml(XmlElement* xml)
266295
}
267296
}
268297

269-
shouldApplySavedParams = true;
270298
}

Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikeDisplayCanvas.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ class SpikeDisplayCanvas : public Visualizer,
125125
/** Pointer to the underlying SpikeDisplayNode*/
126126
SpikeDisplayNode* processor;
127127

128+
void cacheDisplaySettings(int electrodeIndex, int channelIndex, double threshold, double range, bool isMonitored);
129+
130+
bool hasCachedDisplaySettings(int electrodeIndex, int channelIndex);
131+
132+
void invalidateDisplaySettings(int electrodeIndex);
133+
128134
private:
129135

130136
std::unique_ptr<SpikeDisplay> spikeDisplay;
@@ -141,7 +147,7 @@ class SpikeDisplayCanvas : public Visualizer,
141147

142148
std::map<int, std::map<int, double>> ranges;
143149
std::map<int, std::map<int, double>> thresholds;
144-
bool shouldApplySavedParams = false;
150+
std::map<int, bool> monitors;
145151

146152
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SpikeDisplayCanvas);
147153

Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikePlots.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ SpikePlot::SpikePlot(SpikeDisplayCanvas* sdc,
8484

8585
rangeButtons.add(rangeButton);
8686
setDisplayThresholdForChannel(i, 0);
87+
88+
if (!canvas->hasCachedDisplaySettings(electrodeNumber, i))
89+
canvas->cacheDisplaySettings(electrodeNumber, i, 0, 250.0, false);
8790
}
8891

8992
monitorButton = std::make_unique<UtilityButton>("MON", Font("Small Text", 8, Font::plain));
@@ -286,6 +289,13 @@ void SpikePlot::buttonClicked(Button* button)
286289

287290
setLimitsOnAxes();
288291

292+
LOGD("Updating electrode: ", electrodeNumber, " range: ", ranges[index], " index: ", index);
293+
294+
double threshold = getDisplayThresholdForChannel(index);
295+
bool monitorState = monitorButton->getToggleState();
296+
297+
canvas->cacheDisplaySettings(electrodeNumber, index, threshold, ranges[index], monitorState);
298+
289299
}
290300

291301
void SpikePlot::setLimitsOnAxes()
@@ -370,6 +380,16 @@ void SpikePlot::setRangeForChannel(int i, float range)
370380
rangeButtons[i]->setLabel(String(int(range)));
371381
}
372382

383+
bool SpikePlot::getMonitorState()
384+
{
385+
return monitorButton->getToggleState();
386+
}
387+
388+
void SpikePlot::setMonitorState(bool state)
389+
{
390+
monitorButton->setToggleState(state, sendNotification);
391+
}
392+
373393
void SpikePlot::setDetectorThresholdForChannel(int i, float t)
374394
{
375395
// std::cout << "Setting threshold to " << t << std::endl;

Plugins/BasicSpikeDisplay/SpikeDisplayNode/SpikePlots.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,18 @@ class SpikePlot : public Component,
114114
void setDisplayThresholdForChannel(int axisNum, float threshold);
115115
void setDetectorThresholdForChannel(int, float);
116116

117+
/** Returns the range for a given channel*/
117118
float getRangeForChannel(int);
119+
120+
/** Sets the range for a given channel*/
118121
void setRangeForChannel(int axisNum, float range);
119122

123+
/**Returns the monitor state for this electrode */
124+
bool getMonitorState();
125+
126+
/** Sets the monitor state for this electrode */
127+
void setMonitorState(bool);
128+
120129
//For locking the tresholds
121130
void registerThresholdCoordinator(SpikeThresholdCoordinator* stc);
122131
void setAllThresholds(float displayThreshold, float range);

0 commit comments

Comments
 (0)