Skip to content

Commit 5d880f3

Browse files
authored
Merge pull request #303 from tne-lab/lfpviewer-full-subproc
Really view just one subprocessor in the LFP viewer, and also view events not corresponding to any data channels
2 parents c065a69 + ce9a7ba commit 5d880f3

7 files changed

Lines changed: 262 additions & 338 deletions

File tree

Plugins/LfpDisplayNode/LfpDisplayCanvas.cpp

Lines changed: 33 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -212,68 +212,35 @@ void LfpDisplayCanvas::endAnimation()
212212

213213
void LfpDisplayCanvas::update()
214214
{
215-
if (true)
216-
{
217215
nChans = jmax(processor->getNumSubprocessorChannels(), 0);
218216

219-
std::cout << "Num chans: " << nChans << std::endl;
217+
std::cout << "Num chans: " << nChans << std::endl;
220218

221219
resizeSamplesPerPixelBuffer(nChans);
222220

223-
sampleRate.clear();
224-
screenBufferIndex.clear();
225-
lastScreenBufferIndex.clear();
226-
displayBufferIndex.clear();
221+
sampleRate = 30000; // default
222+
223+
for (auto* arr : { &screenBufferIndex, &lastScreenBufferIndex, &displayBufferIndex })
224+
{
225+
arr->clearQuick();
226+
arr->insertMultiple(0, 0, nChans + 1); // extra channel for events
227+
}
227228

228229
options->setEnabled(nChans != 0);
229230
// must manually ensure that overlapSelection propagates up to canvas
230231
channelOverlapFactor = options->selectedOverlapValue.getFloatValue();
231232

232233
std::cout << "Checking channels: " << nChans << std::endl;
233-
for (int i = 0; i < processor->getNumInputs() + 1; i++) // extra channel for events
234-
{
235-
//std::cout << i << std::endl;
236-
if (processor->getNumInputs() > 0)
237-
{
238-
if (i < processor->getNumInputs())
239-
{
240-
if (processor->getDataChannel(i)->getSubProcessorIdx() == drawableSubprocessor)
241-
{
242-
sampleRate.add(processor->getDataChannel(i)->getSampleRate());
243-
//std::cout << "Adding sample rate " << processor->getDataChannel(i)->getSampleRate() << std::endl;
244-
}
245-
246-
}
247-
else
248-
{
249-
//Since for now the canvas only supports one event channel, find the first TTL one and use that as sampleRate.
250-
//This is a bit hackish and should be fixed for proper multi-ttl-channel support
251234

252-
for (int c = 0; c < processor->getTotalEventChannels(); c++)
253-
{
254-
if (processor->getEventChannel(c)->getChannelType() == EventChannel::TTL)
255-
{
256-
sampleRate.add(processor->getEventChannel(c)->getSampleRate());
257-
std::cout << "Sample rate = " << processor->getEventChannel(c)->getSampleRate() << std::endl;
258-
259-
}
260-
}
261-
}
262-
}
263-
else
235+
for (int i = 0, nInputs = processor->getNumInputs(); i < nInputs; i++)
236+
{
237+
if (processor->getDataSubprocId(i) == drawableSubprocessor)
264238
{
265-
sampleRate.add(30000);
239+
sampleRate = processor->getDataChannel(i)->getSampleRate();
240+
break;
266241
}
267-
268-
// std::cout << "Sample rate for ch " << i << " = " << sampleRate[i] << std::endl;
269-
displayBufferIndex.add(0);
270-
screenBufferIndex.add(0);
271-
lastScreenBufferIndex.add(0);
272242
}
273243

274-
lfpDisplay->setDisplayedSampleRate(sampleRate[0]); // only one sample rate possible for now
275-
std::cout << "Setting display sample rate to " << sampleRate[0] << std::endl;
276-
277244
std::cout << "Checking channel alignment: " << nChans << std::endl;
278245
if (nChans != lfpDisplay->getNumChannels())
279246
{
@@ -319,8 +286,6 @@ void LfpDisplayCanvas::update()
319286
lfpDisplay->rebuildDrawableChannelsList();
320287
}
321288
}
322-
323-
}
324289
}
325290

326291

@@ -410,7 +375,7 @@ void LfpDisplayCanvas::updateScreenBuffer()
410375
// std::cout << channel << " " << sbi << " " << dbi << " " << nSamples << std::endl;
411376

412377

413-
float ratio = sampleRate[channel] * timebase / float(getWidth() - leftmargin - scrollBarThickness); // samples / pixel
378+
float ratio = sampleRate * timebase / float(getWidth() - leftmargin - scrollBarThickness); // samples / pixel
414379
// this number is crucial: converting from samples to values (in px) for the screen buffer
415380
int valuesNeeded = (int) float(nSamples) / ratio; // N pixels needed for this update
416381

