Skip to content

Commit 41b6d18

Browse files
committed
Add option to view channel depth values in LFP Viewer
1 parent 575de13 commit 41b6d18

5 files changed

Lines changed: 139 additions & 82 deletions

File tree

Plugins/LfpViewer/LfpChannelDisplayInfo.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ bool shouldDrawDenseChannelLabel (const int channelHeight, const int drawableCha
5353

5454
return (drawableChannelNumber + 1) % 10 == 0;
5555
}
56+
57+
String getChannelLabelString (LfpChannelDisplay& channel, LfpDisplayOptions::ChannelLabelDisplayMode labelMode)
58+
{
59+
switch (labelMode)
60+
{
61+
case LfpDisplayOptions::ChannelLabelDisplayMode::Number:
62+
return String (channel.getChannelNumber() + 1);
63+
64+
case LfpDisplayOptions::ChannelLabelDisplayMode::Depth:
65+
return channel.hasYposMetadata() ? String (roundToInt (channel.getDepth())) + " μm" : "-";
66+
67+
case LfpDisplayOptions::ChannelLabelDisplayMode::Name:
68+
default:
69+
return channel.getName();
70+
}
71+
}
5672
} // namespace
5773

5874
#pragma mark - LfpChannelDisplayInfo -
@@ -208,7 +224,8 @@ void LfpChannelDisplayInfo::paint (Graphics& g)
208224
if (display->options == nullptr)
209225
return;
210226

211-
const bool showChannelNumbers = display->options->getChannelNameState();
227+
const auto channelLabelDisplayMode = display->options->getChannelLabelDisplayMode();
228+
const bool showNumericChannelLabels = channelLabelDisplayMode != LfpDisplayOptions::ChannelLabelDisplayMode::Name;
212229
const int channelHeight = display->getChannelHeight();
213230
const bool isCentered = ! isSingleChannel && channelHeight < 15;
214231

@@ -223,26 +240,13 @@ void LfpChannelDisplayInfo::paint (Graphics& g)
223240
g.setFont (isSingleChannel ? FontOptions (16.0f).withStyle ("SemiBold")
224241
: FontOptions (14.0f));
225242

226-
String channelString = drawChannelLabel ? (showChannelNumbers ? String (channel->getChannelNumber() + 1)
227-
: channel->getName())
228-
: "--";
229-
230-
if (drawChannelLabel)
231-
{
232-
if (showChannelNumbers)
233-
channelString = String (channel->getChannelNumber() + 1);
234-
else
235-
channelString = channel->getName();
236-
}
237-
else
238-
{
239-
channelString = channelHeight >= 10 ? "--" : "";
240-
}
243+
String channelString = drawChannelLabel ? getChannelLabelString (*channel, channelLabelDisplayMode)
244+
: channelHeight >= 10 ? "--" : "";
241245

242246
g.drawText (channelString,
243-
showChannelNumbers ? 6 : 3,
247+
showNumericChannelLabels ? 6 : 3,
244248
center - (channelLabelHeight / 2),
245-
getWidth() - (showChannelNumbers ? 6 : 3),
249+
getWidth() - (showNumericChannelLabels ? 6 : 3),
246250
channelLabelHeight,
247251
isCentered ? Justification::centred : Justification::centredLeft,
248252
false);
@@ -404,10 +408,8 @@ String LfpChannelDisplayInfo::getTooltip()
404408
if (trackIndex < 0)
405409
return {};
406410

407-
const bool showChannelNumbers = display->options->getChannelNameState();
408411
auto* channel = display->drawableChannels[trackIndex];
409-
const String channelString = showChannelNumbers ? String (channel->getChannelNumber() + 1)
410-
: channel->getName();
412+
const String channelString = getChannelLabelString (*channel, display->options->getChannelLabelDisplayMode());
411413

412414
return channelString;
413415
}

