Skip to content

Commit a46bc77

Browse files
committed
Display range marker values in single-channel view in LFP Viewer
1 parent fc6d246 commit a46bc77

3 files changed

Lines changed: 65 additions & 6 deletions

File tree

Plugins/LfpViewer/LfpChannelDisplay.cpp

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@
4141

4242
using namespace LfpViewer;
4343

44+
namespace
45+
{
46+
String formatRangeMarkerValue (float value)
47+
{
48+
if (std::abs (value) < 0.005f)
49+
{
50+
return "0";
51+
}
52+
53+
const float magnitude = std::abs (value);
54+
const int decimals = magnitude >= 100.0f ? 0 : magnitude >= 10.0f ? 1
55+
: 2;
56+
57+
return String (value, decimals);
58+
}
59+
} // namespace
60+
4461
LfpChannelDisplay::LfpChannelDisplay (LfpDisplaySplitter* c, LfpDisplay* d, LfpDisplayOptions* o, int channelNumber)
4562
: canvasSplit (c), display (d), options (o), isSelected (false), isRecorded (false), recordingIsActive (false), chan (channelNumber), name (""), drawableChan (channelNumber), channelOverlap (300), channelHeight (30), range (250.0f), isEnabled (true), inputInverted (false), canBeInverted (true), drawMethod (false), isHidden (false), ifrom (0), ito (0), ifrom_local (0), ito_local (0)
4663
{
@@ -178,6 +195,8 @@ void LfpChannelDisplay::pxPaint()
178195

179196
LfpBitmapPlotterInfo plotterInfo; // hold and pass plotting info for each plotting method class
180197

198+
const bool showRangeMarkers = isSelected || display->getSingleChannelState();
199+
181200
for (int ii = ifrom; ii <= endIndex; ii++)
182201
{
183202
int i = (ifrom_local + ii - ifrom) % getWidth();
@@ -192,7 +211,7 @@ void LfpChannelDisplay::pxPaint()
192211
}
193212

194213
//draw range markers
195-
if (isSelected)
214+
if (showRangeMarkers)
196215
{
197216
int start = getY() + center - channelHeight / 2;
198217
int jump = channelHeight / 4;
@@ -433,6 +452,8 @@ void LfpChannelDisplay::pxPaintHistory (int playhead, int rightEdge, int maxScre
433452

434453
LfpBitmapPlotterInfo plotterInfo; // hold and pass plotting info for each plotting method class
435454

455+
const bool showRangeMarkers = isSelected || display->getSingleChannelState();
456+
436457
for (int ii = 0; ii < rightEdge; ii++)
437458
{
438459
int i = ii;
@@ -478,7 +499,7 @@ void LfpChannelDisplay::pxPaintHistory (int playhead, int rightEdge, int maxScre
478499
}
479500

480501
//draw range markers
481-
if (isSelected)
502+
if (showRangeMarkers)
482503
{
483504
int start = getY() + center - channelHeight / 2;
484505
int jump = channelHeight / 4;
@@ -675,7 +696,43 @@ void LfpChannelDisplay::drawEventOverlay (const int rawEventState, int x, int yf
675696
}
676697
}
677698

678-
void LfpChannelDisplay::paint (Graphics& g) {}
699+
void LfpChannelDisplay::paint (Graphics& g)
700+
{
701+
if (! display->getSingleChannelState() || getWidth() < 80 || getHeight() == 0)
702+
{
703+
return;
704+
}
705+
706+
const int center = getHeight() / 2;
707+
const int start = center - channelHeight / 2;
708+
const int jump = channelHeight / 4;
709+
710+
if (jump <= 0)
711+
{
712+
return;
713+
}
714+
715+
const int labelWidth = 50;
716+
const int textHeight = 16;
717+
const int labelX = getWidth() - labelWidth - 8;
718+
const float markerSign = inputInverted ? -1.0f : 1.0f;
719+
720+
g.setFont (FontOptions (12.0f));
721+
722+
for (const int markerIndex : { 1, 3 })
723+
{
724+
const int markerY = start + jump * markerIndex;
725+
const float markerValue = markerSign * range * (0.5f - 0.25f * markerIndex);
726+
const String markerText = formatRangeMarkerValue (markerValue);
727+
const int textY = jlimit (0, jmax (0, getHeight() - textHeight), markerY - textHeight / 2);
728+
729+
g.setColour (Colours::black.withAlpha (0.55f));
730+
g.fillRoundedRectangle ((float) labelX, (float) textY, (float) labelWidth, (float) textHeight, 3.0f);
731+
732+
g.setColour (Colours::lightgrey.withAlpha (0.95f));
733+
g.drawFittedText (markerText, labelX + 4, textY, labelWidth - 8, textHeight, Justification::centredRight, 1, 0.8f);
734+
}
735+
}
679736

680737
PopupMenu LfpChannelDisplay::getOptions()
681738
{
@@ -702,6 +759,7 @@ void LfpChannelDisplay::changeParameter (int id)
702759
void LfpChannelDisplay::setRange (float r)
703760
{
704761
range = r;
762+
repaint();
705763
}
706764

707765
float LfpChannelDisplay::getRange()
@@ -742,6 +800,7 @@ void LfpChannelDisplay::setChannelHeight (int c)
742800
channelHeightFloat = -channelHeightFloat;
743801

744802
channelOverlap = channelHeight * 2;
803+
repaint();
745804
}
746805

747806
int LfpChannelDisplay::getChannelHeight()

Plugins/LfpViewer/LfpDisplay.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,10 +1344,10 @@ void LfpDisplay::mouseDown (const MouseEvent& event)
13441344
{
13451345
if (event.getNumberOfClicks() == 2)
13461346
{
1347+
drawableChannels[closest].channelInfo->updateXY (0, 0); // reset mouse-selected point
13471348
toggleSingleChannel (drawableChannels[closest]);
13481349
}
1349-
1350-
if (getSingleChannelState()) // show info for point that was selected
1350+
else if (getSingleChannelState()) // show info for point that was selected
13511351
{
13521352
drawableChannels[0].channelInfo->updateXY (
13531353
float (x) / getWidth() * canvasSplit->timebase,

Plugins/LfpViewer/LfpDisplayCanvas.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ void LfpDisplaySplitter::refreshLeftMargin()
762762

763763
if (displayBuffer != nullptr)
764764
{
765-
const auto labelFont = Font (FontOptions (14.0f));
765+
const auto labelFont = Font (FontOptions (16.0f));
766766
constexpr int padding = 20;
767767

768768
for (int i = 0; i < displayBuffer->channelMetadata.size(); ++i)

0 commit comments

Comments
 (0)