Skip to content

Commit c1f27ee

Browse files
committed
Add multiple displayBuffer support in LfpDisplayNode
1 parent 4fb6923 commit c1f27ee

5 files changed

Lines changed: 115 additions & 14 deletions

File tree

Plugins/LfpDisplayNode/LfpDisplayCanvas.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ void LfpDisplayCanvas::endAnimation()
212212

213213
void LfpDisplayCanvas::update()
214214
{
215-
nChans = jmax(processor->getNumSubprocessorChannels(), 0);
215+
displayBufferSize = displayBuffer->getNumSamples();
216+
217+
nChans = jmax(processor->getNumSubprocessorChannels(), 0);
216218

217219
std::cout << "Num chans: " << nChans << std::endl;
218220

@@ -631,6 +633,7 @@ void LfpDisplayCanvas::setDrawableSubprocessor(uint32 sp)
631633
{
632634
drawableSubprocessor = sp;
633635
std::cout << "Setting LFP canvas subprocessor to " << sp << std::endl;
636+
displayBuffer = processor->getDisplayBufferAddress();
634637
update();
635638
}
636639

@@ -816,7 +819,7 @@ LfpDisplayOptions::LfpDisplayOptions(LfpDisplayCanvas* canvas_, LfpTimescale* ti
816819
selectedVoltageRange[DataChannel::HEADSTAGE_CHANNEL] = 4;
817820
rangeGain[DataChannel::HEADSTAGE_CHANNEL] = 1; //uV
818821
rangeSteps[DataChannel::HEADSTAGE_CHANNEL] = 10;
819-
rangeUnits.add("uV");
822+
rangeUnits.add(CharPointer_UTF8("\xC2\xB5V"));
820823
typeNames.add("DATA");
821824

822825
UtilityButton* tbut;

Plugins/LfpDisplayNode/LfpDisplayEditor.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ LfpDisplayEditor::~LfpDisplayEditor()
5858

5959
void LfpDisplayEditor::startAcquisition()
6060
{
61-
subprocessorSelection->setEnabled(false);
61+
//subprocessorSelection->setEnabled(false);
6262
}
6363

6464
void LfpDisplayEditor::stopAcquisition()
6565
{
66-
subprocessorSelection->setEnabled(true);
66+
//subprocessorSelection->setEnabled(true);
6767
}
6868

6969
Visualizer* LfpDisplayEditor::createNewCanvas()
@@ -170,6 +170,11 @@ void LfpDisplayEditor::updateSubprocessorSelectorOptions()
170170
}
171171
}
172172