Plugins/LfpViewer/LfpDisplayCanvas.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ void LfpDisplayCanvas::loadCustomParametersFromXml (XmlElement* xml)
697697
//LOGD(" Resized in ", MS_FROM_START, " milliseconds");
698698
}
699699

700-
701700
LfpDisplaySplitter::LfpDisplaySplitter (LfpDisplayNode* node,
702701
LfpDisplayCanvas* canvas_,
703702
DisplayBuffer* db,
@@ -765,12 +764,21 @@ void LfpDisplaySplitter::refreshLeftMargin()
765764
const auto labelFont = Font (FontOptions (16.0f));
766765
constexpr int padding = 20;
767766

768-
for (int i = 0; i < displayBuffer->channelMetadata.size(); ++i)
767+
if (options->getChannelLabelDisplayMode() == LfpDisplayOptions::ChannelLabelDisplayMode::Depth)
769768
{
770-
const auto& metadata = displayBuffer->channelMetadata.getReference (i);
771-
const float textWidth = labelFont.getStringWidthFloat (metadata.name);
772-
const int requiredWidth = static_cast<int> (std::ceil (textWidth)) + padding;
773-
newMargin = std::max (newMargin, requiredWidth);
769+
// If displaying depth, we want to ensure enough space for the largest possible depth label
770+
const float textWidth = labelFont.getStringWidthFloat ("99999 μm");
771+
newMargin = std::max (newMargin, static_cast<int> (std::ceil (textWidth)) + 10);
772+
}
773+
else
774+
{
775+
for (int i = 0; i < displayBuffer->channelMetadata.size(); ++i)
776+
{
777+
const auto& metadata = displayBuffer->channelMetadata.getReference (i);
778+
const float textWidth = labelFont.getStringWidthFloat (metadata.name);
779+
const int requiredWidth = static_cast<int> (std::ceil (textWidth)) + padding;
780+
newMargin = std::max (newMargin, requiredWidth);
781+
}
774782
}
775783
}
776784

@@ -1254,7 +1262,7 @@ void LfpDisplaySplitter::updateScreenBuffer()
12541262
if (triggerChannel >= 0)
12551263
{
12561264
// we may need to wait for a trigger
1257-
if (hasTrigger)
1265+
if (hasTrigger)
12581266
{
12591267
if (sbi == 0 || reachedEnd)
12601268
{
@@ -1615,7 +1623,6 @@ void LfpDisplaySplitter::updateScreenBuffer()
16151623
displayBufferIndex.set (channel, newDisplayBufferIndex); // need to store this locally
16161624
}
16171625
}
1618-
16191626
}
16201627
}
16211628

Plugins/LfpViewer/LfpDisplayCanvas.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,11 @@ class LfpDisplaySplitter : public Component,
371371
/** Sets the CAR state */
372372
void setCAREnabled (bool enabled);
373373

374-
private:
374+
/** Resizes the channel info margin based on the current channel label display mode */
375375
void refreshLeftMargin();
376376

377+
private:
378+
377379
bool isSelected;
378380
bool isUpdating;
379381

Plugins/LfpViewer/LfpDisplayOptions.cpp