@@ -658,24 +623,16 @@ bool LfpDisplayCanvas::getDrawMethodState()
658623
return options->getDrawMethodState(); //drawMethodButton->getToggleState();
659624
}
660625

661-
int LfpDisplayCanvas::getChannelSampleRate(int channel)
662-
{
663-
return sampleRate[channel];
664-
}
665-
666626
void LfpDisplayCanvas::setDrawableSampleRate(float samplerate)
667627
{
668628
// std::cout << "setting the drawable sample rate in the canvas" << std::endl;
669629
displayedSampleRate = samplerate;
670-
lfpDisplay->setDisplayedSampleRate(samplerate);
671630
}
672631

673-
void LfpDisplayCanvas::setDrawableSubprocessor(int idx)
632+
void LfpDisplayCanvas::setDrawableSubprocessor(uint32 sp)
674633
{
675-
drawableSubprocessor = idx;
676-
lfpDisplay->setDisplayedSubprocessor(idx);
677-
std::cout << "Setting LFP canvas subprocessor to " << idx << std::endl;
678-
processor->setSubprocessor(idx);
634+
drawableSubprocessor = sp;
635+
std::cout << "Setting LFP canvas subprocessor to " << sp << std::endl;
679636
update();
680637
}
681638

@@ -887,7 +844,7 @@ LfpDisplayOptions::LfpDisplayOptions(LfpDisplayCanvas* canvas_, LfpTimescale* ti
887844
voltageRanges[DataChannel::AUX_CHANNEL].add("2000");
888845
//voltageRanges[DataChannel::AUX_CHANNEL].add("5000");
889846
selectedVoltageRange[DataChannel::AUX_CHANNEL] = 9;
890-
rangeGain[DataChannel::AUX_CHANNEL] = 0.001; //mV
847+
rangeGain[DataChannel::AUX_CHANNEL] = 0.001f; //mV
891848
rangeSteps[DataChannel::AUX_CHANNEL] = 10;
892849
rangeUnits.add("mV");
893850
typeNames.add("AUX");
@@ -1493,7 +1450,7 @@ void LfpDisplayOptions::buttonClicked(Button* b)
14931450

14941451
if ((idx >= 0) && (b->getToggleState()))
14951452
{
1496-
for (int i = 0; i < processor->getNumInputs(); i++)
1453+
for (int i = 0; i < lfpDisplay->getNumChannels(); i++)
14971454
{
14981455
if (lfpDisplay->channels[i]->getSelected())
14991456
{
@@ -2172,7 +2129,7 @@ void LfpTimescale::setTimebase(float t)
21722129
if (labelIncrement < 0.2)
21732130
labelIncrement *= 2;
21742131
else
2175-
labelIncrement += 0.2;
2132+
labelIncrement += 0.2f;
21762133
}
21772134

21782135
for (float i = labelIncrement; i < timebase; i += labelIncrement)
@@ -2634,31 +2591,6 @@ void LfpDisplay::cacheNewChannelHeight(int r)
26342591
cachedDisplayChannelHeight = r;
26352592
}
26362593

2637-
float LfpDisplay::getDisplayedSampleRate()
2638-
{
2639-
return drawableSampleRate;
2640-
}
2641-
2642-
// Must manually call rebuildDrawableChannelsList after this is set, typically will happen
2643-
// already as a result of some other procedure
2644-
void LfpDisplay::setDisplayedSampleRate(float samplerate)
2645-
{
2646-
std::cout << "Setting the displayed samplerate for LfpDisplayCanvas to " << samplerate << std::endl;
2647-
drawableSampleRate = samplerate;
2648-
}
2649-
2650-
int LfpDisplay::getDisplayedSubprocessor()
2651-
{
2652-
return drawableSubprocessorIdx;
2653-
}
2654-
2655-
void LfpDisplay::setDisplayedSubprocessor(int subProcessorIdx)
2656-
{
2657-
drawableSubprocessorIdx = subProcessorIdx;
2658-
refresh();
2659-
2660-
}
2661-
26622594
bool LfpDisplay::getChannelsReversed()
26632595
{
26642596
return channelsReversed;
@@ -2673,7 +2605,7 @@ void LfpDisplay::setChannelsReversed(bool state)
26732605
if (getSingleChannelState()) return; // don't reverse if single channel
26742606

26752607
// reverse channels that are currently in drawableChannels
2676-
for (size_t i = 0, j = drawableChannels.size() - 1, len = drawableChannels.size()/2;
2608+
for (int i = 0, j = drawableChannels.size() - 1, len = drawableChannels.size()/2;
26772609
i < len;
26782610
i++, j--)
26792611
{
@@ -2708,7 +2640,7 @@ void LfpDisplay::setChannelsReversed(bool state)
27082640
}
27092641

27102642
// add the channels and channel info again
2711-
for (size_t i = 0, len = drawableChannels.size(); i < len; i++)
2643+
for (int i = 0, len = drawableChannels.size(); i < len; i++)
27122644
{
27132645

27142646
if (!drawableChannels[i].channel->getHidden())
@@ -2890,8 +2822,8 @@ void LfpDisplay::toggleSingleChannel(int chan)
28902822
}
28912823

28922824
// update drawableChannels, give only the single channel to focus on
2893-
Array<LfpChannelTrack> channelsToDraw{lfpChannelTrack};
2894-
drawableChannels = channelsToDraw;
2825+
drawableChannels.clearQuick();
2826+
drawableChannels.add(lfpChannelTrack);
28952827

28962828
addAndMakeVisible(lfpChannelTrack.channel);
28972829
addAndMakeVisible(lfpChannelTrack.channelInfo);
@@ -2940,7 +2872,7 @@ void LfpDisplay::rebuildDrawableChannelsList()
29402872
drawableChannels = Array<LfpDisplay::LfpChannelTrack>();
29412873

29422874
// iterate over all channels and select drawable ones
2943-
for (size_t i = 0, drawableChannelNum = 0; i < channels.size(); i++)
2875+
for (int i = 0, drawableChannelNum = 0; i < channels.size(); i++)
29442876
{
29452877
// std::cout << "\tchannel " << i << " has subprocessor index of " << channelInfo[i]->getSubprocessorIdx() << std::endl;
29462878
// if channel[i] is not sourced from the correct subprocessor, then hide it and continue
@@ -3279,7 +3211,7 @@ void LfpChannelDisplay::pxPaint()
32793211
//draw zero line
32803212
int m = getY()+center;
32813213

3282-
if(m > 0 & m < display->lfpChannelBitmap.getHeight())
3214+
if(m > 0 && m < display->lfpChannelBitmap.getHeight())
32833215
{
32843216
if ( bdLfpChannelBitmap.getPixelColour(i,m) == display->backgroundColour ) { // make sure we're not drawing over an existing plot from another channel
32853217
bdLfpChannelBitmap.setPixelColour(i,m,Colour(50,50,50));
@@ -3294,7 +3226,7 @@ void LfpChannelDisplay::pxPaint()
32943226

32953227
for (m = start; m <= start + jump*4; m += jump)
32963228
{
3297-
if (m > 0 & m < display->lfpChannelBitmap.getHeight())
3229+
if (m > 0 && m < display->lfpChannelBitmap.getHeight())
32983230
{
32993231
if ( bdLfpChannelBitmap.getPixelColour(i,m) == display->backgroundColour ) // make sure we're not drawing over an existing plot from another channel
33003232
bdLfpChannelBitmap.setPixelColour(i, m, Colour(80,80,80));
@@ -3431,7 +3363,7 @@ void LfpChannelDisplay::pxPaint()
34313363
{
34323364
int clipmarker = jto_wholechannel_clip;
34333365

3434-
if(clipmarker>0 & clipmarker<display->lfpChannelBitmap.getHeight()){
3366+
if(clipmarker>0 && clipmarker<display->lfpChannelBitmap.getHeight()){
34353367
bdLfpChannelBitmap.setPixelColour(i,clipmarker-j,Colour(255,255,255));
34363368
}
34373369
}
@@ -3442,7 +3374,7 @@ void LfpChannelDisplay::pxPaint()
34423374
{
34433375
int clipmarker = jfrom_wholechannel_clip;
34443376

3445-
if(clipmarker>0 & clipmarker<display->lfpChannelBitmap.getHeight()){
3377+
if(clipmarker>0 && clipmarker<display->lfpChannelBitmap.getHeight()){
34463378
bdLfpChannelBitmap.setPixelColour(i,clipmarker+j,Colour(255,255,255));
34473379
}
34483380
}
@@ -3455,7 +3387,7 @@ void LfpChannelDisplay::pxPaint()
34553387
if (spikeFlag) // draw spikes
34563388
{
34573389
for (int k=jfrom_wholechannel; k<=jto_wholechannel; k++){ // draw line
3458-
if(k>0 & k<display->lfpChannelBitmap.getHeight()){
3390+
if(k>0 && k<display->lfpChannelBitmap.getHeight()){
34593391
bdLfpChannelBitmap.setPixelColour(i,k,lineColour);
34603392
}
34613393
};
@@ -3473,7 +3405,7 @@ void LfpChannelDisplay::pxPaint()
34733405
if (fmod((i+k),50)>25){
34743406
thiscolour=Colour(255,255,255);
34753407
}
3476-
if(k>0 & k<display->lfpChannelBitmap.getHeight()){
3408+
if(k>0 && k<display->lfpChannelBitmap.getHeight()){
34773409
bdLfpChannelBitmap.setPixelColour(i,k,thiscolour);
34783410
}
34793411
};
@@ -4059,7 +3991,7 @@ void SupersampledBitmapPlotter::plot(Image::BitmapData &bdLfpChannelBitmap, LfpB
40593991
// int sampleCountThisPixel = lfpDisplay->canvas->getSampleCountPerPixel(pInfo.samp);
40603992
int sampleCountThisPixel = pInfo.sampleCountPerPixel;
40613993

4062-
if (pInfo.samplerange>0 & sampleCountThisPixel>0)
3994+
if (pInfo.samplerange>0 && sampleCountThisPixel>0)
40633995
{
40643996

40653997
//float localHist[samplerange]; // simple histogram
@@ -4113,7 +4045,7 @@ void SupersampledBitmapPlotter::plot(Image::BitmapData &bdLfpChannelBitmap, LfpB
41134045
//Colour gradedColor = Colour(0,255,0);
41144046

41154047
int ploty = pInfo.from + s + pInfo.y;
4116-
if(ploty>0 & ploty < display->lfpChannelBitmap.getHeight()) {
4048+
if(ploty>0 && ploty < display->lfpChannelBitmap.getHeight()) {
41174049
bdLfpChannelBitmap.setPixelColour(pInfo.samp, pInfo.from + s + pInfo.y, gradedColor);
41184050
}
41194051
}

Plugins/LfpDisplayNode/LfpDisplayCanvas.h

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ class LfpDisplayCanvas : public Visualizer,
119119
/** Returns the subprocessor index of the given channel */
120120
int getChannelSubprocessorIdx(int channel);
121121

122-
/** Delegates a subprocessor index for drawing to the LfpDisplay referenced by this
122+
/** Delegates a subprocessor for drawing to the LfpDisplay referenced by this
123123
this canvas */
124-
void setDrawableSubprocessor(int idx);
124+
void setDrawableSubprocessor(uint32 sp);
125125

126126
const float getXCoord(int chan, int samp);
127127
const float getYCoord(int chan, int samp);
@@ -168,15 +168,15 @@ class LfpDisplayCanvas : public Visualizer,
168168

169169
private:
170170

171-
Array<float> sampleRate;
171+
float sampleRate;
172172

173173
bool optionsDrawerIsOpen;
174174

175175
float displayGain;
176176
float timeOffset;
177177
//int spread ; // vertical spacing between channels
178178

179-
int drawableSubprocessor;
179+
uint32 drawableSubprocessor;
180180
float displayedSampleRate;
181181

182182
//float waves[MAX_N_CHAN][MAX_N_SAMP*2]; // we need an x and y point for each sample
@@ -502,24 +502,7 @@ class LfpDisplay : public Component
502502
int getChannelHeight();
503503

504504
LfpChannelColourScheme * getColourSchemePtr();
505-
506-
/** Returns the sample rate that is currently filtering the drawable channels */
507-
float getDisplayedSampleRate();
508-
509-
/** Sets the samplerate that displayed channels must be set to. No channels with
510-
differing samplerates will be drawn to screen.
511-
512-
This function does not automatically repopulate the drawableChannels list, so
513-
rebuildDrawableChannelsList must be called before the screen is updated.
514-
515-
@see LfpDisplayCanvas::setDrawableSampleRate, LfpDisplayNode::updateSettings
516-
*/
517-
void setDisplayedSampleRate(float samplerate);
518-
519-
int getDisplayedSubprocessor();
520-
521-
void setDisplayedSubprocessor(int subProcessorIdx);
522-
505+
523506
/** Caches a new channel height without updating the channels */
524507
void cacheNewChannelHeight(int r);
525508

@@ -647,7 +630,7 @@ class LfpDisplay : public Component
647630
int displaySkipAmt;
648631
int cachedDisplayChannelHeight; // holds a channel height if reset during single channel focus
649632
float drawableSampleRate;
650-
int drawableSubprocessorIdx;
633+
uint32 drawableSubprocessor;
651634

652635
int totalHeight;
653636

0 commit comments

Comments
 (0)