Skip to content

Commit 42c7b9b

Browse files
committed
Merge branch 'development-juce8' of https://github.com/open-ephys/plugin-GUI into development-juce8
2 parents 178a313 + de76dc3 commit 42c7b9b

File tree

8 files changed

+102
-52
lines changed

8 files changed

+102
-52
lines changed

Plugins/LfpViewer/LfpChannelDisplay.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void LfpChannelDisplay::pxPaint()
224224
double a = (canvasSplit->getYCoordMax (chan, index) / range * channelHeightFloat);
225225
double b = (canvasSplit->getYCoordMin (chan, index) / range * channelHeightFloat);
226226

227-
double mean = (canvasSplit->getMean (chan) / range * channelHeightFloat);
227+
double mean = (canvasSplit->getScreenBufferMean (chan) / range * channelHeightFloat);
228228

229229
if (drawWithOffsetCorrection)
230230
{
@@ -527,7 +527,7 @@ void LfpChannelDisplay::pxPaintHistory (int playhead, int rightEdge, int maxScre
527527
double a = (canvasSplit->getYCoordMax (chan, index) / range * channelHeightFloat);
528528
double b = (canvasSplit->getYCoordMin (chan, index) / range * channelHeightFloat);
529529

530-
double mean = (canvasSplit->getMean (chan) / range * channelHeightFloat);
530+
double mean = (canvasSplit->getScreenBufferMean (chan) / range * channelHeightFloat);
531531

532532
if (drawWithOffsetCorrection)
533533
{

Plugins/LfpViewer/LfpChannelDisplayInfo.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ LfpChannelDisplayInfo::LfpChannelDisplayInfo (LfpDisplaySplitter* canvas_, LfpDi
4747
: LfpChannelDisplay (canvas_, display_, options_, ch),
4848
x (-1.0f),
4949
y (-1.0f),
50+
rms (0.0f),
51+
mean (0.0f),
5052
isSingleChannel (false)
5153
{
5254
enableButton = std::make_unique<UtilityButton> ("");
@@ -213,11 +215,16 @@ void LfpChannelDisplayInfo::paint (Graphics& g)
213215
: getName());
214216
bool isCentered = ! getEnabledButtonVisibility();
215217

218+
if (isSingleChannel)
219+
g.setFont (FontOptions (16.0f).withStyle ("SemiBold"));
220+
else
221+
g.setFont (FontOptions (14.0f));
222+
216223
g.drawText (channelString,
217-
showChannelNumbers ? 6 : 2,
224+
showChannelNumbers ? 6 : 3,
218225
center - 4,
219226
getWidth(),
220-
10,
227+
12,
221228
isCentered ? Justification::centred : Justification::centredLeft,
222229
false);
223230

@@ -227,29 +234,25 @@ void LfpChannelDisplayInfo::paint (Graphics& g)
227234
if (getChannelTypeStringVisibility())
228235
{
229236
g.setFont (FontOptions (13.0f));
230-
g.drawText (typeStr, 5, center + 10, 41, 10, Justification::centred, false);
237+
g.drawText (typeStr, 5, center + 10, 50, 14, Justification::centred, false);
231238
}
232239

233-
g.setFont (FontOptions (11.0f));
234-
235240
if (isSingleChannel)
236241
{
237-
g.setColour (Colours::darkgrey);
238-
g.drawText ("STD:", 5, center + 90, 41, 10, Justification::centred, false);
239-
g.drawText ("MEAN:", 5, center + 40, 41, 10, Justification::centred, false);
242+
g.setColour (Colours::grey);
243+
g.setFont (FontOptions (13.0f));
240244

241-
if (x > 0)
242-
{
243-
g.drawText ("uV:", 5, center + 140, 41, 10, Justification::centred, false);
244-
}
245+
g.drawText ("MEAN:", 5, center + 40, 50, 12, Justification::centred, false);
246+
g.drawText (String (mean, 2), 5, center + 60, 50, 12, Justification::centred, false);
245247

246-
g.setColour (Colours::grey);
247-
g.drawText (String (canvasSplit->getStd (chan)), 5, center + 110, 41, 10, Justification::centred, false);
248-
g.drawText (String (canvasSplit->getMean (chan)), 5, center + 60, 41, 10, Justification::centred, false);
248+
g.drawText (String (rms, 2), 5, center + 110, 50, 12, Justification::centred, false);
249+
g.drawText ("RMS:", 5, center + 90, 50, 12, Justification::centred, false);
249250

250251
if (x > 0)
251252
{
252-
g.drawText (String (y), 5, center + 160, 41, 10, Justification::centred, false);
253+
g.setColour (Colours::darkgrey);
254+
g.drawText ("uV:", 5, center + 140, 50, 12, Justification::centred, false);
255+
g.drawText (String (y, 2), 5, center + 160, 50, 10, Justification::centred, false);
253256
}
254257
}
255258
}
@@ -260,6 +263,14 @@ void LfpChannelDisplayInfo::updateXY (float x_, float y_)
260263
y = y_;
261264
}
262265

266+
void LfpChannelDisplayInfo::updateMeanAndRMS()
267+
{
268+
rms = canvasSplit->getRMS (chan);
269+
mean = canvasSplit->getDisplayBufferMean (chan);
270+
271+
repaint();
272+
}
273+
263274
void LfpChannelDisplayInfo::resized()
264275
{
265276
int center = getHeight() / 2 - (isSingleChannel ? (75) : (0));

Plugins/LfpViewer/LfpChannelDisplayInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class LfpChannelDisplayInfo : public LfpChannelDisplay,
7575
/** Updates the position of this component*/
7676
void updateXY (float, float);
7777

78+
/** Updates the mean and RMS values of the channel */
79+
void updateMeanAndRMS();
80+
7881
/** Sets whether this channel is in single-channel mode */
7982
void setSingleChannelState (bool);
8083

@@ -94,6 +97,9 @@ class LfpChannelDisplayInfo : public LfpChannelDisplay,
9497
bool isSingleChannel;
9598
float x, y;
9699

100+
float rms;
101+
float mean;
102+
97103
int samplerate;
98104
int subProcessorIdx;
99105

Plugins/LfpViewer/LfpDisplay.cpp

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@ using namespace LfpViewer;
5656
// ---------------------------------------------------------------
5757

5858
LfpDisplay::LfpDisplay (LfpDisplaySplitter* c, Viewport* v)
59-
: singleChan (-1), canvasSplit (c), viewport (v), channelsReversed (false), channelsOrderedByDepth (false), displaySkipAmt (0), m_SpikeRasterPlottingFlag (false), lastBitmapIndex (0), lastFillFrom (-1)
59+
: singleChan (-1),
60+
canvasSplit (c),
61+
viewport (v),
62+
channelsReversed (false),
63+
channelsOrderedByDepth (false),
64+
displaySkipAmt (0),
65+
m_SpikeRasterPlottingFlag (false),
66+
lastBitmapIndex (0),
67+
lastFillFrom (-1),
68+
totalPixelsFilled (0)
6069
{
6170
perPixelPlotter = std::make_unique<PerPixelBitmapPlotter> (this);
6271
supersampledPlotter = std::make_unique<SupersampledBitmapPlotter> (this);
@@ -351,6 +360,7 @@ void LfpDisplay::sync()
351360
if (! displayIsPaused)
352361
{
353362
lastBitmapIndex = 0;
363+
totalPixelsFilled = 0;
354364
}
355365
}
356366

@@ -397,15 +407,15 @@ void LfpDisplay::refresh()
397407

398408
lfpChannelBitmap.clear (Rectangle<int> (0, 0, totalXPixels, totalYPixels));
399409

400-
for (int i = 0; i < numChans; i++)
410+
for (int i = 0; i < drawableChannels.size(); i++)
401411
{
402-
int componentTop = channels[i]->getY();
403-
int componentBottom = channels[i]->getHeight() + componentTop;
412+
int componentTop = drawableChannels[i].channel->getY();
413+
int componentBottom = drawableChannels[i].channel->getBottom();
404414

405415
if ((topBorder <= componentBottom && bottomBorder >= componentTop)) // only draw things that are visible
406416
{
407-
channels[i]->pxPaintHistory (playhead, rightEdge, maxScreenBufferIndex);
408-
channelInfo[i]->repaint();
417+
drawableChannels[i].channel->pxPaintHistory (playhead, rightEdge, maxScreenBufferIndex);
418+
drawableChannels[i].channelInfo->repaint();
409419
}
410420
}
411421

@@ -450,15 +460,15 @@ void LfpDisplay::refresh()
450460

451461
lfpChannelBitmap.clear (Rectangle<int> (0, 0, totalXPixels, totalYPixels));
452462

453-
for (int i = 0; i < numChans; i++)
463+
for (int i = 0; i < drawableChannels.size(); i++)
454464
{
455-
int componentTop = channels[i]->getY();
456-
int componentBottom = channels[i]->getHeight() + componentTop;
465+
int componentTop = drawableChannels[i].channel->getY();
466+
int componentBottom = drawableChannels[i].channel->getBottom();
457467

458468
if ((topBorder <= componentBottom && bottomBorder >= componentTop)) // only draw things that are visible
459469
{
460-
channels[i]->pxPaintHistory (playhead, rightEdge, maxScreenBufferIndex);
461-
channelInfo[i]->repaint();
470+
drawableChannels[i].channel->pxPaintHistory (playhead, rightEdge, maxScreenBufferIndex);
471+
drawableChannels[i].channelInfo->repaint();
462472
}
463473
}
464474

@@ -518,22 +528,25 @@ void LfpDisplay::refresh()
518528
}
519529
}
520530

521-
for (int i = 0; i < numChans; i++)
531+
for (int i = 0; i < drawableChannels.size(); i++)
522532
{
523-
int componentTop = channels[i]->getY();
524-
int componentBottom = channels[i]->getHeight() + componentTop;
533+
int componentTop = drawableChannels[i].channel->getY();
534+
int componentBottom = drawableChannels[i].channel->getBottom();
525535

526536
if ((topBorder <= componentBottom && bottomBorder >= componentTop)) // only draw things that are visible
527537
{
528-
channels[i]->pxPaint(); // draws to lfpChannelBitmap
538+
drawableChannels[i].channel->pxPaint(); // draws to lfpChannelBitmap
529539
}
530540
}
531541

532542
repaint();
533543

534-
if (fillfrom_local == 0 && singleChan != -1)
544+
totalPixelsFilled += totalPixelsToFill;
545+
546+
if (totalPixelsFilled > (totalXPixels / (2 * canvasSplit->timebase)) && singleChan != -1)
535547
{
536-
channelInfo[singleChan]->repaint();
548+
channelInfo[singleChan]->updateMeanAndRMS();
549+
totalPixelsFilled = 0;
537550
}
538551

539552
lastBitmapIndex += totalPixelsToFill;

Plugins/LfpViewer/LfpDisplay.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ class LfpDisplay : public Component,
293293
/** x-index of display bitmap updated on previous refresh */
294294
int lastBitmapIndex;
295295

296+
/** total number of pixels filled in the display bitmap
297+
* (used to update RMS and Mean values in single channel display mode) */
298+
int totalPixelsFilled;
299+
296300
private:
297301
/** Used to throttle refresh speed when scrolling backwards */
298302
void timerCallback() override;

Plugins/LfpViewer/LfpDisplayCanvas.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,16 +1529,15 @@ uint16 LfpDisplaySplitter::getChannelStreamId (int channel)
15291529
return processor->getContinuousChannel (channel)->getStreamId();
15301530
}
15311531