Lines changed: 80 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ LfpDisplayOptions::LfpDisplayOptions (LfpDisplayCanvas* canvas_, LfpDisplaySplit
5252
selectedChannelType (ContinuousChannel::Type::ELECTRODE),
5353
labelColour (100, 100, 100),
5454
medianOffsetOnForSpikeRaster (false),
55-
ttlWordString ("NONE")
55+
ttlWordString ("NONE"),
56+
channelLabelDisplayMode (ChannelLabelDisplayMode::Name),
57+
channelNameButton (nullptr),
58+
channelNumberButton (nullptr),
59+
channelDepthButton (nullptr)
5660
{
5761
setBufferedToImage (true);
5862

@@ -166,7 +170,7 @@ LfpDisplayOptions::LfpDisplayOptions (LfpDisplayCanvas* canvas_, LfpDisplaySplit
166170
voltageRanges[ContinuousChannel::Type::AUX].add ("1000");
167171
voltageRanges[ContinuousChannel::Type::AUX].add ("2000");
168172
selectedVoltageRange[ContinuousChannel::Type::AUX] = 1; // Default to Auto
169-
rangeGain[ContinuousChannel::Type::AUX] = 0.001f; //mV
173+
rangeGain[ContinuousChannel::Type::AUX] = 1; //mV
170174
rangeSteps[ContinuousChannel::Type::AUX] = 10;
171175
rangeUnits.add ("mV");
172176
typeNames.add ("AUX");
@@ -426,19 +430,31 @@ LfpDisplayOptions::LfpDisplayOptions (LfpDisplayCanvas* canvas_, LfpDisplaySplit
426430
channelDisplaySkipLabel->setFont (labelFont);
427431
extendedOptions->addAndMakeVisible (channelDisplaySkipLabel.get());
428432

429-
// Show channel number button
430-
showChannelNumberButton = std::make_unique<UtilityButton> ("OFF");
431-
showChannelNumberButton->setRadius (5.0f);
432-
showChannelNumberButton->setEnabledState (true);
433-
showChannelNumberButton->setCorners (true, true, true, true);
434-
showChannelNumberButton->addListener (this);
435-
showChannelNumberButton->setClickingTogglesState (true);
436-
showChannelNumberButton->setToggleState (false, sendNotification);
437-
extendedOptions->addAndMakeVisible (showChannelNumberButton.get());
433+
// Channel label display mode
434+
channelNameButton = new TextButton ("Name", "Show channel names");
435+
channelNameButton->setClickingTogglesState (true);
436+
channelNameButton->setToggleState (true, dontSendNotification);
438437

439-
showChannelNumberLabel = std::make_unique<Label> ("ShowChannelNumberLabel", "Show number:");
440-
showChannelNumberLabel->setFont (labelFont);
441-
extendedOptions->addAndMakeVisible (showChannelNumberLabel.get());
438+
channelNumberButton = new TextButton ("Num", "Show channel numbers");
439+
channelNumberButton->setClickingTogglesState (true);
440+
channelNumberButton->setToggleState (false, dontSendNotification);
441+
442+
channelDepthButton = new TextButton ("Depth", "Show channel depth values");
443+
channelDepthButton->setClickingTogglesState (true);
444+
channelDepthButton->setToggleState (false, dontSendNotification);
445+
446+
channelLabelButtonManager = std::make_unique<LinearButtonGroupManager>();
447+
channelLabelButtonManager->addButton (channelNameButton);
448+
channelLabelButtonManager->addButton (channelNumberButton);
449+
channelLabelButtonManager->addButton (channelDepthButton);
450+
channelLabelButtonManager->setRadioButtonMode (true);
451+
channelLabelButtonManager->setButtonListener (this);
452+
channelLabelButtonManager->setSelectedButtonIndex (static_cast<int> (channelLabelDisplayMode));
453+
extendedOptions->addAndMakeVisible (channelLabelButtonManager.get());
454+
455+
channelLabelDisplayLabel = std::make_unique<Label> ("ChannelLabelDisplayLabel", "Label:");
456+
channelLabelDisplayLabel->setFont (labelFont);
457+
extendedOptions->addAndMakeVisible (channelLabelDisplayLabel.get());
442458

443459
// SIGNAL PROCESSING SECTION
444460
sectionTitles.add ("SIGNALS");
@@ -675,7 +691,7 @@ void LfpDisplayOptions::resized()
675691
else
676692
extendedOptionsHolder->setBounds (0, 0, getWidth(), 0);
677693

678-
int extendedWidth = getWidth() < 755 ? 755 : getWidth();
694+
int extendedWidth = getWidth() < 775 ? 775 : getWidth();
679695
extendedWidth = extendedWidth > 1500 ? 1500 : extendedWidth;
680696
extendedOptions->setBounds (0, 0, extendedWidth, extendedOptionsHolder->getHeight());
681697

@@ -686,7 +702,7 @@ void LfpDisplayOptions::resized()
686702
extendedOptionsBox.alignItems = FlexBox::AlignItems::center;
687703

688704
extendedOptionsBox.items.add (FlexItem (185, getHeight() - 60)); // THRESHOLDS
689-
extendedOptionsBox.items.add (FlexItem (185, getHeight() - 60)); // CHANNELS
705+
extendedOptionsBox.items.add (FlexItem (205, getHeight() - 60)); // CHANNELS
690706
extendedOptionsBox.items.add (FlexItem (185, getHeight() - 60)); // SIGNAL PROCESSING
691707
extendedOptionsBox.items.add (FlexItem (190, getHeight() - 60)); // TRIGGERED DISPLAY
692708

@@ -721,7 +737,7 @@ void LfpDisplayOptions::resized()
721737
// CHANNELS
722738
xOffset = extendedOptionsBox.items[1].currentBounds.getX();
723739
xLimit = extendedOptionsBox.items[1].currentBounds.getRight();
724-
channelsGroup->setBounds (xOffset, 5, 185, 135);
740+
channelsGroup->setBounds (xOffset, 5, 205, 135);
725741

726742
reverseChannelsDisplayButton->setBounds (xLimit - 45,
727743
startHeight,
@@ -753,15 +769,15 @@ void LfpDisplayOptions::resized()
753769
80,
754770
height);
755771

756-
showChannelNumberButton->setBounds (xLimit - 45,
757-
startHeight + +verticalSpacing * 3,
758-
35,
759-
height);
772+
channelLabelButtonManager->setBounds (xLimit - 145,
773+
startHeight + verticalSpacing * 3,
774+
135,
775+
height);
760776

761-
showChannelNumberLabel->setBounds (xOffset + 10,
762-
startHeight + verticalSpacing * 3,
763-
100,
764-
height);
777+
channelLabelDisplayLabel->setBounds (xOffset + 10,
778+
startHeight + verticalSpacing * 3,
779+
50,
780+
height);
765781

766782
// SIGNAL PROCESSING
767783
xOffset = extendedOptionsBox.items[2].currentBounds.getX();
@@ -789,9 +805,9 @@ void LfpDisplayOptions::resized()
789805
height);
790806

791807
highPassCutoffButton->setBounds (xLimit - 45,
792-
startHeight + verticalSpacing * 2,
793-
35,
794-
height);
808+
startHeight + verticalSpacing * 2,
809+
35,
810+
height);
795811

796812
highPassCutoffLabel->setBounds (xOffset + 10,
797813
startHeight + verticalSpacing * 2,
@@ -871,9 +887,9 @@ bool LfpDisplayOptions::getInputInvertedState()
871887
return invertInputButton->getToggleState();
872888
}
873889

874-
bool LfpDisplayOptions::getChannelNameState()
890+
LfpDisplayOptions::ChannelLabelDisplayMode LfpDisplayOptions::getChannelLabelDisplayMode() const
875891
{
876-
return showChannelNumberButton->getToggleState();
892+
return channelLabelDisplayMode;
877893
}
878894

879895
void LfpDisplayOptions::setPausedState (bool isPaused)
@@ -1069,20 +1085,18 @@ void LfpDisplayOptions::setSortByDepth (bool state)
10691085
}
10701086
}
10711087

