Skip to content

Commit 3d0c01b

Browse files
committed
Simplify handling sample rates and events in LFP viewer
1 parent 9ac0106 commit 3d0c01b

4 files changed

Lines changed: 19 additions & 27 deletions

File tree

Plugins/LfpDisplayNode/LfpDisplayEditor.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ void LfpDisplayEditor::comboBoxChanged(juce::ComboBox *cb)
105105
{
106106
if (cb == subprocessorSelection)
107107
{
108-
std::cout << "Setting subprocessor to " << cb->getSelectedId() << std::endl;
108+
std::cout << "Setting subprocessor to " << cb->getSelectedId() << std::endl;
109109
uint32 subproc = inputSubprocessors[cb->getSelectedId() - 1];
110110

111111
String sampleRateLabelText = "Sample Rate: ";
112-
sampleRateLabelText += String(inputSampleRates[subproc]);
112+
sampleRateLabelText += String(lfpProcessor->getSubprocessorSampleRate(subproc));
113113
subprocessorSampleRateLabel->setText(sampleRateLabelText, dontSendNotification);
114114
std::cout << sampleRateLabelText << std::endl;
115115

@@ -125,7 +125,6 @@ void LfpDisplayEditor::updateSubprocessorSelectorOptions()
125125
{
126126
// clear out the old data
127127
inputSubprocessors.clear();
128-
inputSampleRates.clear();
129128
subprocessorSelection->clear(dontSendNotification);
130129

131130
if (lfpProcessor->getTotalDataChannels() != 0)
@@ -140,12 +139,10 @@ void LfpDisplayEditor::updateSubprocessorSelectorOptions()
140139
uint16 subProcessorIdx = ch->getSubProcessorIdx();
141140
uint32 subProcFullId = GenericProcessor::getProcessorFullId(sourceNodeId, subProcessorIdx);
142141

143-
bool success = inputSubprocessors.add(subProcFullId);
142+
bool added = inputSubprocessors.add(subProcFullId);
144143

145-
if (success)
144+
if (added)
146145
{
147-
inputSampleRates.set(subProcFullId, ch->getSampleRate());
148-
149146
String sourceName = ch->getSourceName();
150147
subprocessorNames.set(subProcFullId,
151148
sourceName + " " + String(sourceNodeId) + "/" + String(subProcessorIdx));

Plugins/LfpDisplayNode/LfpDisplayEditor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class LfpDisplayEditor : public VisualizerEditor,
7979

8080
private:
8181

82-
HashMap<int, float> inputSampleRates; // hold the possible subprocessor sample rates
8382
SortedSet<uint32> inputSubprocessors;
8483

8584
LfpDisplayNode* lfpProcessor;

Plugins/LfpDisplayNode/LfpDisplayNode.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void LfpDisplayNode::updateSettings()
9999
}
100100

101101
int numChans = getNumSubprocessorChannels();
102-
int srate = getSubprocessorSampleRate();
102+
int srate = getSubprocessorSampleRate(subprocessorToDraw);
103103

104104
std::cout << "Re-setting num inputs on LfpDisplayNode to " << numChans << std::endl;
105105
if (numChans > 0)
@@ -136,15 +136,7 @@ void LfpDisplayNode::updateSettings()
136136

137137
uint32 LfpDisplayNode::getEventSourceId(const EventChannel* event)
138138
{
139-
140-
if (event->getTimestampOrigin() == EventChannel::timestampsDerivedFromChannel)
141-
{
142-
return getProcessorFullId(event->getTimestampOriginProcessor(), event->getTimestampOriginSubProcessor());
143-
}
144-
else
145-
{
146-
return getChannelSourceId(event);
147-
}
139+
return getProcessorFullId(event->getTimestampOriginProcessor(), event->getTimestampOriginSubProcessor());
148140
}
149141

150142
uint32 LfpDisplayNode::getChannelSourceId(const InfoObjectCommon* chan)
@@ -184,18 +176,19 @@ int LfpDisplayNode::getNumSubprocessorChannels()
184176
return 0;
185177
}
186178

187-
float LfpDisplayNode::getSubprocessorSampleRate()
179+
float LfpDisplayNode::getSubprocessorSampleRate(uint32 subprocId)
188180
{
189-
if (subprocessorToDraw != 0)
181+
auto entry = subprocessorSampleRate.find(subprocId);
182+
if (entry != subprocessorSampleRate.end())
190183
{
191-
return subprocessorSampleRate[subprocessorToDraw];
184+
return entry->second;
192185
}
193186
return 0.0f;
194187
}
195188

196189
bool LfpDisplayNode::resizeBuffer()
197190
{
198-
int nSamples = (int)getSubprocessorSampleRate() * bufferLength;
191+
int nSamples = (int)getSubprocessorSampleRate(subprocessorToDraw) * bufferLength;
199192
int nInputs = getNumSubprocessorChannels();
200193

201194
std::cout << "Resizing buffer. Samples: " << nSamples << ", Inputs: " << nInputs << std::endl;
@@ -269,12 +262,15 @@ void LfpDisplayNode::handleEvent(const EventChannel* eventInfo, const MidiMessag
269262
const int eventId = ttl->getState() ? 1 : 0;
270263
const int eventChannel = ttl->getChannel();
271264
const int eventTime = samplePosition;
265+
266+
// find sample rate of event channel
272267
uint32 eventSourceNodeId = getEventSourceId(eventInfo);
273-
274-
// treat events with no source as occurring on the subprocessor being drawn.
275-
if (eventSourceNodeId == 0)
268+
float eventSampleRate = getSubprocessorSampleRate(eventSourceNodeId);
269+
270+
if (eventSampleRate == 0)
276271
{
277-
eventSourceNodeId = subprocessorToDraw;
272+
// shouldn't happen for any real event channel at this point
273+
return;
278274
}
279275

280276
//std::cout << "Received event on channel " << eventChannel << std::endl;

Plugins/LfpDisplayNode/LfpDisplayNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class LfpDisplayNode : public GenericProcessor
7373

7474
int getNumSubprocessorChannels();
7575

76-
float getSubprocessorSampleRate();
76+
float getSubprocessorSampleRate(uint32 subprocId);
7777

7878
uint32 getDataSubprocId(int chan) const;
7979

0 commit comments

Comments
 (0)