Skip to content

Commit d2dda07

Browse files
committed
Display units alongside channel type in LFP Viewer
1 parent 1202fbb commit d2dda07

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

Plugins/LfpViewer/DisplayBuffer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ void DisplayBuffer::addChannel (
6868
String description,
6969
String structure,
7070
float inputRangeMin,
71-
float inputRangeMax)
71+
float inputRangeMax,
72+
String units)
7273
{
7374
ChannelMetadata metadata = ChannelMetadata();
7475
metadata.name = name;
@@ -81,6 +82,7 @@ void DisplayBuffer::addChannel (
8182
metadata.description = description;
8283
metadata.inputRangeMin = inputRangeMin;
8384
metadata.inputRangeMax = inputRangeMax;
85+
metadata.units = units;
8486

8587
channelMetadata.add (metadata);
8688
channelMap[channelNum] = numChannels;

Plugins/LfpViewer/DisplayBuffer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class TESTABLE DisplayBuffer : public AudioBuffer<float>
6565
String description = "",
6666
String structure = "None",
6767
float inputRangeMin = -5000.0f,
68-
float inputRangeMax = +5000.0f);
68+
float inputRangeMax = +5000.0f,
69+
String units = "");
6970

7071
/** Initializes the event channel at the start of each buffer */
7172
void initializeEventChannel (int nSamples);
@@ -95,6 +96,7 @@ class TESTABLE DisplayBuffer : public AudioBuffer<float>
9596
String description = "";
9697
float inputRangeMin = -5000.0f;
9798
float inputRangeMax = +5000.0f;
99+
String units = "";
98100
};
99101

100102
Array<ChannelMetadata> channelMetadata;

Plugins/LfpViewer/LfpChannelDisplay.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ void LfpChannelDisplay::setType (ContinuousChannel::Type type_)
7979
typeStr = options->getTypeName (type);
8080
}
8181

82+
void LfpChannelDisplay::setUnits (const String& newUnits)
83+
{
84+
units = newUnits;
85+
}
86+
87+
const String& LfpChannelDisplay::getUnits() const
88+
{
89+
return units;
90+
}
91+
8292
void LfpChannelDisplay::setEnabledState (bool state)
8393
{
8494
/*if (state)

Plugins/LfpViewer/LfpChannelDisplay.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ class LfpChannelDisplay : public Component
113113
/** Return the assigned channel name */
114114
String getName();
115115

116+
/** Set the units string used for display */
117+
void setUnits (const String& newUnits);
118+
119+
/** Return the units string for this channel */
120+
const String& getUnits() const;
121+
116122
/** Returns the assigned channel number for this display, relative
117123
to the subset of channels being drawn to the canvas */
118124
int getDrawableChannelNumber();
@@ -193,6 +199,8 @@ class LfpChannelDisplay : public Component
193199
float depth;
194200
bool isRecorded;
195201

202+
String units;
203+
196204
FontOptions channelFont;
197205

198206
Colour lineColour;

Plugins/LfpViewer/LfpChannelDisplayInfo.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,31 @@ void LfpChannelDisplayInfo::paint (Graphics& g)
239239

240240
if (getChannelTypeStringVisibility())
241241
{
242+
constexpr int textHeight = 14;
243+
constexpr int textStartX = 5;
244+
const int textY = center + 10;
245+
242246
g.setFont (FontOptions (13.0f));
243-
g.drawText (typeStr, 5, center + 10, 50, 14, Justification::centred, false);
247+
g.setColour (lineColour);
248+
const auto currentFont = g.getCurrentFont();
249+
250+
const int typeWidth = currentFont.getStringWidth (typeStr);
251+
const int typeBoundsWidth = typeWidth + 2;
252+
g.drawText (typeStr, textStartX, textY, typeBoundsWidth, textHeight, Justification::centredLeft, false);
253+
254+
const String& unitsText = getUnits();
255+
if (unitsText.isNotEmpty())
256+
{
257+
const int unitsX = textStartX + typeWidth + 5;
258+
const int unitsWidth = getWidth() - unitsX - 4;
259+
260+
if (unitsWidth > 0)
261+
{
262+
g.setColour (Colours::grey.withAlpha (0.8f));
263+
g.setFont (FontOptions (12.0f));
264+
g.drawFittedText (unitsText, unitsX, textY, unitsWidth, textHeight, Justification::centredLeft, 1, 0.8f);
265+
}
266+
}
244267
}
245268

246269
if (isSingleChannel)

Plugins/LfpViewer/LfpDisplayNode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ void LfpDisplayNode::updateSettings()
9595
channel->getDescription(),
9696
"None", // structure
9797
channel->inputRange.min, // inputRangeMin
98-
channel->inputRange.max); // inputRangeMax
98+
channel->inputRange.max, // inputRangeMax
99+
channel->getUnits()); // units
99100
}
100101

101102
Array<DisplayBuffer*> toDelete;

0 commit comments

Comments
 (0)