1072-
void LfpDisplayOptions::setShowChannelNumbers (bool state)
1088+
void LfpDisplayOptions::setChannelLabelDisplayMode (ChannelLabelDisplayMode mode)
10731089
{
1074-
showChannelNumberButton->setToggleState (state, dontSendNotification);
1090+
const int modeIndex = jlimit (0, 2, static_cast<int> (mode));
1091+
channelLabelDisplayMode = static_cast<ChannelLabelDisplayMode> (modeIndex);
10751092

1076-
lfpDisplay->channelInfo->repaint();
1093+
channelNameButton->setToggleState (channelLabelDisplayMode == ChannelLabelDisplayMode::Name, dontSendNotification);
1094+
channelNumberButton->setToggleState (channelLabelDisplayMode == ChannelLabelDisplayMode::Number, dontSendNotification);
1095+
channelDepthButton->setToggleState (channelLabelDisplayMode == ChannelLabelDisplayMode::Depth, dontSendNotification);
1096+
channelLabelButtonManager->setSelectedButtonIndex (modeIndex);
10771097

1078-
if (state)
1079-
{
1080-
showChannelNumberButton->setLabel ("ON");
1081-
}
1082-
else
1083-
{
1084-
showChannelNumberButton->setLabel ("OFF");
1085-
}
1098+
canvasSplit->refreshLeftMargin();
1099+
lfpDisplay->resized();
10861100
}
10871101