1532-
float LfpDisplaySplitter::getMean (int chan)
1532+
float LfpDisplaySplitter::getScreenBufferMean (int chan)
15331533
{
15341534
float total = 0.0f;
15351535
float numPts = 0;
1536+
int sbi = screenBufferIndex[chan];
15361537

1537-
float sample = 0.0f;
15381538
for (int samp = 0; samp < (lfpDisplay->getWidth() - leftmargin); samp += 10)
15391539
{
1540-
sample = *screenBufferMean->getReadPointer (chan, samp);
1541-
total += sample;
1540+
total += screenBufferMean->getSample (chan, (sbi - samp + screenBufferWidth) % screenBufferWidth);
15421541
numPts++;
15431542
}
15441543

@@ -1547,20 +1546,34 @@ float LfpDisplaySplitter::getMean (int chan)
15471546
return total / numPts;
15481547
}
15491548

1550-
float LfpDisplaySplitter::getStd (int chan)
1549+
float LfpDisplaySplitter::getDisplayBufferMean (int chan)
15511550
{
1552-
float std = 0.0f;
1551+
float total = 0.0f;
1552+
float numPts = 0;
1553+
int dbi = displayBufferIndex[chan];
15531554

1554-
float mean = getMean (chan);
1555-
float numPts = 1;
1555+
for (int i = 0; i < displayBufferSize / 2; i += 2)
1556+
{
1557+
total += displayBuffer->getSample (chan, (dbi - i + displayBufferSize) % displayBufferSize);
1558+
numPts++;
1559+
}
15561560

1557-
for (int samp = 0; samp < (lfpDisplay->getWidth() - leftmargin); samp += 10)
1561+
return total / numPts;
1562+
}
1563+
1564+
float LfpDisplaySplitter::getRMS (int chan)
1565+
{
1566+
float rms = 0.0f;
1567+
float numPts = 0;
1568+
int dbi = displayBufferIndex[chan];
1569+
1570+
for (int i = 0; i < displayBufferSize / 2; i += 2)
15581571
{
1559-
std += pow ((*screenBufferMean->getReadPointer (chan, samp) - mean), 2);
1572+
rms += pow (displayBuffer->getSample (chan, (dbi - i + displayBufferSize) % displayBufferSize), 2);
15601573
numPts++;
15611574
}
15621575

1563-
return sqrt (std / numPts);
1576+
return sqrt (rms / numPts);
15641577
}
15651578

