Skip to content

Commit d04adb4

Browse files
committed
Rewrite subprocessor filtering functionality
1 parent 330f0ee commit d04adb4

4 files changed

Lines changed: 88 additions & 30 deletions

File tree

Source/Plugins/LfpDisplayNodeAlpha/LfpDisplayCanvas.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ int LfpDisplayCanvas::getNumChannelsVisible()
493493
return lfpDisplay->drawableChannels.size();
494494
}
495495

496+
int LfpDisplayCanvas::getChannelSubprocessorIdx(int channel)
497+
{
498+
return processor->getDataChannel(channel)->getSubProcessorIdx();
499+
}
500+
496501
const float LfpDisplayCanvas::getYCoord(int chan, int samp)
497502
{
498503
return *screenBuffer->getReadPointer(chan, samp);
@@ -577,6 +582,11 @@ void LfpDisplayCanvas::setDrawableSampleRate(float samplerate)
577582
lfpDisplay->setDisplayedSampleRate(samplerate);
578583
}
579584

585+
void LfpDisplayCanvas::setDrawableSubprocessor(int idx)
586+
{
587+
lfpDisplay->setDisplayedSubprocessor(idx);
588+
}
589+
580590
void LfpDisplayCanvas::redraw()
581591
{
582592
fullredraw=true;
@@ -1956,6 +1966,7 @@ void LfpDisplay::setNumChannels(int numChannels)
19561966
//lfpInfo->setColour(channelColours[i % channelColours.size()]);
19571967
lfpInfo->setRange(range[options->getChannelType(i)]);
19581968
lfpInfo->setChannelHeight(canvas->getChannelHeight());
1969+
lfpInfo->setSubprocessorIdx(canvas->getChannelSubprocessorIdx(i));
19591970

19601971
addAndMakeVisible(lfpInfo);
19611972

@@ -2249,6 +2260,16 @@ void LfpDisplay::setDisplayedSampleRate(float samplerate)
22492260
drawableSampleRate = samplerate;
22502261
}
22512262

