Skip to content

Commit cecc277

Browse files
authored
Update SpikeSorterCanvas.cpp
1 parent 580ed84 commit cecc277

1 file changed

Lines changed: 83 additions & 60 deletions

File tree

Source/Plugins/SpikeSorter/SpikeSorterCanvas.cpp

Lines changed: 83 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ SpikeSorterCanvas::SpikeSorterCanvas(SpikeSorter* n) :
8181
prevElectrode->setRadius(3.0f);
8282
prevElectrode->addListener(this);
8383
addAndMakeVisible(prevElectrode);
84-
84+
85+
editAllThresholds = new UtilityButton("Edit All Thresholds",Font("Small Text", 13, Font::plain));
86+
editAllThresholds->addListener(this);
87+
editAllThresholds->setBounds(140,30,60,20);
88+
editAllThresholds->setClickingTogglesState(true);
89+
addAndMakeVisible(editAllThresholds);
90+
//
91+
8592
addAndMakeVisible(viewport);
8693

8794
setWantsKeyboardFocus(true);
@@ -159,6 +166,8 @@ void SpikeSorterCanvas::resized()
159166

160167
newIDbuttons->setBounds(0, 270, 120,20);
161168
deleteAllUnits->setBounds(0, 300, 120,20);
169+
170+
editAllThresholds->setBounds(0, 330, 120,20);
162171

163172
}
164173

@@ -402,7 +411,15 @@ void SpikeSorterCanvas::buttonClicked(Button* button)
402411
electrode->spikePlot->updateUnitsFromProcessor();
403412
processor->removeAllUnits(electrode->electrodeID);
404413
}
405-
414+
else if (button == editAllThresholds){
415+
416+
}
417+
418+
// new
419+
if (button == editAllThresholds){
420+
processor->setEditAllState(button->getToggleState());
421+
}
422+
406423
repaint();
407424
}
408425

@@ -492,7 +509,7 @@ void SpikeThresholdDisplay::mouseDown(const MouseEvent& event)
492509

493510
}
494511