173+
SortedSet<uint32> LfpDisplayEditor::getInputSubprocessors()
174+
{
175+
return inputSubprocessors;
176+
}
177+
173178
void LfpDisplayEditor::saveVisualizerParameters(XmlElement* xml)
174179
{
175180

Plugins/LfpDisplayNode/LfpDisplayEditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class LfpDisplayEditor : public VisualizerEditor,
7777
*/
7878
void updateSubprocessorSelectorOptions();
7979

80+
SortedSet<uint32> getInputSubprocessors();
81+
8082
private:
8183

8284
SortedSet<uint32> inputSubprocessors;

Plugins/LfpDisplayNode/LfpDisplayNode.cpp

Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ using namespace LfpViewer;
3131
LfpDisplayNode::LfpDisplayNode()
3232
: GenericProcessor ("LFP Viewer")
3333
, displayGain (1)
34-
, bufferLength (10.0f)
34+
, bufferLength (1.0f)
3535
, abstractFifo (100)
3636
{
3737
setProcessorType (PROCESSOR_TYPE_SINK);
3838

39-
displayBuffer = new AudioSampleBuffer (8, 100);
39+
displayBuffer.reset(new AudioSampleBuffer (8, 100));
4040

4141
const int heapSize = 5000;
4242
arrayOfOnes = new float[heapSize];
@@ -83,6 +83,12 @@ void LfpDisplayNode::updateSettings()
8383

8484
numSubprocessors = numChannelsInSubprocessor.size();
8585

86+
displayBuffers.resize(numSubprocessors, std::make_shared<AudioSampleBuffer> (8, 100));
87+
88+
displayBufferIndices.resize(numSubprocessors);
89+
90+
channelIndices.resize(numSubprocessors);
91+
8692
if (numChannelsInSubprocessor.find(subprocessorToDraw) == numChannelsInSubprocessor.end())
8793
{
8894
// subprocessor to draw does not exist
@@ -188,10 +194,13 @@ float LfpDisplayNode::getSubprocessorSampleRate(uint32 subprocId)
188194

189195
bool LfpDisplayNode::resizeBuffer()
190196
{
191-
int nSamples = (int)getSubprocessorSampleRate(subprocessorToDraw) * bufferLength;
197+
LfpDisplayEditor * ed = (LfpDisplayEditor*)getEditor();
198+
allSubprocessors = ed->getInputSubprocessors();
199+
200+
/*int nSamples = (int)getSubprocessorSampleRate(subprocessorToDraw) * bufferLength;
192201
int nInputs = getNumSubprocessorChannels();
193202
194-
std::cout << "Resizing buffer. Samples: " << nSamples << ", Inputs: " << nInputs << std::endl;
203+
//std::cout << "Resizing buffer. Samples: " << nSamples << ", Inputs: " << nInputs << std::endl;
195204
196205
if (nSamples > 0 && nInputs > 0)
197206
{
@@ -202,13 +211,46 @@ bool LfpDisplayNode::resizeBuffer()
202211
displayBufferIndex.clear();
203212
displayBufferIndex.insertMultiple(0, 0, nInputs + 1);
204213
214+
//return true;
215+
}*/
216+
//else
217+
//{
218+
// return false;
219+
//}
220+
221+
int totalResized = 0;
222+
223+
for (int cs = 0; cs < numSubprocessors ; cs++)
224+
{
225+
int nSamples = (int)getSubprocessorSampleRate(allSubprocessors[cs]) * bufferLength;
226+
int nInputs = numChannelsInSubprocessor[allSubprocessors[cs]];
227+
228+
std::cout << "Resizing buffer for Subprocessor " << allSubprocessors[cs] << ". Samples: " << nSamples << ", Inputs: " << nInputs << std::endl;
229+
230+
if (nSamples > 0 && nInputs > 0)
231+
{
232+
//abstractFifo.setTotalSize(nSamples);
233+
displayBuffers[cs]->setSize(nInputs + 1, nSamples); // add extra channel for TTLs
234+
displayBuffers[cs]->clear();
235+
236+
displayBufferIndices[cs].clear();
237+
displayBufferIndices[cs].insert(displayBufferIndices[cs].end(), nInputs + 1, 0);
238+
239+
channelIndices.clear();
240+
241+
totalResized++;
242+
}
243+
}
244+
245+
246+
if (totalResized == numSubprocessors)
247+
{
205248
return true;
206249
}
207250
else
208251
{
209252
return false;
210253
}
211-
212254
}
213255

214256

@@ -396,7 +438,7 @@ void LfpDisplayNode::process (AudioSampleBuffer& buffer)
396438
{
397439
ScopedLock displayLock(displayMutex);
398440

399-
if (true)
441+
if (false)
400442
{
401443
initializeEventChannels();
402444
checkForEvents(); // see if we got any TTL events
@@ -406,10 +448,13 @@ void LfpDisplayNode::process (AudioSampleBuffer& buffer)
406448
if (true)
407449
{
408450
int channelIndex = -1;
451+
channelIndices.insertMultiple(0, -1, numSubprocessors);
452+
uint32 subProcId = 0;
453+
int cs = -1;
409454

410455
for (int chan = 0; chan < buffer.getNumChannels(); ++chan)
411456
{
412-
if (getDataSubprocId(chan) == subprocessorToDraw)
457+
/*if (getDataSubprocId(chan) == subprocessorToDraw)
413458
{
414459
channelIndex++;
415460
const int samplesLeft = displayBuffer->getNumSamples() - displayBufferIndex[channelIndex];
@@ -446,7 +491,48 @@ void LfpDisplayNode::process (AudioSampleBuffer& buffer)
446491
447492
displayBufferIndex.set(channelIndex, extraSamples);
448493
}
494+
}*/
495+
496+
subProcId = getDataSubprocId(chan);
497+
cs = allSubprocessors.indexOf(subProcId);
498+
499+
channelIndices.set(cs, channelIndices[cs] + 1);
500+
501+
const int samplesLeft = displayBuffers[cs]->getNumSamples() - displayBufferIndices[cs][channelIndices[cs]];
502+
const int nSamples = getNumSamples(chan);
503+
504+
if (nSamples < samplesLeft)
505+
{
506+
displayBuffers[cs]->copyFrom(channelIndices[cs], // destChannel
507+
displayBufferIndices[cs][channelIndices[cs]], // destStartSample
508+
buffer, // source
509+
chan, // source channel
510+
0, // source start sample
511+
nSamples); // numSamples
512+
513+
displayBufferIndices[cs].insert(displayBufferIndices[cs].begin() + channelIndices[cs], displayBufferIndices[cs][channelIndices[cs]] + nSamples);
449514
}
515+
else
516+
{
517+
const int extraSamples = nSamples - samplesLeft;
518+
519+
displayBuffers[cs]->copyFrom(channelIndices[cs], // destChannel
520+
displayBufferIndices[cs][channelIndices[cs]], // destStartSample
521+
buffer, // source
522+
chan, // source channel
523+
0, // source start sample
524+
samplesLeft); // numSamples
525+
526+
displayBuffers[cs]->copyFrom(channelIndices[cs], // destChannel
527+
0, // destStartSample
528+
buffer, // source
529+
chan, // source channel
530+
samplesLeft, // source start sample
531+
extraSamples); // numSamples
532+
533+
displayBufferIndices[cs].insert(displayBufferIndices[cs].begin() + channelIndices[cs], extraSamples);
534+
}
535+
450536
}
451537
}
452538
}

Plugins/LfpDisplayNode/LfpDisplayNode.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ class LfpDisplayNode : public GenericProcessor
6262

6363
void handleEvent (const EventChannel* eventInfo, const MidiMessage& event, int samplePosition = 0) override;
6464

65-
AudioSampleBuffer* getDisplayBufferAddress() const { return displayBuffer; }
65+
AudioSampleBuffer* getDisplayBufferAddress() const { return displayBuffers[allSubprocessors.indexOf(subprocessorToDraw)].get(); }
6666

67-
int getDisplayBufferIndex (int chan) const { return displayBufferIndex[chan]; }
67+
int getDisplayBufferIndex (int chan) const { return displayBufferIndices[allSubprocessors.indexOf(subprocessorToDraw)][chan]; }
6868

6969
CriticalSection* getMutex() { return &displayMutex; }
7070

@@ -81,9 +81,13 @@ class LfpDisplayNode : public GenericProcessor
8181
void initializeEventChannels();
8282
void finalizeEventChannels();
8383

84-
ScopedPointer<AudioSampleBuffer> displayBuffer;
84+
std::unique_ptr<AudioSampleBuffer> displayBuffer;
85+
std::vector<std::shared_ptr<AudioSampleBuffer>> displayBuffers;
8586

8687
Array<int> displayBufferIndex;
88+
std::vector<std::vector<int>> displayBufferIndices;
89+
Array<int> channelIndices;
90+
8791
Array<uint32> eventSourceNodes;
8892

8993
float displayGain; //
@@ -100,6 +104,7 @@ class LfpDisplayNode : public GenericProcessor
100104

101105
int numSubprocessors;
102106
uint32 subprocessorToDraw;
107+
SortedSet<uint32> allSubprocessors;
103108
std::map<uint32, int> numChannelsInSubprocessor;
104109
std::map<uint32, float> subprocessorSampleRate;
105110

0 commit comments

Comments
 (0)