File tree Expand file tree Collapse file tree
Source/Processors/GenericProcessor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -729,10 +729,15 @@ int GenericProcessor::checkForEvents(bool checkForSpikes)
729729{
730730 if (m_currentMidiBuffer->getNumEvents () > 0 )
731731 {
732+ // Since adding events to the buffer inside this loop could be dangerous, create a temporal event buffer
733+ // so any call to addEvent will operate on it;
734+ MidiBuffer temporalEventBuffer;
735+ MidiBuffer* originalEventBuffer = m_currentMidiBuffer;
736+ m_currentMidiBuffer = &temporalEventBuffer;
732737 // int m = midiMessages.getNumEvents();
733738 // std::cout << m << " events received by node " << getNodeId() << std::endl;
734739
735- MidiBuffer::Iterator i (*m_currentMidiBuffer );
740+ MidiBuffer::Iterator i (*originalEventBuffer );
736741 MidiMessage message (0xf4 );
737742
738743 int samplePosition = 0 ;
@@ -760,6 +765,11 @@ int GenericProcessor::checkForEvents(bool checkForSpikes)
760765 handleSpike (spikeChannelArray[index], message, samplePosition);
761766 }
762767 }
768+ // Restore the original buffer pointer and, if some new event has been added here, copy it to the original buffer
769+ m_currentMidiBuffer = originalEventBuffer;
770+ if (temporalEventBuffer.getNumEvents () > 0 )
771+ m_currentMidiBuffer->addEvents (temporalEventBuffer, 0 , -1 , 0 );
772+
763773 return 0 ;
764774 }
765775
You can’t perform that action at this time.
0 commit comments