@@ -36,8 +36,6 @@ LfpDisplayNode::LfpDisplayNode()
3636{
3737 setProcessorType (PROCESSOR_TYPE_SINK);
3838
39- displayBuffer.reset (new AudioSampleBuffer (8 , 100 ));
40-
4139 const int heapSize = 5000 ;
4240 arrayOfOnes = new float [heapSize];
4341 for (int n = 0 ; n < heapSize; ++n)
@@ -196,27 +194,6 @@ bool LfpDisplayNode::resizeBuffer()
196194{
197195 LfpDisplayEditor * ed = (LfpDisplayEditor*)getEditor ();
198196 allSubprocessors = ed->getInputSubprocessors ();
199-
200- /* int nSamples = (int)getSubprocessorSampleRate(subprocessorToDraw) * bufferLength;
201- int nInputs = getNumSubprocessorChannels();
202-
203- //std::cout << "Resizing buffer. Samples: " << nSamples << ", Inputs: " << nInputs << std::endl;
204-
205- if (nSamples > 0 && nInputs > 0)
206- {
207- abstractFifo.setTotalSize(nSamples);
208- displayBuffer->setSize(nInputs + 1, nSamples); // add extra channel for TTLs
209- displayBuffer->clear();
210-
211- displayBufferIndex.clear();
212- displayBufferIndex.insertMultiple(0, 0, nInputs + 1);
213-
214- //return true;
215- }*/
216- // else
217- // {
218- // return false;
219- // }
220197
221198 int totalResized = 0 ;
222199
@@ -229,7 +206,7 @@ bool LfpDisplayNode::resizeBuffer()
229206
230207 if (nSamples > 0 && nInputs > 0 )
231208 {
232- // abstractFifo.setTotalSize(nSamples);
209+ abstractFifo.setTotalSize (nSamples);
233210 displayBuffers[cs]->setSize (nInputs + 1 , nSamples); // add extra channel for TTLs
234211 displayBuffers[cs]->clear ();
235212
@@ -247,10 +224,9 @@ bool LfpDisplayNode::resizeBuffer()
247224 {
248225 return true ;
249226 }
250- else
251- {
252- return false ;
253- }
227+
228+ return false ;
229+
254230}
255231
256232
@@ -327,37 +303,36 @@ void LfpDisplayNode::handleEvent(const EventChannel* eventInfo, const MidiMessag
327303 ttlState[eventSourceNodeId] &= ~(1LL << eventChannel);
328304 }
329305
330- if (eventSourceNodeId == subprocessorToDraw)
306+ int subProcIndex = allSubprocessors.indexOf (eventSourceNodeId);
307+
308+ const int chan = numChannelsInSubprocessor[eventSourceNodeId];
309+ const int index = (displayBufferIndices[subProcIndex][chan] + eventTime) % displayBuffers[subProcIndex]->getNumSamples ();
310+ const int samplesLeft = displayBuffers[subProcIndex]->getNumSamples () - index;
311+ const int nSamples = getNumSourceSamples (eventSourceNodeId) - eventTime;
312+
313+ if (nSamples < samplesLeft)
314+ {
315+ displayBuffers[subProcIndex]->copyFrom (chan, // destChannel
316+ index, // destStartSample
317+ arrayOfOnes, // source
318+ nSamples, // numSamples
319+ float (ttlState[eventSourceNodeId])); // gain
320+ }
321+ else
331322 {
332- const int chan = numChannelsInSubprocessor[eventSourceNodeId];
333- const int index = (displayBufferIndex[chan] + eventTime) % displayBuffer->getNumSamples ();
334- const int samplesLeft = displayBuffer->getNumSamples () - index;
335- const int nSamples = getNumSourceSamples (eventSourceNodeId) - eventTime;
336-
337- if (nSamples < samplesLeft)
338- {
339- displayBuffer->copyFrom (chan, // destChannel
340- index, // destStartSample
341- arrayOfOnes, // source
342- nSamples, // numSamples
343- float (ttlState[eventSourceNodeId])); // gain
344- }
345- else
346- {
347- int extraSamples = nSamples - samplesLeft;
348-
349- displayBuffer->copyFrom (chan, // destChannel
350- index, // destStartSample
351- arrayOfOnes, // source
352- samplesLeft, // numSamples
353- float (ttlState[eventSourceNodeId])); // gain
354-
355- displayBuffer->copyFrom (chan, // destChannel
356- 0 , // destStartSample
357- arrayOfOnes, // source
358- extraSamples, // numSamples
359- float (ttlState[eventSourceNodeId])); // gain
360- }
323+ int extraSamples = nSamples - samplesLeft;
324+
325+ displayBuffers[subProcIndex]->copyFrom (chan, // destChannel
326+ index, // destStartSample
327+ arrayOfOnes, // source
328+ samplesLeft, // numSamples
329+ float (ttlState[eventSourceNodeId])); // gain
330+
331+ displayBuffers[subProcIndex]->copyFrom (chan, // destChannel
332+ 0 , // destStartSample
333+ arrayOfOnes, // source
334+ extraSamples, // numSamples
335+ float (ttlState[eventSourceNodeId])); // gain
361336 }
362337
363338 // std::cout << "Received event from " << eventSourceNodeId
@@ -371,61 +346,62 @@ void LfpDisplayNode::handleEvent(const EventChannel* eventInfo, const MidiMessag
371346void LfpDisplayNode::initializeEventChannels ()
372347{
373348
374- // std::cout << "Initializing events..." << std::endl;
375-
376- const int chan = numChannelsInSubprocessor[subprocessorToDraw];
377- const int index = displayBufferIndex[chan];
378- const int samplesLeft = displayBuffer->getNumSamples () - index;
379- const int nSamples = getNumSourceSamples (subprocessorToDraw);
380-
381- // std::cout << chan << " " << index << " " << samplesLeft << " " << nSamples << std::endl;
382-
383- if (nSamples < samplesLeft)
384- {
349+ // std::cout << "Initializing events..." << std::endl
350+
351+ for (int i = 0 ; i < numSubprocessors ; i++)
352+ {
353+ const int chan = numChannelsInSubprocessor[allSubprocessors[i]];
354+ const int nSamples = getNumSourceSamples (allSubprocessors[i]);
355+ const int samplesLeft = displayBuffers[i]->getNumSamples () - displayBufferIndices[i][chan];
356+
357+ if (nSamples < samplesLeft)
358+ {
385359
386- displayBuffer->copyFrom (chan, // destChannel
387- index, // destStartSample
388- arrayOfOnes, // source
389- nSamples, // numSamples
390- float (ttlState[subprocessorToDraw])); // gain
391- }
392- else
393- {
394- int extraSamples = nSamples - samplesLeft;
395-
396- displayBuffer->copyFrom (chan, // destChannel
397- index, // destStartSample
398- arrayOfOnes, // source
399- samplesLeft, // numSamples
400- float (ttlState[subprocessorToDraw])); // gain
401-
402- displayBuffer->copyFrom (chan, // destChannel
403- 0 , // destStartSample
404- arrayOfOnes, // source
405- extraSamples, // numSamples
406- float (ttlState[subprocessorToDraw])); // gain
407- }
360+ displayBuffers[i]->copyFrom (chan, // destChannel
361+ displayBufferIndices[i][chan], // destStartSample
362+ arrayOfOnes, // source
363+ nSamples, // numSamples
364+ float (ttlState[subprocessorToDraw])); // gain
365+ }
366+ else
367+ {
368+ int extraSamples = nSamples - samplesLeft;
369+
370+ displayBuffers[i]->copyFrom (chan, // destChannel
371+ displayBufferIndices[i][chan], // destStartSample
372+ arrayOfOnes, // source
373+ samplesLeft, // numSamples
374+ float (ttlState[subprocessorToDraw])); // gain
375+
376+ displayBuffers[i]->copyFrom (chan, // destChannel
377+ 0 , // destStartSample
378+ arrayOfOnes, // source
379+ extraSamples, // numSamples
380+ float (ttlState[subprocessorToDraw])); // gain
381+ }
382+ }
408383}
409384
410385void LfpDisplayNode::finalizeEventChannels ()
411386{
412- const int chan = numChannelsInSubprocessor[subprocessorToDraw];
413- const int index = displayBufferIndex[chan ];
414- const int samplesLeft = displayBuffer ->getNumSamples () - index ;
415- const int nSamples = getNumSourceSamples (subprocessorToDraw );
387+ for ( int i = 0 ; i < numSubprocessors ; i++){
388+ const int chan = numChannelsInSubprocessor[allSubprocessors[i] ];
389+ const int samplesLeft = displayBuffers[i] ->getNumSamples () - displayBufferIndices[i][chan] ;
390+ const int nSamples = getNumSourceSamples (allSubprocessors[i] );
416391
417- int newIdx = 0 ;
392+ int newIdx = 0 ;
418393
419- if (nSamples < samplesLeft)
420- {
421- newIdx = index + nSamples;
422- }
423- else
424- {
425- newIdx = nSamples - samplesLeft;
426- }
394+ if (nSamples < samplesLeft)
395+ {
396+ newIdx = displayBufferIndices[i][chan] + nSamples;
397+ }
398+ else
399+ {
400+ newIdx = nSamples - samplesLeft;
401+ }
427402
428- displayBufferIndex.set (chan, newIdx);
403+ displayBufferIndices[i].insert (displayBufferIndices[i].begin () + chan, newIdx);
404+ }
429405}
430406
431407
@@ -438,7 +414,7 @@ void LfpDisplayNode::process (AudioSampleBuffer& buffer)
438414 {
439415 ScopedLock displayLock (displayMutex);
440416
441- if (false )
417+ if (true )
442418 {
443419 initializeEventChannels ();
444420 checkForEvents (); // see if we got any TTL events
@@ -454,45 +430,6 @@ void LfpDisplayNode::process (AudioSampleBuffer& buffer)
454430
455431 for (int chan = 0 ; chan < buffer.getNumChannels (); ++chan)
456432 {
457- /* if (getDataSubprocId(chan) == subprocessorToDraw)
458- {
459- channelIndex++;
460- const int samplesLeft = displayBuffer->getNumSamples() - displayBufferIndex[channelIndex];
461- const int nSamples = getNumSamples(chan);
462-
463- if (nSamples < samplesLeft)
464- {
465- displayBuffer->copyFrom(channelIndex, // destChannel
466- displayBufferIndex[channelIndex], // destStartSample
467- buffer, // source
468- chan, // source channel
469- 0, // source start sample
470- nSamples); // numSamples
471-
472- displayBufferIndex.set(channelIndex, displayBufferIndex[channelIndex] + nSamples);
473- }
474- else
475- {
476- const int extraSamples = nSamples - samplesLeft;
477-
478- displayBuffer->copyFrom(channelIndex, // destChannel
479- displayBufferIndex[channelIndex], // destStartSample
480- buffer, // source
481- chan, // source channel
482- 0, // source start sample
483- samplesLeft); // numSamples
484-
485- displayBuffer->copyFrom(channelIndex, // destChannel
486- 0, // destStartSample
487- buffer, // source
488- chan, // source channel
489- samplesLeft, // source start sample
490- extraSamples); // numSamples
491-
492- displayBufferIndex.set(channelIndex, extraSamples);
493- }
494- }*/
495-
496433 subProcId = getDataSubprocId (chan);
497434 cs = allSubprocessors.indexOf (subProcId);
498435
0 commit comments