495-
void SpikeThresholdDisplay::plotSpike(const SpikeObject& spike, int electrodeNum)
512+
void SpikeThresholdDisplay::plotSpike(SorterSpikePtr spike, int electrodeNum)
496513
{
497514
spikePlots[electrodeNum]->processSpikeObject(spike);
498515

@@ -643,7 +660,7 @@ void SpikeHistogramPlot::setPCARange(float p1min, float p2min, float p1max, floa
643660
pAxes[0]->setPCARange(p1min, p2min, p1max, p2max);
644661
}
645662

646-
void SpikeHistogramPlot::processSpikeObject(const SpikeObject& s)
663+
void SpikeHistogramPlot::processSpikeObject(SorterSpikePtr s)
647664
{
648665
const ScopedLock myScopedLock(mut);
649666
if (nWaveAx > 0)
@@ -911,7 +928,7 @@ GenericDrawAxes::~GenericDrawAxes()
911928

912929
}
913930

914-
bool GenericDrawAxes::updateSpikeData(const SpikeObject& newSpike)
931+
bool GenericDrawAxes::updateSpikeData(SorterSpikePtr newSpike)
915932
{
916933
if (!gotFirstSpike)
917934
{
@@ -1038,10 +1055,7 @@ WaveformAxes::WaveformAxes(SpikeHistogramPlot* plt, SpikeSorter* p,int electrode
10381055
int numSamples = 40;
10391056
for (int n = 0; n < bufferSize; n++)
10401057
{
1041-
SpikeObject so;
1042-
generateEmptySpike(&so, 4, numSamples);
1043-
1044-
spikeBuffer.add(so);
1058+
spikeBuffer.add(nullptr);
10451059
}
10461060
}
10471061

@@ -1071,14 +1085,15 @@ void WaveformAxes::setRange(float r)
10711085
repaint();
10721086
}
10731087

1074-
void WaveformAxes::plotSpike(const SpikeObject& s, Graphics& g)
1088+
void WaveformAxes::plotSpike(SorterSpikePtr s, Graphics& g)
10751089
{
10761090

10771091
float h = getHeight();
1078-
g.setColour(Colour(s.color[0],s.color[1],s.color[2]));
1092+
// find me
1093+
g.setColour(Colour(s->color[0], s->color[1], s->color[2]));
10791094
//g.setColour(Colours::pink);
10801095
//compute the spatial width for each waveform sample
1081-
float dx = getWidth()/float(spikeBuffer[0].nSamples);
1096+
float dx = getWidth()/float(spikeBuffer[0]->getChannel()->getTotalSamples());
10821097

10831098
/*
10841099
float align = 8 * getWidth()/float(spikeBuffer[0].nSamples);
@@ -1087,35 +1102,36 @@ void WaveformAxes::plotSpike(const SpikeObject& s, Graphics& g)
10871102
align,
10881103
h);
10891104
*/
1090-
1105+
1106+
int spikeSamples = s->getChannel()->getTotalSamples();
10911107
// type corresponds to channel so we need to calculate the starting
10921108
// sample based upon which channel is getting plotted
1093-
int offset = channel*s.nSamples; //spikeBuffer[0].nSamples * type; //
1109+
int offset = channel*spikeSamples; //spikeBuffer[0].nSamples * type; //
10941110

10951111
//int dSamples = 1;
10961112

10971113
float x = 0.0f;
1098-
1099-
for (int i = 0; i < s.nSamples-1; i++)
1100-
{
1101-
//std::cout << s.data[sampIdx] << std::endl;
1102-
1103-
if (*s.gain != 0)
1104-
{
1105-
float s1 =h- (h/2 + float(s.data[offset+i]-32768)/float(*s.gain)*1000.0f / (range) * h);
1106-
float s2 =h- (h/2 + float(s.data[offset+i+1]-32768)/float(*s.gain)*1000.0f / (range) * h);
1107-
if (signalFlipped)
1108-
{
1109-
s1=h-s1;
1110-
s2=h-s2;
1111-
}
1112-
g.drawLine(x,
1113-
s1,
1114-
x+dx,
1115-
s2);
1116-
}
1117-
x += dx;
1118-
}
1114+
1115+
for (int i = 0; i < spikeSamples - 1; i++)
1116+
{
1117+
//std::cout << s.data[sampIdx] << std::endl;
1118+
1119+
1120+
float s1 = h - (h / 2 + s->getData()[offset + i] / (range)* h);
1121+
float s2 = h - (h / 2 + s->getData()[offset + i + 1] / (range)* h);
1122+
1123+
if (signalFlipped)
1124+
{
1125+
s1 = h - s1;
1126+
s2 = h - s2;
1127+
}
1128+
g.drawLine(x,
1129+
s1,
1130+
x + dx,
1131+
s2);
1132+
1133+
x += dx;
1134+
}
11191135

11201136
}
11211137

@@ -1159,7 +1175,7 @@ void WaveformAxes::drawWaveformGrid(Graphics& g)
11591175
}
11601176

11611177

1162-
bool WaveformAxes::updateSpikeData(const SpikeObject& s)
1178+
bool WaveformAxes::updateSpikeData(SorterSpikePtr s)
11631179
{
11641180
if (!gotFirstSpike)
11651181
{
@@ -1169,12 +1185,10 @@ bool WaveformAxes::updateSpikeData(const SpikeObject& s)
11691185
if (spikesReceivedSinceLastRedraw < bufferSize)
11701186
{
11711187

1172-
SpikeObject newSpike = s;
1173-
11741188
spikeIndex++;
11751189
spikeIndex %= bufferSize;
11761190

1177-
spikeBuffer.set(spikeIndex, newSpike);
1191+
spikeBuffer.set(spikeIndex, s);
11781192

11791193
spikesReceivedSinceLastRedraw++;
11801194

@@ -1184,14 +1198,14 @@ bool WaveformAxes::updateSpikeData(const SpikeObject& s)
11841198

11851199
}
11861200

1187-
bool WaveformAxes::checkThreshold(const SpikeObject& s)
1201+
bool WaveformAxes::checkThreshold(SorterSpikePtr s)
11881202
{
1189-
int sampIdx = 40*type;
1203+
int sampIdx = s->getChannel()->getTotalSamples()*type;
11901204

1191-
for (int i = 0; i < s.nSamples-1; i++)
1205+
for (int i = 0; i < s->getChannel()->getTotalSamples() - 1; i++)
11921206
{
11931207

1194-
if (float(s.data[sampIdx]-32768)/float(*s.gain)*1000.0f > displayThresholdLevel)
1208+
if (s->getData()[sampIdx] > displayThresholdLevel)
11951209
{
11961210
return true;
11971211
}
@@ -1211,10 +1225,7 @@ void WaveformAxes::clear()
12111225
int numSamples=40;
12121226
for (int n = 0; n < bufferSize; n++)
12131227
{
1214-
SpikeObject so;
1215-
generateEmptySpike(&so, 4,numSamples);
1216-
1217-
spikeBuffer.add(so);
1228+
spikeBuffer.add(nullptr);
12181229
}
12191230

12201231
repaint();
@@ -1464,7 +1475,20 @@ void WaveformAxes::mouseDrag(const MouseEvent& event)
14641475

14651476
displayThresholdLevel = (0.5f - thresholdSliderPosition) * range;
14661477
// update processor
1467-
processor->getActiveElectrode()->thresholds[channel] = displayThresholdLevel;
1478+
1479+
if (processor->getEditAllState()){
1480+
int numElectrodes = processor->getNumElectrodes();
1481+
for (int electrodeIt = 0 ; electrodeIt < numElectrodes ; electrodeIt++){
1482+
//processor->setChannelThreshold(electrodeList->getSelectedItemIndex(),i,slider->getValue());
1483+
for (int channelIt = 0 ; channelIt < processor->getNumChannels(electrodeIt) ; channelIt++){
1484+
processor->setChannelThreshold(electrodeIt,channelIt,displayThresholdLevel);
1485+
}
1486+
}
1487+
}
1488+
else{
1489+
processor->getActiveElectrode()->thresholds[channel] = displayThresholdLevel;
1490+
}
1491+
14681492
SpikeSorterEditor* edt = (SpikeSorterEditor*) processor->getEditor();
14691493
for (int k=0; k<processor->getActiveElectrode()->numChannels; k++)
14701494
edt->electrodeButtons[k]->setToggleState(false, dontSendNotification);
@@ -1692,7 +1716,7 @@ void WaveformAxes::paint(Graphics& g)
16921716
for (int spikeNum = 0; spikeNum < bufferSize; spikeNum++)
16931717
{
16941718

1695-
if (spikeNum != spikeIndex)
1719+
if (spikeNum != spikeIndex && spikeBuffer[spikeNum] != nullptr)
16961720
{
16971721
g.setColour(Colours::grey);
16981722
plotSpike(spikeBuffer[spikeNum], g);
@@ -1701,7 +1725,8 @@ void WaveformAxes::paint(Graphics& g)
17011725
}
17021726

17031727
g.setColour(Colours::white);
1704-
plotSpike(spikeBuffer[spikeIndex], g);
1728+
if (spikeBuffer[spikeIndex] != nullptr)
1729+
plotSpike(spikeBuffer[spikeIndex], g);
17051730

17061731
spikesReceivedSinceLastRedraw = 0;
17071732

@@ -1876,16 +1901,16 @@ void PCAProjectionAxes::paint(Graphics& g)
18761901
}
18771902

18781903

1879-
void PCAProjectionAxes::drawProjectedSpike(SpikeObject s)
1904+
void PCAProjectionAxes::drawProjectedSpike(SorterSpikePtr s)
18801905
{
1881-
if (rangeSet)
1906+
if (s != nullptr && rangeSet)
18821907
{
18831908
Graphics g(projectionImage);
18841909

1885-
g.setColour(Colour(s.color[0],s.color[1],s.color[2]));
1910+
g.setColour(Colour(s->color[0],s->color[1],s->color[2]));
18861911

1887-
float x = (s.pcProj[0] - pcaMin[0]) / (pcaMax[0]-pcaMin[0]) * rangeX;
1888-
float y = (s.pcProj[1] - pcaMin[1]) / (pcaMax[1]-pcaMin[1]) * rangeY;
1912+
float x = (s->pcProj[0] - pcaMin[0]) / (pcaMax[0]-pcaMin[0]) * rangeX;
1913+
float y = (s->pcProj[1] - pcaMin[1]) / (pcaMax[1]-pcaMin[1]) * rangeY;
18891914
if (x >= 0 & y >= 0 & x <= rangeX & y <= rangeY)
18901915
g.fillEllipse(x,y,2,2);
18911916
}
@@ -1923,18 +1948,16 @@ void PCAProjectionAxes::setPCARange(float p1min, float p2min, float p1max, float
19231948

19241949
}
19251950

1926-
bool PCAProjectionAxes::updateSpikeData(const SpikeObject& s)
1951+
bool PCAProjectionAxes::updateSpikeData(SorterSpikePtr s)
19271952
{
19281953

19291954
if (spikesReceivedSinceLastRedraw < bufferSize)
19301955
{
19311956

1932-
SpikeObject newSpike = s;
1933-
19341957
spikeIndex++;
19351958
spikeIndex %= bufferSize;
19361959

1937-
spikeBuffer.set(spikeIndex, newSpike);
1960+
spikeBuffer.set(spikeIndex, s);
19381961

19391962
spikesReceivedSinceLastRedraw++;
19401963
//drawProjectedSpike(newSpike);
@@ -2197,4 +2220,4 @@ void PCAProjectionAxes::mouseWheelMove(const MouseEvent& event, const MouseWheel
21972220
rangeDown();
21982221
else
21992222
rangeUp();
2200-
}
2223+
}

0 commit comments

Comments
 (0)