2263+
int LfpDisplay::getDisplayedSubprocessor()
2264+
{
2265+
return drawableSubprocessorIdx;
2266+
}
2267+
2268+
void LfpDisplay::setDisplayedSubprocessor(int subProcessorIdx)
2269+
{
2270+
drawableSubprocessorIdx = subProcessorIdx;
2271+
}
2272+
22522273
bool LfpDisplay::getChannelsReversed()
22532274
{
22542275
return channelsReversed;
@@ -2502,8 +2523,9 @@ void LfpDisplay::rebuildDrawableChannelsList()
25022523
// iterate over all channels and select drawable ones
25032524
for (size_t i = 0; i < channels.size(); i++)
25042525
{
2505-
// if channel[i] is not the right samplerate, hide it and continue
2506-
if (canvas->getChannelSampleRate(i) != getDisplayedSampleRate())
2526+
// std::cout << "\tchannel " << i << " has subprocessor index of " << channelInfo[i]->getSubprocessorIdx() << std::endl;
2527+
// if channel[i] is not sourced from the correct subprocessor, then hide it and continue
2528+
if (channelInfo[i]->getSubprocessorIdx() != getDisplayedSubprocessor())
25072529
{
25082530
channels[i]->setHidden(true);
25092531
channelInfo[i]->setHidden(true);

Source/Plugins/LfpDisplayNodeAlpha/LfpDisplayCanvas.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ class LfpDisplayCanvas : public Visualizer,
107107

108108
/** Delegates a samplerate for drawing to the LfpDisplay referenced by this canvas */
109109
void setDrawableSampleRate(float samplerate);
110+
111+
/** Returns the subprocessor index of the given channel */
112+
int getChannelSubprocessorIdx(int channel);
113+
114+
/** Delegates a subprocessor index for drawing to the LfpDisplay referenced by this
115+
this canvas */
116+
void setDrawableSubprocessor(int idx);
110117

111118
const float getXCoord(int chan, int samp);
112119
const float getYCoord(int chan, int samp);
@@ -467,6 +474,10 @@ class LfpDisplay : public Component
467474
*/
468475
void setDisplayedSampleRate(float samplerate);
469476

477+
int getDisplayedSubprocessor();
478+
479+
void setDisplayedSubprocessor(int subProcessorIdx);
480+
470481
/** Caches a new channel height without updating the channels */
471482
void cacheNewChannelHeight(int r);
472483

@@ -574,6 +585,7 @@ class LfpDisplay : public Component
574585
int displaySkipAmt;
575586
int cachedDisplayChannelHeight; // holds a channel height if reset during single channel focus
576587
float drawableSampleRate;
588+
int drawableSubprocessorIdx;
577589

578590
int totalHeight;
579591

@@ -712,6 +724,7 @@ class LfpChannelDisplay : public Component
712724
class LfpChannelDisplayInfo : public LfpChannelDisplay,
713725
public Button::Listener
714726
{
727+
friend class LfpDisplay;
715728
public:
716729
LfpChannelDisplayInfo(LfpDisplayCanvas*, LfpDisplay*, LfpDisplayOptions*, int channelNumber);
717730

@@ -733,6 +746,10 @@ class LfpChannelDisplayInfo : public LfpChannelDisplay,
733746
/** Sets the sample rate associated with this channel */
734747
void setChannelSampleRate(int samplerate);
735748

749+
int getSubprocessorIdx() { return subProcessorIdx; }
750+
751+
void setSubprocessorIdx(int subProcessorIdx_) { subProcessorIdx = subProcessorIdx_; }
752+
736753
/** Updates the parent LfpDisplay that the track vertical zoom should update */
737754
virtual void mouseDrag(const MouseEvent &event) override;
738755

@@ -747,6 +764,7 @@ class LfpChannelDisplayInfo : public LfpChannelDisplay,
747764
float x, y;
748765

749766
int samplerate;
767+
int subProcessorIdx;
750768

751769
ScopedPointer<UtilityButton> enableButton;
752770

Source/Plugins/LfpDisplayNodeAlpha/LfpDisplayEditor.cpp

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ LfpDisplayEditor::LfpDisplayEditor(GenericProcessor* parentNode, bool useDefault
3535

3636
desiredWidth = 180;
3737

38-
subprocessorSelectionLabel = new Label("Display subprocessor sample rate", "Display Subproc. Sample Rate");
39-
subprocessorSelectionLabel->setBounds(10, 25, 140, 20);
40-
addAndMakeVisible(subprocessorSelectionLabel);
41-
4238
subprocessorSelection = new ComboBox("Subprocessor sample rate");
43-
subprocessorSelection->setBounds(subprocessorSelectionLabel->getX()+5, subprocessorSelectionLabel->getBottom(), 60, 22);
39+
// subprocessorSelection->setBounds(subprocessorSelectionLabel->getX()+5, subprocessorSelectionLabel->getBottom(), 60, 22);
40+
subprocessorSelection->setBounds(10, 30, 50, 22);
4441
subprocessorSelection->addListener(this);
4542
addAndMakeVisible(subprocessorSelection);
43+
44+
subprocessorSelectionLabel = new Label("Display subprocessor sample rate", "Display Subproc.");
45+
// subprocessorSelectionLabel->setBounds(10, 25, 140, 20);
46+
subprocessorSelectionLabel->setBounds(subprocessorSelection->getRight(), subprocessorSelection->getY(), 100, 20);
47+
addAndMakeVisible(subprocessorSelectionLabel);
48+
49+
subprocessorSampleRateLabel = new Label("Subprocessor sample rate label", "Sample Rate:");
50+
subprocessorSampleRateLabel->setFont(Font(Font::getDefaultSerifFontName(), 14, italic));
51+
subprocessorSampleRateLabel->setBounds(subprocessorSelection->getX(), subprocessorSelection->getBottom() + 10, 200, 40);
52+
addAndMakeVisible(subprocessorSampleRateLabel);
4653
}
4754

4855
LfpDisplayEditor::~LfpDisplayEditor()
@@ -67,7 +74,8 @@ void LfpDisplayEditor::buttonClicked(Button *button)
6774
// (else) initialization errors. lots of time-critical cross dependencies here,
6875
// should be cleaned up
6976
updateSubprocessorSelectorOptions();
70-
((LfpDisplayCanvas*)canvas.get())->setDrawableSampleRate(*(inputSampleRates.begin() + (subprocessorSelection->getSelectedId() - 1)));
77+
((LfpDisplayCanvas *)canvas.get())->setDrawableSubprocessor(*(inputSubprocessorIndices.begin() + (subprocessorSelection->getSelectedId() - 1)));
78+
// ((LfpDisplayCanvas*)canvas.get())->setDrawableSampleRate(*(inputSampleRates.begin() + (subprocessorSelection->getSelectedId() - 1)));
7179

7280
canvas->update();
7381

@@ -90,50 +98,57 @@ void LfpDisplayEditor::comboBoxChanged(juce::ComboBox *cb)
9098
{
9199
if (cb == subprocessorSelection)
92100
{
93-
setCanvasDrawableSampleRate(cb->getSelectedId() - 1);
101+
// setCanvasDrawableSampleRate(cb->getSelectedId() - 1);
102+
setCanvasDrawableSubprocessor(cb->getSelectedId() - 1);
94103
}
95104
}
96105

97106
void LfpDisplayEditor::updateSubprocessorSelectorOptions()
98107
{
99108
// clear out the old data
109+
inputSubprocessorIndices.clear();
100110
inputSampleRates.clear();
101111
subprocessorSelection->clear(dontSendNotification);
102112

103-
// get a list of all the sample rates
104-
for (int i = 0, len = lfpProcessor->getNumInputs(); i < len; ++i)
113+
for (int i = 0, len = lfpProcessor->getTotalDataChannels(); i < len; ++i)
105114
{
106-
float samplerate = lfpProcessor->getDataChannel(i)->getSampleRate();
107-
bool success = inputSampleRates.add(samplerate);
115+
int subProcessorIdx = lfpProcessor->getDataChannel(i)->getSubProcessorIdx();
108116

109-
// if (success) std::cout << "\t\tadding sample rate " << samplerate << " ... size = " << inputSampleRates.size() << std::endl;
117+
bool success = inputSubprocessorIndices.add(subProcessorIdx);
118+
119+
if (success) inputSampleRates.set(subProcessorIdx, lfpProcessor->getDataChannel(i)->getSampleRate());
120+
121+
// if (success) std::cout << "\t\tadding subprocessor index " << subProcessorIdx << std::endl;
110122
}
111123

112-
// if the source changes, default to first samplerate given
113-
int sampleRateToSet = -1;
114-
if (inputSampleRates.size() > 0)
124+
int subprocessorToSet = -1;
125+
if (inputSubprocessorIndices.size() > 0)
115126
{
116-
sampleRateToSet = 0;
127+
subprocessorToSet = 0;
117128
}
118129

119-
// add the samplerate options to the combobox
120-
for (int i = 0; i < inputSampleRates.size(); ++i)
130+
for (int i = 0; i < inputSubprocessorIndices.size(); ++i)
121131
{
122-
subprocessorSelection->addItem(String(*(inputSampleRates.begin()+i)), i+1);
132+
subprocessorSelection->addItem (String (*(inputSubprocessorIndices.begin() + i)), i + 1);
123133
}
124134

125-
if (sampleRateToSet >= 0)
135+
if (subprocessorToSet >= 0)
126136
{
127-
subprocessorSelection->setSelectedId(sampleRateToSet + 1, dontSendNotification);
128-
setCanvasDrawableSampleRate(sampleRateToSet);
137+
subprocessorSelection->setSelectedId(subprocessorToSet + 1, dontSendNotification);
138+
139+
String sampleRateLabelText = "Sample Rate: ";
140+
sampleRateLabelText += String(inputSampleRates[*(inputSubprocessorIndices.begin()+subprocessorToSet)]);
141+
142+
subprocessorSampleRateLabel->setText(sampleRateLabelText, dontSendNotification);
143+
setCanvasDrawableSubprocessor(subprocessorToSet);
129144
}
130145
}
131146

132-
void LfpDisplayEditor::setCanvasDrawableSampleRate(int index)
147+
void LfpDisplayEditor::setCanvasDrawableSubprocessor(int index)
133148
{
134149
if (canvas)
135150
{
136-
((LfpDisplayCanvas*)canvas.get())->setDrawableSampleRate(*(inputSampleRates.begin() + (index)));
151+
((LfpDisplayCanvas *)canvas.get())->setDrawableSubprocessor(*(inputSubprocessorIndices.begin() + index));
137152
}
138153
}
139154

Source/Plugins/LfpDisplayNodeAlpha/LfpDisplayEditor.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,21 @@ class LfpDisplayEditor : public VisualizerEditor,
7373

7474
private:
7575

76-
SortedSet<float> inputSampleRates; // hold the possible subprocessor sample rates
76+
HashMap<int, float> inputSampleRates; // hold the possible subprocessor sample rates
77+
SortedSet<int> inputSubprocessorIndices;
7778

7879
LfpDisplayNode* lfpProcessor;
7980

8081
// label and combobox for subprocessor selection
8182
ScopedPointer<Label> subprocessorSelectionLabel;
8283
ScopedPointer<ComboBox> subprocessorSelection;
8384

84-
/** Communicates the drawable sample rate information to the canvas, if
85-
one exists
85+
ScopedPointer<Label> subprocessorSampleRateLabel;
86+
87+
/** Communicates the drawable subprocessor information to the canvas, if
88+
one exists
8689
*/
87-
void setCanvasDrawableSampleRate(int index);
90+
void setCanvasDrawableSubprocessor(int index);
8891

8992
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LfpDisplayEditor);
9093

0 commit comments

Comments
 (0)