15661579
bool LfpDisplaySplitter::getInputInvertedState()
@@ -1618,7 +1631,7 @@ void LfpDisplaySplitter::paint (Graphics& g)
16181631
if (! canvas->makeRoomForOptions (splitID))
16191632
g.drawRect (0, 0, getWidth(), getHeight(), 2);
16201633
else
1621-
g.drawRect (0, 0, getWidth(), getHeight() - 55, 2);
1634+
g.drawRect (0, 0, getWidth(), getHeight() - 60, 2);
16221635

16231636
g.fillRect (2, 2, getWidth() - 4, 28);
16241637
}

Plugins/LfpViewer/LfpDisplayCanvas.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,14 @@ class LfpDisplaySplitter : public Component,
270270
/** Gets the event channel state for a particular sample */
271271
const float getEventState (int samp);
272272

273-
/** Returns the mean of a given channel */
274-
float getMean (int chan);
273+
/** Returns the screen buffer's mean of a given channel */
274+
float getScreenBufferMean (int chan);
275+
276+
/** Returns the display buffer's mean of a given channel */
277+
float getDisplayBufferMean (int chan);
275278

276279
/** Returns the standard deviation of a given channnel*/
277-
float getStd (int chan);
280+
float getRMS (int chan);
278281

279282
/** Sets the channel to use for display triggering */
280283
void setTriggerChannel (int);

Source/MainWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ void MainWindow::saveWindowBounds()
400400
XmlElement* bounds = new XmlElement ("BOUNDS");
401401
bounds->setAttribute ("x", documentWindow->getScreenX());
402402
bounds->setAttribute ("y", documentWindow->getScreenY());
403-
bounds->setAttribute ("w", documentWindow->getContentComponent()->getWidth());
404-
bounds->setAttribute ("h", documentWindow->getContentComponent()->getHeight());
403+
bounds->setAttribute ("w", documentWindow->getWidth());
404+
bounds->setAttribute ("h", documentWindow->getHeight());
405405
bounds->setAttribute ("fullscreen", documentWindow->isFullScreen());
406406

407407
xml->addChildElement (bounds);

0 commit comments

Comments
 (0)