10881102
void LfpDisplayOptions::setTTLWord (String word)
@@ -1149,9 +1163,21 @@ void LfpDisplayOptions::buttonClicked (Button* b)
11491163
canvas->toggleOptionsDrawer (b->getToggleState());
11501164
}
11511165

1152-
if (b == showChannelNumberButton.get())
1166+
if (b == channelNameButton)
1167+
{
1168+
setChannelLabelDisplayMode (ChannelLabelDisplayMode::Name);
1169+
return;
1170+
}
1171+
1172+
if (b == channelNumberButton)
1173+
{
1174+
setChannelLabelDisplayMode (ChannelLabelDisplayMode::Number);
1175+
return;
1176+
}
1177+
1178+
if (b == channelDepthButton)
11531179
{
1154-
setShowChannelNumbers (b->getToggleState());
1180+
setChannelLabelDisplayMode (ChannelLabelDisplayMode::Depth);
11551181
return;
11561182
}
11571183

@@ -1604,7 +1630,7 @@ void LfpDisplayOptions::saveParameters (XmlElement* xml)
16041630
xmlNode->setAttribute ("reverseOrder", reverseChannelsDisplayButton->getToggleState());
16051631
xmlNode->setAttribute ("sortByDepth", sortByDepthButton->getToggleState());
16061632
xmlNode->setAttribute ("channelSkip", channelDisplaySkipSelection->getSelectedId());
1607-
xmlNode->setAttribute ("showChannelNum", showChannelNumberButton->getToggleState());
1633+
xmlNode->setAttribute ("channelLabelMode", static_cast<int> (channelLabelDisplayMode));
16081634
xmlNode->setAttribute ("subtractOffset", medianOffsetPlottingButton->getToggleState());
16091635

16101636
xmlNode->setAttribute ("isInverted", invertInputButton->getToggleState());
@@ -1774,9 +1800,17 @@ void LfpDisplayOptions::loadParameters (XmlElement* xml)
17741800
//LOGD(" --> setSortByDepth: ", MS_FROM_START, " milliseconds");
17751801
start = Time::getHighResolutionTicks();
17761802

1777-
setShowChannelNumbers (xmlNode->getBoolAttribute ("showChannelNum", false));
1803+
if (xmlNode->hasAttribute ("channelLabelMode"))
1804+
{
1805+
setChannelLabelDisplayMode (static_cast<ChannelLabelDisplayMode> (xmlNode->getIntAttribute ("channelLabelMode", 0)));
1806+
}
1807+
else
1808+
{
1809+
const bool showChannelNum = xmlNode->getBoolAttribute ("showChannelNum", false);
1810+
setChannelLabelDisplayMode (showChannelNum ? ChannelLabelDisplayMode::Number : ChannelLabelDisplayMode::Name);
1811+
}
17781812

1779-
//LOGD(" --> setShowChannelNumbers: ", MS_FROM_START, " milliseconds");
1813+
//LOGD(" --> setChannelLabelDisplayMode: ", MS_FROM_START, " milliseconds");
17801814
start = Time::getHighResolutionTicks();
17811815

17821816
bool shouldInvert = xmlNode->getBoolAttribute ("isInverted", false);

0 commit comments

Comments
 (0)